summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateCoreNSSITest.groovy
blob: 48b96fb60ef5fb3f0fd9b728dc7d3a2810db2248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2020  TIM
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.bpmn.infrastructure.scripts

import com.fasterxml.jackson.databind.ObjectMapper
import org.camunda.bpm.engine.ProcessEngineServices
import org.camunda.bpm.engine.RepositoryService
import org.camunda.bpm.engine.impl.cmmn.execution.CaseExecutionImpl
import org.camunda.bpm.engine.impl.core.variable.scope.AbstractVariableScope
import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
import org.camunda.bpm.engine.repository.ProcessDefinition
import org.junit.Rule
import org.junit.rules.ExpectedException
import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer
import org.onap.aai.domain.yang.CloudRegion
import org.onap.aai.domain.yang.Customer
import org.onap.aai.domain.yang.GenericVnf
import org.onap.aai.domain.yang.ModelVer
import org.onap.aai.domain.yang.OwningEntity
import org.onap.aai.domain.yang.Project
import org.onap.aai.domain.yang.Relationship
import org.onap.aai.domain.yang.RelationshipList
import org.onap.aai.domain.yang.ServiceSubscription
import org.onap.aai.domain.yang.SliceProfile
import org.onap.aai.domain.yang.SliceProfiles
import org.onap.aai.domain.yang.Tenant
import org.onap.aai.domain.yang.Tenants
import org.onap.aai.domain.yang.VfModule
import org.onap.aai.domain.yang.VfModules
import org.onap.aaiclient.client.aai.entities.AAIResultWrapper
import org.onap.aaiclient.client.aai.entities.Relationships
import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri
import org.onap.aaiclient.client.aai.entities.uri.ServiceInstanceUri
import org.onap.logging.filter.base.ONAPComponents
import org.onap.so.beans.nsmf.NssiResponse
import org.onap.so.bpmn.common.scripts.ExceptionUtil
import org.onap.so.bpmn.common.scripts.MsoUtils
import org.onap.so.bpmn.mock.FileUtil
import org.onap.so.client.HttpClient
import org.onap.so.client.HttpClientFactory
import org.onap.so.serviceinstancebeans.RequestDetails
import org.onap.so.utils.CryptoUtils

import javax.ws.rs.core.Response

import static org.junit.Assert.*;
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito
import org.onap.aai.domain.yang.ServiceInstance
import org.onap.aaiclient.client.aai.AAIObjectType
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
import org.onap.so.bpmn.common.scripts.MsoGroovyTest

import static org.mockito.ArgumentMatchers.anyDouble
import static org.mockito.ArgumentMatchers.anyInt
import static org.mockito.ArgumentMatchers.anyString
import static org.mockito.ArgumentMatchers.eq
import static org.mockito.Mockito.doNothing
import static org.mockito.Mockito.doReturn
import static org.mockito.Mockito.doThrow
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.spy
import static org.mockito.Mockito.times
import static org.mockito.Mockito.verify
import static org.mockito.Mockito.when

class DoDeallocateCoreNSSITest extends MsoGroovyTest {

    @Before
    void init() throws IOException {
        super.init("DoDeallocateNSSITest")
    }


    @Test
    void testPreProcessRequest() {
        def currentNSSI = [:]
        currentNSSI.put("nssiId","5G-999")
        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        DoDeallocateCoreNSSI dcnssi = new DoDeallocateCoreNSSI()
        dcnssi.preProcessRequest(mockExecution)
        Mockito.verify(mockExecution,times(1)).getVariable("currentNSSI")
    }


    @Test
    void testExecuteTerminateNSSIQuery() {
        HttpClientFactory httpClientFactoryMock
        HttpClient httpClientMock

        def currentNSSI = [:]
        currentNSSI.put("nssiId","5G-999")

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        when(mockExecution.getVariable("mso.oof.endpoint")).thenReturn("http://oof.onap:8088")
        when(mockExecution.getVariable("mso.oof.auth")).thenReturn("mso.oof.auth")
        when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
        when(mockExecution.getVariable("mso-request-id")).thenReturn("mso-request-id")

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
        when(spy.getAAIClient()).thenReturn(client)

        when(spy.encryptBasicAuth("mso.oof.auth", "mso.msoKey")).thenReturn("auth-value")

        String authHeaderResponse =  "auth-header"

      /*  String authHeaderResponse =  "{\n" +
                " \"errorCode\": \"401\",\n" +
                " \"errorMessage\": \"Bad request\"\n" +
                "}" */

        when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)

        String urlString = "http://oof.onap:8088"

        String httpRequest =    "{\n" +
                "  \"type\": \"NSSI\",\n" +
                "  \"NxIId\": \"5G-999\",\n" +
                "  \"requestInfo\": {\n" +
                "    \"transactionId\": \"mso-request-id\",\n" +
                "    \"requestId\": \"mso-request-id\",\n" +
                "    \"sourceId\": \"so\",\n" +
                "    }\n" +
                "}"

        boolean terminateResponse = true

        String oofResponse =   "{\n" +
                " \"requestId\": \"mso-request-id\",\n" +
                " \"transactionId\": \"mso-request-id\",\n" +
                " \"statusMessage\": \"\",\n" +
                " \"requestStatus\": \"accepted\",\n" +
                " \"terminateResponse\": \"${terminateResponse}\",\n" +
                " \"reason\": \"\"\n" +
                " }\n"

        String oofCallResponse = oofResponse

      /*  String oofCallResponse =  "{\n" +
                " \"errorCode\": \"401\",\n" +
                " \"errorMessage\": \"Exception during the call\"\n" +
                "}" */

        when(spy.callOOF(urlString, "auth-header", httpRequest)).thenReturn(oofCallResponse)

        spy.executeTerminateNSSIQuery(mockExecution)

        verify(mockExecution).setVariable("isTerminateNSSI", terminateResponse)

    }


    @Test
    void testGetNetworkServiceInstance() {
        def currentNSSI = [:]
        currentNSSI.put("nssiId","5G-999")

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "5G-999")
        AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "NS-777")

        ServiceInstance nssi = new ServiceInstance()
        nssi.setServiceInstanceId("5G-999")

        ServiceInstance networkServiceInstance = new ServiceInstance()
        networkServiceInstance.setServiceInstanceId("NS-777")
        networkServiceInstance.setServiceRole("Network Service")

        Optional<ServiceInstance> nssiOpt = Optional.of(nssi)
        Optional<ServiceInstance> networkServiceInstaneOpt = Optional.of(networkServiceInstance)

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
        when(spy.getAAIClient()).thenReturn(client)

        when(client.get(ServiceInstance.class, nssiUri)).thenReturn(nssiOpt)

        //String json = FileUtil.readResourceFile("__files/AAI/ServiceInstanceWithAR.json")
        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
        Relationships rsMock = mock(Relationships.class)
        Optional<Relationships> orsMock = Optional.of(rsMock)
        List<AAIResourceUri> arus = new ArrayList<>()
        AAIResourceUri aru = new ServiceInstanceUri(networkServiceInstanceUri)
        arus.add(aru)

        when(client.get(nssiUri)).thenReturn(wrapperMock)
        when(wrapperMock.getRelationships()).thenReturn(orsMock)

        when(rsMock.getRelatedAAIUris(AAIObjectType.SERVICE_INSTANCE)).thenReturn(arus)
        when(client.get(ServiceInstance.class, aru)).thenReturn(networkServiceInstaneOpt)

        spy.getNetworkServiceInstance(mockExecution)

        assertTrue("Either NSSI doesn't exist or unexpected NSSI Service Instance ID",
                    currentNSSI.get("nssi") != null && ((ServiceInstance)currentNSSI.get("nssi")).getServiceInstanceId().equals(nssi.getServiceInstanceId()))

        assertTrue("Either Network Service Instance doesn't exist or unexpected Network Service Instance ID",
                currentNSSI.get("networkServiceInstance") != null && ((ServiceInstance)currentNSSI.get("networkServiceInstance")).getServiceInstanceId().equals(networkServiceInstance.getServiceInstanceId()))

        assertNotNull("networkServiceInstanceUri doesn't exist", currentNSSI.get("networkServiceInstanceUri"))
    }


    @Test
    void testDeleteServiceOrder() {
        def currentNSSI = [:]
        currentNSSI.put("nssiId","5G-999")

        ServiceInstance networkServiceInstance = new ServiceInstance()
        networkServiceInstance.setServiceInstanceId("NS-777")
        networkServiceInstance.setServiceRole("Network Service")

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        currentNSSI.put("networkServiceInstance", networkServiceInstance)

        when(mockExecution.getVariable("nbi.endpoint.url")).thenReturn("http://nbi.onap:8088")
        when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
        when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
        when(spy.getAAIClient()).thenReturn(client)

        when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")

        String authHeaderResponse =  "auth-header"

        /*  String authHeaderResponse =  "{\n" +
                  " \"errorCode\": \"401\",\n" +
                  " \"errorMessage\": \"Bad request\"\n" +
                  "}" */

        when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)

        String urlString = String.format("http://nbi.onap:8088/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())

        String callDeleteServiceOrderResponse = "deleted"

        when(spy.callDeleteServiceOrder(mockExecution, urlString, "auth-header")).thenReturn(callDeleteServiceOrderResponse)

        spy.deleteServiceOrder(mockExecution)
    }



    @Test
    void getConstituteVNFFromNetworkServiceInst() {
        def currentNSSI = [:]

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
        when(spy.getAAIClient()).thenReturn(client)

        ServiceInstance networkServiceInstance = new ServiceInstance()
        networkServiceInstance.setServiceInstanceId("NS-777")
        networkServiceInstance.setServiceRole("Network Service")

        GenericVnf genericVNF = new GenericVnf()
        genericVNF.setVnfId("VNF-1")

        AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, networkServiceInstance.getServiceInstanceId())

        Optional<GenericVnf> genericVnfOpt = Optional.of(genericVNF)
        AAIResourceUri genericVNFUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVNF.getVnfId())

        currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)
        currentNSSI.put("networkServiceInstance", networkServiceInstance)

        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class) //new AAIResultWrapper(json)
        Relationships rsMock = mock(Relationships.class)
        Optional<Relationships> orsMock = Optional.of(rsMock)
        List<AAIResourceUri> arus = new ArrayList<>()
        AAIResourceUri aru = new AAISimpleUri(genericVNFUri)
        arus.add(aru)

        when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
        when(wrapperMock.getRelationships()).thenReturn(orsMock)

        when(rsMock.getRelatedAAIUris(AAIObjectType.GENERIC_VNF)).thenReturn(arus)
        when(client.get(GenericVnf.class, genericVNFUri)).thenReturn(genericVnfOpt)

        spy.getConstituteVNFFromNetworkServiceInst(mockExecution)

        assertNotNull("constituteVnfUri doesn't exist", currentNSSI.get("constituteVnfUri"))

        assertTrue("Either Constitute VNF doesn't exist or unexpected VNF ID",
                currentNSSI.get("constituteVnf") != null && ((GenericVnf)currentNSSI.get("constituteVnf")).getVnfId().equals(genericVNF.getVnfId()))
    }


    @Test
    void testGetNSSIAssociatedProfiles() {
        def currentNSSI = [:]
        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        ServiceInstance nssi = new ServiceInstance()
        nssi.setServiceInstanceId("5G-999")

        SliceProfiles sliceProfiles = new SliceProfiles()

        List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
        slProfiles.add(new SliceProfile())
        slProfiles.add(new SliceProfile())

        nssi.setSliceProfiles(sliceProfiles)
        currentNSSI.put("nssi", nssi)

        DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
        obj.getNSSIAssociatedProfiles(mockExecution)

        List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
        assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
    }


    @Test
    void testCalculateSNSSAI() {
        def currentNSSI = [:]
        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        String theSNSSAI = "theS-NSSAI"

        currentNSSI.put("S-NSSAI", theSNSSAI)

        List<SliceProfile> associatedProfiles = new ArrayList<>()
        SliceProfile sliceProfile1 = new SliceProfile()
        sliceProfile1.setSNssai("snssai1")

        SliceProfile sliceProfile2 = new SliceProfile()
        sliceProfile2.setSNssai(theSNSSAI)

        SliceProfile sliceProfile3 = new SliceProfile()
        sliceProfile3.setSNssai("snssai3")

        associatedProfiles.add(sliceProfile1)
        associatedProfiles.add(sliceProfile2)
        associatedProfiles.add(sliceProfile3)

        int sizeBefore = associatedProfiles.size()

        currentNSSI.put("associatedProfiles", associatedProfiles)

        DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
        obj.calculateSNSSAI(mockExecution)

        List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
        SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")

        assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
        assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
        assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
    }


    @Test
    void testInvokePUTServiceInstance() {
        def currentNSSI = [:]

        ServiceInstance networkServiceInstance = new ServiceInstance()
        networkServiceInstance.setServiceInstanceId("NS-777")
        networkServiceInstance.setServiceRole("Network Service")

        GenericVnf constituteVnf = new GenericVnf()
        constituteVnf.setVnfId("VNF-1")

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        currentNSSI.put("networkServiceInstance", networkServiceInstance)
        currentNSSI.put("constituteVnf", constituteVnf)

        when(mockExecution.getVariable("mso.infra.endpoint.url")).thenReturn("http://mso.onap:8088")
        when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
        when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
        when(spy.getAAIClient()).thenReturn(client)

        when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")

        String authHeaderResponse =  "auth-header"

        when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)

        String urlString = String.format("http://mso.onap:8088/serviceInstantiation/v7/serviceInstances/%s/vnfs/%s", networkServiceInstance.getServiceInstanceId(), constituteVnf.getVnfId())

        String callPUTServiceInstanceResponse = "put"

        RequestDetails requestDetails = new RequestDetails()
        ObjectMapper mapper = new ObjectMapper()
        String requestDetailsStr = mapper.writeValueAsString(requestDetails)

        when(spy.prepareRequestDetails(mockExecution)).thenReturn(requestDetailsStr)

        when(spy.callPUTServiceInstance(urlString, "auth-header", requestDetailsStr)).thenReturn(callPUTServiceInstanceResponse)

        spy.invokePUTServiceInstance(mockExecution)
    }


    @Test
    void testRemoveNSSIAssociationWithNSI() {
        def currentNSSI = [:]

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)

        when(spy.getAAIClient()).thenReturn(client)

        String nssiId = "5G-999"
        String nsiId = "5G-99"
        currentNSSI.put("nssiId", nssiId)
        currentNSSI.put("nsiId", nsiId)

        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
        AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nsiId)

        doNothing().when(client).disconnect(nssiUri, nsiUri)

        spy.removeNSSIAssociationWithNSI(mockExecution)

    }


    @Test
    void testRemoveSPAssociationWithNSSI() {
        def currentNSSI = [:]

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        String nssiId = "5G-999"
        currentNSSI.put("nssiId", nssiId)
        ServiceInstance nssi = new ServiceInstance()
        nssi.setServiceInstanceId(nssiId)
        nssi.setSliceProfiles(new SliceProfiles())

        currentNSSI.put("nssi", nssi)

        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)

        when(spy.getAAIClient()).thenReturn(client)

        String theSNSSAI = "theS-NSSAI"
        currentNSSI.put("S-NSSAI", theSNSSAI)

        List<SliceProfile> associatedProfiles = nssi.getSliceProfiles().getSliceProfile()

        SliceProfile sliceProfile1 = new SliceProfile()
        sliceProfile1.setSNssai("snssai1")

        SliceProfile sliceProfile2 = new SliceProfile()
        sliceProfile2.setSNssai(theSNSSAI)

        SliceProfile sliceProfile3 = new SliceProfile()
        sliceProfile3.setSNssai("snssai3")

        associatedProfiles.add(sliceProfile1)
        associatedProfiles.add(sliceProfile2)
        associatedProfiles.add(sliceProfile3)

        int sizeBefore = associatedProfiles.size()

        doNothing().when(client).update(nssiUri, nssi)

        spy.removeSPAssociationWithNSSI(mockExecution)

        assertTrue("Association between slice profile and NSSI wasn't removed", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBefore - 1))
    }


    @Test
    void testDeleteSliceProfileInstance() {
        def currentNSSI = [:]

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        String globalSubscriberId = "global-id"
        String serviceType = "service"
        String nssiId = "5G-999"

        currentNSSI.put("globalSubscriberId", nssiId)
        currentNSSI.put("serviceType", nssiId)
        currentNSSI.put("nssiId", nssiId)

        String theSNSSAI = "theS-NSSAI"

        SliceProfile sliceProfile = new SliceProfile()
        sliceProfile.setSNssai(theSNSSAI)
        sliceProfile.setProfileId("prof-id")

        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)

        currentNSSI.put("sliceProfileS-NSSAI", sliceProfile)

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)

        when(spy.getAAIClient()).thenReturn(client)

        doNothing().when(client).delete(nssiUri)

        spy.deleteSliceProfileInstance(mockExecution)

    }


    @Test
    void testDeleteNSSIServiceInstance() {
        def currentNSSI = [:]

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        String nssiId = "5G-999"

        currentNSSI.put("nssiId", nssiId)

        AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)

        when(spy.getAAIClient()).thenReturn(client)

        doNothing().when(client).delete(nssiUri)

        spy.deleteNSSIServiceInstance(mockExecution)
    }


    @Test
    void testUpdateServiceOperationStatus() {
        def currentNSSI = [:]

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        String nssiId = "5G-999"

        currentNSSI.put("nssiId", nssiId)
        currentNSSI.put("e2eServiceInstanceId", "e2eServiceInstanceId")
        currentNSSI.put("operationId", "operationId")
        currentNSSI.put("operationType", "operationType")

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)

        spy.updateServiceOperationStatus(mockExecution)

    }


    @Test
    void testPrepareRequestDetails() {
        def currentNSSI = [:]

        when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)

        ServiceInstance networkServiceInstance = new ServiceInstance()
        networkServiceInstance.setServiceInstanceId("NS-777")
        networkServiceInstance.setServiceRole("Network Service")
        networkServiceInstance.setModelInvariantId("model-invariant-id")
        networkServiceInstance.setServiceInstanceName("service-instance-name")

        ServiceInstance nssi = new ServiceInstance()
        nssi.setServiceInstanceId("5G-999")
        nssi.setOrchestrationStatus("orchestration-status")

        AAIResourceUri networkServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "networkServiceInstance.getServiceInstanceId()")

        AAIResourceUri cloudRegionAAIUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "cloud-owner", "cloud-region-id")

        currentNSSI.put("networkServiceInstanceUri", networkServiceInstanceUri)

        currentNSSI.put("networkServiceInstance", networkServiceInstance)

        currentNSSI.put("globalSubscriberId", "globalSubscriberId")

        currentNSSI.put("subscriberName", "subscriber-name")

        currentNSSI.put("serviceId", "service-id")

        currentNSSI.put("nssi", nssi)

        List<SliceProfile> associatedProfiles = new ArrayList<>()
        SliceProfile sliceProfile1 = new SliceProfile()
        sliceProfile1.setSNssai("snssai1")

        SliceProfile sliceProfile2 = new SliceProfile()
        sliceProfile2.setSNssai("snssai2")

        associatedProfiles.add(sliceProfile1)
        associatedProfiles.add(sliceProfile2)

        List<String> snssais = new ArrayList<>()
        snssais.add(sliceProfile1.getSNssai())
        snssais.add(sliceProfile2.getSNssai())

        currentNSSI.put("S-NSSAIs", snssais)


        ServiceSubscription serviceSubscription = new ServiceSubscription()
        serviceSubscription.setServiceType("service-type")

        currentNSSI.put("serviceSubscription", serviceSubscription)

        GenericVnf genericVnf = new GenericVnf()
        genericVnf.setServiceId("service-id")
        genericVnf.setVnfName("vnf-name")
        genericVnf.setModelInvariantId("model-invariant-id")
        genericVnf.setModelCustomizationId("model-customization-id")
        genericVnf.setVnfName("vnf-name")
        genericVnf.setVnfId("vnf-id")

        VfModule vfModule = new VfModule()
        vfModule.setModelInvariantId("model-invariant-id")
        vfModule.setModelCustomizationId("model-customization-id")
        vfModule.setModelVersionId("model-version-id")
        vfModule.setVfModuleName("vf-module-name")

        VfModules vfModules = new VfModules()
        vfModules.getVfModule().add(vfModule)
        genericVnf.setVfModules(vfModules)

        currentNSSI.put("constituteVnf", genericVnf)

        AAIResourceUri constituteVNFURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericVnf.getVnfId())

        currentNSSI.put("constituteVnfUri", constituteVNFURI)

        DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)

        when(spy.getAAIClient()).thenReturn(client)

        prepareModelVer(networkServiceInstance)

        //prepareSubscriberInfo(networkServiceInstanceUri)

        prepareCloudConfiguration(constituteVNFURI, cloudRegionAAIUri)

        prepareModelVer(genericVnf)

        prepareModelVer(vfModule)

        prepareOwningEntity(networkServiceInstanceUri)

        prepareProject(cloudRegionAAIUri)

        String requestDetails = spy.prepareRequestDetails(mockExecution)

    }


    void prepareProject(AAIResourceUri cloudRegionAAIUri) {
        Project project = new Project()
        project.setProjectName("project-name")

        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)
        Relationships rsMock = mock(Relationships.class)
        Optional<Relationships> orsMock = Optional.of(rsMock)

        when(client.get(cloudRegionAAIUri)).thenReturn(wrapperMock)
        when(wrapperMock.getRelationships()).thenReturn(orsMock)

        List<AAIResourceUri> arus = new ArrayList<>()
        AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
        arus.add(aru)

        when(rsMock.getRelatedAAIUris(AAIObjectType.PROJECT)).thenReturn(arus)

        Optional<Project> projectOpt = Optional.of(project)

        when(client.get(Project.class, aru)).thenReturn(projectOpt)
    }


    void prepareOwningEntity(AAIResourceUri networkServiceInstanceUri) {
        OwningEntity owningEntity = new OwningEntity()

        owningEntity.setOwningEntityId("owning-entity-id")
        owningEntity.setOwningEntityName("owning-entity-name")

        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)

        Relationships rsMock = mock(Relationships.class)
        Optional<Relationships> orsMock = Optional.of(rsMock)

        when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
        when(wrapperMock.getRelationships()).thenReturn(orsMock)

        List<AAIResourceUri> arus = new ArrayList<>()
        AAIResourceUri aru = new AAISimpleUri(networkServiceInstanceUri)
        arus.add(aru)

        when(rsMock.getRelatedAAIUris(AAIObjectType.OWNING_ENTITY)).thenReturn(arus)

        Optional<OwningEntity> owningEntityOpt = Optional.of(owningEntity)

        when(client.get(OwningEntity.class, aru)).thenReturn(owningEntityOpt)
    }



    void prepareCloudConfiguration(AAIResourceUri constituteVNFURI, cloudRegionAAIUri) {
        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)

        Relationships rsMock = mock(Relationships.class)
        Optional<Relationships> orsMock = Optional.of(rsMock)

        when(client.get(constituteVNFURI)).thenReturn(wrapperMock)
        when(wrapperMock.getRelationships()).thenReturn(orsMock)

        List<AAIResourceUri> arus = new ArrayList<>()
        AAIResourceUri aru = new AAISimpleUri(cloudRegionAAIUri)
        arus.add(aru)

        when(rsMock.getRelatedAAIUris(AAIObjectType.CLOUD_REGION)).thenReturn(arus)

        CloudRegion cloudRegion = new CloudRegion()
        cloudRegion.setCloudRegionId("cloud-region-id")
        cloudRegion.setCloudOwner("cloud-owner")
        Tenant tenant = new Tenant()
        tenant.setTenantId("tenant-id")

        Tenants tenants = new Tenants()
        tenants.getTenant().add(tenant)
        cloudRegion.setTenants(tenants)
        Optional<CloudRegion> cloudRegionOpt = Optional.of(cloudRegion)

        when(client.get(CloudRegion.class, aru)).thenReturn(cloudRegionOpt)
    }


    void prepareSubscriberInfo( AAIResourceUri networkServiceInstanceUri) {
        AAIResultWrapper wrapperMock = mock(AAIResultWrapper.class)

        Relationships rsMock = mock(Relationships.class)
        Optional<Relationships> orsMock = Optional.of(rsMock)

        when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)
        when(wrapperMock.getRelationships()).thenReturn(orsMock)

        AAIResourceUri serviceSubscriptionUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_SUBSCRIPTION, "global-customer-id", "service-type")

        AAIResourceUri customerUri = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, "global-customer-id")
        List<AAIResourceUri> arus = new ArrayList<>()

        arus.add(serviceSubscriptionUri)

        when(rsMock.getRelatedAAIUris(AAIObjectType.SERVICE_SUBSCRIPTION)).thenReturn(arus)

        ServiceSubscription serviceSubscription = new ServiceSubscription()
        serviceSubscription.setServiceType("service-type")
        Optional<ServiceSubscription> serviceSubscriptionOpt = Optional.of(serviceSubscription)

        when(client.get(ServiceSubscription.class, serviceSubscriptionUri)).thenReturn(serviceSubscriptionOpt)

        when(client.get(networkServiceInstanceUri)).thenReturn(wrapperMock)

        when(rsMock.getRelatedAAIUris(AAIObjectType.CUSTOMER)).thenReturn(arus)

        Customer customer = new Customer()
        customer.setSubscriberName("subscriber-name")
        Optional<Customer> customerOpt = Optional.of(customer)

        when(client.get(Customer.class, customerUri)).thenReturn(customerOpt)
    }


    void prepareModelVer(ServiceInstance networkServiceInstance) {
        ModelVer modelVer = new ModelVer()
        modelVer.setModelVersionId("model-version-id")
        modelVer.setModelName("model-name")
        modelVer.setModelVersion("model-version")

        Optional<ModelVer> modelVerOpt = Optional.of(modelVer)

        AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, networkServiceInstance.getModelInvariantId(), networkServiceInstance.getModelVersionId())
        when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
    }

    void prepareModelVer(GenericVnf genericVnf) {
        ModelVer modelVer = new ModelVer()
        modelVer.setModelVersionId("model-version-id")
        modelVer.setModelName("model-name")
        modelVer.setModelVersion("model-version")

        Optional<ModelVer> modelVerOpt = Optional.of(modelVer)

        AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, genericVnf.getModelInvariantId(), genericVnf.getModelVersionId())
        when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
    }

    void prepareModelVer(VfModule vfModule) {
        ModelVer modelVer = new ModelVer()
        modelVer.setModelVersionId("model-version-id")
        modelVer.setModelName("model-name")
        modelVer.setModelVersion("model-version")

        Optional<ModelVer> modelVerOpt = Optional.of(modelVer)

        AAIResourceUri modelVerUrl = AAIUriFactory.createResourceUri(AAIObjectType.MODEL_VER, vfModule.getModelInvariantId(), vfModule.getModelVersionId())
        when(client.get(ModelVer.class, modelVerUrl)).thenReturn(modelVerOpt)
    }

}