715a7dff6d7c242faa100e73786a8b456afd552f
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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.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.ServiceInstance
31 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
32 import org.onap.so.bpmn.core.domain.Resource
33 import org.onap.so.bpmn.core.domain.ServiceDecomposition
34
35 import static com.shazam.shazamcrest.MatcherAssert.assertThat
36 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs
37 import static org.mockito.Mockito.times
38 import static org.mockito.Mockito.when
39 /**
40  * Copyright 2018 ZTE Corporation.
41  *
42  * Licensed under the Apache License, Version 2.0 (the "License");
43  * you may not use this file except in compliance with the License.
44  * You may obtain a copy of the License at
45  *
46  *     http://www.apache.org/licenses/LICENSE-2.0
47  *
48  * Unless required by applicable law or agreed to in writing, software
49  * distributed under the License is distributed on an "AS IS" BASIS,
50  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51  * See the License for the specific language governing permissions and
52  * limitations under the License.
53  */
54 class DoCompareServiceInstanceDataTest extends MsoGroovyTest {
55
56
57     public static final String uuiSoString = "{\n" +
58             "    \"service\":{\n" +
59             "        \"name\":\"SiteService\",\n" +
60             "        \"description\":\"SiteService\",\n" +
61             "        \"serviceInvariantUuid\":\"5c13f3fb-2744-4635-9f1f-c59c92dc8f70\",\n" +
62             "        \"serviceUuid\":\"3a76b1f5-fb0d-4b6b-82d5-0e8a4ebc3838\",\n" +
63             "        \"globalSubscriberId\":\"test_custormer\",\n" +
64             "        \"serviceType\":\"example-service-type\",\n" +
65             "        \"parameters\":{\n" +
66             "            \"locationConstraints\":[\n" +
67             "\n" +
68             "            ],\n" +
69             "            \"resources\":[\n" +
70             "                {\n" +
71             "                    \"resourceIndex\":\"1\",\n" +
72             "                    \"resourceName\":\"sdwanvpnresource\",\n" +
73             "                    \"resourceInvariantUuid\":\"0c0e1cbe-6e01-4f9e-8c45-a9700ebc14df\",\n" +
74             "                    \"resourceUuid\":\"4ad2d390-5c51-45f5-9710-b467a4ec7a73\",\n" +
75             "                    \"resourceCustomizationUuid\":\"66590e07-0777-415c-af44-36347cf3ddd3\",\n" +
76             "                    \"parameters\":{\n" +
77             "                        \"locationConstraints\":[\n" +
78             "\n" +
79             "                        ],\n" +
80             "                        \"resources\":[\n" +
81             "\n" +
82             "                        ],\n" +
83             "                        \"requestInputs\":{\n" +
84             "\n" +
85             "                        }\n" +
86             "                    }\n" +
87             "                },\n" +
88             "                {\n" +
89             "                    \"resourceIndex\":\"1\",\n" +
90             "                    \"resourceName\":\"sdwansiteresource\",\n" +
91             "                    \"resourceInvariantUuid\":\"97a3e552-08c4-4697-aeeb-d8d3e09ce58e\",\n" +
92             "                    \"resourceUuid\":\"63d8e1af-32dc-4c71-891d-e3f7b6a976d2\",\n" +
93             "                    \"resourceCustomizationUuid\":\"205456e7-3dc0-40c4-8cb0-28e6c1877042\",\n" +
94             "                    \"parameters\":{\n" +
95             "                        \"locationConstraints\":[\n" +
96             "\n" +
97             "                        ],\n" +
98             "                        \"resources\":[\n" +
99             "\n" +
100             "                        ],\n" +
101             "                        \"requestInputs\":{\n" +
102             "\n" +
103             "                        }\n" +
104             "                    }\n" +
105             "                },\n" +
106             "                {\n" +
107             "                    \"resourceIndex\":\"2\",\n" +
108             "                    \"resourceName\":\"sdwansiteresource\",\n" +
109             "                    \"resourceInvariantUuid\":\"97a3e552-08c4-4697-aeeb-d8d3e09ce58e\",\n" +
110             "                    \"resourceUuid\":\"63d8e1af-32dc-4c71-891d-e3f7b6a976d2\",\n" +
111             "                    \"resourceCustomizationUuid\":\"205456e7-3dc0-40c4-8cb0-28e6c1877042\",\n" +
112             "                    \"parameters\":{\n" +
113             "                        \"locationConstraints\":[\n" +
114             "\n" +
115             "                        ],\n" +
116             "                        \"resources\":[\n" +
117             "\n" +
118             "                        ],\n" +
119             "                        \"requestInputs\":{\n" +
120             "\n" +
121             "                        }\n" +
122             "                    }\n" +
123             "                }\n" +
124             "            ],\n" +
125             "            \"requestInputs\":{\n" +
126             "                \"sdwanvpnresource_list\":[\n" +
127             "                    {\n" +
128             "                        \"sdwanvpn_topology\":\"hub_spoke\",\n" +
129             "                        \"sdwanvpn_name\":\"defaultvpn\",\n" +
130             "                        \"sdwansitelan_list\":[\n" +
131             "                            {\n" +
132             "                                \"role\":\"Hub\",\n" +
133             "                                \"portType\":\"GE\",\n" +
134             "                                \"portSwitch\":\"layer3-port\",\n" +
135             "                                \"vlanId\":\"\",\n" +
136             "                                \"ipAddress\":\"192.168.10.1\",\n" +
137             "                                \"deviceName\":\"vCPE\",\n" +
138             "                                \"portNumer\":\"0/0/1\"\n" +
139             "                            },\n" +
140             "                            {\n" +
141             "                                \"role\":\"Hub\",\n" +
142             "                                \"portType\":\"GE\",\n" +
143             "                                \"portSwitch\":\"layer2-port\",\n" +
144             "                                \"vlanId\":\"55\",\n" +
145             "                                \"ipAddress\":\"192.168.11.1\",\n" +
146             "                                \"deviceName\":\"CPE_Beijing\",\n" +
147             "                                \"portNumer\":\"0/0/1\"\n" +
148             "                            }\n" +
149             "                        ]\n" +
150             "                    }\n" +
151             "                ],\n" +
152             "                \"sdwansiteresource_list\":[\n" +
153             "                    {\n" +
154             "                        \"sdwansite_emails\":\"chenchuanyu@huawei.com\",\n" +
155             "                        \"sdwansite_address\":\"Huawei Public Cloud\",\n" +
156             "                        \"sdwansite_description\":\"DC Site\",\n" +
157             "                        \"sdwansite_role\":\"dsvpn_hub\",\n" +
158             "                        \"sdwansite_postcode\":\"20000\",\n" +
159             "                        \"sdwansite_type\":\"single_gateway\",\n" +
160             "                        \"sdwansite_latitude\":\"\",\n" +
161             "                        \"sdwansite_controlPoint\":\"\",\n" +
162             "                        \"sdwansite_longitude\":\"\",\n" +
163             "                        \"sdwansitewan_list\":[\n" +
164             "                            {\n" +
165             "                                \"providerIpAddress\":\"\",\n" +
166             "                                \"portType\":\"GE\",\n" +
167             "                                \"inputBandwidth\":\"1000\",\n" +
168             "                                \"ipAddress\":\"\",\n" +
169             "                                \"name\":\"10000\",\n" +
170             "                                \"transportNetworkName\":\"internet\",\n" +
171             "                                \"outputBandwidth\":\"10000\",\n" +
172             "                                \"deviceName\":\"vCPE\",\n" +
173             "                                \"portNumber\":\"0/0/0\",\n" +
174             "                                \"ipMode\":\"DHCP\",\n" +
175             "                                \"publicIP\":\"119.3.7.113\"\n" +
176             "                            }\n" +
177             "                        ],\n" +
178             "                        \"sdwandevice_list\":[\n" +
179             "                            {\n" +
180             "                                \"esn\":\"XXXXXXX\",\n" +
181             "                                \"vendor\":\"Huawei\",\n" +
182             "                                \"name\":\"vCPE\",\n" +
183             "                                \"type\":\"AR1000V\",\n" +
184             "                                \"version\":\"1.0\",\n" +
185             "                                \"class\":\"VNF\",\n" +
186             "                                \"systemIp\":\"20.20.20.1\"\n" +
187             "                            }\n" +
188             "                        ]\n" +
189             "                    },\n" +
190             "                    {\n" +
191             "                        \"sdwansite_emails\":\"chenchuanyu@huawei.com\",\n" +
192             "                        \"sdwansite_address\":\"Huawei Public Cloud\",\n" +
193             "                        \"sdwansite_description\":\"DC Site\",\n" +
194             "                        \"sdwansite_role\":\"dsvpn_hub\",\n" +
195             "                        \"sdwansite_postcode\":\"20000\",\n" +
196             "                        \"sdwansite_type\":\"single_gateway\",\n" +
197             "                        \"sdwansite_latitude\":\"\",\n" +
198             "                        \"sdwansite_controlPoint\":\"\",\n" +
199             "                        \"sdwansite_longitude\":\"\",\n" +
200             "                        \"sdwansitewan_list\":[\n" +
201             "                            {\n" +
202             "                                \"providerIpAddress\":\"\",\n" +
203             "                                \"portType\":\"GE\",\n" +
204             "                                \"inputBandwidth\":\"1000\",\n" +
205             "                                \"ipAddress\":\"172.18.1.2/24\",\n" +
206             "                                \"name\":\"10000\",\n" +
207             "                                \"transportNetworkName\":\"internet\",\n" +
208             "                                \"outputBandwidth\":\"10000\",\n" +
209             "                                \"deviceName\":\"CPE_Beijing\",\n" +
210             "                                \"portNumber\":\"0/0/0\",\n" +
211             "                                \"ipMode\":\"Static\",\n" +
212             "                                \"publicIP\":\"\"\n" +
213             "                            }\n" +
214             "                        ],\n" +
215             "                        \"sdwandevice_list\":[\n" +
216             "                            {\n" +
217             "                                \"esn\":\"XXXXXXX\",\n" +
218             "                                \"vendor\":\"Huawei\",\n" +
219             "                                \"name\":\"CPE_Beijing\",\n" +
220             "                                \"type\":\"AR161\",\n" +
221             "                                \"version\":\"1.0\",\n" +
222             "                                \"class\":\"PNF\",\n" +
223             "                                \"systemIp\":\"20.20.20.2\"\n" +
224             "                            }\n" +
225             "                        ]\n" +
226             "                    }\n" +
227             "                ]\n" +
228             "            }\n" +
229             "        }\n" +
230             "    }\n" +
231             "}"
232
233     @Before
234     void setUp() {
235         super.init("DoCompareServiceInstanceData")
236     }
237
238     @Captor
239     static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
240
241     @Test
242     void testPreProcessRequest() {
243         mockData()
244         DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
245         csi.preProcessRequest(mockExecution)
246     }
247
248     @Test(expected = BpmnError.class)
249     void testPreProcessRequestException() {
250         DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
251         csi.preProcessRequest(mockExecution)
252     }
253
254     @Test
255     void testPrepareDecomposeService_Original() {
256         mockData()
257         DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
258         csi.prepareDecomposeService_Original(mockExecution)
259         Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
260         String serviceModelInfo = getServiceModelInfo()
261         assertThat(captor.getValue(), sameBeanAs(serviceModelInfo))
262     }
263
264     @Test
265     void testProcessDecomposition_Original() {
266         mockData()
267         DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
268         csi.processDecomposition_Original(mockExecution)
269         Mockito.verify(mockExecution, times(1)).setVariable(captor.capture(), captor.capture())
270         ServiceDecomposition serviceDecomposition = getServiceDecomposition()
271         assertThat(captor.getValue(), sameBeanAs(serviceDecomposition))
272     }
273
274     @Test
275     void testDoCompareUuiRquestInput() {
276         mockData()
277         DoCompareServiceInstanceData csi = new DoCompareServiceInstanceData()
278         csi.doCompareUuiRquestInput(mockExecution)
279         Mockito.verify(mockExecution, times(4)).setVariable(captor.capture(), captor.capture())
280     }
281
282     private String getServiceModelInfo() {
283         String modelInvariantUuid = mockExecution.getVariable("model-invariant-id-original")
284         String modelUuid = mockExecution.getVariable("model-version-id-original")
285         String serviceModelInfo = """{
286             "modelInvariantUuid":"${modelInvariantUuid}",
287             "modelUuid":"${modelUuid}",
288             "modelVersion":""
289              }"""
290         serviceModelInfo
291     }
292
293     private void mockData() {
294         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
295         when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
296         when(mockExecution.getVariable("model-version-id-original")).thenReturn("12345")
297         when(mockExecution.getVariable("model-invariant-id-original")).thenReturn("12345")
298         when(mockExecution.getVariable("uuiRequest")).thenReturn(uuiSoString)
299         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("1234")
300         when(mockExecution.getVariable("serviceInstanceData-original")).thenReturn(getExpectedServiceInstance())
301         when(mockExecution.getVariable("serviceDecomposition")).thenReturn(getServiceDecomposition())
302         when(mockExecution.getVariable("serviceDecomposition_Original")).thenReturn(getServiceDecomposition())
303     }
304
305     private ServiceDecomposition getServiceDecomposition() {
306         ServiceDecomposition decomposition = new ServiceDecomposition()
307         List<Resource> allSR_original = new ArrayList<>()
308         decomposition.setAllottedResources(allSR_original)
309         return decomposition
310     }
311
312     private ServiceInstance getExpectedServiceInstance() {
313         ServiceInstance expectedServiceInstanceData = new ServiceInstance()
314         expectedServiceInstanceData.setServiceInstanceId("1234")
315         expectedServiceInstanceData.setServiceInstanceName("volte-service")
316         expectedServiceInstanceData.setServiceType("E2E Service")
317         expectedServiceInstanceData.setServiceRole("E2E Service")
318         expectedServiceInstanceData.setInputParameters(uuiSoString)
319         return expectedServiceInstanceData
320     }
321 }