+
+ @Test
+ void testGetNSSIAssociatedProfilesCreateSLiceProfileEmptySLiceProfiles() {
+ invokeGetNSSIAssociatedProfiles("true", true)
+ }
+
+ @Test
+ void testGetNSSIAssociatedProfilesCreateSLiceProfileNonEmptySliceProfiles() {
+ invokeGetNSSIAssociatedProfiles("true", false)
+ }
+
+ @Test
+ void testGetNSSIAssociatedProfilesDeleteSLiceProfile() {
+ invokeGetNSSIAssociatedProfiles("false", false)
+ }
+
+ void invokeGetNSSIAssociatedProfiles(String isCreateSliceProfileInstance, boolean isEmptySliceProfiles) {
+ def currentNSSI = [:]
+ when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
+
+ String globalSubscriberId = "5GCustomer"
+ String subscriptionServiceType = "5G"
+ when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId)
+ when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType)
+
+ when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn(isCreateSliceProfileInstance)
+
+ String nssiId = "5G-999"
+ ServiceInstance nssi = new ServiceInstance()
+ nssi.setServiceInstanceId(nssiId)
+ currentNSSI.put("nssiId", nssiId)
+
+ String theSLiceProfileId = "slice-profile-id"
+ currentNSSI.put("sliceProfileId", theSLiceProfileId)
+
+ SliceProfiles sliceProfiles = new SliceProfiles()
+
+ List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
+
+ if(!isEmptySliceProfiles) {
+ SliceProfile sp1 = new SliceProfile()
+ sp1.setProfileId(theSLiceProfileId)
+ slProfiles.add(sp1)
+ slProfiles.add(new SliceProfile())
+ }
+
+ //nssi.setSliceProfiles(sliceProfiles)
+ currentNSSI.put("nssi", nssi)
+
+ DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.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)
+
+ Optional<SliceProfiles> sliceProfilesOpt = Optional.of(sps)
+
+ org.onap.aaiclient.client.generated.fluentbuilders.SliceProfiles sliceProfilesType =
+ AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstance.getServiceInstanceId()).sliceProfiles()
+
+ def sliceProfilesUri = AAIUriFactory.createResourceUri(sliceProfilesType)
+ when(client.exists(sliceProfilesUri)).thenReturn(true)
+
+ when(client.get(sliceProfilesUri)).thenReturn(wrapperMock)
+
+ when(wrapperMock.asBean(SliceProfiles.class)).thenReturn(sliceProfilesOpt)
+
+ spy.getNSSIAssociatedProfiles(mockExecution)
+
+ List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
+ int expectedSize = sps.getSliceProfile().size()
+
+ if(!isEmptySliceProfiles) {
+ 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() == expectedSize))
+ }
+
+