diff options
author | alexanb <alexander.borovitzky@guest.telecomitalia.it> | 2020-09-30 21:02:44 +0300 |
---|---|---|
committer | alexanb <alexander.borovitzky@guest.telecomitalia.it> | 2020-10-01 12:22:55 +0300 |
commit | 289aa8a1de4c0b0c32bfbe13c4da48dc5da64795 (patch) | |
tree | 9a09c523b8c22e280ab29e8ffa223f862542dbb8 /bpmn/so-bpmn-infrastructure-common/src/test/groovy | |
parent | f2f9bec9aee2de5135226b24c70708a5df5ca525 (diff) |
Use Allotted Resources in Deallocate and Modify flows
Issue-ID: SO-3280
Change-Id: I5c325cb45e3230fc7d7e2190233c6ee91b7175b6
Signed-off-by: alexanb <alexander.borovitzky@guest.telecomitalia.it>
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/test/groovy')
3 files changed, 140 insertions, 88 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 6ca3937d68..9707dd2242 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 @@ -36,6 +36,7 @@ import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.T 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.bpmn.core.json.JsonUtils import org.onap.so.serviceinstancebeans.RequestDetails import javax.ws.rs.core.Response @@ -185,8 +186,10 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { def currentNSSI = [:] when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) + String nssiId = "5G-999" ServiceInstance nssi = new ServiceInstance() - nssi.setServiceInstanceId("5G-999") + nssi.setServiceInstanceId(nssiId) + currentNSSI.put("nssiId", nssiId) SliceProfiles sliceProfiles = new SliceProfiles() @@ -194,13 +197,49 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { slProfiles.add(new SliceProfile()) slProfiles.add(new SliceProfile()) - nssi.setSliceProfiles(sliceProfiles) + //nssi.setSliceProfiles(sliceProfiles) currentNSSI.put("nssi", nssi) - DoCommonCoreNSSI obj = new DoCommonCoreNSSI() - obj.getNSSIAssociatedProfiles(mockExecution) + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) + when(spy.getAAIClient()).thenReturn(client) + + AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + + AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json) + Relationships rsMock = mock(Relationships.class) + Optional<Relationships> orsMock = Optional.of(rsMock) + List<AAIResourceUri> allottedUris = new ArrayList<>() + AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id")) + allottedUris.add(allottedUri) + + when(client.get(nssiUri)).thenReturn(wrapperMock) + when(wrapperMock.getRelationships()).thenReturn(orsMock) + when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris) + + String sliceProfileInstanceId = "slice-profile-instance-id" + ServiceInstance sliceProfileInstance = new ServiceInstance() + sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId) + sliceProfileInstance.setServiceRole("slice-profile-instance") + + List<AAIResourceUri> sliceProfileInstanceUris = new ArrayList<>() + AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstance.getServiceInstanceId())) + sliceProfileInstanceUris.add(sliceProfileInstanceUri) + + Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance) + + when(client.get(allottedUri)).thenReturn(wrapperMock) + when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(sliceProfileInstanceUris) + when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt) + + + SliceProfiles sps = new SliceProfiles() + sps.getSliceProfile().addAll(slProfiles) + sliceProfileInstance.setSliceProfiles(sps) + + spy.getNSSIAssociatedProfiles(mockExecution) List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles") + assertTrue("sliceProfileInstanceUri not found in contect Map", currentNSSI.get("sliceProfileInstanceUri") != null) assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2)) } @@ -262,6 +301,20 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type"). + serviceInstance("slice-profile-instance-id")) + + String sliceProfileInstanceId = "slice-profile-instance-id" + ServiceInstance sliceProfileInstance = new ServiceInstance() + sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId) + sliceProfileInstance.setServiceRole("slice-profile-instance") + + Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance) + + when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt) + + currentNSSI.put("sliceProfileInstanceUri", sliceProfileInstanceUri) + DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) when(spy.getAAIClient()).thenReturn(client) @@ -284,13 +337,19 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { associatedProfiles.add(sliceProfile2) associatedProfiles.add(sliceProfile3) + SliceProfiles sps = new SliceProfiles() + sps.getSliceProfile().addAll(associatedProfiles) + sliceProfileInstance.setSliceProfiles(sps) + int sizeBefore = associatedProfiles.size() - doNothing().when(client).update(nssiUri, nssi) + doNothing().when(client).update(sliceProfileInstanceUri, sliceProfileInstance) + + doNothing().when(client). disconnect(nssiUri, sliceProfileInstanceUri) spy.removeSPAssociationWithNSSI(mockExecution) - assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1)) + assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("sliceProfileInstance")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1)) } @@ -300,30 +359,16 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - String globalSubscriberId = "global-id" - String subscriptionServiceType = "subscription-service-type" - String nssiId = "5G-999" + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type"). + serviceInstance("slice-profile-instance-id")) - when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) - when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) - - currentNSSI.put("nssiId", nssiId) - - String theSNSSAI = "theS-NSSAI" - - SliceProfile sliceProfile = new SliceProfile() - sliceProfile.setSNssai(theSNSSAI) - sliceProfile.setProfileId("prof-id") - - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - - currentNSSI.put("sliceProfileS-NSSAI", sliceProfile) + currentNSSI.put("sliceProfileInstanceUri", uri) DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class) when(spy.getAAIClient()).thenReturn(client) - doNothing().when(client).delete(nssiUri) + doNothing().when(client).delete(uri) spy.deleteSliceProfileInstance(mockExecution) @@ -426,8 +471,13 @@ class DoCommonCoreNSSITest extends MsoGroovyTest { prepareProject(cloudRegionAAIUri) - String requestDetails = spy.prepareRequestDetails(mockExecution) + String prepareRequestDetailsResponse = spy.prepareRequestDetails(mockExecution) + + JsonUtils jsonUtil = new JsonUtils() + String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode") + String errMsg = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage") + assertTrue(errMsg, errorCode == null || errorCode.isEmpty()) } 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 c6e874591f..26b96a0a4a 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 @@ -26,6 +26,7 @@ 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 @@ -153,31 +154,6 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { @Test - void testGetNSSIAssociatedProfiles() { - def currentNSSI = [:] - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - - ServiceInstance nssi = new ServiceInstance() - nssi.setServiceInstanceId("5G-999") - - SliceProfiles sliceProfiles = new SliceProfiles() - - List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile() - slProfiles.add(new SliceProfile()) - slProfiles.add(new SliceProfile()) - - nssi.setSliceProfiles(sliceProfiles) - currentNSSI.put("nssi", nssi) - - DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI() - obj.getNSSIAssociatedProfiles(mockExecution) - - List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles") - assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2)) - } - - - @Test void testCalculateSNSSAI() { def currentNSSI = [:] when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) @@ -232,9 +208,30 @@ class DoDeallocateCoreNSSITest extends MsoGroovyTest { currentNSSI.put("nsiId", nsiId) AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + + ServiceInstance nssi = new ServiceInstance() + nssi.setServiceInstanceId(nssiId) + + AllottedResources allottedResources = new AllottedResources() + AllottedResource allottedResource = new AllottedResource() + allottedResource.setId(UUID.randomUUID().toString()) + allottedResources.getAllottedResource().add(allottedResource) + nssi.setAllottedResources(allottedResources) + + currentNSSI.put("nssi", nssi) + AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nsiId)) - doNothing().when(client).disconnect(nssiUri, nsiUri) + doNothing().when(client).update(nssiUri, nssi) + + String globalSubscriberId = "globalSubscriberId" + String subscriptionServiceType = "subscription-service-type" + when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) + when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) + + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).allottedResource(allottedResource.getId())) + + doNothing().when(client).disconnect(nsiUri, allottedResourceUri) spy.removeNSSIAssociationWithNSI(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 32c4c1aa57..ac6f897dfa 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 @@ -23,6 +23,8 @@ package org.onap.so.bpmn.infrastructure.scripts import com.fasterxml.jackson.databind.ObjectMapper import org.junit.Before import org.junit.Test +import org.mockito.Mockito +import org.onap.aai.domain.yang.v19.AllottedResource import org.onap.aai.domain.yang.v19.ServiceInstance import org.onap.aai.domain.yang.v19.SliceProfile import org.onap.aai.domain.yang.v19.SliceProfiles @@ -46,31 +48,6 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { @Test - void testGetNSSIAssociatedProfiles() { - def currentNSSI = [:] - when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) - - ServiceInstance nssi = new ServiceInstance() - nssi.setServiceInstanceId("5G-999") - - SliceProfiles sliceProfiles = new SliceProfiles() - - List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile() - slProfiles.add(new SliceProfile()) - slProfiles.add(new SliceProfile()) - - nssi.setSliceProfiles(sliceProfiles) - currentNSSI.put("nssi", nssi) - - DoModifyCoreNSSI obj = new DoModifyCoreNSSI() - obj.getNSSIAssociatedProfiles(mockExecution) - - List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles") - assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2)) - } - - - @Test void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() { def currentNSSI = [:] when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI) @@ -154,9 +131,15 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { String sliceProfileId = "sliceProfileId" - currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"],\"expDataRateUL\":\"12\"}") + currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"],\"expDataRateUL\":\"12\",\"expDataRateDL\":\"5\"," + + "\"activityFactor\":\"2\",\"resourceSharingLevel\":\"resource-sharing-level\",\"uEMobilityLevel\":\"ue-mobility-level\",\"coverageAreaTAList\":\"coverage-area-ta-list\"," + + "\"maxNumberofUEs\":\"10000\",\"latency\":\"7\"}") currentNSSI.put("sliceProfileId", sliceProfileId) + List<String> snssais = new ArrayList<>() + snssais.add("s-nssai") + currentNSSI.put("S-NSSAIs", snssais) + DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class) when(spy.getAAIClient()).thenReturn(client) @@ -169,17 +152,21 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { currentNSSI.put("nssiId", nssiId) - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileId)) + ServiceInstance sliceProfileInstance = new ServiceInstance() + sliceProfileInstance.setServiceInstanceId(UUID.randomUUID().toString()) + + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType). + serviceInstance(sliceProfileInstance.getServiceInstanceId())) SliceProfile sliceProfile = new SliceProfile() sliceProfile.setProfileId(sliceProfileId) - doNothing().when(client).create(uri, sliceProfile) + doNothing().when(client).create(uri, sliceProfileInstance) spy.createSliceProfileInstance(mockExecution) - assertNotNull("Slice Profile doesn't exist", currentNSSI.get("createdSliceProfile")) - assertTrue("Unexpected Slice Profile Id", ((SliceProfile)currentNSSI.get("createdSliceProfile")).getProfileId().equals(sliceProfile.getProfileId())) + assertTrue("Slice Profile Instance Id doesn't exist", (currentNSSI.get("createdSliceProfileInstanceId")) != null) + } @@ -202,8 +189,19 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { String globalSubscriberId = "globalSubscriberId" String subscriptionServiceType = "subscriptionServiceType" - AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) - AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileId)) + String sliceProfileInstanceId = "slice-rpofile-instance-id" + currentNSSI.put("createdSliceProfileInstanceId", sliceProfileInstanceId) + + AllottedResource allottedResource = new AllottedResource() + + String allottedResourceId = UUID.randomUUID().toString() + + allottedResource.setId(allottedResourceId) + + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstanceId).allottedResource(allottedResourceId)) + doNothing().when(client).create(allottedResourceUri, allottedResource) + + currentNSSI.put("allottedResourceUri", allottedResourceUri) when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId) when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType) @@ -213,19 +211,26 @@ class DoModifyCoreNSSITest extends MsoGroovyTest { SliceProfile sliceProfile = new SliceProfile() currentNSSI.put("createdSliceProfile", sliceProfile) + AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstanceId)) + + AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId)) + + ServiceInstance sliceProfileInstance = new ServiceInstance() + sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId) + Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance) + + when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt) + doNothing().when(client).update(sliceProfileInstanceUri, sliceProfileInstance) + ServiceInstance nssi = new ServiceInstance() nssi.setServiceInstanceId(nssiId) nssi.setSliceProfiles(new SliceProfiles()) currentNSSI.put("nssi", nssi) - int sizeBelore = nssi.getSliceProfiles().getSliceProfile().size() - - doNothing().when(client).update(nssiUri, nssi) - doNothing().when(client).connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO) + doNothing().when(client).connect(nssiUri, sliceProfileInstanceUri, AAIEdgeLabel.USES) spy.associateSliceProfileInstanceWithNSSI(mockExecution) - assertTrue("Wrong number of associated slice profiles", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBelore + 1)) } } |