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