aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/test')
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java65
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java9
-rw-r--r--common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java9
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java2
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java4
-rw-r--r--common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java15
-rw-r--r--common/src/test/resources/__files/aai/query/pathed-result.json12
-rw-r--r--common/src/test/resources/__files/aai/query/single-query-result.json80
8 files changed, 182 insertions, 14 deletions
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java
index 84c3cad0f9..e648ea38da 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java
@@ -20,47 +20,65 @@
package org.onap.so.client.aai;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
-import javax.ws.rs.core.Response;
+import javax.ws.rs.core.GenericType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.Complex;
import org.onap.so.client.RestClient;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.CustomQuery;
+import org.onap.so.client.aai.entities.Results;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.graphinventory.Format;
import org.onap.so.client.graphinventory.GraphInventoryClient;
import org.onap.so.client.graphinventory.GraphInventorySubgraphType;
+import org.onap.so.client.graphinventory.entities.Pathed;
+import org.onap.so.client.graphinventory.entities.ResourceAndUrl;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(MockitoJUnitRunner.class)
public class AAIQueryClientTest {
@Mock
- Response response;
-
- @Mock
- RestClient restClient;
+ private RestClient restClient;
@Mock
- GraphInventoryClient client;
+ private GraphInventoryClient client;
@InjectMocks
- AAIQueryClient aaiQueryClient = new AAIQueryClient();
+ @Spy
+ private AAIQueryClient aaiQueryClient = new AAIQueryClient();
+ private String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/query/";
+
+ private ObjectMapper mapper = new ObjectMapper();
@Test
public void testQuery() {
List<AAIResourceUri> uris = Arrays.asList(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
@@ -91,4 +109,37 @@ public class AAIQueryClientTest {
verify(aaiUri, times(1)).queryParam("nodesOnly", "");
verify(aaiUri, times(1)).queryParam("subgraph", subgraph.toString());
}
+
+ @Test
+ public void querySingleResourceTest() throws IOException {
+ doReturn(getJson("single-query-result.json")).when(aaiQueryClient).query(eq(Format.RESOURCE_AND_URL), any(CustomQuery.class));
+ List<Complex> result = aaiQueryClient.querySingleResource(new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))), Complex.class);
+ assertEquals(2, result.size());
+ assertEquals("complex-id-15100-jc689q2", result.get(1).getPhysicalLocationId());
+ }
+
+ @Test
+ public void getResourceAndUrlTest() throws IOException {
+ doReturn(getJson("single-query-result.json")).when(aaiQueryClient).query(eq(Format.RESOURCE_AND_URL), any(CustomQuery.class));
+ List<ResourceAndUrl<AAIResultWrapper>> result = aaiQueryClient.getResourceAndUrl(new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))));
+ assertEquals(2, result.size());
+
+ assertEquals(1, result.get(1).getWrapper().getRelationships().get().getRelatedUris(AAIObjectType.PSERVER).size());
+ }
+
+ @Test
+ public void querySingleTypeTest() throws IOException {
+ when(client.createClient(isA(AAIUri.class))).thenReturn(restClient);
+ when(restClient.put(any(Object.class), any(GenericType.class))).thenReturn(mapper.readValue(getJson("pathed-result.json"), new TypeReference<Results<Map<String, Object>>>(){}));
+
+
+ List<Pathed> results = aaiQueryClient.queryPathed(new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(AAIObjectType.COMPLEX, "test"))));
+
+ assertEquals(2, results.size());
+ assertEquals("service-instance", results.get(1).getResourceType());
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
index 73fbff6e4f..174c76b1ef 100644
--- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
@@ -33,9 +33,9 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
import javax.ws.rs.BadRequestException;
+
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -50,7 +50,6 @@ import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
-import org.onap.so.client.graphinventory.GraphInventoryClient;
import com.github.tomakehurst.wiremock.admin.NotFoundException;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -60,7 +59,7 @@ public class AAIResourcesClientTest {
@Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443));
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -72,9 +71,11 @@ public class AAIResourcesClientTest {
@InjectMocks
public AAIResourcesClient aaiClient = new AAIResourcesClient();
+ private String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/query/";
+
@Before
public void beforeTest() {
- doReturn(new DefaultAAIPropertiesImpl()).when(client).getRestProperties();
+ doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
}
@Test
diff --git a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
index 69d46de96a..a156e3c158 100644
--- a/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
@@ -80,4 +80,13 @@ public class DSLQueryBuilderTest {
assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build());
}
+
+ @Test
+ public void shortCutToTest() {
+ DSLQueryBuilder<DSLNode, DSLNode> builder = new DSLQueryBuilder<>(new DSLNode(AAIObjectType.PSERVER,
+ __.key("hostname", "my-hostname")).output());
+
+ builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
+ assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')", builder.build());
+ }
}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java b/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java
index 1ce6e4377c..8d11f69308 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java
@@ -44,7 +44,7 @@ public class RelationshipsTest {
AAIResultWrapper wrapper = new AAIResultWrapper(content);
Relationships relationships = wrapper.getRelationships().get();
- List<AAIResourceUri> test = relationships.getRelatedAAIUris(AAIObjectType.VCE);
+ List<AAIResourceUri> test = relationships.getRelatedUris(AAIObjectType.VCE);
System.out.println(test.get(0).build());
List<AAIResourceUri> uris = Arrays.asList(
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
index 15c1c24ae2..979ca39489 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
@@ -69,7 +69,7 @@ public class ServiceInstanceUriTest {
private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
@Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443));
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
@Rule
public final ExpectedException exception = ExpectedException.none();
@@ -82,7 +82,7 @@ public class ServiceInstanceUriTest {
@Before
public void beforeTest() {
- doReturn(new DefaultAAIPropertiesImpl()).when(client).getRestProperties();
+ doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
}
@Test
public void found() throws IOException {
diff --git a/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java b/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java
index 77e1dfee7d..65c76561dc 100644
--- a/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java
+++ b/common/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java
@@ -50,6 +50,21 @@ public class DefaultAAIPropertiesImpl implements AAIProperties {
this.props = temp;
}
+
+ public DefaultAAIPropertiesImpl(int port) {
+ File initialFile = new File("src/test/resources/aai.properties");
+ Map<Object, Object> temp;
+ try (InputStream targetStream = new FileInputStream(initialFile)) {
+ Properties properties = new Properties();
+ properties.load(targetStream);
+ temp = properties;
+ } catch (IOException e) {
+ temp = new HashMap<>();
+ }
+ this.props = temp;
+ this.props.put("aai.endpoint", this.props.get("aai.endpoint").toString().replaceFirst(":\\d+", ":" + port));
+
+ }
@Override
public URL getEndpoint() throws MalformedURLException {
return new URL(props.get("aai.endpoint").toString());
diff --git a/common/src/test/resources/__files/aai/query/pathed-result.json b/common/src/test/resources/__files/aai/query/pathed-result.json
new file mode 100644
index 0000000000..e9a3e65c73
--- /dev/null
+++ b/common/src/test/resources/__files/aai/query/pathed-result.json
@@ -0,0 +1,12 @@
+{
+ "results": [
+ {
+ "resource-type": "service-instance",
+ "resource-link": "https://localhost:8443/aai/v9/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"
+ },
+ {
+ "resource-type": "service-instance",
+ "resource-link": "https://localhost:8443/aai/v9/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"
+ }
+ ]
+} \ No newline at end of file
diff --git a/common/src/test/resources/__files/aai/query/single-query-result.json b/common/src/test/resources/__files/aai/query/single-query-result.json
new file mode 100644
index 0000000000..eb12deae80
--- /dev/null
+++ b/common/src/test/resources/__files/aai/query/single-query-result.json
@@ -0,0 +1,80 @@
+{
+ "results": [
+ {
+ "url": "/aai/v14/cloud-infrastructure/complexes/complex/complex-id-15100-jc689q",
+ "complex": {
+ "physical-location-id": "complex-id-15100-jc689q",
+ "resource-version": "1541786379243",
+ "physical-location-type": "lvXHWJC",
+ "street1": "uAAi5qjc1",
+ "street2": "vkK6XQjc2",
+ "city": "3Ec8JSW0JC",
+ "state": "COczHmeJC",
+ "postal-code": "D4J1",
+ "country": "K0JC1",
+ "region": "JzHqJC1",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "pserver",
+ "relationship-label": "org.onap.relationships.inventory.LocatedIn",
+ "related-link": "/aai/v14/cloud-infrastructure/pservers/pserver/pserver-15100-jc689q",
+ "relationship-data": [
+ {
+ "relationship-key": "pserver.hostname",
+ "relationship-value": "pserver-15100-jc689q"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "pserver.pserver-name2"
+ },
+ {
+ "property-key": "pserver.fqdn"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ },
+ {
+ "url": "/aai/v14/cloud-infrastructure/complexes/complex/complex-id-15100-jc689q2",
+ "complex": {
+ "physical-location-id": "complex-id-15100-jc689q2",
+ "resource-version": "1541786379243",
+ "physical-location-type": "lvXHWJC",
+ "street1": "uAAi5qjc1",
+ "street2": "vkK6XQjc2",
+ "city": "3Ec8JSW0JC",
+ "state": "COczHmeJC",
+ "postal-code": "D4J1",
+ "country": "K0JC1",
+ "region": "JzHqJC1",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "pserver",
+ "relationship-label": "org.onap.relationships.inventory.LocatedIn",
+ "related-link": "/aai/v14/cloud-infrastructure/pservers/pserver/pserver-15100-jc689q",
+ "relationship-data": [
+ {
+ "relationship-key": "pserver.hostname",
+ "relationship-value": "pserver-15100-jc689q"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "pserver.pserver-name2"
+ },
+ {
+ "property-key": "pserver.fqdn"
+ }
+ ]
+ }
+ ]
+ }
+ }
+ }
+ ]
+} \ No newline at end of file