31bd3b56f53492cfcffd6828c5cc0becad1ef270
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoDeallocateTnNssiTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  #
8  # Licensed under the Apache License, Version 2.0 (the "License")
9  # you may not use this file except in compliance with the License.
10  # You may obtain a copy of the License at
11  #
12  #       http://www.apache.org/licenses/LICENSE-2.0
13  #
14  # Unless required by applicable law or agreed to in writing, software
15  # distributed under the License is distributed on an "AS IS" BASIS,
16  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  # See the License for the specific language governing permissions and
18  # limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
25 import org.junit.Test
26 import org.mockito.ArgumentCaptor
27 import org.mockito.Captor
28 import org.mockito.Mockito
29 import org.onap.aaiclient.client.aai.AAIObjectType
30 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
31 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
32 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
34 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
35
36 import static org.junit.Assert.assertNotNull
37 import static org.mockito.ArgumentMatchers.eq
38 import static org.mockito.Mockito.*
39
40
41 class DoDeallocateTnNssiTest extends MsoGroovyTest {
42     @Before
43     void init() throws IOException {
44         super.init("DeallocateTnNssiTest")
45     }
46
47     @Captor
48     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
49
50     @Test
51     void testPreProcessRequest() {
52         when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
53         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
54         when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71")
55         when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6")
56         when(mockExecution.getVariable("serviceInstanceID")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7")
57         when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
58         when(mockExecution.getVariable("operationType")).thenReturn("opTypeTest")
59         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
60         when(mockExecution.getVariable("servicename")).thenReturn("5G-test")
61         when(mockExecution.getVariable("networkType")).thenReturn("5G-network")
62         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G-service")
63         when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
64         when(mockExecution.getVariable("jobId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
65         when(mockExecution.getVariable("sliceParams")).thenReturn("""
66         {
67     "sliceProfile": {
68       "snssaiList": [
69         "001-100001"
70       ],
71       "sliceProfileId": "ab9af40f13f721b5f13539d87484098",
72       "plmnIdList": [
73         "460-00",
74         "460-01"
75       ],
76       "perfReq": {
77       },
78       "coverageAreaTAList": [
79       ],
80       "latency": 2,
81       "maxBandwidth": 100,
82       "resourceSharingLevel": "non-shared"
83     },
84     "transportSliceNetworks": [
85             {
86                 "connectionLinks": [
87                     {
88                         "transportEndpointA": "tranportEp_ID_XXX",
89                         "transportEndpointB": "tranportEp_ID_YYY"
90                     },
91                     {
92                         "transportEndpointA": "tranportEp_ID_AAA",
93                         "transportEndpointB": "tranportEp_ID_BBB"
94                     }
95                 ]
96             },
97             {
98                 "connectionLinks": [
99                     {
100                         "transportEndpointA": "tranportEp_ID_CCC",
101                         "transportEndpointB": "tranportEp_ID_DDD"
102                     },
103                     {
104                         "transportEndpointA": "tranportEp_ID_EEE",
105                         "transportEndpointB": "tranportEp_ID_FFF"
106                     }
107                 ]
108             }
109     ],
110     "nsiInfo": {
111       "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX",
112       "nsiName": "eMBB-001"
113     },
114     "scriptName": "AN1"
115         }""".replaceAll("\\\\s+", ""))
116
117         DoDeallocateTnNssi runScript = new DoDeallocateTnNssi()
118         runScript.preProcessRequest(mockExecution)
119         Mockito.verify(mockExecution, times(1)).setVariable(eq("sliceServiceInstanceId"), captor.capture())
120         String sliceServiceInstanceId = captor.getValue()
121         assertNotNull(sliceServiceInstanceId)
122     }
123
124     @Test
125     void testDeleteServiceInstance() {
126         when(mockExecution.getVariable("serviceInstanceID")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
127         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
128         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G")
129
130         AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5ad89cf9-0569-4a93-9306-d8324321e2be"))
131         DoDeallocateTnNssi obj = spy(DoDeallocateTnNssi.class)
132         when(obj.getAAIClient()).thenReturn(client)
133         doNothing().when(client).delete(serviceInstanceUri)
134
135         obj.deleteServiceInstance(mockExecution)
136         Mockito.verify(client, times(1)).delete(serviceInstanceUri)
137     }
138 }