Merge "Add subscription for notifications"
[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  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License"); 
10  * you may not use this file except in compliance with the License. 
11  * You may obtain a copy of the License at 
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0 
14  * 
15  * Unless required by applicable law or agreed to in writing, software 
16  * distributed under the License is distributed on an "AS IS" BASIS, 
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
18  * See the License for the specific language governing permissions and 
19  * limitations under the License. 
20  * ============LICENSE_END========================================================= 
21  */
22
23 package org.onap.so.bpmn.common;
24
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.onap.so.bpmn.mock.StubResponseVNFAdapter.mockVNFDelete;
29 import static org.onap.so.bpmn.mock.StubResponseVNFAdapter.mockVNFPost;
30 import static org.onap.so.bpmn.mock.StubResponseVNFAdapter.mockVNFPut;
31 import static org.onap.so.bpmn.mock.StubResponseVNFAdapter.mockVNFRollbackDelete;
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.Map;
35 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.onap.so.BaseIntegrationTest;
40 import org.onap.so.bpmn.core.WorkflowException;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 /**
45  * Unit tests for VnfAdapterRestV1.
46  */
47
48 public class VnfAdapterRestV1IT extends BaseIntegrationTest {
49
50     Logger logger = LoggerFactory.getLogger(VnfAdapterRestV1IT.class);
51
52
53     private static final String EOL = "\n";
54
55     private final CallbackSet callbacks = new CallbackSet();
56
57     private final String CREATE_VF_MODULE_REQUEST = "<createVfModuleRequest>" + EOL
58             + "  <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL + "  <cloudOwner>cloudOwner</cloudOwner>" + EOL
59             + "  <tenantId>tenantId</tenantId>" + EOL + "  <vnfId>vnfId</vnfId>" + EOL
60             + "  <vfModuleName>vfModuleName</vfModuleName>" + EOL + "  <vfModuleId>vfModuleId</vfModuleId>" + EOL
61             + "  <vnfType>vnfType</vnfType>" + EOL + "  <vnfVersion>vnfVersion</vnfVersion>" + EOL
62             + "  <vfModuleType>vfModuleType</vfModuleType>" + EOL + "  <volumeGroupId>volumeGroupId</volumeGroupId>"
63             + EOL + "  <volumeGroupStackId>volumeGroupStackId</volumeGroupStackId>" + EOL
64             + "  <baseVfModuleId>baseVfModuleId</baseVfModuleId>" + EOL
65             + "  <baseVfModuleStackId>baseVfModuleStackId</baseVfModuleStackId>" + EOL + "  <skipAAI>true</skipAAI>"
66             + EOL + "  <backout>false</backout>" + EOL + "  <failIfExists>true</failIfExists>" + EOL
67             + "  <vfModuleParams>" + EOL + "    <entry>" + EOL + "      <key>key1</key>" + EOL
68             + "      <value>value1</value>" + EOL + "    </entry>" + EOL + "    <entry>" + EOL + "      <key>key2</key>"
69             + EOL + "      <value>value2</value>" + EOL + "    </entry>" + EOL + "  </vfModuleParams>" + EOL
70             + "  <msoRequest>" + EOL + "    <requestId>requestId</requestId>" + EOL
71             + "    <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL + "  </msoRequest>" + EOL
72             + "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL
73             + "  <notificationUrl>http://localhost:28080/mso/WorkflowMessage</notificationUrl>" + EOL
74             + "</createVfModuleRequest>" + EOL;
75
76     private final String UPDATE_VF_MODULE_REQUEST = "<updateVfModuleRequest>" + EOL
77             + "  <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL + "  <cloudOwner>cloudOwner</cloudOwner>" + EOL
78             + "  <tenantId>tenantId</tenantId>" + EOL + "  <vnfId>vnfId</vnfId>" + EOL
79             + "  <vfModuleName>vfModuleName</vfModuleName>" + EOL + "  <vfModuleId>vfModuleId</vfModuleId>" + EOL
80             + "  <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL + "  <vnfType>vnfType</vnfType>" + EOL
81             + "  <vnfVersion>vnfVersion</vnfVersion>" + EOL + "  <vfModuleType>vfModuleType</vfModuleType>" + EOL
82             + "  <volumeGroupId>volumeGroupId</volumeGroupId>" + EOL
83             + "  <volumeGroupStackId>volumeGroupStackId</volumeGroupStackId>" + EOL
84             + "  <baseVfModuleId>baseVfModuleId</baseVfModuleId>" + EOL
85             + "  <baseVfModuleStackId>baseVfModuleStackId</baseVfModuleStackId>" + EOL + "  <skipAAI>true</skipAAI>"
86             + EOL + "  <backout>false</backout>" + EOL + "  <failIfExists>true</failIfExists>" + EOL
87             + "  <vfModuleParams>" + EOL + "    <entry>" + EOL + "      <key>key1</key>" + EOL
88             + "      <value>value1</value>" + EOL + "    </entry>" + EOL + "    <entry>" + EOL + "      <key>key2</key>"
89             + EOL + "      <value>value2</value>" + EOL + "    </entry>" + EOL + "  </vfModuleParams>" + EOL
90             + "  <msoRequest>" + EOL + "    <requestId>requestId</requestId>" + EOL
91             + "    <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL + "  </msoRequest>" + EOL
92             + "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL
93             + "  <notificationUrl>http://localhost:28080/mso/WorkflowMessage</notificationUrl>" + EOL
94             + "</updateVfModuleRequest>" + EOL;
95
96     private final String DELETE_VF_MODULE_REQUEST = "<deleteVfModuleRequest>" + EOL
97             + "  <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL + "  <cloudOwner>cloudOwner</cloudOwner>" + EOL
98             + "  <tenantId>tenantId</tenantId>" + EOL + "  <vnfId>vnfId</vnfId>" + EOL
99             + "  <vfModuleId>vfModuleId</vfModuleId>" + EOL + "  <vfModuleStackId>vfModuleStackId</vfModuleStackId>"
100             + EOL + "  <skipAAI>true</skipAAI>" + EOL + "  <msoRequest>" + EOL + "    <requestId>requestId</requestId>"
101             + EOL + "    <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL + "  </msoRequest>" + EOL
102             + "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL
103             + "  <notificationUrl>http://localhost:28080/mso/WorkflowMessage</notificationUrl>" + EOL
104             + "</deleteVfModuleRequest>" + EOL;
105
106     private final String ROLLBACK_VF_MODULE_REQUEST = "<rollbackVfModuleRequest>" + EOL
107             + "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL
108             + "  <notificationUrl>http://localhost:28080/mso/WorkflowMessage</notificationUrl>" + EOL
109             + "  <skipAAI>true</skipAAI>" + EOL + "  <vfModuleRollback>" + EOL
110             + "    <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL + "    <cloudOwner>cloudOwner</cloudOwner>" + EOL
111             + "    <tenantId>tenantId</tenantId>" + EOL + "    <vnfId>vnfId</vnfId>" + EOL
112             + "    <vfModuleId>vfModuleId</vfModuleId>" + EOL + "    <vfModuleStackId>vfModuleStackId</vfModuleStackId>"
113             + EOL + "    <msoRequest>" + EOL + "      <requestId>requestId</requestId>" + EOL
114             + "      <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL + "    </msoRequest>" + EOL
115             + "    <messageId>{{MESSAGE-ID}}</messageId>" + EOL + "    <vfModuleCreated>true</vfModuleCreated>" + EOL
116             + "  </vfModuleRollback>" + EOL + "</rollbackVfModuleRequest>" + EOL;
117
118     public VnfAdapterRestV1IT() throws IOException {
119         callbacks.put("createVfModule", "<createVfModuleResponse>" + EOL + "  <vnfId>vnfId</vnfId>" + EOL
120                 + "  <vfModuleId>vfModuleId</vfModuleId>" + EOL + "  <vfModuleStackId>vfModuleStackId</vfModuleStackId>"
121                 + EOL + "  <vfModuleCreated>true</vfModuleCreated>" + EOL + "  <vfModuleOutputs>" + EOL + "    <entry>"
122                 + EOL + "      <key>key1</key>" + EOL + "      <value>value1</value>" + EOL + "    </entry>" + EOL
123                 + "    <entry>" + EOL + "      <key>key2</key>" + EOL + "      <value>value2</value>" + EOL
124                 + "    </entry>" + EOL + "  </vfModuleOutputs>" + EOL + "  <rollback>" + EOL
125                 + "    <vnfId>vnfId</vnfId>" + EOL + "    <vfModuleId>vfModuleId</vfModuleId>" + EOL
126                 + "    <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL
127                 + "    <vfModuleCreated>true</vfModuleCreated>" + EOL + "    <tenantId>tenantId</tenantId>" + EOL
128                 + "    <cloudOwner>cloudOwner</cloudOwner>" + EOL + "    <cloudSiteId>cloudSiteId</cloudSiteId>" + EOL
129                 + "    <msoRequest>" + EOL + "      <requestId>requestId</requestId>" + EOL
130                 + "      <serviceInstanceId>serviceInstanceId</serviceInstanceId>" + EOL + "    </msoRequest>" + EOL
131                 + "    <messageId>messageId</messageId>" + EOL + "  </rollback>" + EOL
132                 + "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL + "</createVfModuleResponse>" + EOL);
133
134         callbacks.put("updateVfModule",
135                 "<updateVfModuleResponse>" + EOL + "  <vnfId>vnfId</vnfId>" + EOL
136                         + "  <vfModuleId>vfModuleId</vfModuleId>" + EOL
137                         + "  <vfModuleStackId>vfModuleStackId</vfModuleStackId>" + EOL + "  <vfModuleOutputs>" + EOL
138                         + "    <entry>" + EOL + "      <key>key1</key>" + EOL + "      <value>value1</value>" + EOL
139                         + "    </entry>" + EOL + "    <entry>" + EOL + "      <key>key2</key>" + EOL
140                         + "      <value>value2</value>" + EOL + "    </entry>" + EOL + "  </vfModuleOutputs>" + EOL
141                         + "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL + "</updateVfModuleResponse>" + EOL);
142
143         callbacks.put("deleteVfModule",
144                 "<deleteVfModuleResponse>" + EOL + "  <vnfId>vnfId</vnfId>" + EOL
145                         + "  <vfModuleId>vfModuleId</vfModuleId>" + EOL + "  <vfModuleDeleted>true</vfModuleDeleted>"
146                         + EOL + "  <messageId>{{MESSAGE-ID}}</messageId>" + EOL + "</deleteVfModuleResponse>" + EOL);
147
148         callbacks.put("rollbackVfModule", "<rollbackVfModuleResponse>" + EOL + "  <messageId>{{MESSAGE-ID}}</messageId>"
149                 + EOL + "  <vfModuleRolledback>true</vfModuleRolledback>" + EOL + "</rollbackVfModuleResponse>" + EOL);
150
151         callbacks.put("vfModuleException",
152                 "<vfModuleException>" + EOL + "  <message>message</message>" + EOL + "  <category>category</category>"
153                         + EOL + "  <rolledBack>false</rolledBack>" + EOL + "  <messageId>{{MESSAGE-ID}}</messageId>"
154                         + EOL + "</vfModuleException>" + EOL);
155     }
156
157     @Test
158
159     public void testCreateVfModuleSuccess() throws Exception {
160         logStart();
161
162         mockVNFPost(wireMockServer, "", 202, "vnfId");
163
164         String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
165         String messageId = requestId + "-" + System.currentTimeMillis();
166         String request = CREATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
167
168         String businessKey = UUID.randomUUID().toString();
169         Map<String, Object> variables = new HashMap<>();
170         variables.put("mso-request-id", requestId);
171         variables.put("isDebugLogEnabled", "true");
172         variables.put("vnfAdapterRestV1Request", request);
173
174         invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
175         injectVNFRestCallbacks(callbacks, "createVfModule");
176         waitForProcessEnd(businessKey, 10000);
177
178         String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response");
179         logger.debug("Response:\n{}", response);
180         assertTrue(response != null && response.contains("<createVfModuleResponse>"));
181         assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
182
183         logEnd();
184     }
185
186     @Test
187
188     public void testUpdateVfModuleSuccess() throws Exception {
189         logStart();
190
191         mockVNFPut(wireMockServer, "/vfModuleId", 202);
192
193         String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
194         String messageId = requestId + "-" + System.currentTimeMillis();
195         String request = UPDATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
196
197         String businessKey = UUID.randomUUID().toString();
198         Map<String, Object> variables = new HashMap<>();
199         variables.put("mso-request-id", requestId);
200         variables.put("isDebugLogEnabled", "true");
201         variables.put("vnfAdapterRestV1Request", request);
202
203         invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
204         injectVNFRestCallbacks(callbacks, "updateVfModule");
205         waitForProcessEnd(businessKey, 10000);
206
207         String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response");
208         logger.debug("Response:\n{}", response);
209         assertTrue(response.contains("<updateVfModuleResponse>"));
210         assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
211
212         logEnd();
213     }
214
215     @Test
216
217     public void testDeleteVfModuleSuccess() throws Exception {
218         logStart();
219
220         mockVNFDelete(wireMockServer, "vnfId", "/vfModuleId", 202);
221
222         String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
223         String messageId = requestId + "-" + System.currentTimeMillis();
224         String request = DELETE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
225
226         String businessKey = UUID.randomUUID().toString();
227         Map<String, Object> variables = new HashMap<>();
228         variables.put("mso-request-id", requestId);
229         variables.put("isDebugLogEnabled", "true");
230         variables.put("vnfAdapterRestV1Request", request);
231
232         invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
233         injectVNFRestCallbacks(callbacks, "deleteVfModule");
234         waitForProcessEnd(businessKey, 10000);
235
236         String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response");
237         logger.debug("Response:\n{}", response);
238         assertTrue(response.contains("<deleteVfModuleResponse>"));
239         assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
240
241         logEnd();
242     }
243
244     @Test
245
246     public void testRollbackVfModuleSuccess() throws Exception {
247         logStart();
248
249         mockVNFRollbackDelete(wireMockServer, "/vfModuleId", 202);
250
251         String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
252         String messageId = requestId + "-" + System.currentTimeMillis();
253         String request = ROLLBACK_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
254
255         String businessKey = UUID.randomUUID().toString();
256         Map<String, Object> variables = new HashMap<>();
257         variables.put("mso-request-id", requestId);
258         variables.put("isDebugLogEnabled", "true");
259         variables.put("vnfAdapterRestV1Request", request);
260
261         invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
262         injectVNFRestCallbacks(callbacks, "rollbackVfModule");
263         waitForProcessEnd(businessKey, 10000);
264
265         String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response");
266         logger.debug("Response:\n{}", response);
267         assertTrue(response.contains("<rollbackVfModuleResponse>"));
268         assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
269
270         logEnd();
271     }
272
273     @Test
274
275     public void testCreateVfModuleException() throws Exception {
276         logStart();
277
278         mockVNFPost(wireMockServer, "", 202, "vnfId");
279
280         String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312";
281         String messageId = requestId + "-" + System.currentTimeMillis();
282         String request = CREATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId);
283
284         String businessKey = UUID.randomUUID().toString();
285         Map<String, Object> variables = new HashMap<>();
286         variables.put("mso-request-id", requestId);
287         variables.put("isDebugLogEnabled", "true");
288         variables.put("vnfAdapterRestV1Request", request);
289
290         invokeSubProcess("vnfAdapterRestV1", businessKey, variables);
291         injectVNFRestCallbacks(callbacks, "vfModuleException");
292         waitForProcessEnd(businessKey, 10000);
293
294         WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException");
295         assertNotNull(wfe);
296         logger.debug(wfe.toString());
297
298         String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
299         logger.debug("Response:\n{}", response);
300         assertTrue(response.contains("<vfModuleException>"));
301         assertFalse((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
302
303         logEnd();
304     }
305 }
306