diff options
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/test')
3 files changed, 235 insertions, 78 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy index 2c943ffc7c..6ca3937d68 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCommonCoreNSSITest.groovy @@ -24,19 +24,23 @@ import com.fasterxml.jackson.databind.ObjectMapper import org.junit.Before import org.junit.Test import org.mockito.Mockito -import org.onap.aai.domain.yang.* -import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aai.domain.yang.v19.* import org.onap.aaiclient.client.aai.entities.AAIResultWrapper import org.onap.aaiclient.client.aai.entities.Relationships import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory +import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types -import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri +import org.onap.so.bpmn.common.scripts.ExternalAPIUtil +import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory import org.onap.so.bpmn.common.scripts.MsoGroovyTest import org.onap.so.serviceinstancebeans.RequestDetails +import javax.ws.rs.core.Response +import java.time.Instant + import static org.junit.Assert.assertNotNull import static org.junit.Assert.assertTrue import static org.mockito.Mockito.* @@ -50,13 +54,32 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { @Test void testPreProcessRequest() { - def currentNSSI = [:] - currentNSSI.put("nssiId","5G-999") - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + + String nssiId = "5G-999" + when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId) + + String nsiId = "5G-777" + when(mockExecution.getVariable("nsiId")).thenReturn(nsiId) + + String snssai = "S-NSSAI" + String snssaiList = "[ \"${snssai}\" ]" + String sliceProfileId = "slice-profile-id" + String sliceParams = "{\n" + + "\"sliceProfile\":{\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}}\n" + + "}" + when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams) DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI() dcnssi.preProcessRequest(mockExecution) - Mockito.verify(mockExecution,times(1)).getVariable("currentNSSI") + + def currentNSSI = [:] + currentNSSI.put("nssiId", nssiId) + currentNSSI.put("nsiId", nsiId) + currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"]}") + currentNSSI.put("S-NSSAI", snssai) + currentNSSI.put("sliceProfileId", sliceProfileId) + Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI) + } @@ -90,13 +113,13 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { Relationships rsMock = mock(Relationships.class) Optional<Relationships> orsMock = Optional.of(rsMock) List<AAIResourceUri> arus = new ArrayList<>() - AAIResourceUri aru = new ServiceInstanceUri(networkServiceInstanceUri) + AAIResourceUri aru = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId())) arus.add(aru) when(client.get(nssiUri)).thenReturn(wrapperMock) when(wrapperMock.getRelationships()).thenReturn(orsMock) - when(rsMockgetRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(arus) when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt) spy.getNetworkServiceInstance(mockExecution) @@ -145,7 +168,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock) when(wrapperMock.getRelationships()).thenReturn(orsMock) - when(rsMockgetRelatedUris(Types.GENERIC_VNF)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.GENERIC_VNF)).thenReturn(arus) when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt) spy.getConstituteVNFFromNetworkServiceInst(mockExecution) @@ -190,13 +213,9 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { networkServiceInstance.setServiceInstanceId("NS-777") networkServiceInstance.setServiceRole("Network Service") - GenericVnf constituteVnf = new GenericVnf() - constituteVnf.setVnfId("VNF-1") - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) currentNSSI.put("networkServiceInstance", networkServiceInstance) - currentNSSI.put("constituteVnf", constituteVnf) when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088") when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey") @@ -211,7 +230,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse) - String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId()) + String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId()) String callPUTServiceInstanceResponse = "put" @@ -282,11 +301,12 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) String globalSubscriberId = "global-id" - String serviceType = "service" + String subscriptionServiceType = "subscription-service-type" String nssiId = "5G-999" - currentNSSI.put("globalSubscriberId", globalSubscriberId) - currentNSSI.put("serviceType", serviceType) + when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) + currentNSSI.put("nssiId", nssiId) String theSNSSAI = "theS-NSSAI" @@ -311,26 +331,6 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { @Test - void testUpdateServiceOperationStatus() { - def currentNSSI = [:] - - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - - String nssiId = "5G-999" - - currentNSSI.put("nssiId", nssiId) - currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId") - currentNSSI.put("operationId", "operationId") - currentNSSI.put("operationType", "operationType") - - DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) - - spy.updateServiceOperationStatus(mockExecution) - - } - - - @Test void testPrepareRequestDetails() { def currentNSSI = [:] @@ -431,6 +431,124 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { } + @Test + void testPrepareFailedOperationStatusUpdate() { + def currentNSSI = [:] + + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + when(mockExecution.getVariable("jobId")).thenReturn("job-id") + when(mockExecution.getVariable("operationType")).thenReturn("operation-type") + + String nssiId = "5G-999" + String nsiId = "5G-777" + + currentNSSI.put("nssiId", nssiId) + currentNSSI.put("nsiId", nsiId) + currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId") + currentNSSI.put("operationId", "operationId") + currentNSSI.put("operationType", "operationType") + + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) + + spy.prepareFailedOperationStatusUpdate(mockExecution) + } + + + @Test + void testPrepareUpdateResourceOperationStatus() { + def currentNSSI = [:] + + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + when(mockExecution.getVariable("jobId")).thenReturn("job-id") + when(mockExecution.getVariable("operationType")).thenReturn("operation-type") + + String nssiId = "5G-999" + String nsiId = "5G-777" + + currentNSSI.put("nssiId", nssiId) + currentNSSI.put("nsiId", nsiId) + currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId") + currentNSSI.put("operationId", "operationId") + currentNSSI.put("operationType", "operationType") + + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) + + spy.prepareUpdateResourceOperationStatus(mockExecution) + + } + + + @Test + void testGetPUTServiceInstanceProgressAcknowledged() { + + executePUTServiceInstanceProgress("ACKNOWLEDGED") + Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing") + } + + + @Test + void testGetPUTServiceInstanceProgressInProgress() { + + executePUTServiceInstanceProgress("INPROGRESS") + Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing") + } + + + @Test + void testGetPUTServiceInstanceProgressCompleted() { + + executePUTServiceInstanceProgress("COMPLETED") + Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "completed") + } + + + @Test + void testTimeDelay() { + DoCommonCoreNSSI obj = spy(DoCommonCoreNSSI.class) + + long before = Instant.now().toEpochMilli() + obj.timeDelay(mockExecution) + + long after = Instant.now().toEpochMilli() + + long delay = 5L + + assertTrue(String.format("Didn't wait %d sec", delay), ((after - before) >= delay)) + } + + + void executePUTServiceInstanceProgress(String state) { + + def currentNSSI = [:] + + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + + String url = "http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/5G-777" + + currentNSSI.put("putServiceInstanceURL", url) + + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) + + ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class) + when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock) + + ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class) + + when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock) + + Response responseMock = mock(Response.class) + when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock) + + when(responseMock.getStatus()).thenReturn(200) + + String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}" + when(responseMock.readEntity(String.class)).thenReturn(entity) + + spy.getPUTServiceInstanceProgress(mockExecution) + + } + + void prepareProject(AAIResourceUri cloudRegionAAIUri) { Project project = new Project() project.setProjectName("project-name") @@ -446,7 +564,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri) arus.add(aru) - when(rsMockgetRelatedUris(Types.PROJECT)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.PROJECT)).thenReturn(arus) Optional<Project> projectOpt = Optional.of(project) @@ -472,7 +590,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri) arus.add(aru) - when(rsMockgetRelatedUris(Types.OWNING_ENTITY)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.OWNING_ENTITY)).thenReturn(arus) Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity) @@ -494,7 +612,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri) arus.add(aru) - when(rsMockgetRelatedUris(Types.CLOUD_REGION)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.CLOUD_REGION)).thenReturn(arus) CloudRegion cloudRegion = new CloudRegion() cloudRegion.setCloudRegionId("cloud-region-id") @@ -527,7 +645,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { arus.add(serviceSubscriptionUri) - when(rsMockgetRelatedUris(Types.SERVICE_SUBSCRIPTION)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.SERVICE_SUBSCRIPTION)).thenReturn(arus) ServiceSubscription serviceSubscription = new ServiceSubscription() serviceSubscription.setServiceType("service-type") @@ -537,7 +655,7 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock) - when(rsMockgetRelatedUris(Types.CUSTOMER)).thenReturn(arus) + when(rsMock.getRelatedUris(Types.CUSTOMER)).thenReturn(arus) Customer customer = new Customer() customer.setSubscriberName("subscriber-name") diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy index eae788666d..c6e874591f 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy @@ -20,19 +20,19 @@ package org.onap.so.bpmn.infrastructure.scripts - import org.junit.Before import org.junit.Test -import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aai.domain.yang.SliceProfile -import org.onap.aai.domain.yang.SliceProfiles -import org.onap.aaiclient.client.aai.AAIObjectType +import org.mockito.Mockito +import org.onap.aai.domain.yang.v19.* import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory -import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types +import org.onap.so.bpmn.common.scripts.ExternalAPIUtil +import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory import org.onap.so.bpmn.common.scripts.MsoGroovyTest +import javax.ws.rs.core.Response + import static org.junit.Assert.assertNotNull import static org.junit.Assert.assertTrue import static org.mockito.Mockito.* @@ -263,4 +263,56 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { } + @Test + void testDeleteServiceOrderProgressAcknowledged() { + + executeDeleteServiceOrderProgress("ACKNOWLEDGED") + Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "processing") + } + + @Test + void testDeleteServiceOrderProgressInProgress() { + + executeDeleteServiceOrderProgress("INPROGRESS") + Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "processing") + } + + + @Test + void testDeleteServiceOrderProgressCompleted() { + + executeDeleteServiceOrderProgress("COMPLETED") + Mockito.verify(mockExecution,times(1)).setVariable("deleteStatus", "completed") + } + + + void executeDeleteServiceOrderProgress(String state) { + def currentNSSI = [:] + + when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + + String url = "http://nbi.onap:8088/api/v4/serviceOrder/NS-777" + + currentNSSI.put("deleteServiceOrderURL", url) + + DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class) + + ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class) + when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock) + + ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class) + + when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock) + + Response responseMock = mock(Response.class) + when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock) + + when(responseMock.getStatus()).thenReturn(200) + + String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}" + when(responseMock.readEntity(String.class)).thenReturn(entity) + + spy.getDeleteServiceOrderProgress(mockExecution) + } + } diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy index bbc237f1f9..32c4c1aa57 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoModifyCoreNSSITest.groovy @@ -20,13 +20,12 @@ package org.onap.so.bpmn.infrastructure.scripts - +import com.fasterxml.jackson.databind.ObjectMapper import org.junit.Before import org.junit.Test -import org.onap.aai.domain.yang.ServiceInstance -import org.onap.aai.domain.yang.SliceProfile -import org.onap.aai.domain.yang.SliceProfiles -import org.onap.aaiclient.client.aai.AAIObjectType +import org.onap.aai.domain.yang.v19.ServiceInstance +import org.onap.aai.domain.yang.v19.SliceProfile +import org.onap.aai.domain.yang.v19.SliceProfiles import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory @@ -155,34 +154,22 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { String sliceProfileId = "sliceProfileId" - when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId) - - Map<String, Object> sliceProfileMap = new HashMap<>() - sliceProfileMap.put("expDataRateUL", "12") - sliceProfileMap.put("expDataRateDL", 5) - sliceProfileMap.put("activityFactor", 2) - sliceProfileMap.put("latency", 10) - - when(mockExecution.getVariable("sliceProfileCn")).thenReturn(sliceProfileMap) - - - Map<String, Object> serviceProfileMap = new HashMap<>() - when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfileMap) - + currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"],\"expDataRateUL\":\"12\"}") + currentNSSI.put("sliceProfileId", sliceProfileId) DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class) when(spy.getAAIClient()).thenReturn(client) String globalSubscriberId = "globalSubscriberId" - String serviceType = "serviceType" + String subscriptionServiceType = "subscription-service-type" String nssiId = "nssiId" - currentNSSI.put("globalSubscriberId", globalSubscriberId) - currentNSSI.put("serviceType", serviceType) + when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) + currentNSSI.put("nssiId", nssiId) - currentNSSI.put("sliceProfileId", sliceProfileId) - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(nssiId).sliceProfile(sliceProfileId)) + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileId)) SliceProfile sliceProfile = new SliceProfile() sliceProfile.setProfileId(sliceProfileId) @@ -213,13 +200,14 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { currentNSSI.put("nssiId", nssiId) String globalSubscriberId = "globalSubscriberId" - String serviceType = "serviceType" + String subscriptionServiceType = "subscriptionServiceType" AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(nssiId).sliceProfile(sliceProfileId)) + AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileId)) + + when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) - currentNSSI.put("globalSubscriberId", globalSubscriberId) - currentNSSI.put("serviceType", serviceType) currentNSSI.put("sliceProfileId", sliceProfileId) SliceProfile sliceProfile = new SliceProfile() @@ -240,5 +228,4 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { assertTrue("Wrong number of associated slice profiles", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBelore + 1)) } - } |