2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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.delegate.BpmnError
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
25 import org.junit.Before
27 import org.mockito.ArgumentCaptor
28 import org.mockito.Captor
29 import org.mockito.Mockito
30 import org.onap.aai.domain.yang.CommunicationServiceProfile
31 import org.onap.aai.domain.yang.ServiceInstance
32 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
33 import org.onap.so.client.aai.AAIResourcesClient
35 import static com.shazam.shazamcrest.MatcherAssert.assertThat
36 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs
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.*
42 class DoCreateCommunicationServiceTest extends MsoGroovyTest {
44 private DoCreateCommunicationService communicationService = new DoCreateCommunicationService()
47 public void setUp() throws Exception {
48 super.init("DoCreateCommunicationService")
49 communicationService.client = spy(AAIResourcesClient.class)
53 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
56 public void testPreProcessRequest(){
58 DoCreateCommunicationService communicationService = new DoCreateCommunicationService()
59 communicationService.preProcessRequest(mockExecution)
60 Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
61 assertNotNull(captor.getAllValues())
65 public void testCreateCommunicationService() {
67 ServiceInstance expectedServiceInstanceData = getExpectedServiceInstance()
70 communicationService.createCommunicationService(mockExecution)
71 } catch (Exception e) {
73 assertEquals(e.class, BpmnError.class)
77 Mockito.verify(mockExecution).setVariable(eq("communicationServiceInstance"), captor.capture())
78 ServiceInstance resData = captor.getValue()
79 resData.setCreatedAt("")
80 resData.setEnvironmentContext("")
81 assertThat(resData, sameBeanAs(expectedServiceInstanceData))
85 public void testCreateCommunicationServiceProfile() {
87 DoCreateCommunicationService communicationService = new DoCreateCommunicationService()
89 CommunicationServiceProfile expectedServiceInstanceData = getExpectedServiceInstanceProfile()
92 communicationService.createCommunicationServiceProfile(mockExecution)
93 } catch (Exception e) {
94 assertEquals(e.class, BpmnError.class)
97 Mockito.verify(mockExecution).setVariable(eq("communicationServiceInstanceProfile"), captor.capture())
98 CommunicationServiceProfile resData = captor.getValue()
99 resData.setProfileId("")
100 assertThat(resData, sameBeanAs(expectedServiceInstanceData))
103 private static CommunicationServiceProfile getExpectedServiceInstanceProfile() {
104 CommunicationServiceProfile expectedServiceInstanceData = new CommunicationServiceProfile()
105 expectedServiceInstanceData.setProfileId("")
106 expectedServiceInstanceData.setLatency(20)
107 expectedServiceInstanceData.setMaxNumberOfUEs(300)
108 expectedServiceInstanceData.setUeMobilityLevel("stationary")
109 expectedServiceInstanceData.setResourceSharingLevel("shared")
110 expectedServiceInstanceData.setExpDataRateUL(30)
111 expectedServiceInstanceData.setExpDataRateDL(10)
112 expectedServiceInstanceData.setCoverageAreaList("01001")
113 return expectedServiceInstanceData
116 private static ServiceInstance getExpectedServiceInstance() {
117 ServiceInstance expectedServiceInstanceData = new ServiceInstance()
118 expectedServiceInstanceData.setServiceInstanceName("CSMFService")
119 expectedServiceInstanceData.setServiceRole("communication-service")
120 expectedServiceInstanceData.setOrchestrationStatus("processing")
121 expectedServiceInstanceData.setModelInvariantId("e75698d9-925a-4cdd-a6c0-edacbe6a0b51")
122 expectedServiceInstanceData.setModelVersionId("8ee5926d-720b-4bb2-86f9-d20e921c143b")
123 expectedServiceInstanceData.setInputParameters("""{
125 "name":"CSMFService",
126 "description":"CSMFService",
127 "serviceInvariantUuid":"e75698d9-925a-4cdd-a6c0-edacbe6a0b51",
128 "serviceUuid":"8ee5926d-720b-4bb2-86f9-d20e921c143b",
129 "globalSubscriberId":"5GCustomer",
136 "maxNumberofUEs":300,
137 "uemobilityLevel":"stationary",
138 "resourceSharingLevel":"shared",
139 "coverageAreaList": "01001",
145 expectedServiceInstanceData.setWorkloadContext("3")
146 expectedServiceInstanceData.setCreatedAt("")
147 expectedServiceInstanceData.setEnvironmentContext("")
148 return expectedServiceInstanceData
151 private void mockData() {
152 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("12345")
153 when(mockExecution.getVariable("serviceInstanceName")).thenReturn("CSMFService")
154 when(mockExecution.getVariable("serviceType")).thenReturn("5G")
155 when(mockExecution.getVariable("uuiRequest")).thenReturn("""{
157 "name":"CSMFService",
158 "description":"CSMFService",
159 "serviceInvariantUuid":"e75698d9-925a-4cdd-a6c0-edacbe6a0b51",
160 "serviceUuid":"8ee5926d-720b-4bb2-86f9-d20e921c143b",
161 "globalSubscriberId":"5GCustomer",
168 "maxNumberofUEs":300,
169 "uemobilityLevel":"stationary",
170 "resourceSharingLevel":"shared",
171 "coverageAreaList": "01001",
177 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
178 when(mockExecution.getVariable("globalSubscriberId")).thenReturn("5GCustomer")
179 Map<String, Object> csInputMap = new HashMap<>()
180 csInputMap.put("expDataRateDL", 10)
181 csInputMap.put("expDataRateUL", 30)
182 csInputMap.put("latency", 20)
183 csInputMap.put("maxNumberofUEs", 300)
184 csInputMap.put("uEMobilityLevel", "stationary")
185 csInputMap.put("resourceSharingLevel", "shared")
186 csInputMap.put("coverageAreaTAList", "01001")
187 csInputMap.put("useInterval", "3")
189 when(mockExecution.getVariable("csInputMap")).thenReturn(csInputMap)
191 when(mockExecution.getVariable("modelInvariantUuid")).thenReturn("e75698d9-925a-4cdd-a6c0-edacbe6a0b51")
192 when(mockExecution.getVariable("modelUuid")).thenReturn("8ee5926d-720b-4bb2-86f9-d20e921c143b")
193 when(mockExecution.getVariable("useInterval")).thenReturn("3")
194 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("5G")