diff options
author | Benjamin, Max <max.benjamin@att.com> | 2020-03-16 12:01:26 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@att.com> | 2020-03-16 12:01:26 -0400 |
commit | a577f75663e5c8ccddee54337328425c5b2361d2 (patch) | |
tree | 3d666976eb291a0e1f558174bfa2341709ae6956 /common/src/test/java/org | |
parent | 7e2f7db5b4007fe470a7ce5794c88d1844021410 (diff) |
split single and plural graph inventory uris
split single and plural graph inventory uris
updated all object references in MSO using graph inventory plurals
corrected unit test stubbings
added additional unit tests
correct interfaces to return plural after related-to
modified the way http aware uris are built
reformated interfaces to no longer duplicate methods
corrected issues with identity of unbuilt uris
removed AAIUri references from groovy files
fixed clone behavior on Uri objects
Issue-ID: SO-2743
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I37aa2a13dcbf010b6c82ad73af3be5db5d9bd673
Diffstat (limited to 'common/src/test/java/org')
13 files changed, 209 insertions, 60 deletions
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java b/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java index 8f449c21f3..20a6678386 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIObjectTypeTest.java @@ -22,7 +22,7 @@ package org.onap.so.client.aai; import static org.junit.Assert.assertEquals; import org.junit.Test; -import org.onap.so.client.aai.entities.uri.AAIUri; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; public class AAIObjectTypeTest { @@ -56,14 +56,14 @@ public class AAIObjectTypeTest { @Test public void instanceGroupObjectTypeTest() { final String id = "test1"; - AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, id); + 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"; - AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, id); + AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, id); assertEquals("/network/collections/collection/test1", aaiUri.build().toString()); } @@ -85,7 +85,7 @@ public class AAIObjectTypeTest { @Test public void networkPolicyObjectTypeTest() { final String id = "test1"; - AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, id); + AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_POLICY, id); assertEquals("/network/network-policies/network-policy/test1", aaiUri.build().toString()); } } diff --git a/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java index 5b2bff277d..c70f16eb83 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIQueryClientTest.java @@ -48,7 +48,6 @@ import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.CustomQuery; import org.onap.so.client.aai.entities.Results; import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.so.client.aai.entities.uri.AAIUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.graphinventory.Format; import org.onap.so.client.graphinventory.GraphInventoryClient; @@ -83,10 +82,10 @@ public class AAIQueryClientTest { Format format = Format.SIMPLE; CustomQuery query = new CustomQuery(uris); - doReturn(restClient).when(client).createClient(isA(AAIUri.class)); + doReturn(restClient).when(client).createClient(isA(AAIResourceUri.class)); aaiQueryClient.query(format, query); - verify(client, times(1)).createClient( - AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).queryParam("format", format.toString())); + verify(client, times(1)) + .createClient(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).format(format)); verify(restClient, times(1)).put(query, String.class); } @@ -99,7 +98,7 @@ public class AAIQueryClientTest { aaiQueryClient.nodesOnly(); aaiQueryClient.subgraph(subgraph); - AAIUri aaiUri = spy(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY)); + AAIResourceUri aaiUri = spy(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY)); doReturn(aaiUri).when(aaiUri).clone(); aaiQueryClient.setupQueryParams(aaiUri); @@ -133,7 +132,7 @@ public class AAIQueryClientTest { @Test public void querySingleTypeTest() throws IOException { - when(client.createClient(isA(AAIUri.class))).thenReturn(restClient); + 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>>>() {})); diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java index 94d14684c7..a7fd6e904e 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java @@ -31,8 +31,12 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMoc 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; @@ -42,12 +46,17 @@ 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; @@ -198,4 +207,102 @@ public class AAIResourcesClientTest { } + @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/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java index 305cdf59cc..cbcb60513b 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAITransactionalClientTest.java @@ -95,7 +95,7 @@ public class AAITransactionalClientTest { @Test public void testConnect() throws IOException { - List<AAIResourceUri> uris = new ArrayList<AAIResourceUri>(); + List<AAIResourceUri> uris = new ArrayList<>(); uris.add(uriB); Map<String, Object> map = new HashMap<>(); @@ -117,7 +117,7 @@ public class AAITransactionalClientTest { @Test public void testDisconnect() throws IOException { - List<AAIResourceUri> uris = new ArrayList<AAIResourceUri>(); + List<AAIResourceUri> uris = new ArrayList<>(); uris.add(uriB); AAITransactionalClient transactions = aaiClient.beginTransaction().disconnect(uriA, uris); diff --git a/common/src/test/java/org/onap/so/client/aai/AAIURITest.java b/common/src/test/java/org/onap/so/client/aai/AAIURITest.java index 556b4429d4..8971f91602 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIURITest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIURITest.java @@ -23,7 +23,7 @@ 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.AAIUri; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; public class AAIURITest { @@ -33,7 +33,7 @@ public class AAIURITest { @Test public void verifyTemplateReplacement() { final String id = "test1"; - AAIUri aaiUri = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, id); + 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/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java b/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java index ec7c6434a7..039bbb3614 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/RelationshipsTest.java @@ -43,15 +43,12 @@ public class RelationshipsTest { Relationships relationships = wrapper.getRelationships().get(); List<AAIResourceUri> test = relationships.getRelatedUris(AAIObjectType.VCE); - - System.out.println(test.get(0).build()); 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/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java index d26ff8d507..0249bea794 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromParentUriTest.java @@ -33,7 +33,7 @@ public class AAISimpleUriFromParentUriTest { AAIResourceUri parentUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "key1", "key2", "key3"); - AAIUri uri = new AAISimpleUri(parentUri, AAIObjectType.ALLOTTED_RESOURCE, "key4"); + 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", diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java index ab1529d3ba..6bf67ffce8 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriFromUriTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals; import javax.ws.rs.core.UriBuilder; import org.junit.Test; import org.onap.so.client.aai.AAIObjectType; -import org.onap.so.client.graphinventory.entities.uri.SimpleUri; public class AAISimpleUriFromUriTest { @@ -33,7 +32,7 @@ public class AAISimpleUriFromUriTest { @Test public void removeHost() { - AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, + AAIResourceUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, UriBuilder .fromUri("https://localhost:8443/aai/v9/network/vces/vce/a9fec18e-1ea3-40e4-a6c0-a89b3de07053") .build()); @@ -46,7 +45,7 @@ public class AAISimpleUriFromUriTest { @Test public void noChange() { - AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, + 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()); @@ -56,11 +55,22 @@ public class AAISimpleUriFromUriTest { @Test public void encodingPreserved() { - AAIUri uri = new AAISimpleUri(AAIObjectType.UNKNOWN, + 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/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java index 4e9d5aa8e8..6c1b3d69a2 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAISimpleUriTest.java @@ -20,14 +20,10 @@ package org.onap.so.client.aai.entities.uri; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -36,7 +32,6 @@ 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; -import org.onap.so.client.graphinventory.entities.uri.SimpleUri; public class AAISimpleUriTest { @@ -44,34 +39,52 @@ public class AAISimpleUriTest { @Test public void relatedToTestPlural() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); - uri.relatedTo(AAIObjectPlurals.PSERVER); + AAIPluralResourceUri uri = + AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1").relatedTo(AAIObjectPlurals.PSERVER); String uriOutput = uri.build().toString(); - assertEquals(true, uriOutput.contains("related-to")); + assertEquals("/network/generic-vnfs/generic-vnf/test1/related-to/pservers", uriOutput); } @Test public void relatedToTestSingular() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1"); - uri.relatedTo(AAIObjectType.PSERVER, "test2"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test1") + .relatedTo(AAIObjectType.PSERVER, "test2"); String uriOutput = uri.build().toString(); - assertEquals(true, uriOutput.contains("related-to")); + 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(); - Map<String, String> keys = cloned.getURIKeys(); - assertThat(keys.values(), contains("test1")); + assertEquals("/network/generic-vnfs/generic-vnf/test1", cloned.build().toString()); + + cloned.limit(2); + + assertNotEquals(uri.build().toString(), cloned.build().toString()); } @Test public void cloneTestPlural() { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF); - AAIResourceUri cloned = uri.clone(); - Map<String, String> keys = cloned.getURIKeys(); - assertThat(keys.values(), empty()); + 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 diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java index 9b4f5dafb5..8a203f6439 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AAIUriFactoryTest.java @@ -24,14 +24,13 @@ import static org.junit.Assert.assertEquals; 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.SimpleUri; public class AAIUriFactoryTest { @Test public void testCreateResourceUri() { - AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); String expected = "/network/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; assertEquals(expected, uri.build().toString()); @@ -40,7 +39,7 @@ public class AAIUriFactoryTest { @Test public void testCreateNodesUri() { - AAIUri uri = AAIUriFactory.createNodesUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); + AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); String expected = "/nodes/generic-vnfs/generic-vnf/VIP%28VelocitytoIP%29"; assertEquals(expected, uri.build().toString()); @@ -49,8 +48,8 @@ public class AAIUriFactoryTest { @Test public void testCreateResourceFromExistingURI() { - AAIUri uri = new AAISimpleUri(AAIObjectType.GENERIC_VNF, "VIP(VelocitytoIP)"); - AAIUri uri2 = AAIUriFactory.createResourceFromExistingURI(AAIObjectType.GENERIC_VNF, uri.build()); + 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()); @@ -59,7 +58,8 @@ public class AAIUriFactoryTest { @Test public void testCreateResourceURIForPluralsWithValues() { - AAIUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, "customerId", "serviceType"); + AAIPluralResourceUri uri = + AAIUriFactory.createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, "customerId", "serviceType"); String expected = "/business/customers/customer/customerId/service-subscriptions/service-subscription/serviceType/service-instances"; diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java index 4be6753894..a92a7c3c1a 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/AllottedResourceLookupUriTest.java @@ -44,7 +44,7 @@ public class AllottedResourceLookupUriTest { "/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.build(); + 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(); diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java index 86ee08c4e6..3fbbc7c110 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/IncorrectNumberOfUriKeysTest.java @@ -21,8 +21,6 @@ package org.onap.so.client.aai.entities.uri; import static org.hamcrest.CoreMatchers.equalTo; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -48,7 +46,7 @@ public class IncorrectNumberOfUriKeysTest { public void verifyIncorrectNumberOfKeysPlural() { thrown.expect(IncorrectNumberOfUriKeys.class); - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, "my-cloud-owner"); + AAISimplePluralUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VOLUME_GROUP, "my-cloud-owner"); } diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java index 9bef35e3b5..71d65b6f45 100644 --- a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java +++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java @@ -56,11 +56,11 @@ 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.AAIObjectType; +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.Depth; +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; @@ -111,7 +111,7 @@ public class ServiceInstanceUriTest { "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3") .when(spy).getObjectById(any(Object.class)); - final URI result = spy.build(); + 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(); @@ -129,7 +129,7 @@ public class ServiceInstanceUriTest { "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3") .when(spy).getObjectById(any(Object.class)); - final URI result = spy.resourceVersion("1234").build(); + 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(); @@ -147,7 +147,7 @@ public class ServiceInstanceUriTest { "/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.build(); + 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(); @@ -175,9 +175,8 @@ public class ServiceInstanceUriTest { ServiceInstanceUri spy = spy(instance); String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3"; - doReturn(uri).when(spy).getObjectById(any(Object.class)); doReturn(Optional.of(uri)).when(spy).getCachedValue(); - final URI result = spy.resourceVersion("1234").clone().build(); + 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(); @@ -210,7 +209,7 @@ public class ServiceInstanceUriTest { when(wrapper.getJson()).thenReturn(content); when(spy.getResourcesClient()).thenReturn(mockResourcesClient); exception.expect(GraphInventoryUriComputationException.class); - spy.build(); + spy.locateAndBuild(); } @@ -233,7 +232,7 @@ public class ServiceInstanceUriTest { .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.build(); + spy.locateAndBuild(); } @Test @@ -250,7 +249,7 @@ public class ServiceInstanceUriTest { ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper); when(wrapper.getJson()).thenReturn(content); when(spy.getResourcesClient()).thenReturn(mockResourcesClient); - spy.build(); + spy.locateAndBuild(); instance = spy.clone(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -271,6 +270,32 @@ public class ServiceInstanceUriTest { // 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); } } |