2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.json.JSONObject
25 import org.junit.Before
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
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
43 class CreateSliceServiceTest extends MsoGroovyTest {
46 void init() throws IOException {
47 super.init("CreateSliceService")
51 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
53 final String bpmnRequest = """
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"
68 "instanceName": "NSMF",
69 "suppressRollback": true
72 "globalSubscriberId": "5GCustomer"
74 "requestParameters": {
75 "subscriptionServiceType": "MOG",
77 "ServiceInstanceName": "NSMF",
81 "description": "CSMFService",
82 "serviceInvariantUuid": "123456",
83 "serviceUuid": "123456",
84 "globalSubscriberId": "5GCustomer",
90 "uEMobilityLevel": "stationary",
91 "areaTrafficCapDL": 123,
92 "maxNumberofUEs": 1000,
93 "expDataRateUL": 2000,
94 "plmnIdList": "39-00|39-01",
95 "areaTrafficCapUL": 456,
98 "coverageAreaTAList": 101001,
100 "resourceSharingLevel": "shared"
109 "serviceInstanceId": null,
110 "vnfInstanceId": null,
111 "networkInstanceId": null,
112 "volumeGroupInstanceId": null,
113 "vfModuleInstanceId": null,
114 "configurationId": null,
115 "instanceGroupId": null
116 }""".replaceAll("\\s+", "")
118 final String uuiRequest = """
121 "description": "CSMFService",
122 "serviceInvariantUuid": "123456",
123 "serviceUuid": "123456",
124 "globalSubscriberId": "5GCustomer",
130 "uEMobilityLevel": "stationary",
131 "areaTrafficCapDL": 123,
132 "maxNumberofUEs": 1000,
133 "expDataRateUL": 2000,
134 "plmnIdList": "39-00|39-01",
135 "areaTrafficCapUL": 456,
137 "expDataRateDL": 400,
138 "coverageAreaTAList": 101001,
139 "activityFactor": 99,
140 "resourceSharingLevel": "shared"
142 }""".replaceAll("\\s+", "")
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"]
149 final def nstSolution = ["UUID": "aaaaaa", "NSTName": "test NST", "invariantUUID": "bbbbbb", "matchLevel": "100%"]
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)
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)
169 String serviceModelInfoExcept = """{
170 "modelInvariantUuid":"123456",
171 "modelUuid":"123456",
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+", ""))
181 void testProcessDecomposition() {
182 when(mockExecution.getVariable("uuiRequest")).thenReturn(uuiRequest)
183 when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfile)
184 when(mockExecution.getVariable("nstSolution")).thenReturn(nstSolution)
186 CreateSliceService sliceService = new CreateSliceService()
187 sliceService.processDecomposition(mockExecution)
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")
202 void testPrepareCreateOrchestrationTask() {
203 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("123456")
204 when(mockExecution.getVariable("serviceInstanceName")).thenReturn("test")
205 when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfile)
207 CreateSliceService sliceService = new CreateSliceService()
208 sliceService.prepareCreateOrchestrationTask(mockExecution)
210 SliceTaskParams sliceTaskParamsExpect = new SliceTaskParams()
211 sliceTaskParamsExpect.setServiceId("123456")
212 sliceTaskParamsExpect.setServiceName("test")
213 sliceTaskParamsExpect.setServiceProfile(serviceProfile)
214 String paramJsonExpect = sliceTaskParamsExpect.convertToJson()
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)
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)