Implemented OOF call in TN NSSMF for deallocate flow
[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 import org.onap.so.bpmn.common.scripts.OofUtils
36
37 import static org.junit.Assert.assertNotNull
38 import static org.junit.Assert.assertTrue
39 import static org.mockito.ArgumentMatchers.eq
40 import static org.mockito.Mockito.*
41
42
43 class DoDeallocateTnNssiTest extends MsoGroovyTest {
44     @Before
45     void init() throws IOException {
46         super.init("DeallocateTnNssiTest")
47     }
48
49     @Captor
50     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
51
52     @Test
53     void testPreProcessRequest() {
54         when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
55         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
56         when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71")
57         when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6")
58         when(mockExecution.getVariable("serviceInstanceID")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7")
59         when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
60         when(mockExecution.getVariable("operationType")).thenReturn("opTypeTest")
61         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
62         when(mockExecution.getVariable("servicename")).thenReturn("5G-test")
63         when(mockExecution.getVariable("networkType")).thenReturn("5G-network")
64         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G-service")
65         when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
66         when(mockExecution.getVariable("jobId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
67         when(mockExecution.getVariable("sliceParams")).thenReturn("""
68         {
69     "sliceProfile": {
70       "snssaiList": [
71         "001-100001"
72       ],
73       "sliceProfileId": "ab9af40f13f721b5f13539d87484098",
74       "plmnIdList": [
75         "460-00",
76         "460-01"
77       ],
78       "perfReq": {
79       },
80       "coverageAreaTAList": [
81       ],
82       "latency": 2,
83       "maxBandwidth": 100,
84       "resourceSharingLevel": "non-shared"
85     },
86     "transportSliceNetworks": [
87             {
88                 "connectionLinks": [
89                     {
90                         "transportEndpointA": "tranportEp_ID_XXX",
91                         "transportEndpointB": "tranportEp_ID_YYY"
92                     },
93                     {
94                         "transportEndpointA": "tranportEp_ID_AAA",
95                         "transportEndpointB": "tranportEp_ID_BBB"
96                     }
97                 ]
98             },
99             {
100                 "connectionLinks": [
101                     {
102                         "transportEndpointA": "tranportEp_ID_CCC",
103                         "transportEndpointB": "tranportEp_ID_DDD"
104                     },
105                     {
106                         "transportEndpointA": "tranportEp_ID_EEE",
107                         "transportEndpointB": "tranportEp_ID_FFF"
108                     }
109                 ]
110             }
111     ],
112     "nsiInfo": {
113       "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX",
114       "nsiName": "eMBB-001"
115     },
116     "scriptName": "AN1"
117         }""".replaceAll("\\\\s+", ""))
118
119         DoDeallocateTnNssi runScript = new DoDeallocateTnNssi()
120         runScript.preProcessRequest(mockExecution)
121         Mockito.verify(mockExecution, times(1)).setVariable(eq("sliceServiceInstanceId"), captor.capture())
122         String sliceServiceInstanceId = captor.getValue()
123         assertNotNull(sliceServiceInstanceId)
124     }
125
126     @Test
127     void testDeleteServiceInstance() {
128         when(mockExecution.getVariable("serviceInstanceID")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
129         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
130         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G")
131
132         AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer("5GCustomer").serviceSubscription("5G").serviceInstance("5ad89cf9-0569-4a93-9306-d8324321e2be"))
133         DoDeallocateTnNssi obj = spy(DoDeallocateTnNssi.class)
134         when(obj.getAAIClient()).thenReturn(client)
135         doNothing().when(client).delete(serviceInstanceUri)
136
137         obj.deleteServiceInstance(mockExecution)
138         Mockito.verify(client, times(1)).delete(serviceInstanceUri)
139     }
140
141     @Test
142     void testPrepareOOFNssiTerminationRequest() {
143         when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
144         when(mockExecution.getVariable("sliceServiceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
145         when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
146         when(mockExecution.getVariable("mso.adapters.oof.timeout")).thenReturn("")
147         DoDeallocateTnNssi obj = spy(DoDeallocateTnNssi.class)
148         OofUtils oofUtils = spy(OofUtils.class)
149         when(oofUtils.buildTerminateNxiRequest()).thenReturn("""
150         {
151         "apiPath": "/api/oof/terminate/nxi/v1",
152         "requestDetails": "{\"type\":\"NSSI\",\"NxIId\":\"f78c1531-55a7-4dfa-8a12-1e2544c9b248\",\"requestInfo\":{\"transactionId\":\"863fb189-33d8-455f-9d3f-bf3f6a2e4509\",\"requestId\":\"863fb189-33d8-455f-9d3f-bf3f6a2e4509\",\"callbackUrl\":\"http://so-oof-adapter.onap:8090/so/adapters/oof/callback/v1/TN_NSSITermination/863fb189-33d8-455f-9d3f-bf3f6a2e4509\",\"sourceId\":\"SO\",\"timeout\":600,\"addtnlArgs\":{\"serviceInstanceId\":\"fe6f0901-292d-4493-bcad-485793605781\"}}}"
153        }""".replaceAll("\\\\s+", ""))
154         obj.prepareOOFNssiTerminationRequest(mockExecution)
155         Mockito.verify(mockExecution, times(1)).setVariable(eq("oofTnNssiPayload"), captor.capture())
156         String oofTnNssiPayload = captor.getValue()
157         assertNotNull(oofTnNssiPayload)
158     }
159
160     @Test
161     void testPerformOofNSSITerminationCall() {
162         when(mockExecution.getVariable("oofTnNssiPayload")).thenReturn("""
163         {
164         "reason": "",
165         "requestId": "e0a026a9-dd6d-4800-ab27-0fdd8f5f64f5",
166         "requestStatus": "success",
167         "terminateResponse": true,
168         "transactionId": "e0a026a9-dd6d-4800-ab27-0fdd8f5f64f5"
169         }""".replaceAll("\\\\s+", ""))
170         DoDeallocateTnNssi obj = spy(DoDeallocateTnNssi.class)
171         when(obj.callOofAdapter()).thenReturn(true)
172         obj.performOofNSSITerminationCall(mockExecution)
173         Mockito.verify(mockExecution, times(1)).setVariable(eq("terminateTnNSSI"), captor.capture())
174         String terminateTnNSSI = captor.getValue()
175         assertTrue(terminateTnNSSI)
176     }
177 }