From d11a4dd882e3337f13a83d219001960339243ba9 Mon Sep 17 00:00:00 2001 From: Eylon Malin Date: Tue, 4 Feb 2020 23:21:33 +0200 Subject: regression unit test for getServicesByProjectNames Issue-ID: VID-758 Signed-off-by: Eylon Malin Change-Id: Ibb4f6b63448dfb53bae5c262b3d8ce4f253935e0 --- .../java/org/onap/vid/services/AaiServiceTest.java | 42 +++++++++- .../responses/aai/listServicesByProject.json | 95 ++++++++++++++++++++++ 2 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 vid-app-common/src/test/resources/responses/aai/listServicesByProject.json (limited to 'vid-app-common/src/test') diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java index 663d86255..90261746e 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import org.jetbrains.annotations.NotNull; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -55,6 +56,7 @@ import org.onap.vid.aai.model.AaiGetPnfs.Pnf; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; import org.onap.vid.aai.model.LogicalLinkResponse; import org.onap.vid.aai.model.OwningEntityResponse; +import org.onap.vid.aai.model.ProjectResponse; import org.onap.vid.aai.model.Relationship; import org.onap.vid.aai.model.RelationshipData; import org.onap.vid.aai.model.RelationshipList; @@ -286,15 +288,17 @@ public class AaiServiceTest { @Test public void testGetServicesByOwningEntityId() { - List owningEntityIds = ImmutableList.of("43b8a85a-0421-4265-9069-117dd6526b8a", "26dcc4aa-725a-447d-8346-aa26dfaa4eb7"); - RoleValidator roleValidator = mock(RoleValidator.class); + //given + List owningEntityIds = ImmutableList.of("43b8a85a-0421-4265-9069-117dd6526b8a", "26dcc4aa-725a-447d-8346-aa26dfaa4eb7"); OwningEntityResponse owningEntityResponse = TestUtils.readJsonResourceFileAsObject("/responses/aai/listServicesByOwningEntity.json", OwningEntityResponse.class); - when(roleValidator.isServicePermitted(any(WithPermissionProperties.class))).thenReturn(true); when(aaiClientInterface.getServicesByOwningEntityId(owningEntityIds)).thenReturn(new AaiResponse<>(owningEntityResponse, "", 200)); - List result = aaiService.getServicesByOwningEntityId(owningEntityIds, roleValidator); + RoleValidator roleValidator = createAlwaysTrueRoleValidator(); + //when + List result = aaiService.getServicesByOwningEntityId(owningEntityIds, roleValidator); + //then ServiceInstanceSearchResult expected1 = new ServiceInstanceSearchResult( "af9d52f9-13b2-4657-a198-463677f82dc0", "256cddb4-3aa1-43cc-a08f-315bb50b275e", "MSO-dev-service-type", "xbghrftgr_shani", null, null, null, null, true); ServiceInstanceSearchResult expected2 = new ServiceInstanceSearchResult( @@ -305,4 +309,34 @@ public class AaiServiceTest { assertThat(result, jsonEquals(ImmutableList.of(expected1, expected2, expected3)).when(IGNORING_ARRAY_ORDER).whenIgnoringPaths("[*].subscriberName")); //ignore in array } + @NotNull + private RoleValidator createAlwaysTrueRoleValidator() { + RoleValidator roleValidator = mock(RoleValidator.class); + when(roleValidator.isServicePermitted(any(WithPermissionProperties.class))).thenReturn(true); + return roleValidator; + } + + @Test + public void testGetServicesByProjectNames() { + + //given + List projectNames = ImmutableList.of("x1", "y2"); + ProjectResponse projectResponse = TestUtils.readJsonResourceFileAsObject("/responses/aai/listServicesByProject.json", ProjectResponse.class); + when(aaiClientInterface.getServicesByProjectNames(projectNames)).thenReturn(new AaiResponse<>(projectResponse, "", 200)); + RoleValidator roleValidator = createAlwaysTrueRoleValidator(); + + //when + List result = aaiService.getServicesByProjectNames(projectNames, roleValidator); + + //then + ServiceInstanceSearchResult expected1 = new ServiceInstanceSearchResult( + "3f826016-3ac9-4928-9561-beee75fd91d5", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", "Emanuel", "Lital_SRIOV2_001", null, null, null, null, true); + ServiceInstanceSearchResult expected2 = new ServiceInstanceSearchResult( + "7e4f8130-5dee-47c4-8770-1abc5f5ded83", "3d15d7ea-4174-49b6-89ec-e569381f7231", "vMOG", "justAname", null, null, null, null, true); + ServiceInstanceSearchResult expected3 = new ServiceInstanceSearchResult( + "ff2d9326-1ef5-4760-aba0-0eaf372ae675", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", "Yoda", "anotherName", null, null, null, null, true); + + assertThat(result, jsonEquals(ImmutableList.of(expected1, expected2, expected3)).when(IGNORING_ARRAY_ORDER).whenIgnoringPaths("[*].subscriberName")); //ignore in array + } + } diff --git a/vid-app-common/src/test/resources/responses/aai/listServicesByProject.json b/vid-app-common/src/test/resources/responses/aai/listServicesByProject.json new file mode 100644 index 000000000..6d6b09f78 --- /dev/null +++ b/vid-app-common/src/test/resources/responses/aai/listServicesByProject.json @@ -0,0 +1,95 @@ +{ + "project": [ + { + "project-name": "x1", + "resource-version": "1527026201826", + "relationship-list": { + "relationship": [ + { + "related-to": "service-instance", + "relationship-label": "org.onap.relationships.inventory.Uses", + "related-link": "/aai/v12/business/customers/customer/a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb/service-subscriptions/service-subscription/Emanuel/service-instances/service-instance/3f826016-3ac9-4928-9561-beee75fd91d5", + "relationship-data": [ + { + "relationship-key": "customer.global-customer-id", + "relationship-value": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb" + }, + { + "relationship-key": "service-subscription.service-type", + "relationship-value": "Emanuel" + }, + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "3f826016-3ac9-4928-9561-beee75fd91d5" + } + ], + "related-to-property": [ + { + "property-key": "service-instance.service-instance-name", + "property-value": "Lital_SRIOV2_001" + } + ] + } + ] + } + }, + { + "project-name": "y2", + "resource-version": "1527026341826", + "relationship-list": { + "relationship": [ + { + "related-to": "service-instance", + "relationship-label": "org.onap.relationships.inventory.BelongsTo", + "related-link": "/aai/v12/business/customers/customer/3d15d7ea-4174-49b6-89ec-e569381f7231/service-subscriptions/service-subscription/vMOG/service-instances/service-instance/7e4f8130-5dee-47c4-8770-1abc5f5ded83", + "relationship-data": [ + { + "relationship-key": "customer.global-customer-id", + "relationship-value": "3d15d7ea-4174-49b6-89ec-e569381f7231" + }, + { + "relationship-key": "service-subscription.service-type", + "relationship-value": "vMOG" + }, + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "7e4f8130-5dee-47c4-8770-1abc5f5ded83" + } + ], + "related-to-property": [ + { + "property-key": "service-instance.service-instance-name", + "property-value": "justAname" + } + ] + }, + { + "related-to": "service-instance", + "relationship-label": "org.onap.relationships.inventory.Uses", + "related-link": "/aai/v12/business/customers/customer/a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb/service-subscriptions/service-subscription/Yoda/service-instances/service-instance/ff2d9326-1ef5-4760-aba0-0eaf372ae675", + "relationship-data": [ + { + "relationship-key": "customer.global-customer-id", + "relationship-value": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb" + }, + { + "relationship-key": "service-subscription.service-type", + "relationship-value": "Yoda" + }, + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "ff2d9326-1ef5-4760-aba0-0eaf372ae675" + } + ], + "related-to-property": [ + { + "property-key": "service-instance.service-instance-name", + "property-value": "anotherName" + } + ] + } + ] + } + } + ] +} -- cgit 1.2.3-korg