2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 TIM
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.camunda.bpm.engine.ProcessEngineServices
25 import org.camunda.bpm.engine.RepositoryService
26 import org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl
27 import org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope
28 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
29 import org.camunda.bpm.engine.repository.ProcessDefinition
31 import org.junit.rules.ExpectedException
32 import org.mockito.invocation.InvocationOnMock
33 import org.mockito.stubbing.Answer
34 import org.onap.aai.domain.yang.CloudRegion
35 import org.onap.aai.domain.yang.Customer
36 import org.onap.aai.domain.yang.GenericVnf
37 import org.onap.aai.domain.yang.ModelVer
38 import org.onap.aai.domain.yang.OwningEntity
39 import org.onap.aai.domain.yang.Project
40 import org.onap.aai.domain.yang.Relationship
41 import org.onap.aai.domain.yang.RelationshipList
42 import org.onap.aai.domain.yang.ServiceSubscription
43 import org.onap.aai.domain.yang.SliceProfile
44 import org.onap.aai.domain.yang.SliceProfiles
45 import org.onap.aai.domain.yang.Tenant
46 import org.onap.aai.domain.yang.Tenants
47 import org.onap.aai.domain.yang.VfModule
48 import org.onap.aai.domain.yang.VfModules
49 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
50 import org.onap.aaiclient.client.aai.entities.Relationships
51 import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri
52 import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri
53 import org.onap.logging.filter.base.ONAPComponents
54 import org.onap.so.beans.nsmf.NssiResponse
55 import org.onap.so.bpmn.common.scripts.ExceptionUtil
56 import org.onap.so.bpmn.common.scripts.MsoUtils
57 import org.onap.so.bpmn.mock.FileUtil
58 import org.onap.so.client.HttpClient
59 import org.onap.so.client.HttpClientFactory
60 import org.onap.so.serviceinstancebeans.RequestDetails
61 import org.onap.so.utils.CryptoUtils
63 import javax.ws.rs.core.Response
65 import static org.junit.Assert.*;
66 import org.junit.Before
68 import org.mockito.Mockito
69 import org.onap.aai.domain.yang.ServiceInstance
70 import org.onap.aaiclient.client.aai.AAIObjectType
71 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
72 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
73 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
75 import static org.mockito.ArgumentMatchers.anyDouble
76 import static org.mockito.ArgumentMatchers.anyInt
77 import static org.mockito.ArgumentMatchers.anyString
78 import static org.mockito.ArgumentMatchers.eq
79 import static org.mockito.Mockito.doNothing
80 import static org.mockito.Mockito.doReturn
81 import static org.mockito.Mockito.doThrow
82 import static org.mockito.Mockito.mock
83 import static org.mockito.Mockito.mock
84 import static org.mockito.Mockito.mock
85 import static org.mockito.Mockito.spy
86 import static org.mockito.Mockito.times
87 import static org.mockito.Mockito.verify
88 import static org.mockito.Mockito.when
90 class DoDeallocateCoreNSSITest extends MsoGroovyTest {
93 void init() throws IOException {
94 super.init("DoDeallocateNSSITest")
99 void testPreProcessRequest() {
100 def currentNSSI = [:]
101 currentNSSI.put("nssiId","5G-999")
102 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
104 DoDeallocateCoreNSSI dcnssi = new DoDeallocateCoreNSSI()
105 dcnssi.preProcessRequest(mockExecution)
106 Mockito.verify(mockExecution,times(1)).getVariable("currentNSSI")
111 void testExecuteTerminateNSSIQuery() {
112 HttpClientFactory httpClientFactoryMock
113 HttpClient httpClientMock
115 def currentNSSI = [:]
116 currentNSSI.put("nssiId","5G-999")
118 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
120 when(mockExecution.getVariable("mso.oof.endpoint")).thenReturn("http://oof.onap:8088")
121 when(mockExecution.getVariable("mso.oof.auth")).thenReturn("mso.oof.auth")
122 when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
123 when(mockExecution.getVariable("mso-request-id")).thenReturn("mso-request-id")
125 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
126 when(spy.getAAIClient()).thenReturn(client)
128 when(spy.encryptBasicAuth("mso.oof.auth", "mso.msoKey")).thenReturn("auth-value")
130 String authHeaderResponse = "auth-header"
132 /* String authHeaderResponse = "{\n" +
133 " \"errorCode\": \"401\",\n" +
134 " \"errorMessage\": \"Bad request\"\n" +
137 when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
139 String urlString = "http://oof.onap:8088"
141 String httpRequest = "{\n" +
142 " \"type\": \"NSSI\",\n" +
143 " \"NxIId\": \"5G-999\",\n" +
144 " \"requestInfo\": {\n" +
145 " \"transactionId\": \"mso-request-id\",\n" +
146 " \"requestId\": \"mso-request-id\",\n" +
147 " \"sourceId\": \"so\",\n" +
151 boolean terminateResponse = true
153 String oofResponse = "{\n" +
154 " \"requestId\": \"mso-request-id\",\n" +
155 " \"transactionId\": \"mso-request-id\",\n" +
156 " \"statusMessage\": \"\",\n" +
157 " \"requestStatus\": \"accepted\",\n" +
158 " \"terminateResponse\": \"${terminateResponse}\",\n" +
159 " \"reason\": \"\"\n" +
162 String oofCallResponse = oofResponse
164 /* String oofCallResponse = "{\n" +
165 " \"errorCode\": \"401\",\n" +
166 " \"errorMessage\": \"Exception during the call\"\n" +
169 when(spy.callOOF(urlString, "auth-header", httpRequest)).thenReturn(oofCallResponse)
171 spy.executeTerminateNSSIQuery(mockExecution)
173 verify(mockExecution).setVariable("isTerminateNSSI", terminateResponse)
179 void testGetNetworkServiceInstance() {
180 def currentNSSI = [:]
181 currentNSSI.put("nssiId","5G-999")
183 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
185 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5G-999")
186 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "NS-777")
188 ServiceInstance nssi = new ServiceInstance()
189 nssi.setServiceInstanceId("5G-999")
191 ServiceInstance networkServiceInstance = new ServiceInstance()
192 networkServiceInstance.setServiceInstanceId("NS-777")
193 networkServiceInstance.setServiceRole("Network Service")
195 Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
196 Optional<ServiceInstance> networkServiceInstaneOpt = Optional.of(networkServiceInstance)
198 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
199 when(spy.getAAIClient()).thenReturn(client)
201 when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)
203 //String json = FileUtil.readResourceFile("__files/AAI/ServiceInstanceWithAR.json")
204 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
205 Relationships rsMock = mock(Relationships.class)
206 Optional<Relationships> orsMock = Optional.of(rsMock)
207 List<AAIResourceUri> arus = new ArrayList<>()
208 AAIResourceUri aru = new ServiceInstanceUri(networkServiceInstanceUri)
211 when(client.get(nssiUri)).thenReturn(wrapperMock)
212 when(wrapperMock.getRelationships()).thenReturn(orsMock)
214 when(rsMock.getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)).thenReturn(arus)
215 when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt)
217 spy.getNetworkServiceInstance(mockExecution)
219 assertTrue("Either NSSI doesn't exist or unexpected NSSI Service Instance ID",
220 currentNSSI.get("nssi") != null && ((ServiceInstance)currentNSSI.get("nssi")).getServiceInstanceId().equals(nssi.getServiceInstanceId()))
222 assertTrue("Either Network Service Instance doesn't exist or unexpected Network Service Instance ID",
223 currentNSSI.get("networkServiceInstance") != null && ((ServiceInstance)currentNSSI.get("networkServiceInstance")).getServiceInstanceId().equals(networkServiceInstance.getServiceInstanceId()))
225 assertNotNull("networkServiceInstanceUri doesn't exist", currentNSSI.get("networkServiceInstanceUri"))
230 void testDeleteServiceOrder() {
231 def currentNSSI = [:]
232 currentNSSI.put("nssiId","5G-999")
234 ServiceInstance networkServiceInstance = new ServiceInstance()
235 networkServiceInstance.setServiceInstanceId("NS-777")
236 networkServiceInstance.setServiceRole("Network Service")
238 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
240 currentNSSI.put("networkServiceInstance", networkServiceInstance)
242 when(mockExecution.getVariable("nbi.endpoint.url")).thenReturn("http://nbi.onap:8088")
243 when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
244 when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
246 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
247 when(spy.getAAIClient()).thenReturn(client)
249 when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
251 String authHeaderResponse = "auth-header"
253 /* String authHeaderResponse = "{\n" +
254 " \"errorCode\": \"401\",\n" +
255 " \"errorMessage\": \"Bad request\"\n" +
258 when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
260 String urlString = String.format("http://nbi.onap:8088/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
262 String callDeleteServiceOrderResponse = "deleted"
264 when(spy.callDeleteServiceOrder(mockExecution, urlString, "auth-header")).thenReturn(callDeleteServiceOrderResponse)
266 spy.deleteServiceOrder(mockExecution)
272 void getConstituteVNFFromNetworkServiceInst() {
273 def currentNSSI = [:]
275 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
277 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
278 when(spy.getAAIClient()).thenReturn(client)
280 ServiceInstance networkServiceInstance = new ServiceInstance()
281 networkServiceInstance.setServiceInstanceId("NS-777")
282 networkServiceInstance.setServiceRole("Network Service")
284 GenericVnf genericVNF = new GenericVnf()
285 genericVNF.setVnfId("VNF-1")
287 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, networkServiceInstance.getServiceInstanceId())
289 Optional<GenericVnf> genericVnfOpt = Optional.of(genericVNF)
290 AAIResourceUri genericVNFUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVNF.getVnfId())
292 currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
293 currentNSSI.put("networkServiceInstance", networkServiceInstance)
295 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
296 Relationships rsMock = mock(Relationships.class)
297 Optional<Relationships> orsMock = Optional.of(rsMock)
298 List<AAIResourceUri> arus = new ArrayList<>()
299 AAIResourceUri aru = new AAISimpleUri(genericVNFUri)
302 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
303 when(wrapperMock.getRelationships()).thenReturn(orsMock)
305 when(rsMock.getRelatedAAIUris(AAIObjectType.GENERIC_VNF)).thenReturn(arus)
306 when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt)
308 spy.getConstituteVNFFromNetworkServiceInst(mockExecution)
310 assertNotNull("constituteVnfUri doesn't exist", currentNSSI.get("constituteVnfUri"))
312 assertTrue("Either Constitute VNF doesn't exist or unexpected VNF ID",
313 currentNSSI.get("constituteVnf") != null && ((GenericVnf)currentNSSI.get("constituteVnf")).getVnfId().equals(genericVNF.getVnfId()))
318 void testGetNSSIAssociatedProfiles() {
319 def currentNSSI = [:]
320 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
322 ServiceInstance nssi = new ServiceInstance()
323 nssi.setServiceInstanceId("5G-999")
325 SliceProfiles sliceProfiles = new SliceProfiles()
327 List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
328 slProfiles.add(new SliceProfile())
329 slProfiles.add(new SliceProfile())
331 nssi.setSliceProfiles(sliceProfiles)
332 currentNSSI.put("nssi", nssi)
334 DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
335 obj.getNSSIAssociatedProfiles(mockExecution)
337 List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
338 assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
343 void testCalculateSNSSAI() {
344 def currentNSSI = [:]
345 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
347 String theSNSSAI = "theS-NSSAI"
349 currentNSSI.put("S-NSSAI", theSNSSAI)
351 List<SliceProfile> associatedProfiles = new ArrayList<>()
352 SliceProfile sliceProfile1 = new SliceProfile()
353 sliceProfile1.setSNssai("snssai1")
355 SliceProfile sliceProfile2 = new SliceProfile()
356 sliceProfile2.setSNssai(theSNSSAI)
358 SliceProfile sliceProfile3 = new SliceProfile()
359 sliceProfile3.setSNssai("snssai3")
361 associatedProfiles.add(sliceProfile1)
362 associatedProfiles.add(sliceProfile2)
363 associatedProfiles.add(sliceProfile3)
365 int sizeBefore = associatedProfiles.size()
367 currentNSSI.put("associatedProfiles", associatedProfiles)
369 DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
370 obj.calculateSNSSAI(mockExecution)
372 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
373 SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
375 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
376 assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
377 assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
382 void testInvokePUTServiceInstance() {
383 def currentNSSI = [:]
385 ServiceInstance networkServiceInstance = new ServiceInstance()
386 networkServiceInstance.setServiceInstanceId("NS-777")
387 networkServiceInstance.setServiceRole("Network Service")
389 GenericVnf constituteVnf = new GenericVnf()
390 constituteVnf.setVnfId("VNF-1")
392 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
394 currentNSSI.put("networkServiceInstance", networkServiceInstance)
395 currentNSSI.put("constituteVnf", constituteVnf)
397 when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
398 when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
399 when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
401 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
402 when(spy.getAAIClient()).thenReturn(client)
404 when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
406 String authHeaderResponse = "auth-header"
408 when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
410 String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())
412 String callPUTServiceInstanceResponse = "put"
414 RequestDetails requestDetails = new RequestDetails()
415 ObjectMapper mapper = new ObjectMapper()
416 String requestDetailsStr = mapper.writeValueAsString(requestDetails)
418 when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
420 when(spy.callPUTServiceInstance(urlString, "auth-header", requestDetailsStr)).thenReturn(callPUTServiceInstanceResponse)
422 spy.invokePUTServiceInstance(mockExecution)
427 void testRemoveNSSIAssociationWithNSI() {
428 def currentNSSI = [:]
430 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
432 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
434 when(spy.getAAIClient()).thenReturn(client)
436 String nssiId = "5G-999"
437 String nsiId = "5G-99"
438 currentNSSI.put("nssiId", nssiId)
439 currentNSSI.put("nsiId", nsiId)
441 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
442 AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nsiId)
444 doNothing().when(client).disconnect(nssiUri, nsiUri)
446 spy.removeNSSIAssociationWithNSI(mockExecution)
452 void testRemoveSPAssociationWithNSSI() {
453 def currentNSSI = [:]
455 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
457 String nssiId = "5G-999"
458 currentNSSI.put("nssiId", nssiId)
459 ServiceInstance nssi = new ServiceInstance()
460 nssi.setServiceInstanceId(nssiId)
461 nssi.setSliceProfiles(new SliceProfiles())
463 currentNSSI.put("nssi", nssi)
465 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
467 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
469 when(spy.getAAIClient()).thenReturn(client)
471 String theSNSSAI = "theS-NSSAI"
472 currentNSSI.put("S-NSSAI", theSNSSAI)
474 List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
476 SliceProfile sliceProfile1 = new SliceProfile()
477 sliceProfile1.setSNssai("snssai1")
479 SliceProfile sliceProfile2 = new SliceProfile()
480 sliceProfile2.setSNssai(theSNSSAI)
482 SliceProfile sliceProfile3 = new SliceProfile()
483 sliceProfile3.setSNssai("snssai3")
485 associatedProfiles.add(sliceProfile1)
486 associatedProfiles.add(sliceProfile2)
487 associatedProfiles.add(sliceProfile3)
489 int sizeBefore = associatedProfiles.size()
491 doNothing().when(client).update(nssiUri, nssi)
493 spy.removeSPAssociationWithNSSI(mockExecution)
495 assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
500 void testDeleteSliceProfileInstance() {
501 def currentNSSI = [:]
503 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
505 String globalSubscriberId = "global-id"
506 String serviceType = "service"
507 String nssiId = "5G-999"
509 currentNSSI.put("globalSubscriberId", nssiId)
510 currentNSSI.put("serviceType", nssiId)
511 currentNSSI.put("nssiId", nssiId)
513 String theSNSSAI = "theS-NSSAI"
515 SliceProfile sliceProfile = new SliceProfile()
516 sliceProfile.setSNssai(theSNSSAI)
517 sliceProfile.setProfileId("prof-id")
519 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
521 currentNSSI.put("sliceProfileS-NSSAI", sliceProfile)
523 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
525 when(spy.getAAIClient()).thenReturn(client)
527 doNothing().when(client).delete(nssiUri)
529 spy.deleteSliceProfileInstance(mockExecution)
535 void testDeleteNSSIServiceInstance() {
536 def currentNSSI = [:]
538 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
540 String nssiId = "5G-999"
542 currentNSSI.put("nssiId", nssiId)
544 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
546 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
548 when(spy.getAAIClient()).thenReturn(client)
550 doNothing().when(client).delete(nssiUri)
552 spy.deleteNSSIServiceInstance(mockExecution)
557 void testUpdateServiceOperationStatus() {
558 def currentNSSI = [:]
560 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
562 String nssiId = "5G-999"
564 currentNSSI.put("nssiId", nssiId)
565 currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
566 currentNSSI.put("operationId", "operationId")
567 currentNSSI.put("operationType", "operationType")
569 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
571 spy.updateServiceOperationStatus(mockExecution)
577 void testPrepareRequestDetails() {
578 def currentNSSI = [:]
580 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
582 ServiceInstance networkServiceInstance = new ServiceInstance()
583 networkServiceInstance.setServiceInstanceId("NS-777")
584 networkServiceInstance.setServiceRole("Network Service")
585 networkServiceInstance.setModelInvariantId("model-invariant-id")
586 networkServiceInstance.setServiceInstanceName("service-instance-name")
588 ServiceInstance nssi = new ServiceInstance()
589 nssi.setServiceInstanceId("5G-999")
590 nssi.setOrchestrationStatus("orchestration-status")
592 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "networkServiceInstance.getServiceInstanceId()")
594 AAIResourceUri cloudRegionAAIUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "cloud-owner", "cloud-region-id")
596 currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
598 currentNSSI.put("networkServiceInstance", networkServiceInstance)
600 currentNSSI.put("globalSubscriberId", "globalSubscriberId")
602 currentNSSI.put("subscriberName", "subscriber-name")
604 currentNSSI.put("serviceId", "service-id")
606 currentNSSI.put("nssi", nssi)
608 List<SliceProfile> associatedProfiles = new ArrayList<>()
609 SliceProfile sliceProfile1 = new SliceProfile()
610 sliceProfile1.setSNssai("snssai1")
612 SliceProfile sliceProfile2 = new SliceProfile()
613 sliceProfile2.setSNssai("snssai2")
615 associatedProfiles.add(sliceProfile1)
616 associatedProfiles.add(sliceProfile2)
618 List<String> snssais = new ArrayList<>()
619 snssais.add(sliceProfile1.getSNssai())
620 snssais.add(sliceProfile2.getSNssai())
622 currentNSSI.put("S-NSSAIs", snssais)
625 ServiceSubscription serviceSubscription = new ServiceSubscription()
626 serviceSubscription.setServiceType("service-type")
628 currentNSSI.put("serviceSubscription", serviceSubscription)
630 GenericVnf genericVnf = new GenericVnf()
631 genericVnf.setServiceId("service-id")
632 genericVnf.setVnfName("vnf-name")
633 genericVnf.setModelInvariantId("model-invariant-id")
634 genericVnf.setModelCustomizationId("model-customization-id")
635 genericVnf.setVnfName("vnf-name")
636 genericVnf.setVnfId("vnf-id")
638 VfModule vfModule = new VfModule()
639 vfModule.setModelInvariantId("model-invariant-id")
640 vfModule.setModelCustomizationId("model-customization-id")
641 vfModule.setModelVersionId("model-version-id")
642 vfModule.setVfModuleName("vf-module-name")
644 VfModules vfModules = new VfModules()
645 vfModules.getVfModule().add(vfModule)
646 genericVnf.setVfModules(vfModules)
648 currentNSSI.put("constituteVnf", genericVnf)
650 AAIResourceUri constituteVNFURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVnf.getVnfId())
652 currentNSSI.put("constituteVnfUri", constituteVNFURI)
654 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
656 when(spy.getAAIClient()).thenReturn(client)
658 prepareModelVer(networkServiceInstance)
660 //prepareSubscriberInfo(networkServiceInstanceUri)
662 prepareCloudConfiguration(constituteVNFURI, cloudRegionAAIUri)
664 prepareModelVer(genericVnf)
666 prepareModelVer(vfModule)
668 prepareOwningEntity(networkServiceInstanceUri)
670 prepareProject(cloudRegionAAIUri)
672 String requestDetails = spy.prepareRequestDetails(mockExecution)
677 void prepareProject(AAIResourceUri cloudRegionAAIUri) {
678 Project project = new Project()
679 project.setProjectName("project-name")
681 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
682 Relationships rsMock = mock(Relationships.class)
683 Optional<Relationships> orsMock = Optional.of(rsMock)
685 when(client.get(cloudRegionAAIUri)).thenReturn(wrapperMock)
686 when(wrapperMock.getRelationships()).thenReturn(orsMock)
688 List<AAIResourceUri> arus = new ArrayList<>()
689 AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
692 when(rsMock.getRelatedAAIUris(AAIObjectType.PROJECT)).thenReturn(arus)
694 Optional<Project> projectOpt = Optional.of(project)
696 when(client.get(Project.class, aru)).thenReturn(projectOpt)
700 void prepareOwningEntity(AAIResourceUri networkServiceInstanceUri) {
701 OwningEntity owningEntity = new OwningEntity()
703 owningEntity.setOwningEntityId("owning-entity-id")
704 owningEntity.setOwningEntityName("owning-entity-name")
706 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
708 Relationships rsMock = mock(Relationships.class)
709 Optional<Relationships> orsMock = Optional.of(rsMock)
711 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
712 when(wrapperMock.getRelationships()).thenReturn(orsMock)
714 List<AAIResourceUri> arus = new ArrayList<>()
715 AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri)
718 when(rsMock.getRelatedAAIUris(AAIObjectType.OWNING_ENTITY)).thenReturn(arus)
720 Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity)
722 when(client.get(OwningEntity.class, aru)).thenReturn(owningEntityOpt)
727 void prepareCloudConfiguration(AAIResourceUri constituteVNFURI, cloudRegionAAIUri) {
728 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
730 Relationships rsMock = mock(Relationships.class)
731 Optional<Relationships> orsMock = Optional.of(rsMock)
733 when(client.get(constituteVNFURI)).thenReturn(wrapperMock)
734 when(wrapperMock.getRelationships()).thenReturn(orsMock)
736 List<AAIResourceUri> arus = new ArrayList<>()
737 AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
740 when(rsMock.getRelatedAAIUris(AAIObjectType.CLOUD_REGION)).thenReturn(arus)
742 CloudRegion cloudRegion = new CloudRegion()
743 cloudRegion.setCloudRegionId("cloud-region-id")
744 cloudRegion.setCloudOwner("cloud-owner")
745 Tenant tenant = new Tenant()
746 tenant.setTenantId("tenant-id")
748 Tenants tenants = new Tenants()
749 tenants.getTenant().add(tenant)
750 cloudRegion.setTenants(tenants)
751 Optional<CloudRegion> cloudRegionOpt = Optional.of(cloudRegion)
753 when(client.get(CloudRegion.class, aru)).thenReturn(cloudRegionOpt)
757 void prepareSubscriberInfo( AAIResourceUri networkServiceInstanceUri) {
758 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
760 Relationships rsMock = mock(Relationships.class)
761 Optional<Relationships> orsMock = Optional.of(rsMock)
763 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
764 when(wrapperMock.getRelationships()).thenReturn(orsMock)
766 AAIResourceUri serviceSubscriptionUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, "global-customer-id", "service-type")
768 AAIResourceUri customerUri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, "global-customer-id")
769 List<AAIResourceUri> arus = new ArrayList<>()
771 arus.add(serviceSubscriptionUri)
773 when(rsMock.getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION)).thenReturn(arus)
775 ServiceSubscription serviceSubscription = new ServiceSubscription()
776 serviceSubscription.setServiceType("service-type")
777 Optional<ServiceSubscription> serviceSubscriptionOpt = Optional.of(serviceSubscription)
779 when(client.get(ServiceSubscription.class, serviceSubscriptionUri)).thenReturn(serviceSubscriptionOpt)
781 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
783 when(rsMock.getRelatedAAIUris(AAIObjectType.CUSTOMER)).thenReturn(arus)
785 Customer customer = new Customer()
786 customer.setSubscriberName("subscriber-name")
787 Optional<Customer> customerOpt = Optional.of(customer)
789 when(client.get(Customer.class, customerUri)).thenReturn(customerOpt)
793 void prepareModelVer(ServiceInstance networkServiceInstance) {
794 ModelVer modelVer = new ModelVer()
795 modelVer.setModelVersionId("model-version-id")
796 modelVer.setModelName("model-name")
797 modelVer.setModelVersion("model-version")
799 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
801 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId(), networkServiceInstance.getModelVersionId())
802 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
805 void prepareModelVer(GenericVnf genericVnf) {
806 ModelVer modelVer = new ModelVer()
807 modelVer.setModelVersionId("model-version-id")
808 modelVer.setModelName("model-name")
809 modelVer.setModelVersion("model-version")
811 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
813 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, genericVnf.getModelInvariantId(), genericVnf.getModelVersionId())
814 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
817 void prepareModelVer(VfModule vfModule) {
818 ModelVer modelVer = new ModelVer()
819 modelVer.setModelVersionId("model-version-id")
820 modelVer.setModelName("model-name")
821 modelVer.setModelVersion("model-version")
823 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
825 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId(), vfModule.getModelVersionId())
826 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)