37207f8022924f4da9b3084ee1f5709b93588176
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  # Copyright (c) 2019, CMCC Technologies Co., Ltd.
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.delegate.BpmnError
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
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.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
34
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.*
41
42 class DoCreateCommunicationServiceTest extends MsoGroovyTest {
43
44     private DoCreateCommunicationService communicationService = new DoCreateCommunicationService()
45
46     @Before
47     public void setUp() throws Exception {
48         super.init("DoCreateCommunicationService")
49         communicationService.client = spy(AAIResourcesClient.class)
50     }
51
52     @Captor
53     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
54
55     @Test
56     public void testPreProcessRequest(){
57         mockData()
58         DoCreateCommunicationService communicationService = new DoCreateCommunicationService()
59         communicationService.preProcessRequest(mockExecution)
60         Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
61         assertNotNull(captor.getAllValues())
62     }
63
64     @Test
65     public void testCreateCommunicationService() {
66         mockData()
67         ServiceInstance expectedServiceInstanceData = getExpectedServiceInstance()
68
69         try {
70             communicationService.createCommunicationService(mockExecution)
71         } catch (Exception e) {
72
73             assertEquals(e.class, BpmnError.class)
74         }
75
76
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))
82     }
83
84     @Test
85     public void testCreateCommunicationServiceProfile() {
86         mockData()
87         DoCreateCommunicationService communicationService = new DoCreateCommunicationService()
88
89         CommunicationServiceProfile expectedServiceInstanceData = getExpectedServiceInstanceProfile()
90
91         try {
92             communicationService.createCommunicationServiceProfile(mockExecution)
93         } catch (Exception e) {
94             assertEquals(e.class, BpmnError.class)
95         }
96
97         Mockito.verify(mockExecution).setVariable(eq("communicationServiceInstanceProfile"), captor.capture())
98         CommunicationServiceProfile resData = captor.getValue()
99         resData.setProfileId("")
100         assertThat(resData, sameBeanAs(expectedServiceInstanceData))
101     }
102
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
114     }
115
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("""{
124             "service":{
125                 "name":"CSMFService",
126                 "description":"CSMFService",
127                 "serviceInvariantUuid":"e75698d9-925a-4cdd-a6c0-edacbe6a0b51",
128                 "serviceUuid":"8ee5926d-720b-4bb2-86f9-d20e921c143b",
129                 "globalSubscriberId":"5GCustomer",
130                 "serviceType":"5G",
131                 "parameters":{
132                     "requestInputs":{
133                         "expDataRateDL":10,
134                         "expDataRateUL":30,
135                         "latency":20,
136                         "maxNumberofUEs":300,
137                         "uemobilityLevel":"stationary",
138                         "resourceSharingLevel":"shared",
139                         "coverageAreaList": "01001",
140                         "useInterval":"3"
141                     }
142                 }
143             }
144         }""")
145         expectedServiceInstanceData.setWorkloadContext("3")
146         expectedServiceInstanceData.setCreatedAt("")
147         expectedServiceInstanceData.setEnvironmentContext("")
148         return expectedServiceInstanceData
149     }
150
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("""{
156             "service":{
157                 "name":"CSMFService",
158                 "description":"CSMFService",
159                 "serviceInvariantUuid":"e75698d9-925a-4cdd-a6c0-edacbe6a0b51",
160                 "serviceUuid":"8ee5926d-720b-4bb2-86f9-d20e921c143b",
161                 "globalSubscriberId":"5GCustomer",
162                 "serviceType":"5G",
163                 "parameters":{
164                     "requestInputs":{
165                         "expDataRateDL":10,
166                         "expDataRateUL":30,
167                         "latency":20,
168                         "maxNumberofUEs":300,
169                         "uemobilityLevel":"stationary",
170                         "resourceSharingLevel":"shared",
171                         "coverageAreaList": "01001",
172                         "useInterval":"3"
173                     }
174                 }
175             }
176         }""")
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")
188
189         when(mockExecution.getVariable("csInputMap")).thenReturn(csInputMap)
190
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")
195     }
196 }