aboutsummaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'aai-traversal/src/test/java/org/onap')
-rw-r--r--aai-traversal/src/test/java/org/onap/aai/PayloadUtil.java9
-rw-r--r--aai-traversal/src/test/java/org/onap/aai/WebClientConfiguration.java50
-rw-r--r--aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java50
-rw-r--r--aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java6
-rw-r--r--aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java59
5 files changed, 160 insertions, 14 deletions
diff --git a/aai-traversal/src/test/java/org/onap/aai/PayloadUtil.java b/aai-traversal/src/test/java/org/onap/aai/PayloadUtil.java
index 5a86d92..75ecb1f 100644
--- a/aai-traversal/src/test/java/org/onap/aai/PayloadUtil.java
+++ b/aai-traversal/src/test/java/org/onap/aai/PayloadUtil.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
@@ -43,7 +44,7 @@ public class PayloadUtil {
String message = String.format("Unable to find the %s in src/test/resources", fileName);
assertNotNull(message, inputStream);
- String resource = IOUtils.toString(inputStream);
+ String resource = IOUtils.toString(inputStream, Charset.defaultCharset());
inputStream.close();
return resource;
@@ -57,7 +58,7 @@ public class PayloadUtil {
String message = String.format("Unable to find the %s in src/test/resources", fileName);
assertNotNull(message, inputStream);
- String resource = IOUtils.toString(inputStream);
+ String resource = IOUtils.toString(inputStream, Charset.defaultCharset());
inputStream.close();
return resource;
@@ -77,7 +78,7 @@ public class PayloadUtil {
if (cache.containsKey(fileName)) {
resource = cache.get(fileName);
} else {
- resource = IOUtils.toString(inputStream);
+ resource = IOUtils.toString(inputStream, Charset.defaultCharset());
cache.put(fileName, resource);
}
@@ -112,7 +113,7 @@ public class PayloadUtil {
.format("Unable to find the %s in src/test/resources/payloads/named-queries", fileName);
assertNotNull(message, inputStream);
- String resource = IOUtils.toString(inputStream);
+ String resource = IOUtils.toString(inputStream, Charset.defaultCharset());
inputStream.close();
return resource;
diff --git a/aai-traversal/src/test/java/org/onap/aai/WebClientConfiguration.java b/aai-traversal/src/test/java/org/onap/aai/WebClientConfiguration.java
new file mode 100644
index 0000000..73239c6
--- /dev/null
+++ b/aai-traversal/src/test/java/org/onap/aai/WebClientConfiguration.java
@@ -0,0 +1,50 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai;
+
+import java.time.Duration;
+import java.util.Collections;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.reactive.server.WebTestClient;
+
+@TestConfiguration
+public class WebClientConfiguration {
+
+ @Lazy
+ @Bean
+ WebTestClient webTestClient(@LocalServerPort int port) {
+ return WebTestClient.bindToServer()
+ .baseUrl("http://localhost:" + port)
+ .responseTimeout(Duration.ofSeconds(300))
+ .defaultHeaders(headers -> {
+ headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
+ headers.set("Real-Time", "true");
+ headers.set("X-FromAppId", "JUNIT");
+ headers.set("X-TransactionId", "JUNIT");
+ headers.setBasicAuth("AAI", "AAI");
+ })
+ .build();
+ }
+}
diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java
index a4fb0a7..ed4a6e6 100644
--- a/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java
+++ b/aai-traversal/src/test/java/org/onap/aai/rest/DslConsumerTest.java
@@ -29,11 +29,9 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
@@ -42,6 +40,7 @@ import org.janusgraph.core.JanusGraphTransaction;
import org.junit.Assert;
import org.junit.Test;
import org.onap.aai.PayloadUtil;
+import org.onap.aai.WebClientConfiguration;
import org.onap.aai.dbmap.AAIGraph;
import org.onap.aai.entities.AAIErrorResponse;
import org.onap.aai.entities.ServiceException;
@@ -49,23 +48,26 @@ import org.onap.aai.util.AAIConfig;
import org.onap.aai.util.TraversalConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Import;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
+import org.springframework.test.web.reactive.server.WebTestClient;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+@Import(WebClientConfiguration.class)
public class DslConsumerTest extends AbstractSpringRestTest {
private static final Logger LOGGER = LoggerFactory.getLogger(DslConsumerTest.class);
- private static final ObjectMapper objectMapper = new ObjectMapper();
+ @Autowired WebTestClient webClient;
@Override
public void createTestGraph() {
@@ -208,6 +210,46 @@ public class DslConsumerTest extends AbstractSpringRestTest {
}
@Test
+ public void thatResultsCanBePaginated() throws Exception {
+ String path = "/aai/v14/dsl";
+ Map<String, String> dslQueryMap = Collections.singletonMap("dsl-query", "pserver*('hostname','test-pserver-dsl')");
+
+ String payload = PayloadUtil.getTemplatePayload("dsl-query.json", dslQueryMap);
+
+ webClient.put()
+ .uri(uriBuilder -> uriBuilder
+ .path(path)
+ .queryParam("format", "console")
+ .build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .bodyValue(payload)
+ .exchange()
+ .expectStatus().isOk();
+
+ String responseEntity = webClient.put()
+ .uri(uriBuilder -> uriBuilder
+ .path(path)
+ .queryParam("format", "console")
+ .queryParam("resultIndex", 0)
+ .queryParam("resultSize", 1)
+ .build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_XML)
+ .bodyValue(payload)
+ .exchange()
+ .expectStatus().isOk()
+ .expectHeader().valueEquals("total-results", 1)
+ .expectHeader().valueEquals("total-pages", 1)
+ .returnResult(String.class)
+ .getResponseBody()
+ .blockFirst();
+
+ assertThat(responseEntity,
+ is(not(containsString("<result><result>"))));
+ assertThat(responseEntity, is(containsString("<results><result>")));
+ }
+
+ @Test
public void thatWildcardContentTypeCanBeUsed() throws Exception {
String endpoint = "/aai/v14/dsl?format=console";
diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java
index f305e14..f43c91f 100644
--- a/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java
+++ b/aai-traversal/src/test/java/org/onap/aai/rest/GfpVserverDataStoredQueryTest.java
@@ -182,7 +182,7 @@ public class GfpVserverDataStoredQueryTest extends AAISetup {
.thenReturn(new StringBuffer("https://localhost:8446" + query));
Response response = queryConsumer.executeQuery(payload, version.toString(),
- "resource_and_url", "" + "no_op", httpHeaders, mockRequest, uriInfo, "-1", "-1");
+ "resource_and_url", "" + "no_op", -1, -1, httpHeaders, mockRequest, uriInfo);
String entity = response.getEntity().toString();
assertEquals("Expected the response to be 200 but got this returned: "
@@ -214,7 +214,7 @@ public class GfpVserverDataStoredQueryTest extends AAISetup {
.thenReturn(new StringBuffer("https://localhost:8446" + query));
Response response = queryConsumer.executeQuery(payload, version.toString(),
- "resource_and_url", "" + "no_op", httpHeaders, mockRequest, uriInfo, "-1", "-1");
+ "resource_and_url", "" + "no_op", -1, -1, httpHeaders, mockRequest, uriInfo);
String entity = response.getEntity().toString();
@@ -247,7 +247,7 @@ public class GfpVserverDataStoredQueryTest extends AAISetup {
.thenReturn(new StringBuffer("https://localhost:8446" + query));
Response response = queryConsumer.executeQuery(payload, version.toString(),
- "resource_and_url", "" + "no_op", httpHeaders, mockRequest, uriInfo, "-1", "-1");
+ "resource_and_url", "" + "no_op", -1, -1, httpHeaders, mockRequest, uriInfo);
String entity = response.getEntity().toString();
diff --git a/aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java b/aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java
index cfb81d4..a6da4fc 100644
--- a/aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java
+++ b/aai-traversal/src/test/java/org/onap/aai/rest/QueryConsumerTest.java
@@ -42,6 +42,7 @@ import org.onap.aai.HttpTestUtil;
import org.onap.aai.PayloadUtil;
import org.onap.aai.TraversalApp;
import org.onap.aai.TraversalTestConfiguration;
+import org.onap.aai.WebClientConfiguration;
import org.onap.aai.config.PropertyPasswordConfiguration;
import org.onap.aai.dbmap.AAIGraph;
import org.onap.aai.exceptions.AAIException;
@@ -55,6 +56,7 @@ import org.springframework.http.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.client.RestTemplate;
@RunWith(SpringRunner.class)
@@ -63,7 +65,7 @@ import org.springframework.web.client.RestTemplate;
classes = TraversalApp.class)
@TestPropertySource(locations = "classpath:application-test.properties")
@ContextConfiguration(initializers = PropertyPasswordConfiguration.class)
-@Import(TraversalTestConfiguration.class)
+@Import({TraversalTestConfiguration.class, WebClientConfiguration.class})
public class QueryConsumerTest {
private static final Logger LOGGER = LoggerFactory.getLogger(QueryConsumerTest.class);
@@ -71,6 +73,8 @@ public class QueryConsumerTest {
private String pserverUri;
+ @Autowired WebTestClient webTestClient;
+
@Autowired
RestTemplate restTemplate;
@@ -124,7 +128,7 @@ public class QueryConsumerTest {
Response response = httpTestUtil.doPut(complexUri, complexPayload);
}
- // @Test
+ @Test
public void testRequiredAGood() throws Exception {
String endpoint = "/aai/v14/query?format=pathed";
Map<String, String> cloudRegionMap = new HashMap<>();
@@ -152,7 +156,7 @@ public class QueryConsumerTest {
String payload = PayloadUtil.getTemplatePayload("custom-query.json", customQueryMap);
httpEntity = new HttpEntity(payload, headers);
- ResponseEntity responseEntity =
+ ResponseEntity<String> responseEntity =
restTemplate.exchange(baseUrl + endpoint, HttpMethod.PUT, httpEntity, String.class);
LOGGER.info("Response of custom query : {}", responseEntity.getBody().toString());
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
@@ -162,6 +166,55 @@ public class QueryConsumerTest {
}
@Test
+ public void thatPaginatedResponseCanBeRetrieved() throws Exception {
+ Map<String, String> cloudRegionMap = new HashMap<>();
+ cloudRegionMap.put("cloud-owner", "test-owner-id1111");
+ cloudRegionMap.put("cloud-region-id", "test-region-id1111");
+ cloudRegionMap.put("tenant-id", "test-tenant-id1111");
+ cloudRegionMap.put("tenant-name", "test-tenant-name-id1111");
+ cloudRegionMap.put("vserver-id", "some-vserver-id-id1111");
+ cloudRegionMap.put("vserver-name", "test-vserver-name-id1111");
+ cloudRegionMap.put("pserver-uri", pserverUri);
+ cloudRegionUri =
+ "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/test-owner-id1111/test-region-id1111";
+ addCloudRegion(cloudRegionMap, cloudRegionUri);
+
+ Map<String, String> complexMap = new HashMap<>();
+ complexMap.put("physical-location-id", "location-1111");
+ complexMap.put("cloud-region-uri", cloudRegionUri);
+ String complexUri = "/aai/v14/cloud-infrastructure/complexes/complex/location-1111";
+ addComplex(complexMap, complexUri);
+
+ Map<String, String> customQueryMap = new HashMap<>();
+ customQueryMap.put("start", "cloud-infrastructure/cloud-regions");
+ customQueryMap.put("query", "cloud-region-sites?owner=test-owner-id1111");
+
+ String payload = PayloadUtil.getTemplatePayload("custom-query.json", customQueryMap);
+ String path = "/aai/v14/query";
+
+ String response = webTestClient.put()
+ .uri(uriBuilder -> uriBuilder
+ .path(path)
+ .queryParam("format", "pathed")
+ .queryParam("resultIndex", 0)
+ .queryParam("resultSize", 1)
+ .build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .bodyValue(payload)
+ .exchange()
+ .expectStatus().isOk()
+ .expectHeader().valueEquals("total-results", 2)
+ .expectHeader().valueEquals("total-pages", 2)
+ .returnResult(String.class)
+ .getResponseBody()
+ .blockFirst();
+
+ String expectedResponse = "{\"results\":[{\"resource-type\":\"cloud-region\",\"resource-link\":\"/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/test-owner-id1111/test-region-id1111\"}]}";
+ assertEquals(expectedResponse, response);
+
+ }
+
+ @Test
public void testRequiredBad() throws Exception {
String endpoint = "/aai/v14/query?format=pathed";
Map<String, String> cloudRegionMap = new HashMap<>();