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)