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