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