46f061d89c9dd3d581b4f27d893c0b4a8cd80740
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License")
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.json.JSONObject
25 import org.junit.Before
26 import org.junit.Test
27 import org.mockito.ArgumentCaptor
28 import org.mockito.Captor
29 import org.mockito.Mockito
30 import org.onap.so.beans.nsmf.SliceTaskParams
31 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
32 import org.onap.so.bpmn.core.domain.ModelInfo
33 import org.onap.so.bpmn.core.domain.ServiceDecomposition
34 import org.onap.so.bpmn.core.domain.ServiceInfo
35 import org.onap.so.bpmn.core.domain.ServiceProxy
36
37 import static org.junit.Assert.assertEquals
38 import static org.junit.Assert.assertNotNull
39 import static org.mockito.ArgumentMatchers.eq
40 import static org.mockito.Mockito.times
41 import static org.mockito.Mockito.when
42
43 class CreateSliceServiceTest extends MsoGroovyTest {
44
45     @Before
46     void init() throws IOException {
47         super.init("CreateSliceService")
48     }
49
50     @Captor
51     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
52
53     final String bpmnRequest =  """
54         {
55             "requestDetails": {
56                 "modelInfo": {
57                     "modelInvariantId": "123456",
58                     "modelType": "service",
59                     "modelNameVersionId": "123456",
60                     "modelName": "Service Profile",
61                     "modelVersion": "1.0",
62                     "modelVersionId": "123456",
63                     "modelUuid": "123456",
64                     "modelInvariantUuid": "123456"
65                 },
66                 "requestInfo": {
67                     "source": "UUI",
68                     "instanceName": "NSMF",
69                     "suppressRollback": true
70                 },
71                 "subscriberInfo": {
72                     "globalSubscriberId": "5GCustomer"
73                 },
74                 "requestParameters": {
75                     "subscriptionServiceType": "MOG",
76                     "userParams": [{
77                         "ServiceInstanceName": "NSMF",
78                          "UUIRequest": {
79                               "service":{
80                                    "name": "NSMF",
81                                    "description": "CSMFService",
82                                    "serviceInvariantUuid": "123456",
83                                    "serviceUuid": "123456",
84                                    "globalSubscriberId": "5GCustomer",
85                                    "serviceType": "5G",
86                                    "parameters": {},
87                                    "requestInputs": {
88                                         "sST": "embb",
89                                         "sNSSAI": "1-10101",
90                                         "uEMobilityLevel": "stationary",
91                                         "areaTrafficCapDL": 123,
92                                         "maxNumberofUEs": 1000,
93                                         "expDataRateUL": 2000,
94                                         "plmnIdList": "39-00|39-01",
95                                         "areaTrafficCapUL": 456,
96                                         "latency": 300,
97                                         "expDataRateDL": 400,
98                                         "coverageAreaTAList": 101001,
99                                         "activityFactor": 99,
100                                         "resourceSharingLevel": "shared"
101                                    }
102                               }
103                          }
104                     }],
105                     "aLaCarte": true,
106                     "usePreload": true
107                 }
108             },
109             "serviceInstanceId": null,
110             "vnfInstanceId": null,
111             "networkInstanceId": null,
112             "volumeGroupInstanceId": null,
113             "vfModuleInstanceId": null,
114             "configurationId": null,
115             "instanceGroupId": null
116         }""".replaceAll("\\s+", "")
117
118     final String uuiRequest = """
119         "service":{
120              "name": "NSMF",
121              "description": "CSMFService",
122              "serviceInvariantUuid": "123456",
123              "serviceUuid": "123456",
124              "globalSubscriberId": "5GCustomer",
125              "serviceType": "5G",
126              "parameters": {},
127              "requestInputs": {
128                   "sST": "embb",
129                   "sNSSAI": "1-10101",
130                   "uEMobilityLevel": "stationary",
131                   "areaTrafficCapDL": 123,
132                   "maxNumberofUEs": 1000,
133                   "expDataRateUL": 2000,
134                   "plmnIdList": "39-00|39-01",
135                   "areaTrafficCapUL": 456,
136                   "latency": 300,
137                   "expDataRateDL": 400,
138                   "coverageAreaTAList": 101001,
139                   "activityFactor": 99,
140                   "resourceSharingLevel": "shared"
141              }
142         }""".replaceAll("\\s+", "")
143
144     final def serviceProfile = ["sST": "embb", "sNSSAI": "1-10101", "uEMobilityLevel": "stationary", "areaTrafficCapDL": 123,
145                                 "maxNumberofUEs": 1000, "expDataRateUL": 2000, "plmnIdList": "39-00|39-01", "areaTrafficCapUL": 456,
146                                 "latency": 300, "expDataRateDL": 400, "coverageAreaTAList": 101001, "activityFactor": 99,
147                                 "resourceSharingLevel": "shared"]
148
149     final def nstSolution = ["UUID": "aaaaaa", "NSTName": "test NST", "invariantUUID": "bbbbbb", "matchLevel": "100%"]
150
151     @Test
152     void testPreProcessRequest() {
153         when(mockExecution.getVariable("bpmnRequest")).thenReturn(bpmnRequest)
154         when(mockExecution.getVariable("mso-request-id")).thenReturn("123456")
155         CreateSliceService sliceService = new CreateSliceService()
156         sliceService.preProcessRequest(mockExecution)
157         Mockito.verify(mockExecution, times(14)).setVariable(captor.capture() as String, captor.capture())
158         List<ExecutionEntity> values = captor.getAllValues()
159         assertNotNull(values)
160     }
161
162     @Test
163     void testPrepareDecomposeService() {
164         when(mockExecution.getVariable("uuiRequest")).thenReturn(uuiRequest)
165         when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfile)
166         CreateSliceService sliceService = new CreateSliceService()
167         sliceService.prepareDecomposeService(mockExecution)
168
169         String serviceModelInfoExcept = """{
170             "modelInvariantUuid":"123456",
171             "modelUuid":"123456",
172             "modelVersion":""
173             }"""
174         Mockito.verify(mockExecution, times(1)).setVariable(eq("ssServiceModelInfo"), captor.capture())
175         String serviceModelInfo = captor.getValue()
176         assertEquals(serviceModelInfoExcept.replaceAll("\\s+", ""),
177                 serviceModelInfo.replaceAll("\\s+", ""))
178     }
179
180     @Test
181     void testProcessDecomposition() {
182         when(mockExecution.getVariable("uuiRequest")).thenReturn(uuiRequest)
183         when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfile)
184         when(mockExecution.getVariable("nstSolution")).thenReturn(nstSolution)
185
186         CreateSliceService sliceService = new CreateSliceService()
187         sliceService.processDecomposition(mockExecution)
188
189         Mockito.verify(mockExecution, times(1)).setVariable(eq("subscriptionServiceType"), captor.capture())
190         assertEquals(captor.getValue(), "5G")
191         Mockito.verify(mockExecution, times(1)).setVariable(eq("serviceType"), captor.capture())
192         assertEquals(captor.getValue(), "embb")
193         Mockito.verify(mockExecution, times(1)).setVariable(eq("resourceSharingLevel"), captor.capture())
194         assertEquals(captor.getValue(), "shared")
195         Mockito.verify(mockExecution, times(1)).setVariable(eq("nstModelUuid"), captor.capture())
196         assertEquals(captor.getValue(), "aaaaaa")
197         Mockito.verify(mockExecution, times(1)).setVariable(eq("nstModelInvariantUuid"), captor.capture())
198         assertEquals(captor.getValue(), "bbbbbb")
199     }
200
201     @Test
202     void testPrepareCreateOrchestrationTask() {
203         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("123456")
204         when(mockExecution.getVariable("serviceInstanceName")).thenReturn("test")
205         when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfile)
206
207         CreateSliceService sliceService = new CreateSliceService()
208         sliceService.prepareCreateOrchestrationTask(mockExecution)
209
210         SliceTaskParams sliceTaskParamsExpect = new SliceTaskParams()
211         sliceTaskParamsExpect.setServiceId("123456")
212         sliceTaskParamsExpect.setServiceName("test")
213         sliceTaskParamsExpect.setServiceProfile(serviceProfile)
214         String paramJsonExpect = sliceTaskParamsExpect.convertToJson()
215
216         Mockito.verify(mockExecution, times(2)).setVariable(eq("subscriptionServiceType"), captor.capture())
217         List allValues = captor.getAllValues()
218         SliceTaskParams sliceTaskParams = allValues.get(0)
219         String paramJson = allValues.get(1)
220         assertEquals(sliceTaskParams.getServiceId(), sliceTaskParams.getServiceId())
221         assertEquals(sliceTaskParams.getServiceName(), sliceTaskParams.getServiceName())
222         assertEquals(sliceTaskParams.getServiceProfile(), sliceTaskParams.getServiceProfile())
223         assertEquals(paramJsonExpect, paramJson)
224     }
225
226     @Test
227     void testSendSyncResponse() {
228         when(mockExecution.getVariable("operationId")).thenReturn("123456")
229         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
230         CreateSliceService sliceService = new CreateSliceService()
231         sliceService.sendSyncResponse(mockExecution)
232         Mockito.verify(mockExecution, times(1)).setVariable(eq("sentSyncResponse"), captor.capture())
233         def catchSyncResponse = captor.getValue()
234         assertEquals(catchSyncResponse, true)
235     }
236
237 }