2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Telecom Italia
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.junit.Before
26 import org.mockito.Mockito
27 import org.onap.aai.domain.yang.v19.*
28 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
29 import org.onap.aaiclient.client.aai.entities.Relationships
30 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
31 import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
33 import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
35 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
36 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
37 import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
38 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
39 import org.onap.so.bpmn.core.json.JsonUtils
40 import org.onap.so.serviceinstancebeans.RequestDetails
42 import javax.ws.rs.core.Response
43 import java.time.Instant
45 import static org.junit.Assert.assertNotNull
46 import static org.junit.Assert.assertTrue
47 import static org.mockito.Mockito.*
49 class DoCommonCoreNSSITest extends MsoGroovyTest {
51 void init() throws IOException {
52 super.init("DoCommonCoreNSSITest")
57 void testPreProcessRequest() {
59 String nssiId = "5G-999"
60 when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId)
62 String nsiId = "5G-777"
63 when(mockExecution.getVariable("nsiId")).thenReturn(nsiId)
65 String snssai = "S-NSSAI"
66 String snssaiList = "[ \"${snssai}\" ]"
67 String sliceProfileId = "slice-profile-id"
68 String sliceParams = "{\n" +
69 "\"sliceProfile\":{\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}}\n" +
71 when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
73 DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI()
74 dcnssi.preProcessRequest(mockExecution)
77 currentNSSI.put("nssiId", nssiId)
78 currentNSSI.put("nsiId", nsiId)
79 currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"]}")
80 currentNSSI.put("S-NSSAI", snssai)
81 currentNSSI.put("sliceProfileId", sliceProfileId)
82 Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI)
88 void testGetNetworkServiceInstance() {
90 currentNSSI.put("nssiId","5G-999")
92 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
94 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment("5G-999"))
95 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment("NS-777"))
97 ServiceInstance nssi = new ServiceInstance()
98 nssi.setServiceInstanceId("5G-999")
100 ServiceInstance networkServiceInstance = new ServiceInstance()
101 networkServiceInstance.setServiceInstanceId("NS-777")
102 networkServiceInstance.setServiceRole("Network Service")
104 Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
105 Optional<ServiceInstance> networkServiceInstaneOpt = Optional.of(networkServiceInstance)
107 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
108 when(spy.getAAIClient()).thenReturn(client)
110 when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)
112 //String json = FileUtil.readResourceFile("__files/AAI/ServiceInstanceWithAR.json")
113 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
114 Relationships rsMock = mock(Relationships.class)
115 Optional<Relationships> orsMock = Optional.of(rsMock)
116 List<AAIResourceUri> arus = new ArrayList<>()
117 AAIResourceUri aru = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
120 when(client.get(nssiUri)).thenReturn(wrapperMock)
121 when(wrapperMock.getRelationships()).thenReturn(orsMock)
123 when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(arus)
124 when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt)
126 spy.getNetworkServiceInstance(mockExecution)
128 assertTrue("Either NSSI doesn't exist or unexpected NSSI Service Instance ID",
129 currentNSSI.get("nssi") != null && ((ServiceInstance)currentNSSI.get("nssi")).getServiceInstanceId().equals(nssi.getServiceInstanceId()))
131 assertTrue("Either Network Service Instance doesn't exist or unexpected Network Service Instance ID",
132 currentNSSI.get("networkServiceInstance") != null && ((ServiceInstance)currentNSSI.get("networkServiceInstance")).getServiceInstanceId().equals(networkServiceInstance.getServiceInstanceId()))
134 assertNotNull("networkServiceInstanceUri doesn't exist", currentNSSI.get("networkServiceInstanceUri"))
139 void getConstituteVNFFromNetworkServiceInst() {
140 def currentNSSI = [:]
142 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
144 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
145 when(spy.getAAIClient()).thenReturn(client)
147 ServiceInstance networkServiceInstance = new ServiceInstance()
148 networkServiceInstance.setServiceInstanceId("NS-777")
149 networkServiceInstance.setServiceRole("Network Service")
151 GenericVnf genericVNF = new GenericVnf()
152 genericVNF.setVnfId("VNF-1")
154 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
156 Optional<GenericVnf> genericVnfOpt = Optional.of(genericVNF)
157 AAIResourceUri genericVNFUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVNF.getVnfId()))
159 currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
160 currentNSSI.put("networkServiceInstance", networkServiceInstance)
162 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
163 Relationships rsMock = mock(Relationships.class)
164 Optional<Relationships> orsMock = Optional.of(rsMock)
165 List<AAIResourceUri> arus = new ArrayList<>()
166 AAIResourceUri aru = new AAISimpleUri(genericVNFUri)
169 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
170 when(wrapperMock.getRelationships()).thenReturn(orsMock)
172 when(rsMock.getRelatedUris(Types.GENERIC_VNF)).thenReturn(arus)
173 when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt)
175 spy.getConstituteVNFFromNetworkServiceInst(mockExecution)
177 assertNotNull("constituteVnfUri doesn't exist", currentNSSI.get("constituteVnfUri"))
179 assertTrue("Either Constitute VNF doesn't exist or unexpected VNF ID",
180 currentNSSI.get("constituteVnf") != null && ((GenericVnf)currentNSSI.get("constituteVnf")).getVnfId().equals(genericVNF.getVnfId()))
185 void testGetNSSIAssociatedProfiles() {
186 def currentNSSI = [:]
187 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
189 String nssiId = "5G-999"
190 ServiceInstance nssi = new ServiceInstance()
191 nssi.setServiceInstanceId(nssiId)
192 currentNSSI.put("nssiId", nssiId)
194 SliceProfiles sliceProfiles = new SliceProfiles()
196 List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
197 slProfiles.add(new SliceProfile())
198 slProfiles.add(new SliceProfile())
200 //nssi.setSliceProfiles(sliceProfiles)
201 currentNSSI.put("nssi", nssi)
203 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
204 when(spy.getAAIClient()).thenReturn(client)
206 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
208 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
209 Relationships rsMock = mock(Relationships.class)
210 Optional<Relationships> orsMock = Optional.of(rsMock)
211 List<AAIResourceUri> allottedUris = new ArrayList<>()
212 AAIResourceUri allottedUri = AAIUriFactory.createResourceUri(Types.ALLOTTED_RESOURCE.getFragment("allotted-id"))
213 allottedUris.add(allottedUri)
215 when(client.get(nssiUri)).thenReturn(wrapperMock)
216 when(wrapperMock.getRelationships()).thenReturn(orsMock)
217 when(rsMock.getRelatedUris(Types.ALLOTTED_RESOURCE)).thenReturn(allottedUris)
219 String sliceProfileInstanceId = "slice-profile-instance-id"
220 ServiceInstance sliceProfileInstance = new ServiceInstance()
221 sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
222 sliceProfileInstance.setServiceRole("slice-profile-instance")
224 List<AAIResourceUri> sliceProfileInstanceUris = new ArrayList<>()
225 AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstance.getServiceInstanceId()))
226 sliceProfileInstanceUris.add(sliceProfileInstanceUri)
228 Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance)
230 when(client.get(allottedUri)).thenReturn(wrapperMock)
231 when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(sliceProfileInstanceUris)
232 when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt)
235 SliceProfiles sps = new SliceProfiles()
236 sps.getSliceProfile().addAll(slProfiles)
237 sliceProfileInstance.setSliceProfiles(sps)
239 spy.getNSSIAssociatedProfiles(mockExecution)
241 List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
242 assertTrue("sliceProfileInstanceUri not found in contect Map", currentNSSI.get("sliceProfileInstanceUri") != null)
243 assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
248 void testInvokePUTServiceInstance() {
249 def currentNSSI = [:]
251 ServiceInstance networkServiceInstance = new ServiceInstance()
252 networkServiceInstance.setServiceInstanceId("NS-777")
253 networkServiceInstance.setServiceRole("Network Service")
255 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
257 currentNSSI.put("networkServiceInstance", networkServiceInstance)
259 when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
260 when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
261 when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
263 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
264 when(spy.getAAIClient()).thenReturn(client)
266 when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
268 String authHeaderResponse = "auth-header"
270 when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
272 String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId())
274 String callPUTServiceInstanceResponse = "put"
276 RequestDetails requestDetails = new RequestDetails()
277 ObjectMapper mapper = new ObjectMapper()
278 String requestDetailsStr = mapper.writeValueAsString(requestDetails)
280 when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
282 when(spy.callPUTServiceInstance(urlString, "auth-header", requestDetailsStr)).thenReturn(callPUTServiceInstanceResponse)
284 spy.invokePUTServiceInstance(mockExecution)
289 void testRemoveSPAssociationWithNSSI() {
290 def currentNSSI = [:]
292 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
294 String nssiId = "5G-999"
295 currentNSSI.put("nssiId", nssiId)
296 ServiceInstance nssi = new ServiceInstance()
297 nssi.setServiceInstanceId(nssiId)
298 nssi.setSliceProfiles(new SliceProfiles())
300 currentNSSI.put("nssi", nssi)
302 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
304 AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type").
305 serviceInstance("slice-profile-instance-id"))
307 String sliceProfileInstanceId = "slice-profile-instance-id"
308 ServiceInstance sliceProfileInstance = new ServiceInstance()
309 sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
310 sliceProfileInstance.setServiceRole("slice-profile-instance")
312 Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance)
314 when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt)
316 currentNSSI.put("sliceProfileInstanceUri", sliceProfileInstanceUri)
318 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
320 when(spy.getAAIClient()).thenReturn(client)
322 String theSNSSAI = "theS-NSSAI"
323 currentNSSI.put("S-NSSAI", theSNSSAI)
325 List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
327 SliceProfile sliceProfile1 = new SliceProfile()
328 sliceProfile1.setSNssai("snssai1")
330 SliceProfile sliceProfile2 = new SliceProfile()
331 sliceProfile2.setSNssai(theSNSSAI)
333 SliceProfile sliceProfile3 = new SliceProfile()
334 sliceProfile3.setSNssai("snssai3")
336 associatedProfiles.add(sliceProfile1)
337 associatedProfiles.add(sliceProfile2)
338 associatedProfiles.add(sliceProfile3)
340 SliceProfiles sps = new SliceProfiles()
341 sps.getSliceProfile().addAll(associatedProfiles)
342 sliceProfileInstance.setSliceProfiles(sps)
344 int sizeBefore = associatedProfiles.size()
346 doNothing().when(client).update(sliceProfileInstanceUri, sliceProfileInstance)
348 doNothing().when(client). disconnect(nssiUri, sliceProfileInstanceUri)
350 spy.removeSPAssociationWithNSSI(mockExecution)
352 assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("sliceProfileInstance")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
357 void testDeleteSliceProfileInstance() {
358 def currentNSSI = [:]
360 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
362 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type").
363 serviceInstance("slice-profile-instance-id"))
365 currentNSSI.put("sliceProfileInstanceUri", uri)
367 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
369 when(spy.getAAIClient()).thenReturn(client)
371 doNothing().when(client).delete(uri)
373 spy.deleteSliceProfileInstance(mockExecution)
379 void testPrepareRequestDetails() {
380 def currentNSSI = [:]
382 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
384 ServiceInstance networkServiceInstance = new ServiceInstance()
385 networkServiceInstance.setServiceInstanceId("NS-777")
386 networkServiceInstance.setServiceRole("Network Service")
387 networkServiceInstance.setModelInvariantId("model-invariant-id")
388 networkServiceInstance.setServiceInstanceName("service-instance-name")
390 ServiceInstance nssi = new ServiceInstance()
391 nssi.setServiceInstanceId("5G-999")
392 nssi.setOrchestrationStatus("orchestration-status")
394 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
396 AAIResourceUri cloudRegionAAIUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("cloud-owner", "cloud-region-id"))
398 currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
400 currentNSSI.put("networkServiceInstance", networkServiceInstance)
402 currentNSSI.put("globalSubscriberId", "globalSubscriberId")
404 currentNSSI.put("subscriberName", "subscriber-name")
406 currentNSSI.put("serviceId", "service-id")
408 currentNSSI.put("nssi", nssi)
410 List<SliceProfile> associatedProfiles = new ArrayList<>()
411 SliceProfile sliceProfile1 = new SliceProfile()
412 sliceProfile1.setSNssai("snssai1")
414 SliceProfile sliceProfile2 = new SliceProfile()
415 sliceProfile2.setSNssai("snssai2")
417 associatedProfiles.add(sliceProfile1)
418 associatedProfiles.add(sliceProfile2)
420 List<String> snssais = new ArrayList<>()
421 snssais.add(sliceProfile1.getSNssai())
422 snssais.add(sliceProfile2.getSNssai())
424 currentNSSI.put("S-NSSAIs", snssais)
427 ServiceSubscription serviceSubscription = new ServiceSubscription()
428 serviceSubscription.setServiceType("service-type")
430 currentNSSI.put("serviceSubscription", serviceSubscription)
432 GenericVnf genericVnf = new GenericVnf()
433 genericVnf.setServiceId("service-id")
434 genericVnf.setVnfName("vnf-name")
435 genericVnf.setModelInvariantId("model-invariant-id")
436 genericVnf.setModelCustomizationId("model-customization-id")
437 genericVnf.setVnfName("vnf-name")
438 genericVnf.setVnfId("vnf-id")
440 VfModule vfModule = new VfModule()
441 vfModule.setModelInvariantId("model-invariant-id")
442 vfModule.setModelCustomizationId("model-customization-id")
443 vfModule.setModelVersionId("model-version-id")
444 vfModule.setVfModuleName("vf-module-name")
446 VfModules vfModules = new VfModules()
447 vfModules.getVfModule().add(vfModule)
448 genericVnf.setVfModules(vfModules)
450 currentNSSI.put("constituteVnf", genericVnf)
452 AAIResourceUri constituteVNFURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnf.getVnfId()))
454 currentNSSI.put("constituteVnfUri", constituteVNFURI)
456 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
458 when(spy.getAAIClient()).thenReturn(client)
460 prepareModelVer(networkServiceInstance)
462 //prepareSubscriberInfo(networkServiceInstanceUri)
464 prepareCloudConfiguration(constituteVNFURI, cloudRegionAAIUri)
466 prepareModelVer(genericVnf)
468 prepareModelVer(vfModule)
470 prepareOwningEntity(networkServiceInstanceUri)
472 prepareProject(cloudRegionAAIUri)
474 String prepareRequestDetailsResponse = spy.prepareRequestDetails(mockExecution)
476 JsonUtils jsonUtil = new JsonUtils()
477 String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
478 String errMsg = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage")
480 assertTrue(errMsg, errorCode == null || errorCode.isEmpty())
485 void testPrepareFailedOperationStatusUpdate() {
486 def currentNSSI = [:]
488 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
489 when(mockExecution.getVariable("jobId")).thenReturn("job-id")
490 when(mockExecution.getVariable("operationType")).thenReturn("operation-type")
492 String nssiId = "5G-999"
493 String nsiId = "5G-777"
495 currentNSSI.put("nssiId", nssiId)
496 currentNSSI.put("nsiId", nsiId)
497 currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
498 currentNSSI.put("operationId", "operationId")
499 currentNSSI.put("operationType", "operationType")
501 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
503 spy.prepareFailedOperationStatusUpdate(mockExecution)
508 void testPrepareUpdateResourceOperationStatus() {
509 def currentNSSI = [:]
511 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
512 when(mockExecution.getVariable("jobId")).thenReturn("job-id")
513 when(mockExecution.getVariable("operationType")).thenReturn("operation-type")
515 String nssiId = "5G-999"
516 String nsiId = "5G-777"
518 currentNSSI.put("nssiId", nssiId)
519 currentNSSI.put("nsiId", nsiId)
520 currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
521 currentNSSI.put("operationId", "operationId")
522 currentNSSI.put("operationType", "operationType")
524 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
526 spy.prepareUpdateResourceOperationStatus(mockExecution)
532 void testGetPUTServiceInstanceProgressAcknowledged() {
534 executePUTServiceInstanceProgress("ACKNOWLEDGED")
535 Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing")
540 void testGetPUTServiceInstanceProgressInProgress() {
542 executePUTServiceInstanceProgress("INPROGRESS")
543 Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing")
548 void testGetPUTServiceInstanceProgressCompleted() {
550 executePUTServiceInstanceProgress("COMPLETED")
551 Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "completed")
556 void testTimeDelay() {
557 DoCommonCoreNSSI obj = spy(DoCommonCoreNSSI.class)
559 long before = Instant.now().toEpochMilli()
560 obj.timeDelay(mockExecution)
562 long after = Instant.now().toEpochMilli()
566 assertTrue(String.format("Didn't wait %d sec", delay), ((after - before) >= delay))
570 void executePUTServiceInstanceProgress(String state) {
572 def currentNSSI = [:]
574 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
576 String url = "http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/5G-777"
578 currentNSSI.put("putServiceInstanceURL", url)
580 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
582 ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
583 when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock)
585 ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
587 when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
589 Response responseMock = mock(Response.class)
590 when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
592 when(responseMock.getStatus()).thenReturn(200)
594 String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}"
595 when(responseMock.readEntity(String.class)).thenReturn(entity)
597 spy.getPUTServiceInstanceProgress(mockExecution)
602 void prepareProject(AAIResourceUri cloudRegionAAIUri) {
603 Project project = new Project()
604 project.setProjectName("project-name")
606 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
607 Relationships rsMock = mock(Relationships.class)
608 Optional<Relationships> orsMock = Optional.of(rsMock)
610 when(client.get(cloudRegionAAIUri)).thenReturn(wrapperMock)
611 when(wrapperMock.getRelationships()).thenReturn(orsMock)
613 List<AAIResourceUri> arus = new ArrayList<>()
614 AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
617 when(rsMock.getRelatedUris(Types.PROJECT)).thenReturn(arus)
619 Optional<Project> projectOpt = Optional.of(project)
621 when(client.get(Project.class, aru)).thenReturn(projectOpt)
625 void prepareOwningEntity(AAIResourceUri networkServiceInstanceUri) {
626 OwningEntity owningEntity = new OwningEntity()
628 owningEntity.setOwningEntityId("owning-entity-id")
629 owningEntity.setOwningEntityName("owning-entity-name")
631 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
633 Relationships rsMock = mock(Relationships.class)
634 Optional<Relationships> orsMock = Optional.of(rsMock)
636 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
637 when(wrapperMock.getRelationships()).thenReturn(orsMock)
639 List<AAIResourceUri> arus = new ArrayList<>()
640 AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri)
643 when(rsMock.getRelatedUris(Types.OWNING_ENTITY)).thenReturn(arus)
645 Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity)
647 when(client.get(OwningEntity.class, aru)).thenReturn(owningEntityOpt)
652 void prepareCloudConfiguration(AAIResourceUri constituteVNFURI, cloudRegionAAIUri) {
653 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
655 Relationships rsMock = mock(Relationships.class)
656 Optional<Relationships> orsMock = Optional.of(rsMock)
658 when(client.get(constituteVNFURI)).thenReturn(wrapperMock)
659 when(wrapperMock.getRelationships()).thenReturn(orsMock)
661 List<AAIResourceUri> arus = new ArrayList<>()
662 AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
665 when(rsMock.getRelatedUris(Types.CLOUD_REGION)).thenReturn(arus)
667 CloudRegion cloudRegion = new CloudRegion()
668 cloudRegion.setCloudRegionId("cloud-region-id")
669 cloudRegion.setCloudOwner("cloud-owner")
670 Tenant tenant = new Tenant()
671 tenant.setTenantId("tenant-id")
673 Tenants tenants = new Tenants()
674 tenants.getTenant().add(tenant)
675 cloudRegion.setTenants(tenants)
676 Optional<CloudRegion> cloudRegionOpt = Optional.of(cloudRegion)
678 when(client.get(CloudRegion.class, aru)).thenReturn(cloudRegionOpt)
682 void prepareSubscriberInfo( AAIResourceUri networkServiceInstanceUri) {
683 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
685 Relationships rsMock = mock(Relationships.class)
686 Optional<Relationships> orsMock = Optional.of(rsMock)
688 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
689 when(wrapperMock.getRelationships()).thenReturn(orsMock)
691 AAIResourceUri serviceSubscriptionUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-customer-id").serviceSubscription("service-type"))
693 AAIResourceUri customerUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-customer-id"))
694 List<AAIResourceUri> arus = new ArrayList<>()
696 arus.add(serviceSubscriptionUri)
698 when(rsMock.getRelatedUris(Types.SERVICE_SUBSCRIPTION)).thenReturn(arus)
700 ServiceSubscription serviceSubscription = new ServiceSubscription()
701 serviceSubscription.setServiceType("service-type")
702 Optional<ServiceSubscription> serviceSubscriptionOpt = Optional.of(serviceSubscription)
704 when(client.get(ServiceSubscription.class, serviceSubscriptionUri)).thenReturn(serviceSubscriptionOpt)
706 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
708 when(rsMock.getRelatedUris(Types.CUSTOMER)).thenReturn(arus)
710 Customer customer = new Customer()
711 customer.setSubscriberName("subscriber-name")
712 Optional<Customer> customerOpt = Optional.of(customer)
714 when(client.get(Customer.class, customerUri)).thenReturn(customerOpt)
718 void prepareModelVer(ServiceInstance networkServiceInstance) {
719 ModelVer modelVer = new ModelVer()
720 modelVer.setModelVersionId("model-version-id")
721 modelVer.setModelName("model-name")
722 modelVer.setModelVersion("model-version")
724 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
726 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(networkServiceInstance.getModelInvariantId()).modelVer(networkServiceInstance.getModelVersionId()))
727 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
730 void prepareModelVer(GenericVnf genericVnf) {
731 ModelVer modelVer = new ModelVer()
732 modelVer.setModelVersionId("model-version-id")
733 modelVer.setModelName("model-name")
734 modelVer.setModelVersion("model-version")
736 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
738 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(genericVnf.getModelInvariantId()).modelVer(genericVnf.getModelVersionId()))
739 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
742 void prepareModelVer(VfModule vfModule) {
743 ModelVer modelVer = new ModelVer()
744 modelVer.setModelVersionId("model-version-id")
745 modelVer.setModelName("model-name")
746 modelVer.setModelVersion("model-version")
748 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
750 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
751 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)