6b7944cc6effad417edb07d738f1d656da929e6a
[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 }