diff options
Diffstat (limited to 'vid-app-common/src')
5 files changed, 20 insertions, 60 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java index 7e96c93cd..159401009 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java @@ -459,7 +459,7 @@ public class AaiClient implements AaiClientInterface { } @Override - public AaiResponse getVNFData(String globalSubscriberId, String serviceType) { + public AaiResponse<AaiGetVnfResponse> getVNFData(String globalSubscriberId, String serviceType) { String payload = "{\"start\": [\"business/customers/customer/" + globalSubscriberId + SERVICE_SUBSCRIPTIONS_PATH + encodePathSegment(serviceType) +"/service-instances\"]," + "\"query\": \"query/vnf-topology-fromServiceInstance\"}"; Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false); diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java index af5429c28..2a879e295 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java @@ -65,7 +65,7 @@ public interface AaiClientInterface extends ProbeInterface { AaiResponse getInstanceGroupsByCloudRegion(String cloudOwner, String cloudRegionId, String networkFunction); - AaiResponse getVNFData(String globalSubscriberId, String serviceType); + AaiResponse<AaiGetVnfResponse> getVNFData(String globalSubscriberId, String serviceType); AaiResponse getVNFData(String globalSubscriberId, String serviceType, String serviceInstanceId); diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java index 984812103..b64a233c7 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java @@ -75,7 +75,6 @@ import org.onap.vid.aai.model.RelationshipData; import org.onap.vid.aai.model.RelationshipList; import org.onap.vid.aai.model.Result; import org.onap.vid.aai.model.ServiceRelationships; -import org.onap.vid.aai.model.VnfResult; import org.onap.vid.asdc.beans.Service; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.ServiceInstanceSearchResult; @@ -152,6 +151,10 @@ public class AaiServiceImpl implements AaiService { return services; } + private boolean hasData(AaiResponse<?> aaiResponse) { + return aaiResponse != null && aaiResponse.getT() != null; + } + private boolean validateModel(Model model){ if (model == null) { return false; @@ -390,24 +393,7 @@ public class AaiServiceImpl implements AaiService { @Override public AaiResponse<AaiGetVnfResponse> getVNFData(String globalSubscriberId, String serviceType) { AaiResponse<AaiGetVnfResponse> response = aaiClient.getVNFData(globalSubscriberId, serviceType); - return filterChangeManagementVNFCandidatesResponse(response); - } - - protected AaiResponse<AaiGetVnfResponse> filterChangeManagementVNFCandidatesResponse(AaiResponse<AaiGetVnfResponse> response) { - - if (response != null && response.getT() != null) { - List<VnfResult> filteredVnfs = response.getT().results.stream() - .filter(result -> ( - result.nodeType.equalsIgnoreCase("generic-vnf") || - result.nodeType.equalsIgnoreCase("service-instance"))) - .collect(Collectors.toList()); - - AaiGetVnfResponse aaiGetVnfResponse = new AaiGetVnfResponse(); - aaiGetVnfResponse.results = filteredVnfs; - return new AaiResponse<>(aaiGetVnfResponse, response.getErrorMessage(), response.getHttpCode()); - } - - return new AaiResponse<>(); + return hasData(response) ? response : new AaiResponse<>(); } @Override diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java index 2eae1864f..9df99faa6 100644 --- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java @@ -103,7 +103,6 @@ public class AaiServiceImplTest { private static final String SUBSCRIBER_ID = "SUBSCRIBER_ID_EXPECTED"; private static final String STATUS_TEXT = "STATUS_TEXT"; private static final String GLOBAL_SUBSCRIBER_ID = "GLOBAL_SUBSCRIBER_ID"; - private static final String GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE = "ID_NULL"; private static final String VNF_INSTANCE_ID_OK = "VNF_INSTANCE_ID_OK"; private static final String VNF_INSTANCE_ID_FAIL = "VNF_INSTANCE_ID_FAIL"; private static final String PARENT_NAME = "PARENT_NAME"; @@ -277,7 +276,7 @@ public class AaiServiceImplTest { } @Test - public void shouldGetVNFDataWithoutFiltering() { + public void shouldGetVNFDataOfInstanceWithoutFiltering() { when(aaiClient.getVNFData(anyString(), anyString(), anyString())).thenReturn(aaiResponse); AaiResponse actualResponse = aaiService.getVNFData(anyString(), anyString(), anyString()); @@ -286,30 +285,26 @@ public class AaiServiceImplTest { } @Test - public void shouldGetVNFDataWithFiltering() { + public void shouldGetVNFDataOfServiceWithoutFiltering() { VnfResult vnfResult1 = createVnfResult("ID1", "generic-vnf"); VnfResult vnfResult2 = createVnfResult("ID2", "service-instance"); VnfResult vnfResult3 = createVnfResult("ID3", "anything-else"); - List<VnfResult> vnfResults = Arrays.asList(vnfResult1, vnfResult2, vnfResult3); - AaiResponse<AaiGetVnfResponse> aaiResponseGetVnfResponse = createAaiResponseVnfResponse(vnfResults); - - vnfResults = Arrays.asList(vnfResult1, vnfResult2); - AaiResponse<AaiGetVnfResponse> expectedResponseWithReturnedVnfs = createAaiResponseVnfResponse(vnfResults); - AaiResponse expectedResponseWithoutReturnedVnfs = new AaiResponse(); + AaiResponse<AaiGetVnfResponse> aaiResponseGetVnfResponse = createAaiResponseVnfResponse( + Arrays.asList(vnfResult1, vnfResult2, vnfResult3)); when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)).thenReturn(aaiResponseGetVnfResponse); - when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE, SERVICE_TYPE)).thenReturn(null); - AaiResponse<AaiGetVnfResponse> actualResponseWithReturnedVnfs = - aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE); - AaiResponse<AaiGetVnfResponse> actualResponseWithoutReturnedVnfs = - aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE, SERVICE_TYPE); + assertThat(aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)) + .isEqualTo(aaiResponseGetVnfResponse); + } + + @Test + public void shouldGetNonNullVNFDataOfServiceWhenNoResult() { + when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)).thenReturn(null); - assertThat(actualResponseWithReturnedVnfs) - .isEqualToComparingFieldByFieldRecursively(expectedResponseWithReturnedVnfs); - assertThat(actualResponseWithoutReturnedVnfs) - .isEqualToComparingFieldByField(expectedResponseWithoutReturnedVnfs); + assertThat(aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)) + .isEqualToComparingFieldByField(new AaiResponse()); } @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 92a55f0b8..6aa67051e 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 @@ -22,7 +22,6 @@ package org.onap.vid.services; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.arrayWithSize; -import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -33,14 +32,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.vid.aai.AaiClientInterface; -import org.onap.vid.aai.AaiGetVnfResponse; import org.onap.vid.aai.AaiResponse; import org.onap.vid.aai.model.AaiGetPnfResponse; import org.onap.vid.aai.model.AaiGetPnfs.Pnf; @@ -50,7 +46,6 @@ import org.onap.vid.aai.model.Relationship; import org.onap.vid.aai.model.RelationshipData; import org.onap.vid.aai.model.RelationshipList; import org.onap.vid.aai.model.ServiceRelationships; -import org.onap.vid.aai.model.VnfResult; import org.onap.vid.model.aaiTree.AAITreeNode; import org.onap.vid.roles.Role; import org.onap.vid.roles.RoleValidator; @@ -211,20 +206,4 @@ public class AaiServiceTest { assertThat(anyMatch, equalTo(expectedMatch)); } - @Test - public void testFilterChangeManagementVNFCandidatesResponse() { - AaiGetVnfResponse aaiGetVnfResponse = new AaiGetVnfResponse(); - aaiGetVnfResponse.results = new ArrayList<>(); - Stream.of("genEric-vNf", "l3-interface-ipv6-address-list", "vserver", "pserver", "serviCe-inStance").forEach( - nodeType->{ - VnfResult vnfResult = new VnfResult(); - vnfResult.nodeType=nodeType; - aaiGetVnfResponse.results.add(vnfResult); - } - ); - - AaiResponse<AaiGetVnfResponse> result = aaiService.filterChangeManagementVNFCandidatesResponse(new AaiResponse<>(aaiGetVnfResponse, "", 200)); - assertEquals(2, result.getT().results.size()); - assertThat(result.getT().results.stream().map(x->x.nodeType).collect(Collectors.toList()), containsInAnyOrder("genEric-vNf","serviCe-inStance")); - } } |