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.logging.filter.base.ONAPComponents
37 import org.onap.so.bpmn.common.scripts.CatalogDbUtils
38 import org.onap.so.bpmn.common.scripts.CatalogDbUtilsFactory
39 import org.onap.so.bpmn.common.scripts.ExternalAPIUtil
40 import org.onap.so.bpmn.common.scripts.ExternalAPIUtilFactory
41 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
42 import org.onap.so.bpmn.common.scripts.MsoUtils
43 import org.onap.so.bpmn.core.json.JsonUtils
44 import org.onap.so.client.HttpClient
45 import org.onap.so.client.HttpClientFactory
46 import org.onap.so.serviceinstancebeans.RequestDetails
48 import javax.ws.rs.core.Response
49 import java.time.Instant
51 import static org.junit.Assert.assertNotNull
52 import static org.junit.Assert.assertNull
53 import static org.junit.Assert.assertTrue
54 import static org.mockito.Mockito.*
56 class DoCommonCoreNSSITest extends MsoGroovyTest {
58 void init() throws IOException {
59 super.init("DoCommonCoreNSSITest")
64 void testGetNetworkServiceInstance() {
66 currentNSSI.put("nssiId","5G-999")
68 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
70 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment("5G-999"))
71 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment("NS-777"))
73 ServiceInstance nssi = new ServiceInstance()
74 nssi.setServiceInstanceId("5G-999")
76 ServiceInstance networkServiceInstance = new ServiceInstance()
77 networkServiceInstance.setServiceInstanceId("NS-777")
78 networkServiceInstance.setServiceRole("Network Service")
80 Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
81 Optional<ServiceInstance> networkServiceInstaneOpt = Optional.of(networkServiceInstance)
83 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
84 when(spy.getAAIClient()).thenReturn(client)
86 when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)
88 //String json = FileUtil.readResourceFile("__files/AAI/ServiceInstanceWithAR.json")
89 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
90 Relationships rsMock = mock(Relationships.class)
91 Optional<Relationships> orsMock = Optional.of(rsMock)
92 List<AAIResourceUri> arus = new ArrayList<>()
93 AAIResourceUri aru = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
96 when(client.get(nssiUri)).thenReturn(wrapperMock)
97 when(wrapperMock.getRelationships()).thenReturn(orsMock)
99 when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(arus)
100 when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt)
102 spy.getNetworkServiceInstance(mockExecution)
104 assertTrue("Either NSSI doesn't exist or unexpected NSSI Service Instance ID",
105 currentNSSI.get("nssi") != null && ((ServiceInstance)currentNSSI.get("nssi")).getServiceInstanceId().equals(nssi.getServiceInstanceId()))
107 assertTrue("Either Network Service Instance doesn't exist or unexpected Network Service Instance ID",
108 currentNSSI.get("networkServiceInstance") != null && ((ServiceInstance)currentNSSI.get("networkServiceInstance")).getServiceInstanceId().equals(networkServiceInstance.getServiceInstanceId()))
110 assertNotNull("networkServiceInstanceUri doesn't exist", currentNSSI.get("networkServiceInstanceUri"))
115 void getConstituteVNFFromNetworkServiceInst() {
116 def currentNSSI = [:]
118 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
120 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
121 when(spy.getAAIClient()).thenReturn(client)
123 ServiceInstance networkServiceInstance = new ServiceInstance()
124 networkServiceInstance.setServiceInstanceId("NS-777")
125 networkServiceInstance.setServiceRole("Network Service")
127 GenericVnf genericVNF = new GenericVnf()
128 genericVNF.setVnfId("VNF-1")
130 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
132 Optional<GenericVnf> genericVnfOpt = Optional.of(genericVNF)
133 AAIResourceUri genericVNFUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVNF.getVnfId()))
135 currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
136 currentNSSI.put("networkServiceInstance", networkServiceInstance)
138 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
139 Relationships rsMock = mock(Relationships.class)
140 Optional<Relationships> orsMock = Optional.of(rsMock)
141 List<AAIResourceUri> arus = new ArrayList<>()
142 AAIResourceUri aru = new AAISimpleUri(genericVNFUri)
145 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
146 when(wrapperMock.getRelationships()).thenReturn(orsMock)
148 when(rsMock.getRelatedUris(Types.GENERIC_VNF)).thenReturn(arus)
149 when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt)
151 spy.getConstituteVNFFromNetworkServiceInst(mockExecution)
153 assertNotNull("constituteVnfUri doesn't exist", currentNSSI.get("constituteVnfUri"))
155 assertTrue("Either Constitute VNF doesn't exist or unexpected VNF ID",
156 currentNSSI.get("constituteVnf") != null && ((GenericVnf)currentNSSI.get("constituteVnf")).getVnfId().equals(genericVNF.getVnfId()))
161 void testInvokePUTServiceInstance() {
162 def currentNSSI = [:]
164 ServiceInstance networkServiceInstance = new ServiceInstance()
165 networkServiceInstance.setServiceInstanceId("NS-777")
166 networkServiceInstance.setServiceRole("Network Service")
168 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
170 currentNSSI.put("networkServiceInstance", networkServiceInstance)
172 when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
173 when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
174 when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
176 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
177 when(spy.getAAIClient()).thenReturn(client)
179 GenericVnf genericVnf = new GenericVnf()
180 genericVnf.setServiceId("service-id")
181 genericVnf.setVnfName("vnf-name")
182 genericVnf.setModelInvariantId("model-invariant-id")
183 genericVnf.setModelCustomizationId("model-customization-id")
184 genericVnf.setVnfName("vnf-name")
185 genericVnf.setVnfId("vnf-id")
187 currentNSSI.put("constituteVnf", genericVnf)
190 String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), genericVnf.getVnfId())
192 String callPUTServiceInstanceResponse = "put"
194 RequestDetails requestDetails = new RequestDetails()
195 ObjectMapper mapper = new ObjectMapper()
196 String requestDetailsStr = mapper.writeValueAsString(requestDetails)
198 when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
200 MsoUtils msoUtilsMock = mock(MsoUtils.class)
201 String basicAuth = "basicAuth"
202 when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
204 HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
205 when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
206 Response responseMock = mock(Response.class)
208 HttpClient httpClientMock = mock(HttpClient.class)
210 when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
212 when(httpClientMock.put(requestDetailsStr)).thenReturn(responseMock)
214 when(responseMock.getStatus()).thenReturn(200)
215 when(responseMock.hasEntity()).thenReturn(true)
217 String macroOperationId = "request-id"
218 String requestSelfLink = "request-self-link"
219 String entity = "{\"requestReferences\":{\"requestId\": \"${macroOperationId}\",\"requestSelfLink\":\"${requestSelfLink}\"}}"
220 when(responseMock.readEntity(String.class)).thenReturn(entity)
222 spy.invokePUTServiceInstance(mockExecution)
224 Mockito.verify(mockExecution,times(1)).setVariable("macroOperationId", macroOperationId)
225 Mockito.verify(mockExecution,times(1)).setVariable("requestSelfLink", requestSelfLink)
229 @Test(expected = Test.None.class)
230 void testRemoveSPAssociationWithNSSI() {
231 def currentNSSI = [:]
233 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
235 String nssiId = "5G-999"
236 currentNSSI.put("nssiId", nssiId)
237 ServiceInstance nssi = new ServiceInstance()
238 nssi.setServiceInstanceId(nssiId)
239 nssi.setSliceProfiles(new SliceProfiles())
241 currentNSSI.put("nssi", nssi)
243 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
245 AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type").
246 serviceInstance("slice-profile-instance-id"))
248 String sliceProfileInstanceId = "slice-profile-instance-id"
249 ServiceInstance sliceProfileInstance = new ServiceInstance()
250 sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
251 sliceProfileInstance.setServiceRole("slice-profile-instance")
253 Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance)
255 when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt)
257 currentNSSI.put("sliceProfileInstanceUri", sliceProfileInstanceUri)
259 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
261 when(spy.getAAIClient()).thenReturn(client)
263 String theSNSSAI = "theS-NSSAI"
264 currentNSSI.put("S-NSSAI", theSNSSAI)
266 List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
268 SliceProfile sliceProfile1 = new SliceProfile()
269 sliceProfile1.setSNssai("snssai1")
271 SliceProfile sliceProfile2 = new SliceProfile()
272 sliceProfile2.setSNssai(theSNSSAI)
274 SliceProfile sliceProfile3 = new SliceProfile()
275 sliceProfile3.setSNssai("snssai3")
277 associatedProfiles.add(sliceProfile1)
278 associatedProfiles.add(sliceProfile2)
279 associatedProfiles.add(sliceProfile3)
281 SliceProfiles sps = new SliceProfiles()
282 sps.getSliceProfile().addAll(associatedProfiles)
283 sliceProfileInstance.setSliceProfiles(sps)
285 int sizeBefore = associatedProfiles.size()
287 doNothing().when(client).update(sliceProfileInstanceUri, sliceProfileInstance)
289 doNothing().when(client). disconnect(nssiUri, sliceProfileInstanceUri)
291 spy.removeSPAssociationWithNSSI(mockExecution)
293 // assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("sliceProfileInstance")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
298 void testDeleteSliceProfileInstance() {
299 def currentNSSI = [:]
301 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
303 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-subscriber-id").serviceSubscription("subscription-service-type").
304 serviceInstance("slice-profile-instance-id"))
306 currentNSSI.put("sliceProfileInstanceUri", uri)
308 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
310 when(spy.getAAIClient()).thenReturn(client)
312 doNothing().when(client).delete(uri)
314 spy.deleteSliceProfileInstance(mockExecution)
320 void testPrepareRequestDetails() {
321 def currentNSSI = [:]
323 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
325 ServiceInstance networkServiceInstance = new ServiceInstance()
326 networkServiceInstance.setServiceInstanceId("NS-777")
327 networkServiceInstance.setServiceRole("Network Service")
328 networkServiceInstance.setModelInvariantId("model-invariant-id")
329 networkServiceInstance.setServiceInstanceName("service-instance-name")
331 ServiceInstance nssi = new ServiceInstance()
332 nssi.setServiceInstanceId("5G-999")
333 nssi.setOrchestrationStatus("orchestration-status")
335 AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
337 AAIResourceUri cloudRegionAAIUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("cloud-owner", "cloud-region-id"))
339 currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
341 currentNSSI.put("networkServiceInstance", networkServiceInstance)
343 currentNSSI.put("globalSubscriberId", "globalSubscriberId")
345 currentNSSI.put("subscriberName", "subscriber-name")
347 currentNSSI.put("serviceId", "service-id")
349 currentNSSI.put("nssi", nssi)
351 List<SliceProfile> associatedProfiles = new ArrayList<>()
352 SliceProfile sliceProfile1 = new SliceProfile()
353 sliceProfile1.setSNssai("snssai1")
355 SliceProfile sliceProfile2 = new SliceProfile()
356 sliceProfile2.setSNssai("snssai2")
358 associatedProfiles.add(sliceProfile1)
359 associatedProfiles.add(sliceProfile2)
361 List<String> snssais = new ArrayList<>()
362 snssais.add(sliceProfile1.getSNssai())
363 snssais.add(sliceProfile2.getSNssai())
365 currentNSSI.put("S-NSSAIs", snssais)
368 ServiceSubscription serviceSubscription = new ServiceSubscription()
369 serviceSubscription.setServiceType("service-type")
371 currentNSSI.put("serviceSubscription", serviceSubscription)
373 GenericVnf genericVnf = new GenericVnf()
374 genericVnf.setServiceId("service-id")
375 genericVnf.setVnfName("vnf-name")
376 genericVnf.setModelInvariantId("model-invariant-id")
377 genericVnf.setModelCustomizationId("model-customization-id")
378 genericVnf.setVnfName("vnf-name")
379 genericVnf.setVnfId("vnf-id")
381 VfModule vfModule = new VfModule()
382 vfModule.setModelInvariantId("model-invariant-id")
383 vfModule.setModelCustomizationId("model-customization-id")
384 vfModule.setModelVersionId("model-version-id")
385 vfModule.setVfModuleName("vf-module-name")
387 VfModules vfModules = new VfModules()
388 vfModules.getVfModule().add(vfModule)
389 genericVnf.setVfModules(vfModules)
391 currentNSSI.put("constituteVnf", genericVnf)
393 AAIResourceUri constituteVNFURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnf.getVnfId()))
395 currentNSSI.put("constituteVnfUri", constituteVNFURI)
397 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
399 when(spy.getAAIClient()).thenReturn(client)
401 prepareModelVer(networkServiceInstance)
403 //prepareSubscriberInfo(networkServiceInstanceUri)
405 prepareCloudConfiguration(constituteVNFURI, cloudRegionAAIUri)
407 prepareModelVer(genericVnf)
409 prepareModelVer(vfModule)
411 prepareOwningEntity(networkServiceInstanceUri)
413 prepareProject(cloudRegionAAIUri)
415 CatalogDbUtilsFactory catalogDbUtilsFactoryMock = mock(CatalogDbUtilsFactory.class)
416 when(spy.getCatalogDbUtilsFactory()).thenReturn(catalogDbUtilsFactoryMock)
418 CatalogDbUtils catalogDbUtilsMock = mock(CatalogDbUtils.class)
419 when(catalogDbUtilsFactoryMock.create()).thenReturn(catalogDbUtilsMock)
421 String json = "{\"serviceResources\":{\"serviceVnfs\": [{\"modelInfo\": {\"modelCustomizationUuid\":\"model-customization-uuid\",\"modelId\":\"model-id\"},\"vfModules\":[{\"modelInfo\": {\"modelCustomizationUuid\":\"model-customization-uuid\",\"modelId\":\"model-id\"}}]}]}}"
422 when(catalogDbUtilsMock.getServiceResourcesByServiceModelInvariantUuidString(mockExecution, networkServiceInstance.getModelInvariantId())).thenReturn(json)
424 String prepareRequestDetailsResponse = spy.prepareRequestDetails(mockExecution)
426 JsonUtils jsonUtil = new JsonUtils()
427 String errorCode = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorCode")
428 String errMsg = jsonUtil.getJsonValue(prepareRequestDetailsResponse, "errorMessage")
430 assertTrue(errMsg, errorCode == null || errorCode.isEmpty())
435 void testPrepareFailedOperationStatusUpdate() {
436 def currentNSSI = [:]
438 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
439 when(mockExecution.getVariable("jobId")).thenReturn("job-id")
440 when(mockExecution.getVariable("operationType")).thenReturn("operation-type")
442 String nssiId = "5G-999"
443 String nsiId = "5G-777"
445 ServiceInstance nssi = new ServiceInstance()
446 nssi.setServiceInstanceId(nssiId)
447 nssi.setModelVersionId(UUID.randomUUID().toString())
449 currentNSSI.put("nssiId", nssiId)
450 currentNSSI.put("nsiId", nsiId)
451 currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
452 currentNSSI.put("operationId", "operationId")
453 currentNSSI.put("operationType", "operationType")
454 currentNSSI.put("nssi", nssi)
456 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
458 spy.prepareFailedOperationStatusUpdate(mockExecution)
463 void testPrepareUpdateResourceOperationStatus() {
464 def currentNSSI = [:]
466 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
467 when(mockExecution.getVariable("jobId")).thenReturn("job-id")
468 when(mockExecution.getVariable("operationType")).thenReturn("operation-type")
470 String nssiId = "5G-999"
471 String nsiId = "5G-777"
473 ServiceInstance nssi = new ServiceInstance()
474 nssi.setServiceInstanceId(nssiId)
475 nssi.setModelVersionId(UUID.randomUUID().toString())
477 currentNSSI.put("nssiId", nssiId)
478 currentNSSI.put("nsiId", nsiId)
479 currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
480 currentNSSI.put("operationId", "operationId")
481 currentNSSI.put("operationType", "operationType")
482 currentNSSI.put("nssi", nssi)
484 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
486 spy.prepareUpdateResourceOperationStatus(mockExecution)
492 void testGetPUTServiceInstanceProgressAcknowledged() {
494 executePUTServiceInstanceProgress("ACKNOWLEDGED")
495 Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing")
500 void testGetPUTServiceInstanceProgressInProgress() {
502 executePUTServiceInstanceProgress("IN_PROGRESS")
503 Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing")
508 void testGetPUTServiceInstanceProgressCompleted() {
510 executePUTServiceInstanceProgress("COMPLETE")
511 Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "completed")
516 void testTimeDelay() {
517 DoCommonCoreNSSI obj = spy(DoCommonCoreNSSI.class)
519 long before = Instant.now().toEpochMilli()
520 obj.timeDelay(mockExecution)
522 long after = Instant.now().toEpochMilli()
526 assertTrue(String.format("Didn't wait %d sec", delay), ((after - before) >= delay))
531 void testPostProcessRequest() {
533 def currentNSSI = [:]
534 mockExecution.setVariable("currentNSSI", currentNSSI)
536 DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI()
537 dcnssi.postProcessRequest(mockExecution)
539 currentNSSI = mockExecution.getVariable("currentNSSI")
540 assertNull("currentNSSI is not null", currentNSSI)
545 void executePUTServiceInstanceProgress(String state) {
547 def currentNSSI = [:]
549 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
551 String url = "http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/5G-777"
553 currentNSSI['requestSelfLink'] = url
555 DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
557 ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
558 when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock)
560 // ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
562 // when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
564 MsoUtils msoUtilsMock = mock(MsoUtils.class)
565 String basicAuth = "basicAuth"
566 when(msoUtilsMock.getBasicAuth(anyString(), anyString())).thenReturn(basicAuth)
568 HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class)
569 when(spy.getHttpClientFactory()).thenReturn(httpClientFactoryMock)
570 Response responseMock = mock(Response.class)
572 HttpClient httpClientMock = mock(HttpClient.class)
575 when(httpClientFactoryMock.newJsonClient(any(), any())).thenReturn(httpClientMock)
577 when(httpClientMock.get()).thenReturn(responseMock)
578 // when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
580 when(responseMock.getStatus()).thenReturn(200)
581 when(responseMock.hasEntity()).thenReturn(true)
583 String entity = "{\"request\":{\"requestStatus\":{\"requestState\":\"${state}\"}},\"state\":\"ACCEPTED\"}"
584 when(responseMock.readEntity(String.class)).thenReturn(entity)
586 spy.getPUTServiceInstanceProgress(mockExecution)
591 void prepareProject(AAIResourceUri cloudRegionAAIUri) {
592 Project project = new Project()
593 project.setProjectName("project-name")
595 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
596 Relationships rsMock = mock(Relationships.class)
597 Optional<Relationships> orsMock = Optional.of(rsMock)
599 when(client.get(cloudRegionAAIUri)).thenReturn(wrapperMock)
600 when(wrapperMock.getRelationships()).thenReturn(orsMock)
602 List<AAIResourceUri> arus = new ArrayList<>()
603 AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
606 when(rsMock.getRelatedUris(Types.PROJECT)).thenReturn(arus)
608 Optional<Project> projectOpt = Optional.of(project)
610 when(client.get(Project.class, aru)).thenReturn(projectOpt)
614 void prepareOwningEntity(AAIResourceUri networkServiceInstanceUri) {
615 OwningEntity owningEntity = new OwningEntity()
617 owningEntity.setOwningEntityId("owning-entity-id")
618 owningEntity.setOwningEntityName("owning-entity-name")
620 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
622 Relationships rsMock = mock(Relationships.class)
623 Optional<Relationships> orsMock = Optional.of(rsMock)
625 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
626 when(wrapperMock.getRelationships()).thenReturn(orsMock)
628 List<AAIResourceUri> arus = new ArrayList<>()
629 AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri)
632 when(rsMock.getRelatedUris(Types.OWNING_ENTITY)).thenReturn(arus)
634 Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity)
636 when(client.get(OwningEntity.class, aru)).thenReturn(owningEntityOpt)
641 void prepareCloudConfiguration(AAIResourceUri constituteVNFURI, cloudRegionAAIUri) {
642 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
644 Relationships rsMock = mock(Relationships.class)
645 Optional<Relationships> orsMock = Optional.of(rsMock)
647 when(client.get(constituteVNFURI)).thenReturn(wrapperMock)
648 when(wrapperMock.getRelationships()).thenReturn(orsMock)
650 List<AAIResourceUri> arus = new ArrayList<>()
651 AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
654 when(rsMock.getRelatedUris(Types.CLOUD_REGION)).thenReturn(arus)
656 CloudRegion cloudRegion = new CloudRegion()
657 cloudRegion.setCloudRegionId("cloud-region-id")
658 cloudRegion.setCloudOwner("cloud-owner")
659 Tenant tenant = new Tenant()
660 tenant.setTenantId("tenant-id")
662 Tenants tenants = new Tenants()
663 tenants.getTenant().add(tenant)
664 cloudRegion.setTenants(tenants)
665 Optional<CloudRegion> cloudRegionOpt = Optional.of(cloudRegion)
667 when(client.get(CloudRegion.class, aru)).thenReturn(cloudRegionOpt)
671 void prepareSubscriberInfo( AAIResourceUri networkServiceInstanceUri) {
672 AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
674 Relationships rsMock = mock(Relationships.class)
675 Optional<Relationships> orsMock = Optional.of(rsMock)
677 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
678 when(wrapperMock.getRelationships()).thenReturn(orsMock)
680 AAIResourceUri serviceSubscriptionUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-customer-id").serviceSubscription("service-type"))
682 AAIResourceUri customerUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-customer-id"))
683 List<AAIResourceUri> arus = new ArrayList<>()
685 arus.add(serviceSubscriptionUri)
687 when(rsMock.getRelatedUris(Types.SERVICE_SUBSCRIPTION)).thenReturn(arus)
689 ServiceSubscription serviceSubscription = new ServiceSubscription()
690 serviceSubscription.setServiceType("service-type")
691 Optional<ServiceSubscription> serviceSubscriptionOpt = Optional.of(serviceSubscription)
693 when(client.get(ServiceSubscription.class, serviceSubscriptionUri)).thenReturn(serviceSubscriptionOpt)
695 when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
697 when(rsMock.getRelatedUris(Types.CUSTOMER)).thenReturn(arus)
699 Customer customer = new Customer()
700 customer.setSubscriberName("subscriber-name")
701 Optional<Customer> customerOpt = Optional.of(customer)
703 when(client.get(Customer.class, customerUri)).thenReturn(customerOpt)
707 void prepareModelVer(ServiceInstance networkServiceInstance) {
708 ModelVer modelVer = new ModelVer()
709 modelVer.setModelVersionId("model-version-id")
710 modelVer.setModelName("model-name")
711 modelVer.setModelVersion("model-version")
713 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
715 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(networkServiceInstance.getModelInvariantId()).modelVer(networkServiceInstance.getModelVersionId()))
716 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
719 void prepareModelVer(GenericVnf genericVnf) {
720 ModelVer modelVer = new ModelVer()
721 modelVer.setModelVersionId("model-version-id")
722 modelVer.setModelName("model-name")
723 modelVer.setModelVersion("model-version")
725 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
727 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(genericVnf.getModelInvariantId()).modelVer(genericVnf.getModelVersionId()))
728 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
731 void prepareModelVer(VfModule vfModule) {
732 ModelVer modelVer = new ModelVer()
733 modelVer.setModelVersionId("model-version-id")
734 modelVer.setModelName("model-name")
735 modelVer.setModelVersion("model-version")
737 Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
739 AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
740 when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)