aboutsummaryrefslogtreecommitdiffstats
path: root/graph-inventory/aai-client/src/test/java/org
diff options
context:
space:
mode:
authorBenjamin, Max <max.benjamin@att.com>2020-04-28 15:13:12 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-04-28 15:26:09 -0400
commit4f774eeef8c1797c7073754412535be47ea1a8d7 (patch)
tree567fd081f18e7dbbfc068f326d748cf0dc5844db /graph-inventory/aai-client/src/test/java/org
parentac42fe6ee5e461c3053d40f23cc62882b6a59fe5 (diff)
move aai-client into its own project
move aai-client into its own project Issue-ID: SO-2837 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: I20b700d160efbdf81ff22c9ca0fab73b28d3649b
Diffstat (limited to 'graph-inventory/aai-client/src/test/java/org')
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java68
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java104
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java91
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIPServerTest.java52
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java150
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java308
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java121
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java76
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java140
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java174
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIURITest.java41
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIUpdatorImplTest.java53
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java60
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java113
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java149
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java110
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java56
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java43
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java76
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java133
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java68
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java54
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java69
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java301
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java42
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java95
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java118
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java47
-rw-r--r--graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryPayloadExceptionTest.java40
29 files changed, 2952 insertions, 0 deletions
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java
new file mode 100644
index 0000000000..7af36b0bdd
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIClientResponseExceptionMapperTest.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.junit.Assert.assertEquals;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.so.client.aai.entities.AAIError;
+import org.onap.so.client.aai.entities.RequestError;
+import org.onap.so.client.aai.entities.ServiceException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class AAIClientResponseExceptionMapperTest {
+
+ AAIClientResponseExceptionMapper mapper;
+ String errorMsg;
+
+ @Before
+ public void before() {
+ mapper = new AAIClientResponseExceptionMapper();
+ errorMsg = "Error calling A&AI. Request-Id=" + mapper.getRequestId() + " ";
+ }
+
+ @Test
+ public void testExtractMessageWithEntity() throws JsonProcessingException {
+ ServiceException svcException = new ServiceException();
+ svcException.setText("test %1 message - %2");
+ svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
+
+ RequestError requestError = new RequestError();
+ requestError.setServiceException(svcException);
+
+ AAIError error = new AAIError();
+ error.setRequestError(requestError);
+
+ ObjectMapper objMapper = new ObjectMapper();
+ String strRequestError = objMapper.writeValueAsString(error);
+
+ assertEquals(errorMsg + "test error message - service exception error test",
+ mapper.extractMessage(strRequestError).get());
+ }
+
+ @Test
+ public void testExtractMessageWithoutEntity() {
+ assertEquals(errorMsg, mapper.extractMessage("").get());
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java
new file mode 100644
index 0000000000..3587c71de0
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIErrorFormatterTest.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.so.client.aai.entities.AAIError;
+import org.onap.so.client.aai.entities.RequestError;
+import org.onap.so.client.aai.entities.ServiceException;
+
+public class AAIErrorFormatterTest {
+
+ @Mock
+ private AAIError errorObj;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testFillInTemplateWithReplace() {
+ String error = "Error %1 on %2";
+ List<String> list = Arrays.asList("PUT", "hello %1");
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.fillInTemplate(error, list);
+ assertEquals("equal", "Error PUT on hello PUT", result);
+
+ }
+
+ @Test
+ public void testFillInTemplateWithoutReplace() {
+ String error = "Error";
+ List<String> list = new ArrayList<>();
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.fillInTemplate(error, list);
+ assertEquals("equal", "Error", result);
+ }
+
+ @Test
+ public void testGetMessage() {
+ ServiceException svcException = new ServiceException();
+ svcException.setText("test %1 message - %2");
+ svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
+
+ RequestError requestError = new RequestError();
+ requestError.setServiceException(svcException);
+
+ doReturn(requestError).when(errorObj).getRequestError();
+
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.getMessage();
+ assertEquals("equal", "test error message - service exception error test", result);
+ }
+
+ @Test
+ public void errorMessageOnPercentEncodedTest() {
+ ServiceException svcException = new ServiceException();
+ svcException.setText("test my%20Test %1 message - %2");
+ svcException.setVariables(Arrays.asList("error", "service exception %1 test"));
+
+ RequestError requestError = new RequestError();
+ requestError.setServiceException(svcException);
+
+ doReturn(requestError).when(errorObj).getRequestError();
+
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.getMessage();
+ assertEquals("equal", "test my%20Test error message - service exception error test", result);
+ }
+
+ @Test
+ public void testGetMessageNoParsable() {
+ errorObj.setRequestError(null);
+ AAIErrorFormatter formatter = new AAIErrorFormatter(errorObj);
+ String result = formatter.getMessage();
+ assertEquals("equal", "no parsable error message found", result);
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java
new file mode 100644
index 0000000000..20a6678386
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+
+public class AAIObjectTypeTest {
+
+
+ @Test
+ public void fromTypeNameTest() throws IllegalArgumentException, IllegalAccessException, InstantiationException {
+ AAIObjectType type = AAIObjectType.fromTypeName("allotted-resource");
+ assertEquals("allotted-resource", type.typeName());
+
+ }
+
+ @Test
+ public void customTypeTest() throws IllegalArgumentException, IllegalAccessException, InstantiationException {
+ AAIObjectType type = AAIObjectType.fromTypeName("my-custom-name");
+ assertEquals("my-custom-name", type.typeName());
+
+ }
+
+ @Test
+ public void verifyDefaultCase() {
+ assertEquals("default removed for tenant", "tenant", AAIObjectType.DEFAULT_TENANT.typeName());
+ assertEquals("default removed for cloud-region", "cloud-region", AAIObjectType.DEFAULT_CLOUD_REGION.typeName());
+ }
+
+ @Test
+ public void verifyRegularCase() {
+ assertEquals("default removed for tenant", "allotted-resource", AAIObjectType.ALLOTTED_RESOURCE.typeName());
+ }
+
+ @Test
+ public void instanceGroupObjectTypeTest() {
+ final String id = "test1";
+ AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, id);
+ assertEquals("/network/instance-groups/instance-group/test1", aaiUri.build().toString());
+ }
+
+ @Test
+ public void collectionObjectTypeTest() {
+ final String id = "test1";
+ AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, id);
+ assertEquals("/network/collections/collection/test1", aaiUri.build().toString());
+ }
+
+ @Test
+ public void genericVnfTest() {
+ AAIObjectType type = AAIObjectType.GENERIC_VNF;
+ assertEquals("/network/generic-vnfs/generic-vnf/{vnf-id}", type.uriTemplate());
+ assertEquals("/generic-vnfs/generic-vnf/{vnf-id}", type.partialUri());
+ }
+
+ @Test
+ public void pInterfaceTest() {
+ AAIObjectType type = AAIObjectType.P_INTERFACE;
+ assertEquals("/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces/p-interface/{interface-name}",
+ type.uriTemplate());
+ assertEquals("/p-interfaces/p-interface/{interface-name}", type.partialUri());
+ }
+
+ @Test
+ public void networkPolicyObjectTypeTest() {
+ final String id = "test1";
+ AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, id);
+ assertEquals("/network/network-policies/network-policy/test1", aaiUri.build().toString());
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIPServerTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIPServerTest.java
new file mode 100644
index 0000000000..4b3b7e9881
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIPServerTest.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.junit.Assert.assertEquals;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.onap.aai.domain.yang.Pserver;
+
+public class AAIPServerTest {
+
+ @Test
+ public void pserverTest() throws IOException {
+ AAIRestClientImpl client = new AAIRestClientImpl();
+ String json = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/aai/pserver.json")));
+ List<Pserver> list = client.getListOfPservers(json);
+
+ assertEquals("", list.get(0).getHostname(), "test");
+ assertEquals("", list.size(), 2);
+ }
+
+ @Test
+ @Ignore // IGNORED FOR 1710 MERGE TO ONAP
+ public void pserverActualTest() throws IOException {
+ AAIRestClientImpl client = new AAIRestClientImpl();
+ List<Pserver> list = client.getPhysicalServerByVnfId("d946afed-8ebe-4c5d-9665-54fcc043b8e7");
+ assertEquals("", list.size(), 0);
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java
new file mode 100644
index 0000000000..c70f16eb83
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java
@@ -0,0 +1,150 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.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.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.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
+ private RestClient restClient;
+
+ @Mock
+ private GraphInventoryClient client;
+
+ @InjectMocks
+ @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));
+
+ Format format = Format.SIMPLE;
+ CustomQuery query = new CustomQuery(uris);
+
+ doReturn(restClient).when(client).createClient(isA(AAIResourceUri.class));
+ aaiQueryClient.query(format, query);
+ verify(client, times(1))
+ .createClient(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).format(format));
+ verify(restClient, times(1)).put(query, String.class);
+ }
+
+ @Test
+ public void testCreateClient() {
+ String depth = "testDepth";
+ GraphInventorySubgraphType subgraph = GraphInventorySubgraphType.STAR;
+
+ aaiQueryClient.depth(depth);
+ aaiQueryClient.nodesOnly();
+ aaiQueryClient.subgraph(subgraph);
+
+ AAIResourceUri aaiUri = spy(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY));
+ doReturn(aaiUri).when(aaiUri).clone();
+ aaiQueryClient.setupQueryParams(aaiUri);
+
+ verify(aaiUri, times(1)).queryParam("depth", depth);
+ 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(AAIResourceUri.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/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
new file mode 100644
index 0000000000..a7fd6e904e
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java
@@ -0,0 +1,308 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.delete;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.put;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import java.util.Optional;
+import javax.ws.rs.BadRequestException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.so.client.RestClient;
+import org.onap.so.client.aai.entities.AAIEdgeLabel;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.uri.AAIPluralResourceUri;
+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.exceptions.GraphInventoryMultipleItemsException;
+import com.github.tomakehurst.wiremock.admin.NotFoundException;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAIResourcesClientTest {
+
+
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+
+ @Spy
+ public AAIClient client;
+
+ @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(wireMockRule.port())).when(client).getRestProperties();
+ }
+
+ @Test
+ public void verifyNotExists() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404)));
+ AAIResourcesClient client = aaiClient;
+ boolean result = client.exists(path);
+ assertEquals("path not found", false, result);
+ }
+
+ @Test
+ public void verifyDelete() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("aai/resources/mockObject.json").withStatus(200)));
+ wireMockRule.stubFor(delete(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .withQueryParam("resource-version", equalTo("1234")).willReturn(aResponse().withStatus(204)));
+ AAIResourcesClient client = aaiClient;
+ client.delete(path);
+ }
+
+ @Test
+ public void verifyBasicAuth() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString()))
+ .withHeader("Authorization", equalTo("Basic dGVzdDp0ZXN0"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBodyFile("aai/resources/mockObject.json").withStatus(200)));
+ AAIResourcesClient client = aaiClient;
+ client.get(path);
+ }
+
+ @Test
+ public void verifyConnect() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
+ AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
+ wireMockRule.stubFor(
+ put(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship"))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(200)));
+
+ AAIResourceUri pathClone = path.clone();
+ AAIResourcesClient client = aaiClient;
+ client.connect(path, path2);
+ assertEquals("uri not modified", pathClone.build().toString(), path.build().toString());
+ }
+
+ @Test
+ public void verifyDisconnect() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
+ AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
+
+ wireMockRule.stubFor(
+ delete(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build() + "/relationship-list/relationship"))
+ .willReturn(aResponse().withStatus(204)));
+
+ AAIResourceUri pathClone = path.clone();
+ AAIResourcesClient client = aaiClient;
+ client.disconnect(path, path2);
+ assertEquals("uri not modified", pathClone.build().toString(), path.build().toString());
+ }
+
+ @Test
+ public void verifyPatch() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2");
+
+ wireMockRule.stubFor(post(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withStatus(200)));
+
+ AAIResourcesClient client = aaiClient;
+
+ client.update(path, "{}");
+ }
+
+ @Test
+ public void verifyNotExistsGet() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404)));
+ AAIResourcesClient client = aaiClient;
+ AAIResultWrapper result = client.get(path);
+ assertEquals("is empty", true, result.isEmpty());
+ }
+
+ @Test
+ public void verifyNotExistsGetException() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build()))
+ .willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("hello").withStatus(404)));
+ AAIResourcesClient client = aaiClient;
+ thrown.expect(NotFoundException.class);
+ thrown.expectMessage(containsString(path.build() + " not found in A&AI"));
+ AAIResultWrapper result = client.get(path, NotFoundException.class);
+ }
+
+ @Test
+ public void verifyFailedCallException() {
+ AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ wireMockRule.stubFor(get(urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build())).willReturn(aResponse()
+ .withHeader("Content-Type", "text/plain").withBodyFile("aai/error-message.json").withStatus(400)));
+ AAIResourcesClient client = aaiClient;
+
+ thrown.expect(BadRequestException.class);
+ thrown.expectMessage(containsString(
+ "Invalid input performing PUT on url (msg=Precondition Required:resource-version not passed for update of url"));
+ AAIResultWrapper result = client.get(path);
+ }
+
+ @Test
+ public void buildRelationshipTest() {
+ AAIResourcesClient client = aaiClient;
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test");
+ Relationship relationship = new Relationship();
+ relationship.setRelatedLink(uri.build().toString());
+ Relationship actual = client.buildRelationship(uri);
+ assertThat("expect equal no label", actual, sameBeanAs(relationship));
+
+ relationship.setRelationshipLabel(AAIEdgeLabel.USES.toString());
+ actual = client.buildRelationship(uri, AAIEdgeLabel.USES);
+ assertThat("expect equal has label", actual, sameBeanAs(relationship));
+
+ }
+
+ @Test
+ public void testGetOne() {
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("my-vnf-id");
+ GenericVnfs vnfs = new GenericVnfs();
+ vnfs.getGenericVnf().add(vnf);
+ AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
+ RestClient restClientMock = mock(RestClient.class);
+ doReturn(restClientMock).when(client).createClient(uri);
+ when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs));
+
+ Optional<GenericVnf> result = aaiClient.getOne(GenericVnfs.class, GenericVnf.class, uri);
+
+ assertEquals("my-vnf-id", result.get().getVnfId());
+ }
+
+ @Test
+ public void testGetOneMultipleResults() {
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("my-vnf-id");
+ GenericVnf vnf2 = new GenericVnf();
+ vnf.setVnfId("my-vnf-id2");
+ GenericVnfs vnfs = new GenericVnfs();
+ vnfs.getGenericVnf().add(vnf);
+ vnfs.getGenericVnf().add(vnf2);
+ AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
+ RestClient restClientMock = mock(RestClient.class);
+ doReturn(restClientMock).when(client).createClient(uri);
+ when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs));
+
+ thrown.expect(GraphInventoryMultipleItemsException.class);
+ aaiClient.getOne(GenericVnfs.class, GenericVnf.class, uri);
+ }
+
+ @Test
+ public void testGetFirstMultipleResults() {
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("my-vnf-id");
+ GenericVnf vnf2 = new GenericVnf();
+ vnf2.setVnfId("my-vnf-id2");
+ GenericVnfs vnfs = new GenericVnfs();
+ vnfs.getGenericVnf().add(vnf);
+ vnfs.getGenericVnf().add(vnf2);
+ AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
+ RestClient restClientMock = mock(RestClient.class);
+ doReturn(restClientMock).when(client).createClient(uri);
+ when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs));
+
+ Optional<GenericVnf> result = aaiClient.getFirst(GenericVnfs.class, GenericVnf.class, uri);
+
+ assertEquals("my-vnf-id", result.get().getVnfId());
+ }
+
+ @Test
+ public void testGetOneNoResults() {
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("my-vnf-id");
+ GenericVnfs vnfs = new GenericVnfs();
+ vnfs.getGenericVnf().add(vnf);
+ AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
+ RestClient restClientMock = mock(RestClient.class);
+ doReturn(restClientMock).when(client).createClient(uri);
+ when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.empty());
+
+ Optional<GenericVnf> result = aaiClient.getOne(GenericVnfs.class, GenericVnf.class, uri);
+
+ assertFalse(result.isPresent());
+ }
+
+ @Test
+ public void testGetFirstNoResults() {
+ GenericVnf vnf = new GenericVnf();
+ vnf.setVnfId("my-vnf-id");
+ GenericVnfs vnfs = new GenericVnfs();
+ vnfs.getGenericVnf().add(vnf);
+ AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
+ RestClient restClientMock = mock(RestClient.class);
+ doReturn(restClientMock).when(client).createClient(uri);
+ when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.empty());
+
+ Optional<GenericVnf> result = aaiClient.getFirst(GenericVnfs.class, GenericVnf.class, uri);
+
+ assertFalse(result.isPresent());
+ }
+
+ @Test
+ public void testGetFirstWrongPluralClass() {
+ GenericVnf vnf = new GenericVnf();
+ AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
+ RestClient restClientMock = mock(RestClient.class);
+ doReturn(restClientMock).when(client).createClient(uri);
+ when(restClientMock.get(GenericVnf.class)).thenReturn(Optional.of(vnf));
+
+ Optional<GenericVnf> result = aaiClient.getFirst(GenericVnf.class, GenericVnf.class, uri);
+
+ assertFalse(result.isPresent());
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
new file mode 100644
index 0000000000..55da6e7d52
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
@@ -0,0 +1,121 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. 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.so.client.aai;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import java.util.List;
+import java.util.Optional;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.aai.entities.uri.ServiceInstanceUri;
+import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAIResourcesClientWithServiceInstanceUriTest {
+
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Spy
+ public AAIClient client;
+
+ @InjectMocks
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ private ServiceInstanceUri uri;
+
+ @Before
+ public void setUp() {
+ doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
+ wireMockRule.stubFor(get(urlMatching("/aai/v[0-9]+/nodes.*")).willReturn(
+ aResponse().withStatus(404).withHeader("Content-Type", "application/json").withHeader("Mock", "true")));
+
+ uri = spy((ServiceInstanceUri) AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "id"));
+ doReturn(aaiClient).when(uri).getResourcesClient();
+ }
+
+ @Test
+ public void getWithClass() {
+ AAIResourcesClient client = aaiClient;
+ Optional<String> result = client.get(String.class, uri);
+
+ assertThat(result.isPresent(), equalTo(false));
+ }
+
+ @Test
+ public void getFullResponse() {
+ AAIResourcesClient client = aaiClient;
+ Response result = client.getFullResponse(uri);
+ assertThat(result.getStatus(), equalTo(Status.NOT_FOUND.getStatusCode()));
+ }
+
+ @Test
+ public void getWithGenericType() {
+ AAIResourcesClient client = aaiClient;
+ Optional<List<String>> result = client.get(new GenericType<List<String>>() {}, uri);
+ assertThat(result.isPresent(), equalTo(false));
+ }
+
+ @Test
+ public void getAAIWrapper() {
+ AAIResourcesClient client = aaiClient;
+ AAIResultWrapper result = client.get(uri);
+ assertThat(result.isEmpty(), equalTo(true));
+ }
+
+ @Test
+ public void getWithException() {
+ AAIResourcesClient client = aaiClient;
+ this.thrown.expect(IllegalArgumentException.class);
+ AAIResultWrapper result = client.get(uri, IllegalArgumentException.class);
+ }
+
+ @Test
+ public void existsTest() {
+ AAIResourcesClient client = aaiClient;
+ doReturn(uri).when(uri).clone();
+ boolean result = client.exists(uri);
+ assertThat(result, equalTo(false));
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java
new file mode 100644
index 0000000000..2f551fecc4
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIRestClientTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.ws.rs.core.Response;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.client.RestClientSSL;
+import org.onap.so.client.graphinventory.GraphInventoryPatchConverter;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAIRestClientTest {
+
+ @Mock
+ private AAIProperties props;
+
+ private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void failPatchOnComplexObject() throws URISyntaxException {
+ AAIRestClient client = new AAIRestClient(props, new URI(""));
+ this.thrown.expect(GraphInventoryPatchDepthExceededException.class);
+ this.thrown.expectMessage(containsString("Object exceeds allowed depth for update action"));
+ client.patch(
+ "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}");
+ }
+
+ @Test
+ public void verifyPatchValidation() throws URISyntaxException {
+ AAIRestClient client = new AAIRestClient(props, new URI(""));
+ AAIRestClient spy = spy(client);
+ GraphInventoryPatchConverter patchValidatorMock = mock(GraphInventoryPatchConverter.class);
+ doReturn(patchValidatorMock).when(spy).getPatchConverter();
+ String payload = "{}";
+ doReturn(Response.ok().build()).when(spy).method(eq("PATCH"), any());
+ spy.patch(payload);
+ verify(patchValidatorMock, times(1)).convertPatchFormat(eq((Object) payload));
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java
new file mode 100644
index 0000000000..b07d893adb
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAISingleTransactionClientTest.java
@@ -0,0 +1,140 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import javax.ws.rs.core.GenericType;
+import org.json.JSONException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.Pserver;
+import org.onap.aai.domain.yang.v9.Complex;
+import org.onap.so.client.aai.entities.singletransaction.SingleTransactionRequest;
+import org.onap.so.client.aai.entities.singletransaction.SingleTransactionResponse;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.graphinventory.GraphInventoryPatchConverter;
+import org.skyscreamer.jsonassert.JSONAssert;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAISingleTransactionClientTest {
+
+ private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/singletransaction/";
+ AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "pserver-hostname");
+ AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex");
+ AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, "my-complex2");
+
+ ObjectMapper mapper;
+
+ public AAIClient client = new AAIClient();
+
+ @Spy
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ @Before
+ public void before() throws JsonParseException, JsonMappingException, IOException {
+ mapper = new AAICommonObjectMapperProvider().getMapper();
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ }
+
+ @Test
+ public void testRequest() throws JSONException, IOException {
+ Pserver pserver = new Pserver();
+ pserver.setHostname("pserver-hostname");
+ pserver.setFqdn("pserver-bulk-process-single-transactions-multiple-actions-1-fqdn");
+ Pserver pserver2 = new Pserver();
+ pserver2.setFqdn("patched-fqdn");
+ Complex complex = new Complex();
+ complex.setCity("my-city");
+ Map<String, Object> map = new HashMap<>();
+ map.put("resource-version", "1234");
+ doReturn(Optional.of(map)).when(aaiClient).get(any(GenericType.class), eq(uriC));
+ AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction().create(uriA, pserver)
+ .update(uriA, pserver2).create(uriB, complex).delete(uriC);
+
+ SingleTransactionRequest actual = singleTransaction.getRequest();
+
+ SingleTransactionRequest expected =
+ mapper.readValue(this.getJson("sample-request.json"), SingleTransactionRequest.class);
+
+ JSONAssert.assertEquals(mapper.writeValueAsString(expected), mapper.writeValueAsString(actual), false);
+ }
+
+ @Test
+ public void testFailure() throws IOException {
+ AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction();
+ SingleTransactionResponse expected =
+ mapper.readValue(this.getJson("sample-response-failure.json"), SingleTransactionResponse.class);
+ Optional<String> errorMessage = singleTransaction.locateErrorMessages(expected);
+
+ assertThat(expected.getOperationResponses().size(), greaterThan(0));
+ assertThat(errorMessage.isPresent(), equalTo(true));
+
+ }
+
+ @Test
+ public void testSuccessResponse() throws IOException {
+ AAISingleTransactionClient singleTransaction = aaiClient.beginSingleTransaction();
+ SingleTransactionResponse expected =
+ mapper.readValue(this.getJson("sample-response.json"), SingleTransactionResponse.class);
+ Optional<String> errorMessage = singleTransaction.locateErrorMessages(expected);
+
+ assertThat(expected.getOperationResponses().size(), greaterThan(0));
+ assertThat(errorMessage.isPresent(), equalTo(false));
+
+ }
+
+ @Test
+ public void confirmPatchFormat() {
+ AAISingleTransactionClient singleTransaction = spy(new AAISingleTransactionClient(aaiClient, client));
+ GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class);
+ doReturn(mock).when(singleTransaction).getPatchConverter();
+ singleTransaction.update(uriA, "{}");
+ verify(mock, times(1)).convertPatchFormat(any());
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java
new file mode 100644
index 0000000000..cbcb60513b
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.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.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import javax.ws.rs.core.GenericType;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.graphinventory.GraphInventoryPatchConverter;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAITransactionalClientTest {
+
+ private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/bulkprocess/";
+ AAIResourceUri uriA = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
+ AAIResourceUri uriB = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test2");
+ AAIResourceUri uriC = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3");
+ AAIResourceUri uriD = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test4");
+ AAIResourceUri uriE = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test5");
+ AAIResourceUri uriF = AAIUriFactory.createResourceUri(AAIObjectType.PSERVER, "test6");
+ AAIResourceUri uriG = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test7");
+
+ ObjectMapper mapper;
+
+ public AAIClient client = new AAIClient();
+
+ @Spy
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ @Before
+ public void before() throws JsonParseException, JsonMappingException, IOException {
+ mapper = new AAICommonObjectMapperProvider().getMapper();
+ mapper.enable(SerializationFeature.INDENT_OUTPUT);
+ }
+
+ @Test
+ public void testCreate() throws IOException {
+ final Relationship body = new Relationship();
+ body.setRelatedLink(uriB.build().toString());
+
+ AAITransactionalClient transactions = aaiClient.beginTransaction().create(uriA.clone().relationshipAPI(), body);
+
+ String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
+ Map<String, Object> actual =
+ mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> expected =
+ mapper.readValue(getJson("test-request-small.json"), new TypeReference<Map<String, Object>>() {});
+
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void testConnect() throws IOException {
+ List<AAIResourceUri> uris = new ArrayList<>();
+ uris.add(uriB);
+
+ Map<String, Object> map = new HashMap<>();
+ map.put("resource-version", "1234");
+ doReturn(Optional.of(map)).when(aaiClient).get(any(GenericType.class), eq(uriG));
+ AAIResourceUri uriAClone = uriA.clone();
+ AAITransactionalClient transactions = aaiClient.beginTransaction().connect(uriA, uris).connect(uriC, uriD)
+ .beginNewTransaction().connect(uriE, uriF).beginNewTransaction().delete(uriG);
+
+ String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
+ Map<String, Object> actual =
+ mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> expected =
+ mapper.readValue(getJson("test-request.json"), new TypeReference<Map<String, Object>>() {});
+
+ assertEquals(actual, expected);
+ assertEquals("uri not manipulated", uriAClone.build().toString(), uriA.build().toString());
+ }
+
+ @Test
+ public void testDisconnect() throws IOException {
+ List<AAIResourceUri> uris = new ArrayList<>();
+ uris.add(uriB);
+
+ AAITransactionalClient transactions = aaiClient.beginTransaction().disconnect(uriA, uris);
+
+ String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
+ Map<String, Object> actual =
+ mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> expected = mapper.readValue(getJson("test-request-small.json").replace("put", "delete"),
+ new TypeReference<Map<String, Object>>() {});
+
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void testUpdate() throws IOException {
+ final Relationship body = new Relationship();
+ body.setRelatedLink(uriB.build().toString());
+
+ AAIResourceUri uriAClone = uriA.clone().relationshipAPI();
+ AAITransactionalClient transactions = aaiClient.beginTransaction().update(uriAClone, body);
+
+ String serializedTransactions = mapper.writeValueAsString(transactions.getTransactions());
+ Map<String, Object> actual =
+ mapper.readValue(serializedTransactions, new TypeReference<Map<String, Object>>() {});
+ Map<String, Object> expected = mapper.readValue(getJson("test-request-small.json").replace("put", "patch"),
+ new TypeReference<Map<String, Object>>() {});
+
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void verifyResponse() throws IOException {
+ AAITransactionalClient transactions = aaiClient.beginTransaction();
+
+ assertEquals("success status", Optional.empty(),
+ transactions.locateErrorMessages(getJson("response-success.json")));
+ assertEquals(transactions.locateErrorMessages(getJson("response-failure.json")).get(),
+ "another error message\nmy great error");
+ }
+
+ @Test
+ public void confirmPatchFormat() {
+ AAITransactionalClient transactionClient = spy(new AAITransactionalClient(aaiClient, client));
+ GraphInventoryPatchConverter mock = mock(GraphInventoryPatchConverter.class);
+ doReturn(mock).when(transactionClient).getPatchConverter();
+ transactionClient.update(uriA, "{}");
+ verify(mock, times(1)).convertPatchFormat(any());
+ }
+
+ private String getJson(String filename) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + filename)));
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIURITest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIURITest.java
new file mode 100644
index 0000000000..8971f91602
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIURITest.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.junit.Assert.assertEquals;
+import javax.ws.rs.core.UriBuilder;
+import org.junit.Test;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+
+public class AAIURITest {
+
+
+
+ @Test
+ public void verifyTemplateReplacement() {
+ final String id = "test1";
+ AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, id);
+ String manualReplace = AAIObjectType.CONFIGURATION.toString().replaceAll("\\{configuration-id\\}", id);
+ assertEquals("uri template replaced", aaiUri.build(), UriBuilder.fromPath(manualReplace).build());
+
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIUpdatorImplTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIUpdatorImplTest.java
new file mode 100644
index 0000000000..fdfe41f12a
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIUpdatorImplTest.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Intellectual Property. 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.so.client.aai;
+
+import org.junit.Test;
+
+public class AAIUpdatorImplTest {
+
+ AAIUpdatorImpl test = new AAIUpdatorImpl();
+
+ protected AAIRestClientI client;
+
+ @Test
+ public void getClientTest() throws Exception {
+ test.getClient();
+ }
+
+ @Test
+ public void setClientTest() throws Exception {
+ test.setClient(client);
+ }
+
+
+ @Test(expected = NullPointerException.class)
+ public void updateVnfToLockedTest() throws Exception {
+ test.updateVnfToLocked("vnfId");
+ }
+
+
+ @Test(expected = NullPointerException.class)
+ public void updateVnfToUnLockedTest() throws Exception {
+ test.updateVnfToUnLocked("vnfId");
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java
new file mode 100644
index 0000000000..d18dbec944
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIUpdatorTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAIUpdatorTest {
+
+ @Mock
+ protected AAIRestClientI client;
+ String vnfName = "testVnf";
+ AAIUpdatorImpl updator;
+
+ @Before
+ public void init() {
+ updator = new AAIUpdatorImpl();
+ updator.setClient(client);
+ }
+
+ @Test
+ public void testUpdateVnfToLocked() throws Exception {
+ doNothing().when(client).updateMaintenceFlagVnfId(isA(String.class), isA(Boolean.class));
+ updator.updateVnfToLocked(vnfName);
+ verify(client, times(1)).updateMaintenceFlagVnfId(vnfName, true);
+ }
+
+ @Test
+ public void testUpdateVnfToUnLocked() throws Exception {
+ doNothing().when(client).updateMaintenceFlagVnfId(isA(String.class), isA(Boolean.class));
+ updator.updateVnfToUnLocked(vnfName);
+ verify(client, times(1)).updateMaintenceFlagVnfId(vnfName, false);
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java
new file mode 100644
index 0000000000..b91d0e705a
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.Pserver;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAIValidatorTest {
+
+ @Mock
+ protected AAIRestClientI client;
+ String vnfName = "testVnf";
+ String uuid = "UUID";
+ AAIValidatorImpl validator;
+
+ @Before
+ public void init() {
+ validator = new AAIValidatorImpl();
+ validator.setClient(client);
+ }
+
+ public List<Pserver> getPserversLocked() {
+ Pserver pserver1 = new Pserver();
+ pserver1.setInMaint(true);
+ Pserver pserver2 = new Pserver();
+ pserver2.setInMaint(false);
+ List<Pserver> pservers = new ArrayList<Pserver>();
+ pservers.add(pserver1);
+ pservers.add(pserver2);
+ return pservers;
+ }
+
+ public List<Pserver> getPserversNotLocked() {
+ Pserver pserver1 = new Pserver();
+ pserver1.setInMaint(false);
+ Pserver pserver2 = new Pserver();
+ pserver2.setInMaint(false);
+ List<Pserver> pservers = new ArrayList<Pserver>();
+ pservers.add(pserver1);
+ pservers.add(pserver2);
+ return pservers;
+ }
+
+ public GenericVnf createGenericVnfs(boolean locked) {
+ GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setInMaint(locked);
+ return genericVnf;
+ }
+
+ @Test
+ public void test_IsPhysicalServerLocked_True() throws IOException {
+ when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversLocked());
+ boolean locked = validator.isPhysicalServerLocked(vnfName);
+ assertEquals(true, locked);
+ }
+
+ @Test
+ public void test_IsPhysicalServerLocked_False() throws IOException {
+ when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversNotLocked());
+ boolean locked = validator.isPhysicalServerLocked(vnfName);
+ assertEquals(false, locked);
+ }
+
+ @Test
+ public void test_IsPhysicalServerLocked_NoServers_False() throws IOException {
+ when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(null);
+ boolean locked = validator.isPhysicalServerLocked(vnfName);
+ assertEquals(false, locked);
+ }
+
+ @Test
+ public void test_IsVNFLocked_False() {
+ when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(false));
+ boolean locked = validator.isVNFLocked(vnfName);
+ assertEquals(false, locked);
+ }
+
+ @Test
+ public void test_IsVNFLocked_True() {
+ when(client.getVnfByName(vnfName)).thenReturn(createGenericVnfs(true));
+ boolean locked = validator.isVNFLocked(vnfName);
+ assertEquals(true, locked);
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
new file mode 100644
index 0000000000..1a1a7d124e
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/DSLQueryBuilderTest.java
@@ -0,0 +1,149 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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.so.client.aai;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.onap.so.client.graphinventory.entities.DSLNodeKey;
+import org.onap.so.client.graphinventory.entities.DSLQueryBuilder;
+import org.onap.so.client.graphinventory.entities.DSLStartNode;
+import org.onap.so.client.graphinventory.entities.Output;
+import org.onap.so.client.graphinventory.entities.Start;
+import org.onap.so.client.graphinventory.entities.TraversalBuilder;
+import org.onap.so.client.graphinventory.entities.__;
+
+public class DSLQueryBuilderTest {
+
+ @Test
+ public void whereTest() {
+ DSLQueryBuilder<Start, Start> builder = TraversalBuilder.fragment(new DSLStartNode(AAIObjectType.CLOUD_REGION,
+ __.key("cloud-owner", "att-nc"), __.key("cloud-region-id", "test")));
+
+ builder.to(__.node(AAIObjectType.VLAN_TAG))
+ .where(__.node(AAIObjectType.OWNING_ENTITY, __.key("owning-entity-name", "name")))
+ .to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", "108")).output());
+
+ assertEquals("cloud-region('cloud-owner', 'att-nc')('cloud-region-id', 'test') > "
+ + "vlan-tag (> owning-entity('owning-entity-name', 'name')) > " + "vlan-tag*('vlan-id-outer', '108')",
+ builder.build().get());
+ }
+
+ @Test
+ public void unionTest() {
+ DSLQueryBuilder<Output, Output> builder = TraversalBuilder
+ .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output());
+
+ builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()),
+ __.node(AAIObjectType.VSERVER)
+ .to(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output())));
+
+ assertEquals(
+ "generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + "vserver > pserver* > complex* ]",
+ builder.build().get());
+ }
+
+ @Test
+ public void whereUnionTest() {
+ DSLQueryBuilder<Output, Output> builder = TraversalBuilder
+ .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output());
+
+ builder.where(__.union(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")),
+ __.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.PSERVER, __.key("hostname", "hostname1")))));
+
+ assertEquals("generic-vnf*('vnf-id', 'vnfId') (> [ pserver('hostname', 'hostname1'), "
+ + "vserver > pserver('hostname', 'hostname1') ])", builder.build().get());
+ }
+
+ @Test
+ public void notNullTest() {
+ DSLQueryBuilder<Output, Output> builder = TraversalBuilder.traversal(
+ new DSLStartNode(AAIObjectType.CLOUD_REGION, __.key("cloud-owner", "", "null").not()).output());
+
+ assertEquals("cloud-region* !('cloud-owner', ' ', ' null ')", builder.build().get());
+ }
+
+ @Test
+ public void shortCutToTest() {
+ DSLQueryBuilder<Output, Output> builder = TraversalBuilder
+ .traversal(new DSLStartNode(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().get());
+ }
+
+ @Test
+ public void limitTest() {
+ DSLQueryBuilder<Output, Output> builder = TraversalBuilder
+ .traversal(new DSLStartNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output());
+
+ builder.to(AAIObjectType.P_INTERFACE).limit(2).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
+ assertEquals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id') LIMIT 2",
+ builder.build().get());
+ }
+
+ @Test
+ public void equalsTest() {
+ DSLQueryBuilder<Output, Output> builder = TraversalBuilder
+ .traversal(new DSLStartNode(AAIObjectType.PSERVER, __.key("hostname", "my-hostname")).output());
+
+ builder.to(AAIObjectType.P_INTERFACE).to(AAIObjectType.SRIOV_PF, __.key("pf-pci-id", "my-id"));
+ assertTrue(
+ builder.equals("pserver*('hostname', 'my-hostname') > p-interface > sriov-pf('pf-pci-id', 'my-id')"));
+ assertTrue(builder.equals(builder));
+ }
+
+ @Test
+ public void mixedTypeTest() {
+ DSLQueryBuilder<Start, Start> builder = TraversalBuilder.fragment(new DSLStartNode(AAIObjectType.CLOUD_REGION,
+ __.key("cloud-owner", "owner"), __.key("cloud-region-id", "id")));
+ builder.to(__.node(AAIObjectType.VLAN_TAG, __.key("vlan-id-outer", 167), __.key("my-boolean", true)).output());
+ assertTrue(builder.equals(
+ "cloud-region('cloud-owner', 'owner')('cloud-region-id', 'id') > vlan-tag*('vlan-id-outer', 167)('my-boolean', true)"));
+ }
+
+ @Test
+ public void outputOnNodeLambdasTest() {
+ DSLQueryBuilder<Start, Start> builder = TraversalBuilder
+ .fragment(new DSLStartNode(AAIObjectType.L_INTERFACE, new DSLNodeKey("interface-id", "myId")));
+
+ builder.to(AAIObjectType.VSERVER, __.key("vserver-name", "myName")).output().to(AAIObjectType.P_INTERFACE)
+ .output();
+ assertEquals("l-interface('interface-id', 'myId') > vserver*('vserver-name', 'myName') > p-interface*",
+ builder.build().get());
+ }
+
+ @Test
+ public void skipOutputOnUnionTest() {
+ DSLQueryBuilder<Output, Output> builder = TraversalBuilder
+ .traversal(new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", "vnfId")).output());
+
+ builder.union(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output()),
+ __.node(AAIObjectType.VSERVER)
+ .to(__.node(AAIObjectType.PSERVER).output().to(__.node(AAIObjectType.COMPLEX).output())))
+ .output();
+
+ assertEquals(
+ "generic-vnf*('vnf-id', 'vnfId') > " + "[ pserver* > complex*, " + "vserver > pserver* > complex* ]",
+ builder.build().get());
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java
new file mode 100644
index 0000000000..157109c119
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java
@@ -0,0 +1,110 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai.entities;
+
+import static org.junit.Assert.assertEquals;
+import java.io.IOException;
+import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.so.client.aai.AAICommonObjectMapperProvider;
+import org.springframework.util.SerializationUtils;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAIResultWrapperTest {
+ String json;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ AAIResultWrapper aaiResultWrapper;
+ AAIResultWrapper aaiResultWrapperEmpty;
+
+ @Before
+ public void init() throws IOException {
+ final String RESOURCE_PATH = "src/test/resources/__files/aai/resources/";
+ json = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "e2e-complex.json")));
+
+ aaiResultWrapper = new AAIResultWrapper(json);
+ aaiResultWrapperEmpty = new AAIResultWrapper("{}");
+ }
+
+ @Test
+ public void testAAIResultWrapperIsSerializable() throws IOException {
+ AAIResultWrapper original = new AAIResultWrapper("");
+ byte[] serialized = SerializationUtils.serialize(original);
+ AAIResultWrapper deserialized = (AAIResultWrapper) SerializationUtils.deserialize(serialized);
+ assertEquals(deserialized.getJson(), original.getJson());
+ }
+
+ @Test
+ public void testGetRelationshipsEmpty() {
+ Optional<Relationships> relationships = aaiResultWrapperEmpty.getRelationships();
+ assertEquals("Compare relationships", Optional.empty(), relationships);
+ }
+
+ @Test
+ public void testAsMap() throws JsonParseException, JsonMappingException, IOException {
+ ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
+ Map<String, Object> expected = mapper.readValue(json, new TypeReference<Map<String, Object>>() {});
+
+ Map<String, Object> actual = aaiResultWrapper.asMap();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testAsMapEmpty() {
+ Map<String, Object> actual = aaiResultWrapperEmpty.asMap();
+ assertEquals(new HashMap<>(), actual);
+ }
+
+ @Test
+ public void nullCases() {
+
+ AAIResultWrapper wrapper = new AAIResultWrapper(null);
+
+ assertEquals(Optional.empty(), wrapper.getRelationships());
+ assertEquals("{}", wrapper.getJson());
+ assertEquals(Optional.empty(), wrapper.asBean(GenericVnf.class));
+ assertEquals(true, wrapper.asMap().isEmpty());
+ assertEquals("{}", wrapper.toString());
+
+ }
+
+ @Test
+ public void objectConstructor() {
+ AAIResultWrapper wrapper = new AAIResultWrapper(new GenericVnf());
+ assertEquals("{}", wrapper.getJson());
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java
new file mode 100644
index 0000000000..039bbb3614
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai.entities;
+
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Test;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+
+public class RelationshipsTest {
+
+ private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
+
+ @Test
+ public void run() throws IOException {
+ final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "e2e-complex.json")));
+
+ AAIResultWrapper wrapper = new AAIResultWrapper(content);
+ Relationships relationships = wrapper.getRelationships().get();
+
+ List<AAIResourceUri> test = relationships.getRelatedUris(AAIObjectType.VCE);
+ List<AAIResourceUri> uris = Arrays.asList(
+ AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a9fec18e-1ea3-40e4-a6c0-a89b3de07053"),
+ AAIUriFactory.createResourceUri(AAIObjectType.VCE, "8ae1e5f8-61f1-4c71-913a-b40cc4593cb9"),
+ AAIUriFactory.createResourceUri(AAIObjectType.VCE, "a2935fa9-b743-49f4-9813-a127f13c4e93"),
+ AAIUriFactory.createResourceUri(AAIObjectType.VCE, "c7fe7698-8063-4e26-8bd3-ca3edde0b0d4"));
+
+ assertTrue(uris.containsAll(test) && test.containsAll(uris));
+
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java
new file mode 100644
index 0000000000..0249bea794
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. 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.so.client.aai.entities.uri;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.onap.so.client.aai.AAIObjectType;
+
+public class AAISimpleUriFromParentUriTest {
+
+
+ @Test
+ public void appendChildren() {
+
+ AAIResourceUri parentUri =
+ AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "key1", "key2", "key3");
+
+ AAIResourceUri uri = new AAISimpleUri(parentUri, AAIObjectType.ALLOTTED_RESOURCE, "key4");
+
+ assertEquals("path appended",
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4",
+ uri.build().toString());
+
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java
new file mode 100644
index 0000000000..6bf67ffce8
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai.entities.uri;
+
+import static org.junit.Assert.assertEquals;
+import javax.ws.rs.core.UriBuilder;
+import org.junit.Test;
+import org.onap.so.client.aai.AAIObjectType;
+
+public class AAISimpleUriFromUriTest {
+
+
+
+ @Test
+ public void removeHost() {
+
+ AAIResourceUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN,
+ UriBuilder
+ .fromUri("https://localhost:8443/aai/v9/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053")
+ .build());
+
+ assertEquals("root and version removed", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053",
+ uri.build().toString());
+
+ }
+
+ @Test
+ public void noChange() {
+
+ AAIResourceUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN,
+ UriBuilder.fromUri("/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053").build());
+
+ assertEquals("no change", "/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053", uri.build().toString());
+
+ }
+
+ @Test
+ public void encodingPreserved() {
+
+ AAIResourceUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN,
+ UriBuilder.fromUri("/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053").build());
+
+ assertEquals("encoding preserved", "/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053",
+ uri.build().toString());
+
+ }
+
+ @Test
+ public void beforeBuildEquality() {
+
+ AAIResourceUri uri = new AAISimpleUri(AAIObjectType.VCE,
+ UriBuilder.fromUri("/network/vces/vce/a9f%20%20ec18e-1ea3-40e4-a6c0-a89b3de07053").build());
+
+ AAIResourceUri uri2 = new AAISimpleUri(AAIObjectType.VCE, "a9f ec18e-1ea3-40e4-a6c0-a89b3de07053");
+ assertEquals("are equal", uri2, uri);
+
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java
new file mode 100644
index 0000000000..6c1b3d69a2
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java
@@ -0,0 +1,133 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai.entities.uri;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.so.client.aai.AAIObjectPlurals;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.graphinventory.entities.uri.Depth;
+
+public class AAISimpleUriTest {
+
+
+
+ @Test
+ public void relatedToTestPlural() {
+ AAIPluralResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1").relatedTo(AAIObjectPlurals.PSERVER);
+ String uriOutput = uri.build().toString();
+ assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers", uriOutput);
+ }
+
+ @Test
+ public void relatedToTestSingular() {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1")
+ .relatedTo(AAIObjectType.PSERVER, "test2");
+ String uriOutput = uri.build().toString();
+ assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers/pserver/test2", uriOutput);
+ }
+
+ @Test
+ public void cloneTestSingular() {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
+ AAIResourceUri cloned = uri.clone();
+ assertEquals("/network/generic-vnfs/generic-vnf/test1", cloned.build().toString());
+
+ cloned.limit(2);
+
+ assertNotEquals(uri.build().toString(), cloned.build().toString());
+ }
+
+ @Test
+ public void cloneTestPlural() {
+ AAISimplePluralUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF);
+ AAISimplePluralUri cloned = uri.clone();
+ assertEquals("/network/generic-vnfs", cloned.build().toString());
+ }
+
+ @Test
+ public void cloneTestWithRelatedTo() {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1")
+ .relatedTo(AAIObjectType.PSERVER, "test2");
+ String uriOutput = uri.clone().build().toString();
+ assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers/pserver/test2", uriOutput);
+ }
+
+ @Test
+ public void cloneTestPluralWithRelatedTo() {
+ AAIPluralResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1").relatedTo(AAIObjectPlurals.PSERVER);
+ String uriOutput = uri.clone().build().toString();
+ assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers", uriOutput);
+ }
+
+ @Test
+ public void getKeysTest() {
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, "cloud1", "cloud2", "tenant1", "vserver1");
+ Map<String, String> keys = uri.getURIKeys();
+ System.out.println(keys);
+ System.out.println(uri.build());
+ assertEquals("vserver1", keys.get("vserver-id"));
+ }
+
+ @Test
+ public void getEncodedKeyTest() {
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "test1", "my value", "test3");
+ Map<String, String> keys = uri.getURIKeys();
+
+ assertEquals("my value", keys.get("service-type"));
+ }
+
+ @Test
+ public void serializeTest() throws IOException, ClassNotFoundException {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1");
+
+ uri.depth(Depth.ONE);
+ uri.limit(1);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
+ objectOutputStream.writeObject(uri);
+ objectOutputStream.flush();
+ objectOutputStream.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+
+ ObjectInputStream objectInputStream = new ObjectInputStream(bis);
+ AAIResourceUri e2 = (AAIResourceUri) objectInputStream.readObject();
+ objectInputStream.close();
+
+ uri.queryParam("test", "value");
+ e2.queryParam("test", "value");
+
+ assertEquals(e2.build().toString(), uri.build().toString());
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java
new file mode 100644
index 0000000000..8a203f6439
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai.entities.uri;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.onap.so.client.aai.AAIObjectPlurals;
+import org.onap.so.client.aai.AAIObjectType;
+
+public class AAIUriFactoryTest {
+
+ @Test
+ public void testCreateResourceUri() {
+
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
+
+ String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
+ assertEquals(expected, uri.build().toString());
+ }
+
+ @Test
+ public void testCreateNodesUri() {
+
+ AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
+
+ String expected = "/nodes/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
+ assertEquals(expected, uri.build().toString());
+ }
+
+ @Test
+ public void testCreateResourceFromExistingURI() {
+
+ AAIResourceUri uri = new AAISimpleUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)");
+ AAIResourceUri uri2 = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.GENERIC_VNF, uri.build());
+
+ String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29";
+ assertEquals(expected, uri2.build().toString());
+ }
+
+ @Test
+ public void testCreateResourceURIForPluralsWithValues() {
+
+ AAIPluralResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, "customerId", "serviceType");
+
+ String expected =
+ "/business/customers/customer/customerId/service-subscriptions/service-subscription/serviceType/service-instances";
+ assertEquals(expected, uri.build().toString());
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java
new file mode 100644
index 0000000000..a92a7c3c1a
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai.entities.uri;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.ws.rs.core.UriBuilder;
+import org.junit.Test;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
+
+public class AllottedResourceLookupUriTest {
+
+ @Test
+ public void oneKey()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ AllottedResourceLookupUri instance = new AllottedResourceLookupUri("key1");
+ AllottedResourceLookupUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = spy.locateAndBuild();
+ final URI expected = UriBuilder.fromPath(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/allotted-resources/allotted-resource/key4")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java
new file mode 100644
index 0000000000..3fbbc7c110
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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.so.client.aai.entities.uri;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.client.aai.AAIObjectPlurals;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.graphinventory.exceptions.IncorrectNumberOfUriKeys;
+
+public class IncorrectNumberOfUriKeysTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void verifyIncorrectNumberOfKeysSingle() {
+
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ thrown.expectMessage(equalTo("Expected 3 variables: [cloud-owner, cloud-region-id, volume-group-id]"));
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VOLUME_GROUP, "volume-group-id");
+
+ }
+
+ @Test
+ public void verifyIncorrectNumberOfKeysPlural() {
+
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ AAISimplePluralUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, "my-cloud-owner");
+
+ }
+
+ @Test
+ public void verifyIncorrectNumberOfKeysFromParent() {
+
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ AAIResourceUri parentUri =
+ AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "my-cloud-owner", "my-cloud-region-id");
+ AAIResourceUri uri = AAIUriFactory.createResourceFromParentURI(parentUri, AAIObjectType.VOLUME_GROUP);
+ }
+
+ @Test
+ public void verifyIncorrectNumberOfKeysHttpAware() {
+
+ thrown.expect(IncorrectNumberOfUriKeys.class);
+ AAIResourceUri uri =
+ AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "customer-id", "subscription-id");
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
new file mode 100644
index 0000000000..71d65b6f45
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
@@ -0,0 +1,301 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.aai.entities.uri;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Optional;
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.core.UriBuilder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.client.aai.AAIClient;
+import org.onap.so.client.aai.AAIObjectPlurals;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
+import org.onap.so.client.graphinventory.entities.uri.HttpAwareUri;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ServiceInstanceUriTest {
+
+ private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
+
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+
+ @Spy
+ public AAIClient client;
+
+ @InjectMocks
+ public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+ @Before
+ public void beforeTest() {
+ doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
+ }
+
+ @Test
+ public void found() throws IOException {
+ final String content = new String(
+ Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+ final Optional<String> result = instance.extractRelatedLink(content);
+ final String expected =
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
+ assertEquals("result is equal", expected, result.get());
+
+ }
+
+ @Test
+ public void oneKey()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = spy.locateAndBuild();
+ final URI expected = UriBuilder.fromPath(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+
+ @Test
+ public void oneKeyQueryParams()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = ((HttpAwareUri) spy.resourceVersion("1234")).locateAndBuild();
+ final URI expected = UriBuilder.fromUri(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+
+ @Test
+ public void oneKeyEncoded()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = spy.locateAndBuild();
+ final URI expected = UriBuilder.fromUri(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+
+ @Test
+ public void oneKeyGetKeys()
+ throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%28space")
+ .when(spy).getObjectById(any(Object.class));
+
+ assertThat(spy.getURIKeys().values(), contains("key1", "key2", "key3(space"));
+
+ }
+
+ @Test
+ public void oneKeyClone() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ String uri =
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
+ doReturn(Optional.of(uri)).when(spy).getCachedValue();
+ final URI result = ((HttpAwareUri) spy.resourceVersion("1234").clone()).locateAndBuild();
+ final URI expected = UriBuilder.fromUri(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234")
+ .build();
+ assertEquals("result is equal", expected, result);
+ }
+
+ @Test
+ public void threeKey() throws IOException {
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
+ final URI result = instance.build();
+ final URI expected = UriBuilder.fromPath(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .build();
+ assertEquals("result is equal", expected, result);
+
+ }
+
+ @Test
+ public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+ final String content =
+ new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json")));
+
+ ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+ ServiceInstanceUri spy = spy(instance);
+ AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
+ AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
+ when(mockResourcesClient.get(ArgumentMatchers.<AAIResourceUri>any(AAIResourceUri.class),
+ ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
+ when(wrapper.getJson()).thenReturn(content);
+ when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
+ exception.expect(GraphInventoryUriComputationException.class);
+ spy.locateAndBuild();
+
+ }
+
+ @Test
+ public void cloneTest() {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
+ final URI result = instance.build();
+ final URI result2 = instance.clone().queryParam("something", "new").build();
+ assertEquals("uris are not equal", false, result.toString().equals(result2.toString()));
+
+ }
+
+ @Test
+ public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+ ServiceInstanceUri spy = spy(instance);
+ AAIResourcesClient client = aaiClient;
+ doReturn(client).when(spy).getResourcesClient();
+ wireMockRule
+ .stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3")).willReturn(
+ aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBodyFile("")));
+ exception.expect(NotFoundException.class);
+ spy.locateAndBuild();
+ }
+
+ @Test
+ public void serializeTest() throws IOException, ClassNotFoundException, GraphInventoryUriNotFoundException,
+ GraphInventoryPayloadException {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+ final String content = new String(
+ Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
+
+ ServiceInstanceUri spy = spy(instance);
+ AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
+ AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
+ when(mockResourcesClient.get(ArgumentMatchers.<AAIResourceUri>any(AAIResourceUri.class),
+ ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
+ when(wrapper.getJson()).thenReturn(content);
+ when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
+ spy.locateAndBuild();
+ instance = spy.clone();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
+ objectOutputStream.writeObject(instance);
+ objectOutputStream.flush();
+ objectOutputStream.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+
+ ObjectInputStream objectInputStream = new ObjectInputStream(bis);
+ ServiceInstanceUri e2 = (ServiceInstanceUri) objectInputStream.readObject();
+ objectInputStream.close();
+
+ ServiceInstanceUri spy2 = spy(e2);
+
+ assertEquals(spy2.build().toString(), instance.build().toString());
+
+ // use the cached value do not call out to external system
+ verify(spy2, times(0)).getResourcesClient();
+ }
+
+ @Test
+ public void relatedToTest() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+ doReturn(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+ .when(spy).getObjectById(any(Object.class));
+
+ final URI result = spy.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", "my-vnf-name").build();
+ final URI expected = UriBuilder.fromUri(
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3/related-to/generic-vnfs?vnf-name=my-vnf-name")
+ .build();
+ assertEquals("result is equal", expected, result);
+ }
+
+ @Test
+ public void relatedToEqualityTestBeforeBuildTest()
+ throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+ ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+ ServiceInstanceUri spy = spy(instance);
+
+ final AAIPluralResourceUri result =
+ spy.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", "my-vnf-name");
+
+ assertEquals("result is equal", result, result);
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java
new file mode 100644
index 0000000000..f437197f71
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/aai/objects/CustomAAIObjectType.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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.so.client.aai.objects;
+
+import org.onap.so.client.aai.AAINamespaceConstants;
+import org.onap.so.client.aai.AAIObjectType;
+
+public class CustomAAIObjectType extends AAIObjectType {
+
+ private static final long serialVersionUID = 1919729212831978098L;
+
+ public static final AAIObjectType CUSTOM =
+ new CustomAAIObjectType(AAINamespaceConstants.NETWORK, "my-url", "my-custom-name");
+
+ /* Default constructor automatically called by AAIObjectType */
+ public CustomAAIObjectType() {
+ super();
+ }
+
+ protected CustomAAIObjectType(String parent, String uri, String name) {
+ super(parent, uri, name);
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java
new file mode 100644
index 0000000000..7789386667
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/defaultproperties/DefaultAAIPropertiesImpl.java
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.defaultproperties;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.onap.so.client.aai.AAIProperties;
+import org.onap.so.client.aai.AAIVersion;
+
+public class DefaultAAIPropertiesImpl implements AAIProperties {
+
+
+ final Map<Object, Object> props;
+
+ public DefaultAAIPropertiesImpl() {
+ 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;
+
+ }
+
+ 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());
+ }
+
+ @Override
+ public String getSystemName() {
+ return "MSO";
+ }
+
+ @Override
+ public AAIVersion getDefaultVersion() {
+ return AAIVersion.LATEST;
+ }
+
+ @Override
+ public String getAuth() {
+ Object value = props.get("aai.auth");
+ return value == null ? null : value.toString();
+ }
+
+ @Override
+ public String getKey() {
+ Object value = props.get("mso.msoKey");
+ return value == null ? null : value.toString();
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java
new file mode 100644
index 0000000000..1f047b3b36
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/GraphInventoryPatchConverterTest.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. 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.so.client.graphinventory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.so.client.aai.AAICommonObjectMapperProvider;
+import org.onap.so.client.graphinventory.GraphInventoryPatchConverter;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class GraphInventoryPatchConverterTest {
+
+ private ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
+
+ @Test
+ public void convertObjectToPatchFormatTest()
+ throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ GenericVnf vnf = new GenericVnf();
+ vnf.setIpv4Loopback0Address("");
+ String result = validator.marshallObjectToPatchFormat(vnf);
+ GenericVnf resultObj = mapper.readValue(result.toString(), GenericVnf.class);
+ assertTrue("expect object to become a String to prevent double marshalling", result instanceof String);
+ assertNull("expect null because of custom mapper", resultObj.getIpv4Loopback0Address());
+
+ }
+
+ @Test
+ public void convertStringToPatchFormatTest()
+ throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ String payload = "{\"ipv4-loopback0-address\":\"\"}";
+ String result = validator.marshallObjectToPatchFormat(payload);
+
+ assertEquals("expect no change", payload, result);
+ }
+
+ @Test
+ public void convertStringToPatchFormatNull_Test()
+ throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ String payload = "{\"ipv4-loopback0-address\": null}";
+ String result = validator.marshallObjectToPatchFormat(payload);
+ System.out.println(result);
+ assertEquals("expect no change", payload, result);
+ }
+
+ @Test
+ public void convertMapToPatchFormatTest()
+ throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ HashMap<String, String> map = new HashMap<>();
+ map.put("ipv4-loopback0-address", "");
+ map.put("ipv4-loopback1-address", "192.168.1.1");
+ String result = validator.marshallObjectToPatchFormat(map);
+
+ assertEquals("expect string", "{\"ipv4-loopback1-address\":\"192.168.1.1\"}", result);
+ }
+
+ @Test
+ public void hasComplexObjectTest() {
+ GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter();
+ String hasNesting = "{ \"hello\" : \"world\", \"nested\" : { \"key\" : \"value\" } }";
+ String noNesting = "{ \"hello\" : \"world\" }";
+ String arrayCase =
+ "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"nestedComplex\" : [{\"key\" : \"value\"}]}";
+ String empty = "{}";
+ String arrayCaseSimpleOnly = "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"]}";
+ String relationshipListCaseNesting =
+ "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}], \"nested\" : { \"key\" : \"value\" }}";
+ String relationshipListCase =
+ "{ \"hello\" : \"world\", \"nestedSimple\" : [\"value1\" , \"value2\"], \"relationship-list\" : [{\"key\" : \"value\"}]}";
+ String nothing = "";
+
+ assertTrue("expect has nesting", validator.hasComplexObject(hasNesting));
+ assertFalse("expect no nesting", validator.hasComplexObject(noNesting));
+ assertTrue("expect has nesting", validator.hasComplexObject(arrayCase));
+ assertFalse("expect no nesting", validator.hasComplexObject(empty));
+ assertFalse("expect no nesting", validator.hasComplexObject(arrayCaseSimpleOnly));
+ assertFalse("expect no nesting", validator.hasComplexObject(relationshipListCase));
+ assertTrue("expect has nesting", validator.hasComplexObject(relationshipListCaseNesting));
+ assertFalse("expect no nesting", validator.hasComplexObject(nothing));
+ }
+
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java
new file mode 100644
index 0000000000..fb26e1870e
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImplTest.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.so.client.graphinventory.entities.uri.parsers;
+
+import static org.junit.Assert.assertEquals;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.graphinventory.entities.uri.parsers.UriParser;
+import org.onap.so.client.graphinventory.entities.uri.parsers.UriParserSpringImpl;
+
+public class UriParserSpringImplTest {
+
+
+
+ @Test
+ public void reverseTemplate() {
+ final UriParser parser = new UriParserSpringImpl(AAIObjectType.SERVICE_INSTANCE.toString());
+ final String uri =
+ "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
+
+ Map<String, String> result = parser.parse(uri);
+
+ assertEquals("found customer-id", "key1", result.get("global-customer-id"));
+ assertEquals("found service-type", "key2", result.get("service-type"));
+ assertEquals("found service-instance-id", "key3", result.get("service-instance-id"));
+
+ }
+}
diff --git a/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryPayloadExceptionTest.java b/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryPayloadExceptionTest.java
new file mode 100644
index 0000000000..6b23cbbe86
--- /dev/null
+++ b/graph-inventory/aai-client/src/test/java/org/onap/so/client/graphinventory/exceptions/GraphInventoryPayloadExceptionTest.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Intellectual Property. 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.so.client.graphinventory.exceptions;
+
+import org.junit.Test;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
+
+public class GraphInventoryPayloadExceptionTest {
+
+ Throwable t = new Throwable();
+
+ @Test
+ public void callConstructorTest() throws Exception {
+
+ GraphInventoryPayloadException test1 = new GraphInventoryPayloadException("testing");
+
+ GraphInventoryPayloadException test2 = new GraphInventoryPayloadException("testing", t);
+
+ GraphInventoryPayloadException test3 = new GraphInventoryPayloadException(t);
+ }
+
+}