Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / vcpe / DoCreateAllottedResourceTXCRollbackTest.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 package org.openecomp.mso.bpmn.vcpe;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource;
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
29 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
30 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
31
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.UUID;
36
37 import org.camunda.bpm.engine.test.Deployment;
38 import org.junit.Test;
39 import org.openecomp.mso.bpmn.common.BPMNUtil;
40 import org.openecomp.mso.bpmn.core.RollbackData;
41 import org.openecomp.mso.bpmn.mock.FileUtil;
42
43
44 public class DoCreateAllottedResourceTXCRollbackTest extends AbstractTestBase {
45
46         private static final String PROCNAME = "DoCreateAllottedResourceTXCRollback";
47         private static final String RbType = "DCARTXC_";
48         private final CallbackSet callbacks = new CallbackSet();
49         
50         public DoCreateAllottedResourceTXCRollbackTest() throws IOException {
51                 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
52                 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
53                 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
54         }
55         
56         @Test
57         @Deployment(resources = {
58                         "subprocess/SDNCAdapterV1.bpmn",
59                         "subprocess/FalloutHandler.bpmn",
60                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn"})
61         public void testDoCreateAllottedResourceTXCRollback_Success() throws Exception {
62                 
63                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml");
64                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
65                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
66                 mockSDNCAdapter(200);
67                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
68                 
69                 String businessKey = UUID.randomUUID().toString();
70                 Map<String, Object> variables = new HashMap<>();
71                 setVariablesSuccess(variables, "testRequestId1");
72                 
73                 invokeSubProcess(PROCNAME, businessKey, variables);
74                 
75                 injectSDNCCallbacks(callbacks, "deactivate");
76                 injectSDNCCallbacks(callbacks, "delete");
77                 injectSDNCCallbacks(callbacks, "unassign");
78
79                 waitForProcessEnd(businessKey, 10000);
80                 
81                 assertTrue(isProcessEnded(businessKey));
82                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
83                 System.out.println("workflowException:\n" + workflowException);
84                 assertEquals(null, workflowException);
85                 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, "rolledBack"));
86                 assertNull(BPMNUtil.getVariable(processEngineRule, PROCNAME, "rollbackError"));
87         }
88         
89         @Test
90         @Deployment(resources = {
91                         "subprocess/SDNCAdapterV1.bpmn",
92                         "subprocess/FalloutHandler.bpmn",
93                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn"})
94         public void testDoCreateAllottedResourceTXCRollback_skipRollback() throws Exception {
95                 
96                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml");
97                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
98                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
99                 mockSDNCAdapter(200);
100                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
101                 
102                 String businessKey = UUID.randomUUID().toString();
103                 Map<String, Object> variables = new HashMap<>();
104                 RollbackData rollbackData = setVariablesSuccess(variables, "testRequestId1");
105
106                 rollbackData.put(RbType, "rollbackAAI", "false");
107                 rollbackData.put(RbType, "rollbackSDNCassign", "false");
108                 
109                 invokeSubProcess(PROCNAME, businessKey, variables);
110
111                 waitForProcessEnd(businessKey, 10000);
112                 
113                 assertTrue(isProcessEnded(businessKey));
114                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
115                 System.out.println("workflowException:\n" + workflowException);
116                 assertEquals(null, workflowException);
117                 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, "rolledBack"));
118                 assertNull(BPMNUtil.getVariable(processEngineRule, PROCNAME, "rollbackError"));
119         }
120         
121         @Test
122         @Deployment(resources = {
123                         "subprocess/SDNCAdapterV1.bpmn",
124                         "subprocess/FalloutHandler.bpmn",
125                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn"})
126         public void testDoCreateAllottedResourceTXCRollback_DoNotRollBack() throws Exception {
127                 
128                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
129                 
130                 String businessKey = UUID.randomUUID().toString();
131                 Map<String, Object> variables = new HashMap<>();
132                 RollbackData rollbackData = setVariablesSuccess(variables, "testRequestId1");
133
134                 // this will cause "rollbackSDNC" to be set to false
135                 rollbackData.put(RbType, "rollbackSDNCassign", "false");
136                 
137                 invokeSubProcess(PROCNAME, businessKey, variables);
138
139                 waitForProcessEnd(businessKey, 10000);
140                 
141                 assertTrue(isProcessEnded(businessKey));
142                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
143                 System.out.println("workflowException:\n" + workflowException);
144                 assertEquals(null, workflowException);
145                 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, "rolledBack"));
146                 assertNull(BPMNUtil.getVariable(processEngineRule, PROCNAME, "rollbackError"));
147         }
148         
149         @Test
150         @Deployment(resources = {
151                         "subprocess/SDNCAdapterV1.bpmn",
152                         "subprocess/FalloutHandler.bpmn",
153                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn"})
154         public void testDoCreateAllottedResourceTXCRollback_NoDeactivate() throws Exception {
155                 
156                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml");
157                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
158                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
159                 mockSDNCAdapter(200);
160                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
161                 
162                 String businessKey = UUID.randomUUID().toString();
163                 Map<String, Object> variables = new HashMap<>();
164                 RollbackData rollbackData = setVariablesSuccess(variables, "testRequestId1");
165
166                 rollbackData.put(RbType, "rollbackSDNCactivate", "false");
167                 
168                 invokeSubProcess(PROCNAME, businessKey, variables);
169
170                 injectSDNCCallbacks(callbacks, "delete");
171                 injectSDNCCallbacks(callbacks, "unassign");
172
173                 waitForProcessEnd(businessKey, 10000);
174                 
175                 assertTrue(isProcessEnded(businessKey));
176                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
177                 System.out.println("workflowException:\n" + workflowException);
178                 assertEquals(null, workflowException);
179                 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, "rolledBack"));
180                 assertNull(BPMNUtil.getVariable(processEngineRule, PROCNAME, "rollbackError"));
181         }
182         
183         @Test
184         @Deployment(resources = {
185                         "subprocess/SDNCAdapterV1.bpmn",
186                         "subprocess/FalloutHandler.bpmn",
187                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn"})
188         public void testDoCreateAllottedResourceTXCRollback_NoDelete() throws Exception {
189                 
190                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml");
191                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
192                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
193                 mockSDNCAdapter(200);
194                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
195                 
196                 String businessKey = UUID.randomUUID().toString();
197                 Map<String, Object> variables = new HashMap<>();
198                 RollbackData rollbackData = setVariablesSuccess(variables, "testRequestId1");
199
200                 rollbackData.put(RbType, "rollbackSDNCcreate", "false");
201                 
202                 invokeSubProcess(PROCNAME, businessKey, variables);
203
204                 injectSDNCCallbacks(callbacks, "deactivate");
205                 injectSDNCCallbacks(callbacks, "unassign");
206
207                 waitForProcessEnd(businessKey, 10000);
208                 
209                 assertTrue(isProcessEnded(businessKey));
210                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
211                 System.out.println("workflowException:\n" + workflowException);
212                 assertEquals(null, workflowException);
213                 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, "rolledBack"));
214                 assertNull(BPMNUtil.getVariable(processEngineRule, PROCNAME, "rollbackError"));
215         }
216         
217         @Test
218         @Deployment(resources = {
219                         "subprocess/SDNCAdapterV1.bpmn",
220                         "subprocess/FalloutHandler.bpmn",
221                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn"})
222         public void testDoCreateAllottedResourceTXCRollback_NoUnassign() throws Exception {
223                 
224                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml");
225                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
226                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
227                 mockSDNCAdapter(200);
228                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
229                 
230                 String businessKey = UUID.randomUUID().toString();
231                 Map<String, Object> variables = new HashMap<>();
232                 RollbackData rollbackData = setVariablesSuccess(variables, "testRequestId1");
233
234                 rollbackData.put(RbType, "rollbackSDNCassign", "false");
235                 
236                 /*
237                  * Note: if assign == false then the flow/script will set
238                  * "skipRollback" to false, which will cause ALL of the SDNC steps
239                  * to be skipped, not just the unassign step.
240                  */
241                 
242                 invokeSubProcess(PROCNAME, businessKey, variables);
243
244                 waitForProcessEnd(businessKey, 10000);
245                 
246                 assertTrue(isProcessEnded(businessKey));
247                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
248                 System.out.println("workflowException:\n" + workflowException);
249                 assertEquals(null, workflowException);
250                 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, "rolledBack"));
251                 assertNull(BPMNUtil.getVariable(processEngineRule, PROCNAME, "rollbackError"));
252         }
253         
254         @Test
255         @Deployment(resources = {
256                         "subprocess/SDNCAdapterV1.bpmn",
257                         "subprocess/FalloutHandler.bpmn",
258                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn"})
259         public void testDoCreateAllottedResourceTXCRollback_SubProcessError() throws Exception {
260                 
261                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml");
262                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
263                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
264                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
265
266                 mockSDNCAdapter(404);
267                 
268                 String businessKey = UUID.randomUUID().toString();
269                 Map<String, Object> variables = new HashMap<>();
270                 setVariablesSuccess(variables, "testRequestId1");
271                 
272                 invokeSubProcess(PROCNAME, businessKey, variables);
273
274                 waitForProcessEnd(businessKey, 10000);
275                 
276                 assertTrue(isProcessEnded(businessKey));
277                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
278                 System.out.println("workflowException:\n" + workflowException);
279                 assertEquals(null, workflowException);
280                 assertEquals("false", BPMNUtil.getVariable(processEngineRule, PROCNAME, "rolledBack"));
281                 assertNotNull(BPMNUtil.getVariable(processEngineRule, PROCNAME, "rollbackError"));
282         }
283         
284         @Test
285         @Deployment(resources = {
286                         "subprocess/SDNCAdapterV1.bpmn",
287                         "subprocess/FalloutHandler.bpmn",
288                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn"})
289         public void testDoCreateAllottedResourceTXCRollback_JavaException() throws Exception {
290                 
291                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/DoCreateAllottedResourceTXCRollback/arGetById.xml");
292                 MockPatchAllottedResource(CUST, SVC, INST, ARID);
293                 MockDeleteAllottedResource(CUST, SVC, INST, ARID, ARVERS);
294                 mockSDNCAdapter(200);
295                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
296                 
297                 String businessKey = UUID.randomUUID().toString();
298                 Map<String, Object> variables = new HashMap<>();
299                 setVariablesSuccess(variables, "testRequestId1");
300
301                 variables.put("rollbackData", "string instead of rollback data");
302                 
303                 invokeSubProcess(PROCNAME, businessKey, variables);
304
305                 waitForProcessEnd(businessKey, 10000);
306                 
307                 assertTrue(isProcessEnded(businessKey));
308                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
309                 System.out.println("workflowException:\n" + workflowException);
310                 assertEquals(null, workflowException);
311                 assertEquals("false", BPMNUtil.getVariable(processEngineRule, PROCNAME, "rolledBack"));
312                 assertNotNull(BPMNUtil.getVariable(processEngineRule, PROCNAME, "rollbackError"));
313         }
314
315         private RollbackData setVariablesSuccess(Map<String, Object> variables, String requestId) {
316                 variables.put("isDebugLogEnabled", "true");
317                 variables.put("failNotFound", "true");
318                 variables.put("msoRequestId", requestId);
319                 variables.put("mso-request-id", "requestId");
320                 variables.put("allottedResourceId", ARID);
321
322                 variables.put("serviceInstanceId", DEC_INST);
323                 variables.put("parentServiceInstanceId", DEC_PARENT_INST);
324                 
325                 RollbackData rollbackData = new RollbackData();
326
327                 rollbackData.put(RbType, "serviceInstanceId", DEC_INST);
328                 rollbackData.put(RbType, "serviceSubscriptionType", SVC);
329                 rollbackData.put(RbType, "disablerollback", "false");
330                 rollbackData.put(RbType, "rollbackAAI", "true");
331                 rollbackData.put(RbType, "rollbackSDNCassign", "true");
332                 rollbackData.put(RbType, "rollbackSDNCactivate", "true");
333                 rollbackData.put(RbType, "rollbackSDNCcreate", "true");
334                 rollbackData.put(RbType, "aaiARPath", "http://localhost:28090/aai/v9/business/customers/customer/"+CUST+"/service-subscriptions/service-subscription/"+SVC+"/service-instances/service-instance/"+INST+"/allotted-resources/allotted-resource/"+ARID);
335                 
336                 rollbackData.put(RbType, "sdncActivateRollbackReq", FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXCRollback/sdncActivateRollbackReq.xml"));
337                 rollbackData.put(RbType, "sdncCreateRollbackReq", FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXCRollback/sdncCreateRollbackReq.xml")); 
338                 rollbackData.put(RbType, "sdncAssignRollbackReq", FileUtil.readResourceFile("__files/VCPE/DoCreateAllottedResourceTXCRollback/sdncAssignRollbackReq.xml"));
339                 
340                 variables.put("rollbackData",rollbackData);
341                 
342                 return rollbackData;
343         }
344
345 }