From cc778524df33ee66a3f17416761ea4cd7b2ef952 Mon Sep 17 00:00:00 2001 From: mharazin Date: Fri, 24 Jan 2020 09:20:09 +0100 Subject: Refactoring tests in BBInputSetupUtilsTest Issue-ID: SO-2613 Signed-off-by: Mateusz Harazin Change-Id: I277277b0b5ca1c76afb9a466b20479c97d033401 --- .../tasks/BBInputSetupUtilsTest.java | 654 ++++++++------------- 1 file changed, 251 insertions(+), 403 deletions(-) (limited to 'bpmn/MSOCommonBPMN/src/test/java') diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java index 0bb92e32ff..fcc59c3340 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java @@ -9,9 +9,9 @@ * 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. @@ -27,6 +27,7 @@ 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.assertNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -36,6 +37,9 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -53,6 +57,7 @@ import org.onap.aai.domain.yang.Configuration; import org.onap.aai.domain.yang.Configurations; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.GenericVnfs; +import org.onap.aai.domain.yang.InstanceGroup; import org.onap.aai.domain.yang.L3Network; import org.onap.aai.domain.yang.L3Networks; import org.onap.aai.domain.yang.ServiceInstance; @@ -74,20 +79,13 @@ import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.graphinventory.entities.uri.Depth; import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; -import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; -import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; -import org.onap.so.db.catalog.beans.VfModuleCustomization; -import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.RequestProcessingData; import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.serviceinstancebeans.CloudConfiguration; -import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.RequestDetails; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(MockitoJUnitRunner.class) @@ -119,296 +117,192 @@ public class BBInputSetupUtilsTest { } @Test - public void testGetCatalogServiceByModelUUID() throws JsonParseException, JsonMappingException, IOException { + public void getCatalogServiceByModelUUIDTest() throws IOException { Service expected = mapper.readValue(new File(RESOURCE_PATH + "CatalogServiceExpected.json"), Service.class); + final String modelUUID = "modelUUIDTest"; - RequestDetails requestDetails = new RequestDetails(); - ModelInfo modelInfo = new ModelInfo(); - modelInfo.setModelVersionId("modelUUID"); - requestDetails.setModelInfo(modelInfo); - doReturn(expected).when(MOCK_catalogDbClient).getServiceByID("modelUUID"); - Service actual = bbInputSetupUtils.getCatalogServiceByModelUUID(modelInfo.getModelVersionId()); + doReturn(expected).when(MOCK_catalogDbClient).getServiceByID(modelUUID); - assertThat(actual, sameBeanAs(expected)); + assertThat(bbInputSetupUtils.getCatalogServiceByModelUUID(modelUUID), sameBeanAs(expected)); } @Test - public void testGetCatalogServiceByModelVersionAndModelInvariantUUID() - throws JsonParseException, JsonMappingException, IOException { - String modelVersion = "modelVersion"; - String modelInvariantUUID = "modelInvariantUUID"; + public void getCatalogServiceByModelVersionAndModelInvariantUUIDTest() throws IOException { + final String modelVersion = "modelVersionTest"; + final String modelInvariantUUID = "modelInvariantUUIDTest"; Service expectedService = mapper.readValue(new File(RESOURCE_PATH + "CatalogServiceExpected.json"), Service.class); - doReturn(expectedService).when(MOCK_catalogDbClient) - .getServiceByModelVersionAndModelInvariantUUID(isA(String.class), isA(String.class)); - - Service actualService = bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(modelVersion, + doReturn(expectedService).when(MOCK_catalogDbClient).getServiceByModelVersionAndModelInvariantUUID(modelVersion, modelInvariantUUID); - assertThat(actualService, sameBeanAs(expectedService)); + assertThat(bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(modelVersion, + modelInvariantUUID), sameBeanAs(expectedService)); } @Test - public void testGetVnfcInstanceGroups() throws JsonParseException, JsonMappingException, IOException { + public void getVnfcInstanceGroupsTest() throws IOException { + final String modelCustomizationUUID = "modelCustomizationUUIDTest"; VnfcInstanceGroupCustomization vnfc = mapper.readValue( new File(RESOURCE_PATH + "VnfcInstanceGroupCustomization.json"), VnfcInstanceGroupCustomization.class); - String modelCustomizationUUID = "modelCustomizationUUID"; doReturn(Arrays.asList(vnfc)).when(MOCK_catalogDbClient) - .getVnfcInstanceGroupsByVnfResourceCust(isA(String.class)); - - List actualVnfcList = - bbInputSetupUtils.getVnfcInstanceGroups(modelCustomizationUUID); + .getVnfcInstanceGroupsByVnfResourceCust(modelCustomizationUUID); - assertThat(actualVnfcList, sameBeanAs(Arrays.asList(vnfc))); + assertThat(bbInputSetupUtils.getVnfcInstanceGroups(modelCustomizationUUID), sameBeanAs(Arrays.asList(vnfc))); } @Test - public void testGetRequestDetails() throws JsonParseException, JsonMappingException, IOException { + public void getRequestDetailsTest() throws IOException { + final String requestId = "requestId"; InfraActiveRequests infraActiveRequest = mapper .readValue(new File(RESOURCE_PATH + "InfraActiveRequestExpected.json"), InfraActiveRequests.class); - RequestDetails expected = mapper.readValue(new File(RESOURCE_PATH + "RequestDetailsExpected.json"), RequestDetails.class); - String requestId = "requestId"; + doReturn(infraActiveRequest).when(MOCK_requestsDbClient).getInfraActiveRequestbyRequestId(requestId); - RequestDetails actual = bbInputSetupUtils.getRequestDetails(requestId); - assertThat(actual, sameBeanAs(expected)); + assertThat(bbInputSetupUtils.getRequestDetails(requestId), sameBeanAs(expected)); } @Test public void getRequestDetailsNullTest() throws IOException { - RequestDetails requestDetails = bbInputSetupUtils.getRequestDetails(""); - - assertNull(requestDetails); + assertNull(bbInputSetupUtils.getRequestDetails("")); } @Test - public void testGetCloudRegion() { + public void getCloudRegionTest() { CloudConfiguration cloudConfig = new CloudConfiguration(); cloudConfig.setLcpCloudRegionId("lcpCloudRegionId"); - Optional expected = - Optional.of(new org.onap.aai.domain.yang.CloudRegion()); - expected.get().setCloudOwner("cloudOwner"); - expected.get().setCloudRegionId("lcpCloudRegionId"); - doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.CloudRegion.class, + Optional expected = Optional.of(new CloudRegion()); + + doReturn(expected).when(MOCK_aaiResourcesClient).get(CloudRegion.class, AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudConfig.getCloudOwner(), cloudConfig.getLcpCloudRegionId()).depth(Depth.TWO)); - AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, - cloudConfig.getCloudOwner(), cloudConfig.getLcpCloudRegionId()).depth(Depth.TWO); - bbInputSetupUtils.getCloudRegion(cloudConfig); - - verify(MOCK_aaiResourcesClient, times(1)).get(CloudRegion.class, expectedUri); + assertThat(bbInputSetupUtils.getCloudRegion(cloudConfig), sameBeanAs(expected.get())); } @Test - public void testGetCloudRegionExceptionTest() { - + public void getCloudRegionNullTest() { CloudConfiguration cloudConfig = new CloudConfiguration(); cloudConfig.setLcpCloudRegionId("lcpCloudRegionId"); - RequestDetails requestDetails = new RequestDetails(); - requestDetails.setCloudConfiguration(cloudConfig); - - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - - CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfig); - - assertNull(cloudRegion); + assertNull(bbInputSetupUtils.getCloudRegion(cloudConfig)); } @Test - public void testGetCloudRegionEmptyId() { + public void getCloudRegionEmptyIdTest() { CloudConfiguration cloudConfig = new CloudConfiguration(); cloudConfig.setLcpCloudRegionId(""); - RequestDetails requestDetails = new RequestDetails(); - requestDetails.setCloudConfiguration(cloudConfig); - - CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(cloudConfig); - - assertNull(cloudRegion); + assertNull(bbInputSetupUtils.getCloudRegion(cloudConfig)); } @Test - public void testGetCloudRegionEmptyConfiguration() { - RequestDetails requestDetails = new RequestDetails(); - - CloudRegion cloudRegion = bbInputSetupUtils.getCloudRegion(requestDetails.getCloudConfiguration()); - - assertNull(cloudRegion); - } - - @Test - public void testGetAAIInstanceGroup() { - Optional expected = - Optional.of(new org.onap.aai.domain.yang.InstanceGroup()); - String instanceGroupId = "instanceGroupId"; + public void getAAIInstanceGroupTest() { + final String instanceGroupId = "instanceGroupId"; + Optional expected = Optional.of(new InstanceGroup()); expected.get().setId(instanceGroupId); - doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.InstanceGroup.class, + + doReturn(expected).when(MOCK_aaiResourcesClient).get(InstanceGroup.class, AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId)); - AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId); - bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId); - verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.InstanceGroup.class, expectedUri); + assertThat(bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId), sameBeanAs(expected.get())); } @Test - public void testGetAAIInstanceGroupThrowNotFound() { - String instanceGroupId = "instanceGroupId"; - doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.InstanceGroup.class, - AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroupId)); - - org.onap.aai.domain.yang.InstanceGroup actual = bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId); - - assertNull(actual); + public void getAAIInstanceGroupNullTest() { + assertNull(bbInputSetupUtils.getAAIInstanceGroup("")); } @Test - public void testGetAAICustomer() { + public void getAAICustomerTest() { + final String globalSubscriberId = "globalSubscriberId"; Optional expected = Optional.of(new org.onap.aai.domain.yang.Customer()); - String globalSubscriberId = "globalSubscriberId"; expected.get().setGlobalCustomerId(globalSubscriberId); + doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.Customer.class, AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId)); - AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId); - bbInputSetupUtils.getAAICustomer(globalSubscriberId); - verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.Customer.class, expectedUri); + assertThat(bbInputSetupUtils.getAAICustomer(globalSubscriberId), sameBeanAs(expected.get())); } @Test - public void testGetAAICustomerThrowNotFound() { - String globalSubscriberId = "globalSubscriberId"; - doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.Customer.class, - AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId)); - - org.onap.aai.domain.yang.Customer actual = bbInputSetupUtils.getAAICustomer(globalSubscriberId); - - assertNull(actual); + public void getAAICustomerNullTest() { + assertNull(bbInputSetupUtils.getAAICustomer("")); } @Test - public void testGetAAIServiceSubscription() { + public void getAAIServiceSubscriptionTest() { + final String globalSubscriberId = "globalSubscriberId"; + final String subscriptionServiceType = "subscriptionServiceType"; Optional expected = Optional.of(new org.onap.aai.domain.yang.ServiceSubscription()); - String globalSubscriberId = "globalSubscriberId"; - String subscriptionServiceType = "subscriptionServiceType"; + expected.get().setServiceType(subscriptionServiceType); doReturn(expected).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.ServiceSubscription.class, AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId, subscriptionServiceType)); - AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, - globalSubscriberId, subscriptionServiceType); - bbInputSetupUtils.getAAIServiceSubscription(globalSubscriberId, subscriptionServiceType); - verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceSubscription.class, expectedUri); + assertThat(bbInputSetupUtils.getAAIServiceSubscription(globalSubscriberId, subscriptionServiceType), + sameBeanAs(expected.get())); } @Test - public void testGetAAIServiceSubscriptionErrors() { - String globalSubId = null; - String subServiceType = null; - org.onap.aai.domain.yang.ServiceSubscription actual = - bbInputSetupUtils.getAAIServiceSubscription(globalSubId, subServiceType); - assertNull(actual); - - String globalSubId2 = ""; - String subServiceType2 = ""; - org.onap.aai.domain.yang.ServiceSubscription actual2 = - bbInputSetupUtils.getAAIServiceSubscription(globalSubId2, subServiceType2); - assertNull(actual2); - - String globalSubId3 = ""; - String subServiceType3 = null; - org.onap.aai.domain.yang.ServiceSubscription actual3 = - bbInputSetupUtils.getAAIServiceSubscription(globalSubId3, subServiceType3); - assertNull(actual3); - - String globalSubId4 = null; - String subServiceType4 = ""; - org.onap.aai.domain.yang.ServiceSubscription actual4 = - bbInputSetupUtils.getAAIServiceSubscription(globalSubId4, subServiceType4); - assertNull(actual4); + public void getAAIServiceSubscriptionErrorsTest() { + assertNull(bbInputSetupUtils.getAAIServiceSubscription(null, null)); + assertNull(bbInputSetupUtils.getAAIServiceSubscription("", "")); + assertNull(bbInputSetupUtils.getAAIServiceSubscription("", null)); + assertNull(bbInputSetupUtils.getAAIServiceSubscription(null, "")); } @Test - public void testGetAAIServiceSubscriptionThrowNotFound() { - String globalSubscriberId = "globalSubscriberId"; - String subscriptionServiceType = "subscriptionServiceType"; - doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(org.onap.aai.domain.yang.ServiceSubscription.class, - AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, globalSubscriberId, - subscriptionServiceType)); - org.onap.aai.domain.yang.ServiceSubscription actual = - bbInputSetupUtils.getAAIServiceSubscription(globalSubscriberId, subscriptionServiceType); - assertNull(actual); - } - - @Test - public void testGetAAIServiceInstanceById() { - String serviceInstanceId = "serviceInstanceId"; - + public void getAAIServiceInstanceByIdTest() { + final String serviceInstanceId = "serviceInstanceId"; ServiceInstance expectedServiceInstance = new ServiceInstance(); doReturn(Optional.of(expectedServiceInstance)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - ServiceInstance actualServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); - - assertThat(actualServiceInstance, sameBeanAs(expectedServiceInstance)); + assertThat(bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId), sameBeanAs(expectedServiceInstance)); } @Test - public void testGetAAIServiceInstanceByIdThrowNotFound() { - String serviceInstanceId = "serviceInstanceId"; - - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - - ServiceInstance actualServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId); + public void getAAIServiceInstanceById_ifEmptyReturnNull() { + doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(ServiceInstance.class), + any(AAIResourceUri.class)); - assertNull(actualServiceInstance); + assertNull(bbInputSetupUtils.getAAIServiceInstanceById("any")); } @Test - public void testGetAAIServiceInstanceByIdAndCustomer() { - String globalCustomerId = "globalCustomerId"; - String serviceType = "serviceType"; - String serviceInstanceId = "serviceInstanceId"; + public void getAAIServiceInstanceByIdAndCustomerTest() { + final String globalCustomerId = "globalCustomerId"; + final String serviceType = "serviceType"; + final String serviceInstanceId = "serviceInstanceId"; ServiceInstance expected = new ServiceInstance(); expected.setServiceInstanceId(serviceInstanceId); - doReturn(Optional.of(expected)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - AAIResourceUri expectedUri = AAIUriFactory - .createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId) - .depth(Depth.TWO); - this.bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(globalCustomerId, serviceType, serviceInstanceId); - verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceInstance.class, expectedUri); + doReturn(Optional.of(expected)).when(MOCK_aaiResourcesClient).get(ServiceInstance.class, AAIUriFactory + .createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalCustomerId, serviceType, serviceInstanceId) + .depth(Depth.TWO)); + assertThat(bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(globalCustomerId, serviceType, + serviceInstanceId), sameBeanAs(expected)); } @Test - public void testGetAAIServiceInstanceByIdAndCustomerThrowNotFound() { - String globalCustomerId = "globalCustomerId"; - String serviceType = "serviceType"; - String serviceInstanceId = "serviceInstanceId"; - - doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient(); - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - ServiceInstance actual = this.bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer(globalCustomerId, - serviceType, serviceInstanceId); + public void getAAIServiceInstanceByIdAndCustomerNullTest() { + doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(ServiceInstance.class), + any(AAIResourceUri.class)); - assertNull(actual); + assertNull(bbInputSetupUtils.getAAIServiceInstanceByIdAndCustomer("", "", "")); } @Test - public void testGetAAIServiceInstanceByName() throws Exception { - String serviceInstanceName = "serviceInstanceName"; + public void getAAIServiceInstanceByNameTest() throws Exception { + final String serviceInstanceName = "serviceInstanceName"; ServiceInstance expectedServiceInstance = new ServiceInstance(); expectedServiceInstance.setServiceInstanceId("serviceInstanceId"); @@ -425,20 +319,17 @@ public class BBInputSetupUtilsTest { doReturn(Optional.of(serviceInstances)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - AAIResourceUri expectedUri = AAIUriFactory - .createResourceUri(AAIObjectPlurals.SERVICE_INSTANCE, customer.getGlobalCustomerId(), - customer.getServiceSubscription().getServiceType()) - .queryParam("service-instance-name", serviceInstanceName).depth(Depth.TWO); - bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer); - verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.ServiceInstances.class, expectedUri); + assertThat(bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer), + sameBeanAs(serviceInstances.getServiceInstance().get(0))); } @Test - public void testGetAAIServiceInstanceByNameException() throws Exception { - expectedException.expect(Exception.class); + public void getAAIServiceInstanceByNameExceptionTest() throws Exception { + final String serviceInstanceName = "serviceInstanceName"; - String serviceInstanceName = "serviceInstanceName"; + expectedException.expect(Exception.class); + expectedException.expectMessage("Multiple Service Instances Returned"); ServiceInstance serviceInstance = new ServiceInstance(); serviceInstance.setServiceInstanceId("serviceInstanceId"); @@ -461,45 +352,26 @@ public class BBInputSetupUtilsTest { } @Test - public void testGetAAIServiceInstanceByNameNull() throws Exception { - String serviceInstanceName = "serviceInstanceName"; - - ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); - - ServiceSubscription serviceSubscription = new ServiceSubscription(); - serviceSubscription.setServiceType("serviceType"); - + public void getAAIServiceInstanceByNameNullTest() throws Exception { Customer customer = new Customer(); - customer.setGlobalCustomerId("globalCustomerId"); - customer.setServiceSubscription(serviceSubscription); - - ServiceInstances serviceInstances = new ServiceInstances(); - serviceInstances.getServiceInstance().add(serviceInstance); - serviceInstances.getServiceInstance().add(serviceInstance); + customer.setServiceSubscription(new ServiceSubscription()); - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - - ServiceInstance actualServiceInstance = - bbInputSetupUtils.getAAIServiceInstanceByName(serviceInstanceName, customer); - - assertNull(actualServiceInstance); + assertNull(bbInputSetupUtils.getAAIServiceInstanceByName("", customer)); } @Test - public void testGetOptionalAAIServiceInstanceByNameException() throws Exception { + public void getOptionalAAIServiceInstanceByNameExceptionTest() throws Exception { expectedException.expect(MultipleObjectsFoundException.class); expectedException.expectMessage(containsString( "Multiple service instances found for customer-id: globalCustomerId, service-type: serviceType and service-instance-name: serviceInstanceId.")); - String globalCustomerId = "globalCustomerId"; - String serviceType = "serviceType"; - String serviceInstanceId = "serviceInstanceId"; + final String globalCustomerId = "globalCustomerId"; + final String serviceType = "serviceType"; + final String serviceInstanceId = "serviceInstanceId"; ServiceInstance serviceInstance = new ServiceInstance(); - serviceInstance.setServiceInstanceId("serviceInstanceId"); + serviceInstance.setServiceInstanceId(serviceInstanceId); serviceInstance.setServiceType(serviceType); - serviceInstance.setServiceInstanceName("serviceInstanceName"); ServiceInstances serviceInstances = new ServiceInstances(); serviceInstances.getServiceInstance().add(serviceInstance); @@ -512,99 +384,81 @@ public class BBInputSetupUtilsTest { } @Test - public void testGetOptionalAAIServiceInstanceByNameNull() throws Exception { - String globalCustomerId = "globalCustomerId"; - String serviceType = "serviceType"; - String serviceInstanceId = "serviceInstanceId"; - - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - Optional actual = - this.bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, serviceInstanceId); + public void getOptionalAAIServiceInstanceByNameNullTest() throws Exception { + Optional actual = bbInputSetupUtils.getAAIServiceInstanceByName("", "", ""); assertThat(actual, sameBeanAs(Optional.empty())); } @Test - public void testGetCatalogInstanceGroup() throws JsonParseException, JsonMappingException, IOException { - String modelUUID = "modelUUID"; + public void getCatalogInstanceGroupNullTest() { + assertNull(bbInputSetupUtils.getCatalogInstanceGroup("")); + } + @Test + public void getCatalogInstanceGroupTest() throws IOException { + final String modelUUID = "modelUUIDTest"; org.onap.so.db.catalog.beans.InstanceGroup expectedInstanceGroup = mapper.readValue( new File(RESOURCE_PATH + "InstanceGroup.json"), org.onap.so.db.catalog.beans.InstanceGroup.class); - doReturn(expectedInstanceGroup).when(MOCK_catalogDbClient).getInstanceGroupByModelUUID(isA(String.class)); + doReturn(expectedInstanceGroup).when(MOCK_catalogDbClient).getInstanceGroupByModelUUID(modelUUID); - org.onap.so.db.catalog.beans.InstanceGroup actualInstanceGroup = - bbInputSetupUtils.getCatalogInstanceGroup(modelUUID); - - assertThat(actualInstanceGroup, sameBeanAs(expectedInstanceGroup)); + assertThat(bbInputSetupUtils.getCatalogInstanceGroup(modelUUID), sameBeanAs(expectedInstanceGroup)); } @Test - public void testGetCollectionResourceInstanceGroupCustomization() { - String modelCustomizationUUID = "modelCustomizationUUID"; - + public void getCollectionResourceInstanceGroupCustomizationTest() { + final String modelCustomizationUUID = "modelCustomizationUUID"; CollectionResourceInstanceGroupCustomization expectedCollection = new CollectionResourceInstanceGroupCustomization(); doReturn(Arrays.asList(expectedCollection)).when(MOCK_catalogDbClient) .getCollectionResourceInstanceGroupCustomizationByModelCustUUID(modelCustomizationUUID); - List actualCollection = - bbInputSetupUtils.getCollectionResourceInstanceGroupCustomization(modelCustomizationUUID); - - assertThat(actualCollection, sameBeanAs(Arrays.asList(expectedCollection))); + assertThat(bbInputSetupUtils.getCollectionResourceInstanceGroupCustomization(modelCustomizationUUID), + sameBeanAs(Arrays.asList(expectedCollection))); } @Test - public void testGetAAIGenericVnf() throws JsonParseException, JsonMappingException, IOException { - String vnfId = "vnfId"; - - GenericVnf expectedAaiVnf = - mapper.readValue(new File(RESOURCE_PATH + "aaiGenericVnfInput.json"), GenericVnf.class); - - doReturn(Optional.of(expectedAaiVnf)).when(MOCK_aaiResourcesClient).get(isA(Class.class), - isA(AAIResourceUri.class)); - AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE); - GenericVnf actualAaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId); - - assertThat(actualAaiVnf, sameBeanAs(expectedAaiVnf)); - - verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.GenericVnf.class, expectedUri); + public void getAAIConfigurationNullTest() { + assertNull(bbInputSetupUtils.getAAIConfiguration("")); } @Test - public void testGetAAIConfiguration() throws JsonParseException, JsonMappingException, IOException { - String configurationId = "configurationId"; - + public void getAAIConfigurationTest() throws IOException { + final String configurationId = "configurationId"; Configuration expectedAaiConfiguration = mapper.readValue(new File(RESOURCE_PATH + "ConfigurationInput.json"), Configuration.class); doReturn(Optional.of(expectedAaiConfiguration)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); - AAIResourceUri expectedUri = - AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId).depth(Depth.ONE); - bbInputSetupUtils.getAAIConfiguration(configurationId); - verify(MOCK_aaiResourcesClient, times(1)).get(org.onap.aai.domain.yang.Configuration.class, expectedUri); + assertThat(bbInputSetupUtils.getAAIConfiguration(configurationId), sameBeanAs(expectedAaiConfiguration)); } @Test - public void testGetAAIGenericVnfThrowNotFound() throws JsonParseException, JsonMappingException, IOException { - String vnfId = "vnfId"; + public void getAAIGenericVnfNullTest() { + assertNull(bbInputSetupUtils.getAAIGenericVnf("")); + } - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class)); + @Test + public void getAAIGenericVnfTest() throws IOException { + final String vnfId = "vnfId"; + GenericVnf expectedAaiVnf = + mapper.readValue(new File(RESOURCE_PATH + "aaiGenericVnfInput.json"), GenericVnf.class); - GenericVnf actualAaiVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId); + doReturn(Optional.of(expectedAaiVnf)).when(MOCK_aaiResourcesClient).get(isA(Class.class), + eq(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId).depth(Depth.ONE))); - assertNull(actualAaiVnf); + assertThat(bbInputSetupUtils.getAAIGenericVnf(vnfId), sameBeanAs(expectedAaiVnf)); } @Test - public void testGetAAIResourceDepthOne() { - String vnfId = "vnfId"; - AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId); + public void getAAIResourceDepthOneTest() { + AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "anyVnfId"); AAIResourceUri expectedUri = aaiResourceUri.clone().depth(Depth.ONE); AAIResourceUri aaiResourceUriClone = aaiResourceUri.clone(); + bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri); verify(MOCK_aaiResourcesClient, times(1)).get(expectedUri); @@ -612,11 +466,11 @@ public class BBInputSetupUtilsTest { } @Test - public void testGetAAIResourceDepthTwo() { - String vnfId = "vnfId"; - AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId); + public void getAAIResourceDepthTwoTest() { + AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "anyVnfId"); AAIResourceUri expectedUri = aaiResourceUri.clone().depth(Depth.TWO); AAIResourceUri aaiResourceUriClone = aaiResourceUri.clone(); + bbInputSetupUtils.getAAIResourceDepthTwo(aaiResourceUri); verify(MOCK_aaiResourcesClient, times(1)).get(expectedUri); @@ -625,25 +479,33 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedNetworkByNameFromServiceInstanceTest() throws Exception { + final String networkId = "id123"; + final String networkName = "name123"; + Optional expected = Optional.of(new L3Networks()); L3Network network = new L3Network(); - network.setNetworkId("id123"); - network.setNetworkName("name123"); + network.setNetworkId(networkId); + network.setNetworkName(networkName); expected.get().getL3Network().add(network); + doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class)); Optional actual = - this.bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance("id123", "name123"); - assertEquals(actual.get().getNetworkId(), expected.get().getL3Network().get(0).getNetworkId()); + bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(networkId, networkName); + + assertTrue(actual.isPresent()); + assertEquals(networkId, actual.get().getNetworkId()); + assertEquals(networkName, actual.get().getNetworkName()); + assertEquals(expected.get().getL3Network().get(0).getNetworkId(), actual.get().getNetworkId()); } @Test public void getRelatedNetworkByNameFromServiceInstanceMultipleNetworksExceptionTest() throws Exception { + final String serviceInstanceId = "serviceInstanceId"; + final String networkName = "networkName"; expectedException.expect(MultipleObjectsFoundException.class); - expectedException.expectMessage(containsString( - "Multiple networks found for service-instance-id: serviceInstanceId and network-name: networkName.")); - - String serviceInstanceId = "serviceInstanceId"; - String networkName = "networkName"; + expectedException.expectMessage( + String.format("Multiple networks found for service-instance-id: %s and network-name: %s.", + serviceInstanceId, networkName)); L3Network network = new L3Network(); network.setNetworkId("id123"); @@ -661,15 +523,7 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedNetworkByNameFromServiceInstanceNotFoundTest() throws Exception { - String serviceInstanceId = "serviceInstanceId"; - String networkName = "networkName"; - - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class)); - - Optional actualNetwork = - bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(serviceInstanceId, networkName); - - assertEquals(Optional.empty(), actualNetwork); + assertEquals(Optional.empty(), bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance("", "")); } @Test @@ -682,13 +536,19 @@ public class BBInputSetupUtilsTest { doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIResourceUri.class)); Optional actual = this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001"); - assertEquals(actual.get().getServiceInstanceId(), - expected.get().getServiceInstance().get(0).getServiceInstanceId()); + + assertTrue(actual.isPresent()); + assertEquals(expected.get().getServiceInstance().get(0).getServiceInstanceId(), + actual.get().getServiceInstanceId()); } @Test - public void getRelatedServiceInstanceFromInstanceGroupMultipleTest() throws Exception { + public void getRelatedServiceInstanceFromInstanceGroupMultipleExceptionTest() throws Exception { + final String instanceGroupId = "ig-001"; expectedException.expect(MultipleObjectsFoundException.class); + expectedException.expectMessage( + String.format("Mulitple service instances were found for instance-group-id: %s.", instanceGroupId)); + Optional serviceInstances = Optional.of(new ServiceInstances()); ServiceInstance si1 = Mockito.mock(ServiceInstance.class); ServiceInstance si2 = Mockito.mock(ServiceInstance.class); @@ -697,39 +557,46 @@ public class BBInputSetupUtilsTest { doReturn(serviceInstances).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIResourceUri.class)); - this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001"); + bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup(instanceGroupId); } @Test - public void getRelatedServiceInstanceFromInstanceGroupNotFoundTest() throws Exception { + public void getRelatedServiceInstanceFromInstanceGroupNotFoundExceptionTest() throws Exception { expectedException.expect(NoServiceInstanceFoundException.class); + expectedException.expectMessage("No ServiceInstances Returned"); + Optional serviceInstances = Optional.of(new ServiceInstances()); doReturn(serviceInstances).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIResourceUri.class)); - this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001"); + bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001"); } @Test public void getRelatedVnfByNameFromServiceInstanceTest() throws Exception { + final String vnfId = "id123"; + final String vnfName = "name123"; + Optional expected = Optional.of(new GenericVnfs()); GenericVnf vnf = new GenericVnf(); - vnf.setVnfId("id123"); - vnf.setVnfName("name123"); + vnf.setVnfId(vnfId); + vnf.setVnfName(vnfName); expected.get().getGenericVnf().add(vnf); + doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class)); - Optional actual = this.bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance("id123", "name123"); - assertEquals(actual.get().getVnfId(), expected.get().getGenericVnf().get(0).getVnfId()); + Optional actual = this.bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(vnfId, vnfName); + + assertTrue(actual.isPresent()); + assertEquals(expected.get().getGenericVnf().get(0).getVnfId(), actual.get().getVnfId()); } @Test public void getRelatedVnfByNameFromServiceInstanceMultipleVnfsExceptionTest() throws Exception { + final String serviceInstanceId = "serviceInstanceId"; + final String vnfName = "vnfName"; expectedException.expect(MultipleObjectsFoundException.class); - expectedException.expectMessage(containsString( - "Multiple vnfs found for service-instance-id: serviceInstanceId and vnf-name: vnfName.")); - - String serviceInstanceId = "serviceInstanceId"; - String vnfName = "vnfName"; + expectedException.expectMessage(String.format( + "Multiple vnfs found for service-instance-id: %s and vnf-name: %s.", serviceInstanceId, vnfName)); GenericVnf vnf = new GenericVnf(); vnf.setVnfId("id123"); @@ -740,7 +607,6 @@ public class BBInputSetupUtilsTest { vnfs.getGenericVnf().add(vnf); Optional optVnfs = Optional.of(vnfs); - doReturn(optVnfs).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class)); bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName); @@ -748,38 +614,38 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedVnfByNameFromServiceInstanceNotFoundTest() throws Exception { - String serviceInstanceId = "serviceInstanceId"; - String vnfName = "vnfName"; - - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class)); - - Optional actualVnf = - this.bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName); + final String serviceInstanceId = "serviceInstanceId"; + final String vnfName = "vnfName"; - assertEquals(actualVnf, Optional.empty()); + assertEquals(Optional.empty(), + bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName)); } @Test public void getRelatedVolumeGroupByNameFromVnfTest() throws Exception { + final String vnfId = "id123"; + final String vnfName = "name123"; + Optional expected = Optional.of(new VolumeGroups()); VolumeGroup volumeGroup = new VolumeGroup(); - volumeGroup.setVolumeGroupId("id123"); - volumeGroup.setVolumeGroupName("name123"); + volumeGroup.setVolumeGroupId(vnfId); + volumeGroup.setVolumeGroupName(vnfName); expected.get().getVolumeGroup().add(volumeGroup); + doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); - Optional actual = this.bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf("id123", "name123"); - assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId()); + Optional actual = this.bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(vnfId, vnfName); + + assertTrue(actual.isPresent()); + assertEquals(expected.get().getVolumeGroup().get(0).getVolumeGroupId(), actual.get().getVolumeGroupId()); } @Test public void getRelatedVolumeGroupByNameFromVnfMultipleVolumeGroupsExceptionTest() throws Exception { + final String vnfId = "vnfId"; + final String volumeGroupName = "volumeGroupName"; expectedException.expect(MultipleObjectsFoundException.class); - expectedException.expectMessage(containsString( - "Multiple volume-groups found for vnf-id: vnfId and volume-group-name: volumeGroupName.")); - - - String vnfId = "vnfId"; - String volumeGroupName = "volumeGroupName"; + expectedException.expectMessage(String.format( + "Multiple volume-groups found for vnf-id: %s and volume-group-name: %s.", vnfId, volumeGroupName)); VolumeGroup volumeGroup = new VolumeGroup(); volumeGroup.setVolumeGroupId("id123"); @@ -797,15 +663,7 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedVolumeGroupByNameFromVnfNotFoundTest() throws Exception { - String vnfId = "vnfId"; - String volumeGroupName = "volumeGroupName"; - - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); - - Optional actualVolumeGroup = - bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(vnfId, volumeGroupName); - - assertEquals(actualVolumeGroup, Optional.empty()); + assertEquals(Optional.empty(), bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf("", "")); } @Test @@ -815,18 +673,20 @@ public class BBInputSetupUtilsTest { volumeGroup.setVolumeGroupId("id123"); volumeGroup.setVolumeGroupName("name123"); expected.get().getVolumeGroup().add(volumeGroup); + doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); Optional actual = this.bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule("id123", "id123", "name123"); - assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId()); + + assertTrue(actual.isPresent()); + assertEquals(expected.get().getVolumeGroup().get(0).getVolumeGroupId(), actual.get().getVolumeGroupId()); } @Test public void getRelatedVolumeGroupFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception { expectedException.expect(Exception.class); - - String vnfId = "vnfId"; - String volumeGroupId = "volumeGroupId"; + final String vnfId = "vnfId"; + final String volumeGroupId = "volumeGroupId"; VolumeGroup volumeGroup = new VolumeGroup(); volumeGroup.setVolumeGroupId("id123"); @@ -844,15 +704,10 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedVolumeGroupFromVfModuleNotFoundTest() throws Exception { - String vnfId = "vnfId"; - String volumeGroupId = "volumeGroupId"; - - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); - - Optional actualVolumeGroup = - bbInputSetupUtils.getRelatedVolumeGroupFromVfModule(vnfId, volumeGroupId); + final String vnfId = "vnfId"; + final String volumeGroupId = "volumeGroupId"; - assertEquals(actualVolumeGroup, Optional.empty()); + assertEquals(Optional.empty(), bbInputSetupUtils.getRelatedVolumeGroupFromVfModule(vnfId, volumeGroupId)); } @Test @@ -861,19 +716,24 @@ public class BBInputSetupUtilsTest { VolumeGroup volumeGroup = new VolumeGroup(); volumeGroup.setVolumeGroupId("id123"); expected.get().getVolumeGroup().add(volumeGroup); + doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); - Optional actual = this.bbInputSetupUtils.getRelatedVolumeGroupFromVfModule("id123", "id123"); - assertEquals(actual.get().getVolumeGroupId(), expected.get().getVolumeGroup().get(0).getVolumeGroupId()); + Optional actual = bbInputSetupUtils.getRelatedVolumeGroupFromVfModule("id123", "id123"); + + assertTrue(actual.isPresent()); + assertEquals(expected.get().getVolumeGroup().get(0).getVolumeGroupId(), actual.get().getVolumeGroupId()); } @Test public void getRelatedVolumeGroupByNameFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception { + final String vnfId = "vnfId"; + final String vfModuleId = "vfModuleId"; + final String volumeGroupName = "volumeGroupName"; + expectedException.expect(MultipleObjectsFoundException.class); - expectedException.expectMessage(containsString( - "Multiple voulme-groups found for vnf-id: vnfId, vf-module-id: volumeGroupId and volume-group-name: volumeGroupName.")); - String vnfId = "vnfId"; - String volumeGroupId = "volumeGroupId"; - String volumeGroupName = "volumeGroupName"; + expectedException.expectMessage(String.format( + "Multiple voulme-groups found for vnf-id: %s, vf-module-id: %s and volume-group-name: %s.", vnfId, + vfModuleId, volumeGroupName)); VolumeGroup volumeGroup = new VolumeGroup(); volumeGroup.setVolumeGroupId("id123"); @@ -884,54 +744,39 @@ public class BBInputSetupUtilsTest { volumeGroups.getVolumeGroup().add(volumeGroup); Optional optVolumeGroups = Optional.of(volumeGroups); - doReturn(optVolumeGroups).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); - bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, volumeGroupId, volumeGroupName); + bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, vfModuleId, volumeGroupName); } @Test public void getRelatedVolumeGroupByNameFromVfModuleNotFoundTest() throws Exception { - String vnfId = "vnfId"; - String volumeGroupId = "volumeGroupId"; - String volumeGroupName = "volumeGroupName"; - - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class)); - - Optional actualVolumeGroup = - bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, volumeGroupId, volumeGroupName); - - assertEquals(actualVolumeGroup, Optional.empty()); + assertEquals(Optional.empty(), bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule("", "", "")); } - @Test - public void loadOriginalFlowExecutionPathTest() throws Exception { - - String requestId = "123"; - String flowsToExecuteString = - "[{\"buildingBlock\":{\"mso-id\":\"2f9ddc4b-4dcf-4129-a35f-be1625ae0176\",\"bpmn-flow-name\":\"DeactivateFabricConfigurationBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":{\"vfModuleCustomizationUUID\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"vnfResourceCustomizationUUID\":\"a80f05b8-d651-44af-b999-8ed78fb4582f\",\"cvnfcCustomizationUUID\":\"69cce457-9ffd-4359-962b-0596a1e83ad1\",\"vnfcName\":\"zauk51bmcmr01mcm001\"}},{\"buildingBlock\":{\"mso-id\":\"1ca5584e-38a9-4c3f-a4b4-99b0d42089ba\",\"bpmn-flow-name\":\"UnassignFabricConfigurationBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":{\"vfModuleCustomizationUUID\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"vnfResourceCustomizationUUID\":\"a80f05b8-d651-44af-b999-8ed78fb4582f\",\"cvnfcCustomizationUUID\":\"69cce457-9ffd-4359-962b-0596a1e83ad1\",\"vnfcName\":\"zauk51bmcmr01mcm001\"}},{\"buildingBlock\":{\"mso-id\":\"68d16097-4810-477d-803b-8322106106ef\",\"bpmn-flow-name\":\"DeactivateVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null},{\"buildingBlock\":{\"mso-id\":\"0b02eb09-bc23-4329-b19e-716dcca4e4a6\",\"bpmn-flow-name\":\"DeleteVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null},{\"buildingBlock\":{\"mso-id\":\"bcf95d05-0782-44ff-920d-d5100525c275\",\"bpmn-flow-name\":\"UnassignVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null}]"; - ObjectMapper om = new ObjectMapper(); - List expectedFlowsToExecute = null; - try { - ExecuteBuildingBlock[] asArray = om.readValue(flowsToExecuteString, ExecuteBuildingBlock[].class); - expectedFlowsToExecute = Arrays.asList(asArray); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + public void loadOriginalFlowExecutionPathTest() throws IOException { + final String requestId = "123"; + final String originalRequestId = "originalRequestId"; + final String flowsToExecuteString = new String( + Files.readAllBytes(Paths.get(RESOURCE_PATH + "FlowsToExecute.json")), StandardCharsets.UTF_8); InfraActiveRequests request = new InfraActiveRequests(); - request.setRequestId("requestId"); - request.setOriginalRequestId("originalRequestId"); - doReturn(request).when(MOCK_requestsDbClient).getInfraActiveRequestbyRequestId(anyString()); - RequestProcessingData rpd = new RequestProcessingData(); - rpd.setValue(flowsToExecuteString); - doReturn(rpd).when(MOCK_requestsDbClient).getRequestProcessingDataBySoRequestIdAndName(anyString(), - anyString()); + ExecuteBuildingBlock[] expectedFlowsToExecute = + mapper.readValue(flowsToExecuteString, ExecuteBuildingBlock[].class); + + request.setRequestId(requestId); + request.setOriginalRequestId(originalRequestId); + doReturn(request).when(MOCK_requestsDbClient).getInfraActiveRequestbyRequestId(requestId); + + RequestProcessingData requestProcessingData = new RequestProcessingData(); + requestProcessingData.setValue(flowsToExecuteString); + doReturn(requestProcessingData).when(MOCK_requestsDbClient) + .getRequestProcessingDataBySoRequestIdAndName(anyString(), anyString()); List flowsToExecute = bbInputSetupUtils.loadOriginalFlowExecutionPath(requestId); - assertEquals(expectedFlowsToExecute.size(), flowsToExecute.size()); + + assertEquals(mapper.writeValueAsString(expectedFlowsToExecute), mapper.writeValueAsString(flowsToExecute)); } @Test @@ -954,11 +799,7 @@ public class BBInputSetupUtilsTest { @Test public void getRelatedConfigurationByNameFromServiceInstanceNotFoundTest() throws Exception { - doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(Configurations.class), - any(AAIResourceUri.class)); - Optional actualConfiguration = - bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123"); - assertEquals(actualConfiguration, Optional.empty()); + assertEquals(Optional.empty(), bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("", "")); } @Test @@ -967,40 +808,47 @@ public class BBInputSetupUtilsTest { Configuration configuration = new Configuration(); configuration.setConfigurationId("id123"); expected.get().getConfiguration().add(configuration); + doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(Configurations.class), any(AAIResourceUri.class)); Optional actual = this.bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123"); - assertEquals(actual.get().getConfigurationId(), expected.get().getConfiguration().get(0).getConfigurationId()); + + assertTrue(actual.isPresent()); + assertEquals(expected.get().getConfiguration().get(0).getConfigurationId(), actual.get().getConfigurationId()); } @Test - public void existsAAIVfModuleGloballyByNameTest() throws Exception { + public void existsAAIVfModuleGloballyByNameTest() { AAIResourceUri expectedUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VF_MODULE).queryParam("vf-module-name", "testVfModule"); bbInputSetupUtils.existsAAIVfModuleGloballyByName("testVfModule"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); } @Test - public void existsAAIConfigurationGloballyByNameTest() throws Exception { + public void existsAAIConfigurationGloballyByNameTest() { AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.CONFIGURATION) .queryParam("configuration-name", "testConfig"); bbInputSetupUtils.existsAAIConfigurationGloballyByName("testConfig"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); } @Test - public void existsAAINetworksGloballyByNameTest() throws Exception { + public void existsAAINetworksGloballyByNameTest() { AAIResourceUri expectedUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", "testNetwork"); bbInputSetupUtils.existsAAINetworksGloballyByName("testNetwork"); + verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); } @Test - public void existsAAIVolumeGroupGloballyByNameTest() throws Exception { + public void existsAAIVolumeGroupGloballyByNameTest() { AAIResourceUri expectedUri = AAIUriFactory.createNodesUri(AAIObjectPlurals.VOLUME_GROUP) .queryParam("volume-group-name", "testVoumeGroup"); + bbInputSetupUtils.existsAAIVolumeGroupGloballyByName("testVoumeGroup"); verify(MOCK_aaiResourcesClient, times(1)).exists(expectedUri); } -- cgit 1.2.3-korg