2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.bpmn.common;
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;
31 import java.io.IOException;
32 import java.util.HashMap;
34 import java.util.UUID;
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;
42 * Unit tests for VnfAdapterRestV1.
44 public class VnfAdapterRestV1Test extends WorkflowTest {
46 private static final String EOL = "\n";
48 private final CallbackSet callbacks = new CallbackSet();
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 +
69 " <key>key1</key>" + EOL +
70 " <value>value1</value>" + EOL +
73 " <key>key2</key>" + EOL +
74 " <value>value2</value>" + 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;
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 +
105 " <key>key1</key>" + EOL +
106 " <value>value1</value>" + EOL +
109 " <key>key2</key>" + EOL +
110 " <value>value2</value>" + 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;
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;
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;
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 +
166 " <key>key1</key>" + EOL +
167 " <value>value1</value>" + EOL +
170 " <key>key2</key>" + EOL +
171 " <value>value2</value>" + 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);
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 +
197 " <key>key1</key>" + EOL +
198 " <value>value1</value>" + EOL +
201 " <key>key2</key>" + EOL +
202 " <value>value2</value>" + EOL +
204 " </vfModuleOutputs>" + EOL +
205 " <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
206 "</updateVfModuleResponse>" + EOL);
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);
216 callbacks.put("rollbackVfModule",
217 "<rollbackVfModuleResponse>" + EOL +
218 " <messageId>{{MESSAGE-ID}}</messageId>" + EOL +
219 " <vfModuleRolledback>true</vfModuleRolledback>" + EOL +
220 "</rollbackVfModuleResponse>" + EOL);
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);
232 @Deployment(resources = {
233 "subprocess/VnfAdapterRestV1.bpmn"
235 public void testCreateVfModuleSuccess() throws Exception {
238 mockVNFPost("", 202, "vnfId");
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);
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);
250 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
251 injectVNFRestCallbacks(callbacks, "createVfModule");
252 waitForProcessEnd(businessKey, 10000);
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"));
263 @Deployment(resources = {
264 "subprocess/VnfAdapterRestV1.bpmn"
266 public void testUpdateVfModuleSuccess() throws Exception {
269 mockVNFPut("/vfModuleId", 202);
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);
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);
281 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
282 injectVNFRestCallbacks(callbacks, "updateVfModule");
283 waitForProcessEnd(businessKey, 10000);
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"));
294 @Deployment(resources = {
295 "subprocess/VnfAdapterRestV1.bpmn"
297 public void testDeleteVfModuleSuccess() throws Exception {
300 mockVNFDelete("vnfId", "/vfModuleId", 202);
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);
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);
312 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
313 injectVNFRestCallbacks(callbacks, "deleteVfModule");
314 waitForProcessEnd(businessKey, 10000);
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"));
325 @Deployment(resources = {
326 "subprocess/VnfAdapterRestV1.bpmn"
328 public void testRollbackVfModuleSuccess() throws Exception {
331 mockVNFRollbackDelete("/vfModuleId", 202);
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);
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);
343 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
344 injectVNFRestCallbacks(callbacks, "rollbackVfModule");
345 waitForProcessEnd(businessKey, 10000);
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"));
356 @Deployment(resources = {
357 "subprocess/VnfAdapterRestV1.bpmn"
359 public void testCreateVfModuleException() throws Exception {
362 mockVNFPost("", 202, "vnfId");
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);
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);
374 invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
375 injectVNFRestCallbacks(callbacks, "vfModuleException");
376 waitForProcessEnd(businessKey, 10000);
378 WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
380 System.out.println(wfe.toString());
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"));