Implementation of TN NSSMF WF on SO
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoActivateTnNssiTest.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.so.bpmn.common.scripts.MsoGroovyTest
30
31 import static org.junit.Assert.assertNotNull
32 import static org.mockito.ArgumentMatchers.eq
33 import static org.mockito.Mockito.*
34
35 class DoActivateTnNssiTest extends MsoGroovyTest {
36     @Before
37     void init() throws IOException {
38         super.init("DoActivateTnNssiTest")
39     }
40
41     @Captor
42     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
43
44     @Test
45     void testPreProcessRequest() {
46         when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
47         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
48         when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71")
49         when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6")
50         when(mockExecution.getVariable("serviceInstanceID")).thenReturn("eb0863e9-a69b-4b17-8a56-f05ad110bef7")
51         when(mockExecution.getVariable("operationId")).thenReturn("998c2081-5a71-4a39-9ae6-d6b7c5bb50c0")
52         when(mockExecution.getVariable("operationType")).thenReturn("opTypeTest")
53         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
54         when(mockExecution.getVariable("servicename")).thenReturn("5G-test")
55         when(mockExecution.getVariable("networkType")).thenReturn("5G-network")
56         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G-service")
57         when(mockExecution.getVariable("nsiId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")
58         when(mockExecution.getVariable("jobId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")
59         when(mockExecution.getVariable("operationType")).thenReturn("activateInstance")
60         when(mockExecution.getVariable("sliceParams")).thenReturn(mockSliceParams())
61
62         DoActivateTnNssi obj = new DoActivateTnNssi()
63         obj.preProcessRequest(mockExecution)
64         Mockito.verify(mockExecution, times(1)).setVariable(eq("sliceServiceInstanceId"), captor.capture())
65         String sliceServiceInstanceId = captor.getValue()
66         assertNotNull(sliceServiceInstanceId)
67     }
68
69     @Test
70     void testPreprocessSdncRequest() {
71         when(mockExecution.getVariable("msoRequestId")).thenReturn("4c614769-f58a-4556-8ad9-dcd903077c82")
72         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:8090/SDNCAdapterCallback")
73         when(mockExecution.getVariable("sliceServiceInstanceId")).thenReturn("5ad89cf9-0569-4a93-9306-d8324321e2be")
74         when(mockExecution.getVariable("sliceServiceInstanceName")).thenReturn("5G-service")
75         when(mockExecution.getVariable("actionType")).thenReturn("activate")
76         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
77         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G")
78         when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("f85cbcc0-ad74-45d7-a5a1-17c8744fdb71")
79         when(mockExecution.getVariable("modelUuid")).thenReturn("36a3a8ea-49a6-4ac8-b06c-89a54544b9b6")
80         when(mockExecution.getVariable("sliceParams")).thenReturn(mockSliceParams())
81         when(mockExecution.getVariable("serviceModelInfo")).thenReturn(mockServiceModelInfo())
82 //        JsonUtils jsonUtil = new JsonUtils()
83 //        String sliceProfile = jsonUtil.getJsonValue(mockSliceParams(), "sliceProfile")
84 //        when(mockExecution.getVariable("sliceProfile")).thenReturn(sliceProfile)
85
86         DoActivateTnNssi obj = spy(DoActivateTnNssi.class)
87
88         obj.preprocessSdncActOrDeactTnNssiRequest(mockExecution)
89         Mockito.verify(mockExecution, times(1)).setVariable(eq("TNNSSMF_SDNCRequest"), captor.capture())
90         String request = captor.getValue()
91         assertNotNull(request)
92     }
93
94
95     private String mockSliceParams() {
96         String expect = """{
97     "sliceProfile": {
98       "snssaiList": [
99         "001-100001"
100       ],
101       "sliceProfileId": "ab9af40f13f721b5f13539d87484098",
102       "plmnIdList": [
103         "460-00",
104         "460-01"
105       ],
106       "perfReq": {
107       },
108       "coverageAreaTAList": [
109       ],
110       "latency": 2,
111       "maxBandwidth": 100,
112       "resourceSharingLevel": "non-shared"
113     },
114     "transportSliceNetworks": [
115             {
116                 "connectionLinks": [
117                     {
118                         "transportEndpointA": "tranportEp_ID_XXX",
119                         "transportEndpointB": "tranportEp_ID_YYY"
120                     },
121                     {
122                         "transportEndpointA": "tranportEp_ID_AAA",
123                         "transportEndpointB": "tranportEp_ID_BBB"
124                     }
125                 ]
126             },
127             {
128                 "connectionLinks": [
129                     {
130                         "transportEndpointA": "tranportEp_ID_CCC",
131                         "transportEndpointB": "tranportEp_ID_DDD"
132                     },
133                     {
134                         "transportEndpointA": "tranportEp_ID_EEE",
135                         "transportEndpointB": "tranportEp_ID_FFF"
136                     }
137                 ]
138             }
139     ],
140     "nsiInfo": {
141       "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX",
142       "nsiName": "eMBB-001"
143     },
144     "scriptName": "AN1"
145         }"""
146         return expect.replaceAll("\\\\s+", "")
147     }
148
149     private String mockSliceProfile() {
150         String expect = """{
151       "snssaiList": [
152         "001-100001"
153       ],
154       "sliceProfileId": "ab9af40f13f721b5f13539d87484098",
155       "plmnIdList": [
156         "460-00",
157         "460-01"
158       ],
159       "perfReq": {
160       },
161       "coverageAreaTAList": [
162       ],
163       "latency": 2,
164       "maxBandwidth": 100,
165       "resourceSharingLevel": "non-shared"
166      }"""
167         return expect.replaceAll("\\\\s+", "")
168     }
169
170     private String mockServiceModelInfo() {
171         String expect = """{
172             "modelInvariantUuid":"f85cbcc0-ad74-45d7-a5a1-17c8744fdb71",
173             "modelUuid":"36a3a8ea-49a6-4ac8-b06c-89a54544b9b6",
174             "modelVersion":""
175             }"""
176         return expect.replaceAll("\\\\s+", "")
177     }
178 }