d2b0e274e9ea7533d9310c4da87b98e5061b6eb7
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / VnfAdapterRestV1Test.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * OPENECOMP - MSO 
4  * ================================================================================ 
5  * Copyright (C) 2017 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.openecomp.mso.bpmn.common;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.openecomp.mso.bpmn.mock.StubResponseVNFAdapter.mockVNFDelete;
27 import static org.openecomp.mso.bpmn.mock.StubResponseVNFAdapter.mockVNFPost;
28 import static org.openecomp.mso.bpmn.mock.StubResponseVNFAdapter.mockVNFPut;
29 import static org.openecomp.mso.bpmn.mock.StubResponseVNFAdapter.mockVNFRollbackDelete;
30
31 import java.io.IOException;
32 import java.util.HashMap;
33 import java.util.Map;
34 import java.util.UUID;
35
36 import org.camunda.bpm.engine.test.Deployment;
37 import org.junit.Test;
38 import org.openecomp.mso.bpmn.core.WorkflowException;
39
40 /**
41  * Unit tests for VnfAdapterRestV1.
42  */
43 public class VnfAdapterRestV1Test extends WorkflowTest {
44
45         private static final String EOL = "\n";
46
47         private final CallbackSet callbacks = new CallbackSet();
48
49         private final String CREATE_VF_MODULE_REQUEST =
50                 "<createVfModuleRequest>" + EOL +
51                 "  <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL +
52                 "  <tenantId>tenantId</tenantId>" + EOL +
53                 "  <vnfId>vnfId</vnfId>" + EOL +
54                 "  <vfModuleName>vfModuleName</vfModuleName>" + EOL +
55                 "  <vfModuleId>vfModuleId</vfModuleId>" + EOL +
56                 "  <vnfType>vnfType</vnfType>" + EOL +
57                 "  <vnfVersion>vnfVersion</vnfVersion>" + EOL +
58                 "  <vfModuleType>vfModuleType</vfModuleType>" + EOL +
59                 "  <volumeGroupId>volumeGroupId</volumeGroupId>" + EOL +
60                 "  <volumeGroupStackId>volumeGroupStackId</volumeGroupStackId>" + EOL +
61                 "  <baseVfModuleId>baseVfModuleId</baseVfModuleId>" + EOL +
62                 "  <baseVfModuleStackId>baseVfModuleStackId</baseVfModuleStackId>" + EOL +
63                 "  <skipAAI>true</skipAAI>" + EOL +
64                 "  <backout>false</backout>" + EOL +
65                 "  <failIfExists>true</failIfExists>" + EOL +
66                 "  <vfModuleParams>" + EOL +
67                 "    <entry>" + EOL +
68                 "      <key>key1</key>" + EOL +
69                 "      <value>value1</value>" + EOL +
70                 "    </entry>" + EOL +
71                 "    <entry>" + EOL +
72                 "      <key>key2</key>" + EOL +
73                 "      <value>value2</value>" + EOL +
74                 "    </entry>" + EOL +
75                 "  </vfModuleParams>" + EOL +
76                 "  <msoRequest>" + EOL +
77                 "    <requestId>requestId</requestId>" + EOL +
78                 "    <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL +
79                 "  </msoRequest>" + EOL +
80                 "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
81                 "  <notificationUrl>http://localhost:28080/mso/WorkflowMessage</notificationUrl>" + EOL +
82                 "</createVfModuleRequest>" + EOL;
83
84         private final String UPDATE_VF_MODULE_REQUEST =
85                 "<updateVfModuleRequest>" + EOL +
86                 "  <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL +
87                 "  <tenantId>tenantId</tenantId>" + EOL +
88                 "  <vnfId>vnfId</vnfId>" + EOL +
89                 "  <vfModuleName>vfModuleName</vfModuleName>" + EOL +
90                 "  <vfModuleId>vfModuleId</vfModuleId>" + EOL +
91                 "  <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL +
92                 "  <vnfType>vnfType</vnfType>" + EOL +
93                 "  <vnfVersion>vnfVersion</vnfVersion>" + EOL +
94                 "  <vfModuleType>vfModuleType</vfModuleType>" + EOL +
95                 "  <volumeGroupId>volumeGroupId</volumeGroupId>" + EOL +
96                 "  <volumeGroupStackId>volumeGroupStackId</volumeGroupStackId>" + EOL +
97                 "  <baseVfModuleId>baseVfModuleId</baseVfModuleId>" + EOL +
98                 "  <baseVfModuleStackId>baseVfModuleStackId</baseVfModuleStackId>" + EOL +
99                 "  <skipAAI>true</skipAAI>" + EOL +
100                 "  <backout>false</backout>" + EOL +
101                 "  <failIfExists>true</failIfExists>" + EOL +
102                 "  <vfModuleParams>" + EOL +
103                 "    <entry>" + EOL +
104                 "      <key>key1</key>" + EOL +
105                 "      <value>value1</value>" + EOL +
106                 "    </entry>" + EOL +
107                 "    <entry>" + EOL +
108                 "      <key>key2</key>" + EOL +
109                 "      <value>value2</value>" + EOL +
110                 "    </entry>" + EOL +
111                 "  </vfModuleParams>" + EOL +
112                 "  <msoRequest>" + EOL +
113                 "    <requestId>requestId</requestId>" + EOL +
114                 "    <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL +
115                 "  </msoRequest>" + EOL +
116                 "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
117                 "  <notificationUrl>http://localhost:28080/mso/WorkflowMessage</notificationUrl>" + EOL +
118                 "</updateVfModuleRequest>" + EOL;
119
120         private final String DELETE_VF_MODULE_REQUEST =
121                 "<deleteVfModuleRequest>" + EOL +
122                 "  <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL +
123                 "  <tenantId>tenantId</tenantId>" + EOL +
124                 "  <vnfId>vnfId</vnfId>" + EOL +
125                 "  <vfModuleId>vfModuleId</vfModuleId>" + EOL +
126                 "  <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL +
127                 "  <skipAAI>true</skipAAI>" + EOL +
128                 "  <msoRequest>" + EOL +
129                 "    <requestId>requestId</requestId>" + EOL +
130                 "    <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL +
131                 "  </msoRequest>" + EOL +
132                 "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
133                 "  <notificationUrl>http://localhost:28080/mso/WorkflowMessage</notificationUrl>" + EOL +
134                 "</deleteVfModuleRequest>" + EOL;
135
136         private final String ROLLBACK_VF_MODULE_REQUEST =
137                         "<rollbackVfModuleRequest>" + EOL +
138                         "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
139                         "  <notificationUrl>http://localhost:28080/mso/WorkflowMessage</notificationUrl>" + EOL +
140                         "  <skipAAI>true</skipAAI>" + EOL +
141                         "  <vfModuleRollback>" + EOL +
142                         "    <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL +
143                         "    <tenantId>tenantId</tenantId>" + EOL +
144                         "    <vnfId>vnfId</vnfId>" + EOL +
145                         "    <vfModuleId>vfModuleId</vfModuleId>" + EOL +
146                         "    <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL +
147                         "    <msoRequest>" + EOL +
148                         "      <requestId>requestId</requestId>" + EOL +
149                         "      <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL +
150                         "    </msoRequest>" + EOL +
151                         "    <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
152                         "    <vfModuleCreated>true</vfModuleCreated>" + EOL +
153                         "  </vfModuleRollback>" + EOL +
154                         "</rollbackVfModuleRequest>" + EOL;
155
156         public VnfAdapterRestV1Test() throws IOException {
157                 callbacks.put("createVfModule",
158                         "<createVfModuleResponse>" + EOL +
159                         "  <vnfId>vnfId</vnfId>" + EOL +
160                         "  <vfModuleId>vfModuleId</vfModuleId>" + EOL +
161                         "  <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL +
162                         "  <vfModuleCreated>true</vfModuleCreated>" + EOL +
163                         "  <vfModuleOutputs>" + EOL +
164                         "    <entry>" + EOL +
165                         "      <key>key1</key>" + EOL +
166                         "      <value>value1</value>" + EOL +
167                         "    </entry>" + EOL +
168                         "    <entry>" + EOL +
169                         "      <key>key2</key>" + EOL +
170                         "      <value>value2</value>" + EOL +
171                         "    </entry>" + EOL +
172                         "  </vfModuleOutputs>" + EOL +
173                         "  <rollback>" + EOL +
174                         "    <vnfId>vnfId</vnfId>" + EOL +
175                         "    <vfModuleId>vfModuleId</vfModuleId>" + EOL +
176                         "    <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL +
177                         "    <vfModuleCreated>true</vfModuleCreated>" + EOL +
178                         "    <tenantId>tenantId</tenantId>" + EOL +
179                         "    <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL +
180                         "    <msoRequest>" + EOL +
181                         "      <requestId>requestId</requestId>" + EOL +
182                         "      <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL +
183                         "    </msoRequest>" + EOL +
184                         "    <messageId>messageId</messageId>" + EOL +
185                         "  </rollback>" + EOL +
186                         "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
187                         "</createVfModuleResponse>" + EOL);
188
189                 callbacks.put("updateVfModule",
190                         "<updateVfModuleResponse>" + EOL +
191                         "  <vnfId>vnfId</vnfId>" + EOL +
192                         "  <vfModuleId>vfModuleId</vfModuleId>" + EOL +
193                         "  <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL +
194                         "  <vfModuleOutputs>" + EOL +
195                         "    <entry>" + EOL +
196                         "      <key>key1</key>" + EOL +
197                         "      <value>value1</value>" + EOL +
198                         "    </entry>" + EOL +
199                         "    <entry>" + EOL +
200                         "      <key>key2</key>" + EOL +
201                         "      <value>value2</value>" + EOL +
202                         "    </entry>" + EOL +
203                         "  </vfModuleOutputs>" + EOL +
204                         "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
205                         "</updateVfModuleResponse>" + EOL);
206
207                 callbacks.put("deleteVfModule",
208                         "<deleteVfModuleResponse>" + EOL +
209                         "  <vnfId>vnfId</vnfId>" + EOL +
210                         "  <vfModuleId>vfModuleId</vfModuleId>" + EOL +
211                         "  <vfModuleDeleted>true</vfModuleDeleted>" + EOL +
212                         "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
213                         "</deleteVfModuleResponse>" + EOL);
214
215                 callbacks.put("rollbackVfModule",
216                         "<rollbackVfModuleResponse>" + EOL +
217                         "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
218                         "  <vfModuleRolledback>true</vfModuleRolledback>" + EOL +
219                         "</rollbackVfModuleResponse>" + EOL);
220
221                 callbacks.put("vfModuleException",
222                         "<vfModuleException>" + EOL +
223                         "  <message>message</message>" + EOL +
224                         "  <category>category</category>" + EOL +
225                         "  <rolledBack>false</rolledBack>" + EOL +
226                         "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
227                         "</vfModuleException>" + EOL);
228         }
229
230         @Test
231         @Deployment(resources = {
232                 "subprocess/VnfAdapterRestV1.bpmn"
233                 })
234         public void testCreateVfModuleSuccess() throws Exception {
235                 logStart();
236
237                 mockVNFPost("", 202, "vnfId");
238
239                 String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
240                 String messageId = requestId + "-" + System.currentTimeMillis();
241                 String request = CREATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
242
243                 String businessKey = UUID.randomUUID().toString();
244                 Map<String, Object> variables = new HashMap<String, Object>();
245                 variables.put("mso-request-id", requestId);
246                 variables.put("isDebugLogEnabled", "true");
247                 variables.put("vnfAdapterRestV1Request", request);
248
249                 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
250                 injectVNFRestCallbacks(callbacks, "createVfModule");
251                 waitForProcessEnd(businessKey, 10000);
252
253                 String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response");
254                 System.out.println("Response:\n" + response);
255                 assertTrue(response.contains("<createVfModuleResponse>"));
256                 assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
257
258                 logEnd();
259         }
260
261         @Test
262         @Deployment(resources = {
263                 "subprocess/VnfAdapterRestV1.bpmn"
264                 })
265         public void testUpdateVfModuleSuccess() throws Exception {
266                 logStart();
267
268                 mockVNFPut("/vfModuleId", 202);
269
270                 String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
271                 String messageId = requestId + "-" + System.currentTimeMillis();
272                 String request = UPDATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
273
274                 String businessKey = UUID.randomUUID().toString();
275                 Map<String, Object> variables = new HashMap<String, Object>();
276                 variables.put("mso-request-id", requestId);
277                 variables.put("isDebugLogEnabled", "true");
278                 variables.put("vnfAdapterRestV1Request", request);
279
280                 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
281                 injectVNFRestCallbacks(callbacks, "updateVfModule");
282                 waitForProcessEnd(businessKey, 10000);
283
284                 String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response");
285                 System.out.println("Response:\n" + response);
286                 assertTrue(response.contains("<updateVfModuleResponse>"));
287                 assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
288
289                 logEnd();
290         }
291
292         @Test
293         @Deployment(resources = {
294                 "subprocess/VnfAdapterRestV1.bpmn"
295                 })
296         public void testDeleteVfModuleSuccess() throws Exception {
297                 logStart();
298
299                 mockVNFDelete("vnfId", "/vfModuleId", 202);
300
301                 String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
302                 String messageId = requestId + "-" + System.currentTimeMillis();
303                 String request = DELETE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
304
305                 String businessKey = UUID.randomUUID().toString();
306                 Map<String, Object> variables = new HashMap<String, Object>();
307                 variables.put("mso-request-id", requestId);
308                 variables.put("isDebugLogEnabled", "true");
309                 variables.put("vnfAdapterRestV1Request", request);
310
311                 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
312                 injectVNFRestCallbacks(callbacks, "deleteVfModule");
313                 waitForProcessEnd(businessKey, 10000);
314
315                 String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response");
316                 System.out.println("Response:\n" + response);
317                 assertTrue(response.contains("<deleteVfModuleResponse>"));
318                 assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
319
320                 logEnd();
321         }
322
323         @Test
324         @Deployment(resources = {
325                 "subprocess/VnfAdapterRestV1.bpmn"
326                 })
327         public void testRollbackVfModuleSuccess() throws Exception {
328                 logStart();
329
330                 mockVNFRollbackDelete("/vfModuleId", 202);
331
332                 String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
333                 String messageId = requestId + "-" + System.currentTimeMillis();
334                 String request = ROLLBACK_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
335
336                 String businessKey = UUID.randomUUID().toString();
337                 Map<String, Object> variables = new HashMap<String, Object>();
338                 variables.put("mso-request-id", requestId);
339                 variables.put("isDebugLogEnabled", "true");
340                 variables.put("vnfAdapterRestV1Request", request);
341
342                 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
343                 injectVNFRestCallbacks(callbacks, "rollbackVfModule");
344                 waitForProcessEnd(businessKey, 10000);
345
346                 String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response");
347                 System.out.println("Response:\n" + response);
348                 assertTrue(response.contains("<rollbackVfModuleResponse>"));
349                 assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
350
351                 logEnd();
352         }
353
354         @Test
355         @Deployment(resources = {
356                 "subprocess/VnfAdapterRestV1.bpmn"
357                 })
358         public void testCreateVfModuleException() throws Exception {
359                 logStart();
360
361                 mockVNFPost("", 202, "vnfId");
362
363                 String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
364                 String messageId = requestId + "-" + System.currentTimeMillis();
365                 String request = CREATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
366
367                 String businessKey = UUID.randomUUID().toString();
368                 Map<String, Object> variables = new HashMap<String, Object>();
369                 variables.put("mso-request-id", requestId);
370                 variables.put("isDebugLogEnabled", "true");
371                 variables.put("vnfAdapterRestV1Request", request);
372
373                 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
374                 injectVNFRestCallbacks(callbacks, "vfModuleException");
375                 waitForProcessEnd(businessKey, 10000);
376
377                 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
378                 assertNotNull(wfe);
379                 System.out.println(wfe.toString());
380
381                 String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
382                 System.out.println("Response:\n" + response);
383                 assertTrue(response.contains("<vfModuleException>"));
384                 assertFalse((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
385
386                 logEnd();
387         }
388 }
389