6ca3937d6831b313c0a5a9221b6c47417a66e59a
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.junit.Before
25 import org.junit.Test
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.serviceinstancebeans.RequestDetails
40
41 import javax.ws.rs.core.Response
42 import java.time.Instant
43
44 import static org.junit.Assert.assertNotNull
45 import static org.junit.Assert.assertTrue
46 import static org.mockito.Mockito.*
47
48 class DoCommonCoreNSSITest extends MsoGroovyTest {
49     @Before
50     void init() throws IOException {
51         super.init("DoCommonCoreNSSITest")
52     }
53
54
55     @Test
56     void testPreProcessRequest() {
57
58         String nssiId = "5G-999"
59         when(mockExecution.getVariable("serviceInstanceID")).thenReturn(nssiId)
60
61         String nsiId = "5G-777"
62         when(mockExecution.getVariable("nsiId")).thenReturn(nsiId)
63
64         String snssai = "S-NSSAI"
65         String snssaiList = "[ \"${snssai}\" ]"
66         String sliceProfileId = "slice-profile-id"
67         String sliceParams =  "{\n" +
68                 "\"sliceProfile\":{\"sliceProfileId\":\"${sliceProfileId}\",\"snssaiList\":${snssaiList}}\n" +
69                 "}"
70         when(mockExecution.getVariable("sliceParams")).thenReturn(sliceParams)
71
72         DoCommonCoreNSSI dcnssi = new DoCommonCoreNSSI()
73         dcnssi.preProcessRequest(mockExecution)
74
75         def currentNSSI = [:]
76         currentNSSI.put("nssiId", nssiId)
77         currentNSSI.put("nsiId", nsiId)
78         currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"]}")
79         currentNSSI.put("S-NSSAI", snssai)
80         currentNSSI.put("sliceProfileId", sliceProfileId)
81         Mockito.verify(mockExecution,times(1)).setVariable("currentNSSI", currentNSSI)
82
83     }
84
85
86     @Test
87     void testGetNetworkServiceInstance() {
88         def currentNSSI = [:]
89         currentNSSI.put("nssiId","5G-999")
90
91         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
92
93         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment("5G-999"))
94         AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment("NS-777"))
95
96         ServiceInstance nssi = new ServiceInstance()
97         nssi.setServiceInstanceId("5G-999")
98
99         ServiceInstance networkServiceInstance = new ServiceInstance()
100         networkServiceInstance.setServiceInstanceId("NS-777")
101         networkServiceInstance.setServiceRole("Network Service")
102
103         Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
104         Optional<ServiceInstance> networkServiceInstaneOpt = Optional.of(networkServiceInstance)
105
106         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
107         when(spy.getAAIClient()).thenReturn(client)
108
109         when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)
110
111         //String json = FileUtil.readResourceFile("__files/AAI/ServiceInstanceWithAR.json")
112         AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
113         Relationships rsMock = mock(Relationships.class)
114         Optional<Relationships> orsMock = Optional.of(rsMock)
115         List<AAIResourceUri> arus = new ArrayList<>()
116         AAIResourceUri aru = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
117         arus.add(aru)
118
119         when(client.get(nssiUri)).thenReturn(wrapperMock)
120         when(wrapperMock.getRelationships()).thenReturn(orsMock)
121
122         when(rsMock.getRelatedUris(Types.SERVICE_INSTANCE)).thenReturn(arus)
123         when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt)
124
125         spy.getNetworkServiceInstance(mockExecution)
126
127         assertTrue("Either NSSI doesn't exist or unexpected NSSI Service Instance ID",
128                 currentNSSI.get("nssi") != null && ((ServiceInstance)currentNSSI.get("nssi")).getServiceInstanceId().equals(nssi.getServiceInstanceId()))
129
130         assertTrue("Either Network Service Instance doesn't exist or unexpected Network Service Instance ID",
131                 currentNSSI.get("networkServiceInstance") != null && ((ServiceInstance)currentNSSI.get("networkServiceInstance")).getServiceInstanceId().equals(networkServiceInstance.getServiceInstanceId()))
132
133         assertNotNull("networkServiceInstanceUri doesn't exist", currentNSSI.get("networkServiceInstanceUri"))
134     }
135
136
137     @Test
138     void getConstituteVNFFromNetworkServiceInst() {
139         def currentNSSI = [:]
140
141         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
142
143         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
144         when(spy.getAAIClient()).thenReturn(client)
145
146         ServiceInstance networkServiceInstance = new ServiceInstance()
147         networkServiceInstance.setServiceInstanceId("NS-777")
148         networkServiceInstance.setServiceRole("Network Service")
149
150         GenericVnf genericVNF = new GenericVnf()
151         genericVNF.setVnfId("VNF-1")
152
153         AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
154
155         Optional<GenericVnf> genericVnfOpt = Optional.of(genericVNF)
156         AAIResourceUri genericVNFUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVNF.getVnfId()))
157
158         currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
159         currentNSSI.put("networkServiceInstance", networkServiceInstance)
160
161         AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
162         Relationships rsMock = mock(Relationships.class)
163         Optional<Relationships> orsMock = Optional.of(rsMock)
164         List<AAIResourceUri> arus = new ArrayList<>()
165         AAIResourceUri aru = new AAISimpleUri(genericVNFUri)
166         arus.add(aru)
167
168         when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
169         when(wrapperMock.getRelationships()).thenReturn(orsMock)
170
171         when(rsMock.getRelatedUris(Types.GENERIC_VNF)).thenReturn(arus)
172         when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt)
173
174         spy.getConstituteVNFFromNetworkServiceInst(mockExecution)
175
176         assertNotNull("constituteVnfUri doesn't exist", currentNSSI.get("constituteVnfUri"))
177
178         assertTrue("Either Constitute VNF doesn't exist or unexpected VNF ID",
179                 currentNSSI.get("constituteVnf") != null && ((GenericVnf)currentNSSI.get("constituteVnf")).getVnfId().equals(genericVNF.getVnfId()))
180     }
181
182
183     @Test
184     void testGetNSSIAssociatedProfiles() {
185         def currentNSSI = [:]
186         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
187
188         ServiceInstance nssi = new ServiceInstance()
189         nssi.setServiceInstanceId("5G-999")
190
191         SliceProfiles sliceProfiles = new SliceProfiles()
192
193         List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
194         slProfiles.add(new SliceProfile())
195         slProfiles.add(new SliceProfile())
196
197         nssi.setSliceProfiles(sliceProfiles)
198         currentNSSI.put("nssi", nssi)
199
200         DoCommonCoreNSSI obj = new DoCommonCoreNSSI()
201         obj.getNSSIAssociatedProfiles(mockExecution)
202
203         List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
204         assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
205     }
206
207
208     @Test
209     void testInvokePUTServiceInstance() {
210         def currentNSSI = [:]
211
212         ServiceInstance networkServiceInstance = new ServiceInstance()
213         networkServiceInstance.setServiceInstanceId("NS-777")
214         networkServiceInstance.setServiceRole("Network Service")
215
216         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
217
218         currentNSSI.put("networkServiceInstance", networkServiceInstance)
219
220         when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
221         when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
222         when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
223
224         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
225         when(spy.getAAIClient()).thenReturn(client)
226
227         when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
228
229         String authHeaderResponse =  "auth-header"
230
231         when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
232
233         String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s", networkServiceInstance.getServiceInstanceId())
234
235         String callPUTServiceInstanceResponse = "put"
236
237         RequestDetails requestDetails = new RequestDetails()
238         ObjectMapper mapper = new ObjectMapper()
239         String requestDetailsStr = mapper.writeValueAsString(requestDetails)
240
241         when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)
242
243         when(spy.callPUTServiceInstance(urlString, "auth-header", requestDetailsStr)).thenReturn(callPUTServiceInstanceResponse)
244
245         spy.invokePUTServiceInstance(mockExecution)
246     }
247
248
249     @Test
250     void testRemoveSPAssociationWithNSSI() {
251         def currentNSSI = [:]
252
253         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
254
255         String nssiId = "5G-999"
256         currentNSSI.put("nssiId", nssiId)
257         ServiceInstance nssi = new ServiceInstance()
258         nssi.setServiceInstanceId(nssiId)
259         nssi.setSliceProfiles(new SliceProfiles())
260
261         currentNSSI.put("nssi", nssi)
262
263         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
264
265         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
266
267         when(spy.getAAIClient()).thenReturn(client)
268
269         String theSNSSAI = "theS-NSSAI"
270         currentNSSI.put("S-NSSAI", theSNSSAI)
271
272         List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()
273
274         SliceProfile sliceProfile1 = new SliceProfile()
275         sliceProfile1.setSNssai("snssai1")
276
277         SliceProfile sliceProfile2 = new SliceProfile()
278         sliceProfile2.setSNssai(theSNSSAI)
279
280         SliceProfile sliceProfile3 = new SliceProfile()
281         sliceProfile3.setSNssai("snssai3")
282
283         associatedProfiles.add(sliceProfile1)
284         associatedProfiles.add(sliceProfile2)
285         associatedProfiles.add(sliceProfile3)
286
287         int sizeBefore = associatedProfiles.size()
288
289         doNothing().when(client).update(nssiUri, nssi)
290
291         spy.removeSPAssociationWithNSSI(mockExecution)
292
293         assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
294     }
295
296
297     @Test
298     void testDeleteSliceProfileInstance() {
299         def currentNSSI = [:]
300
301         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
302
303         String globalSubscriberId = "global-id"
304         String subscriptionServiceType = "subscription-service-type"
305         String nssiId = "5G-999"
306
307         when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId)
308         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType)
309
310         currentNSSI.put("nssiId", nssiId)
311
312         String theSNSSAI = "theS-NSSAI"
313
314         SliceProfile sliceProfile = new SliceProfile()
315         sliceProfile.setSNssai(theSNSSAI)
316         sliceProfile.setProfileId("prof-id")
317
318         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
319
320         currentNSSI.put("sliceProfileS-NSSAI", sliceProfile)
321
322         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
323
324         when(spy.getAAIClient()).thenReturn(client)
325
326         doNothing().when(client).delete(nssiUri)
327
328         spy.deleteSliceProfileInstance(mockExecution)
329
330     }
331
332
333     @Test
334     void testPrepareRequestDetails() {
335         def currentNSSI = [:]
336
337         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
338
339         ServiceInstance networkServiceInstance = new ServiceInstance()
340         networkServiceInstance.setServiceInstanceId("NS-777")
341         networkServiceInstance.setServiceRole("Network Service")
342         networkServiceInstance.setModelInvariantId("model-invariant-id")
343         networkServiceInstance.setServiceInstanceName("service-instance-name")
344
345         ServiceInstance nssi = new ServiceInstance()
346         nssi.setServiceInstanceId("5G-999")
347         nssi.setOrchestrationStatus("orchestration-status")
348
349         AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(networkServiceInstance.getServiceInstanceId()))
350
351         AAIResourceUri cloudRegionAAIUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("cloud-owner", "cloud-region-id"))
352
353         currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
354
355         currentNSSI.put("networkServiceInstance", networkServiceInstance)
356
357         currentNSSI.put("globalSubscriberId", "globalSubscriberId")
358
359         currentNSSI.put("subscriberName", "subscriber-name")
360
361         currentNSSI.put("serviceId", "service-id")
362
363         currentNSSI.put("nssi", nssi)
364
365         List<SliceProfile> associatedProfiles = new ArrayList<>()
366         SliceProfile sliceProfile1 = new SliceProfile()
367         sliceProfile1.setSNssai("snssai1")
368
369         SliceProfile sliceProfile2 = new SliceProfile()
370         sliceProfile2.setSNssai("snssai2")
371
372         associatedProfiles.add(sliceProfile1)
373         associatedProfiles.add(sliceProfile2)
374
375         List<String> snssais = new ArrayList<>()
376         snssais.add(sliceProfile1.getSNssai())
377         snssais.add(sliceProfile2.getSNssai())
378
379         currentNSSI.put("S-NSSAIs", snssais)
380
381
382         ServiceSubscription serviceSubscription = new ServiceSubscription()
383         serviceSubscription.setServiceType("service-type")
384
385         currentNSSI.put("serviceSubscription", serviceSubscription)
386
387         GenericVnf genericVnf = new GenericVnf()
388         genericVnf.setServiceId("service-id")
389         genericVnf.setVnfName("vnf-name")
390         genericVnf.setModelInvariantId("model-invariant-id")
391         genericVnf.setModelCustomizationId("model-customization-id")
392         genericVnf.setVnfName("vnf-name")
393         genericVnf.setVnfId("vnf-id")
394
395         VfModule vfModule = new VfModule()
396         vfModule.setModelInvariantId("model-invariant-id")
397         vfModule.setModelCustomizationId("model-customization-id")
398         vfModule.setModelVersionId("model-version-id")
399         vfModule.setVfModuleName("vf-module-name")
400
401         VfModules vfModules = new VfModules()
402         vfModules.getVfModule().add(vfModule)
403         genericVnf.setVfModules(vfModules)
404
405         currentNSSI.put("constituteVnf", genericVnf)
406
407         AAIResourceUri constituteVNFURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnf.getVnfId()))
408
409         currentNSSI.put("constituteVnfUri", constituteVNFURI)
410
411         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
412
413         when(spy.getAAIClient()).thenReturn(client)
414
415         prepareModelVer(networkServiceInstance)
416
417         //prepareSubscriberInfo(networkServiceInstanceUri)
418
419         prepareCloudConfiguration(constituteVNFURI, cloudRegionAAIUri)
420
421         prepareModelVer(genericVnf)
422
423         prepareModelVer(vfModule)
424
425         prepareOwningEntity(networkServiceInstanceUri)
426
427         prepareProject(cloudRegionAAIUri)
428
429         String requestDetails = spy.prepareRequestDetails(mockExecution)
430
431     }
432
433
434     @Test
435     void testPrepareFailedOperationStatusUpdate() {
436         def currentNSSI = [:]
437
438         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
439         when(mockExecution.getVariable("jobId")).thenReturn("job-id")
440         when(mockExecution.getVariable("operationType")).thenReturn("operation-type")
441
442         String nssiId = "5G-999"
443         String nsiId = "5G-777"
444
445         currentNSSI.put("nssiId", nssiId)
446         currentNSSI.put("nsiId", nsiId)
447         currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
448         currentNSSI.put("operationId", "operationId")
449         currentNSSI.put("operationType", "operationType")
450
451         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
452
453         spy.prepareFailedOperationStatusUpdate(mockExecution)
454     }
455
456
457     @Test
458     void testPrepareUpdateResourceOperationStatus() {
459         def currentNSSI = [:]
460
461         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
462         when(mockExecution.getVariable("jobId")).thenReturn("job-id")
463         when(mockExecution.getVariable("operationType")).thenReturn("operation-type")
464
465         String nssiId = "5G-999"
466         String nsiId = "5G-777"
467
468         currentNSSI.put("nssiId", nssiId)
469         currentNSSI.put("nsiId", nsiId)
470         currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
471         currentNSSI.put("operationId", "operationId")
472         currentNSSI.put("operationType", "operationType")
473
474         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
475
476         spy.prepareUpdateResourceOperationStatus(mockExecution)
477
478     }
479
480
481     @Test
482     void testGetPUTServiceInstanceProgressAcknowledged() {
483
484         executePUTServiceInstanceProgress("ACKNOWLEDGED")
485         Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing")
486     }
487
488
489     @Test
490     void testGetPUTServiceInstanceProgressInProgress() {
491
492         executePUTServiceInstanceProgress("INPROGRESS")
493         Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "processing")
494     }
495
496
497     @Test
498     void testGetPUTServiceInstanceProgressCompleted() {
499
500         executePUTServiceInstanceProgress("COMPLETED")
501         Mockito.verify(mockExecution,times(1)).setVariable("putStatus", "completed")
502     }
503
504
505     @Test
506     void testTimeDelay() {
507         DoCommonCoreNSSI obj = spy(DoCommonCoreNSSI.class)
508
509         long before = Instant.now().toEpochMilli()
510         obj.timeDelay(mockExecution)
511
512         long after = Instant.now().toEpochMilli()
513
514         long delay = 5L
515
516         assertTrue(String.format("Didn't wait %d sec", delay), ((after - before) >= delay))
517     }
518
519
520     void executePUTServiceInstanceProgress(String state) {
521
522         def currentNSSI = [:]
523
524         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
525
526         String url = "http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/5G-777"
527
528         currentNSSI.put("putServiceInstanceURL", url)
529
530         DoCommonCoreNSSI spy = spy(DoCommonCoreNSSI.class)
531
532         ExternalAPIUtilFactory externalAPIUtilFactoryMock = mock(ExternalAPIUtilFactory.class)
533         when(spy.getExternalAPIUtilFactory()).thenReturn(externalAPIUtilFactoryMock)
534
535         ExternalAPIUtil externalAPIUtilMock = mock(ExternalAPIUtil.class)
536
537         when(externalAPIUtilFactoryMock.create()).thenReturn(externalAPIUtilMock)
538
539         Response responseMock = mock(Response.class)
540         when(externalAPIUtilMock.executeExternalAPIGetCall(mockExecution, url)).thenReturn(responseMock)
541
542         when(responseMock.getStatus()).thenReturn(200)
543
544         String entity = "{\"state\":\"ACCEPTED\",\"orderItem\":[{\"service\":{\"id\":\"5G-999\"},\"state\":\"${state}\"}]}"
545         when(responseMock.readEntity(String.class)).thenReturn(entity)
546
547         spy.getPUTServiceInstanceProgress(mockExecution)
548
549     }
550
551
552     void prepareProject(AAIResourceUri cloudRegionAAIUri) {
553         Project project = new Project()
554         project.setProjectName("project-name")
555
556         AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
557         Relationships rsMock = mock(Relationships.class)
558         Optional<Relationships> orsMock = Optional.of(rsMock)
559
560         when(client.get(cloudRegionAAIUri)).thenReturn(wrapperMock)
561         when(wrapperMock.getRelationships()).thenReturn(orsMock)
562
563         List<AAIResourceUri> arus = new ArrayList<>()
564         AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
565         arus.add(aru)
566
567         when(rsMock.getRelatedUris(Types.PROJECT)).thenReturn(arus)
568
569         Optional<Project> projectOpt = Optional.of(project)
570
571         when(client.get(Project.class, aru)).thenReturn(projectOpt)
572     }
573
574
575     void prepareOwningEntity(AAIResourceUri networkServiceInstanceUri) {
576         OwningEntity owningEntity = new OwningEntity()
577
578         owningEntity.setOwningEntityId("owning-entity-id")
579         owningEntity.setOwningEntityName("owning-entity-name")
580
581         AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
582
583         Relationships rsMock = mock(Relationships.class)
584         Optional<Relationships> orsMock = Optional.of(rsMock)
585
586         when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
587         when(wrapperMock.getRelationships()).thenReturn(orsMock)
588
589         List<AAIResourceUri> arus = new ArrayList<>()
590         AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri)
591         arus.add(aru)
592
593         when(rsMock.getRelatedUris(Types.OWNING_ENTITY)).thenReturn(arus)
594
595         Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity)
596
597         when(client.get(OwningEntity.class, aru)).thenReturn(owningEntityOpt)
598     }
599
600
601
602     void prepareCloudConfiguration(AAIResourceUri constituteVNFURI, cloudRegionAAIUri) {
603         AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
604
605         Relationships rsMock = mock(Relationships.class)
606         Optional<Relationships> orsMock = Optional.of(rsMock)
607
608         when(client.get(constituteVNFURI)).thenReturn(wrapperMock)
609         when(wrapperMock.getRelationships()).thenReturn(orsMock)
610
611         List<AAIResourceUri> arus = new ArrayList<>()
612         AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
613         arus.add(aru)
614
615         when(rsMock.getRelatedUris(Types.CLOUD_REGION)).thenReturn(arus)
616
617         CloudRegion cloudRegion = new CloudRegion()
618         cloudRegion.setCloudRegionId("cloud-region-id")
619         cloudRegion.setCloudOwner("cloud-owner")
620         Tenant tenant = new Tenant()
621         tenant.setTenantId("tenant-id")
622
623         Tenants tenants = new Tenants()
624         tenants.getTenant().add(tenant)
625         cloudRegion.setTenants(tenants)
626         Optional<CloudRegion> cloudRegionOpt = Optional.of(cloudRegion)
627
628         when(client.get(CloudRegion.class, aru)).thenReturn(cloudRegionOpt)
629     }
630
631
632     void prepareSubscriberInfo( AAIResourceUri networkServiceInstanceUri) {
633         AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
634
635         Relationships rsMock = mock(Relationships.class)
636         Optional<Relationships> orsMock = Optional.of(rsMock)
637
638         when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
639         when(wrapperMock.getRelationships()).thenReturn(orsMock)
640
641         AAIResourceUri serviceSubscriptionUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-customer-id").serviceSubscription("service-type"))
642
643         AAIResourceUri customerUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("global-customer-id"))
644         List<AAIResourceUri> arus = new ArrayList<>()
645
646         arus.add(serviceSubscriptionUri)
647
648         when(rsMock.getRelatedUris(Types.SERVICE_SUBSCRIPTION)).thenReturn(arus)
649
650         ServiceSubscription serviceSubscription = new ServiceSubscription()
651         serviceSubscription.setServiceType("service-type")
652         Optional<ServiceSubscription> serviceSubscriptionOpt = Optional.of(serviceSubscription)
653
654         when(client.get(ServiceSubscription.class, serviceSubscriptionUri)).thenReturn(serviceSubscriptionOpt)
655
656         when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
657
658         when(rsMock.getRelatedUris(Types.CUSTOMER)).thenReturn(arus)
659
660         Customer customer = new Customer()
661         customer.setSubscriberName("subscriber-name")
662         Optional<Customer> customerOpt = Optional.of(customer)
663
664         when(client.get(Customer.class, customerUri)).thenReturn(customerOpt)
665     }
666
667
668     void prepareModelVer(ServiceInstance networkServiceInstance) {
669         ModelVer modelVer = new ModelVer()
670         modelVer.setModelVersionId("model-version-id")
671         modelVer.setModelName("model-name")
672         modelVer.setModelVersion("model-version")
673
674         Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
675
676         AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(networkServiceInstance.getModelInvariantId()).modelVer(networkServiceInstance.getModelVersionId()))
677         when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
678     }
679
680     void prepareModelVer(GenericVnf genericVnf) {
681         ModelVer modelVer = new ModelVer()
682         modelVer.setModelVersionId("model-version-id")
683         modelVer.setModelName("model-name")
684         modelVer.setModelVersion("model-version")
685
686         Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
687
688         AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(genericVnf.getModelInvariantId()).modelVer(genericVnf.getModelVersionId()))
689         when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
690     }
691
692     void prepareModelVer(VfModule vfModule) {
693         ModelVer modelVer = new ModelVer()
694         modelVer.setModelVersionId("model-version-id")
695         modelVer.setModelName("model-name")
696         modelVer.setModelVersion("model-version")
697
698         Optional<ModelVer> modelVerOpt = Optional.of(modelVer)
699
700         AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().model(vfModule.getModelInvariantId()).modelVer(vfModule.getModelVersionId()))
701         when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
702     }
703 }