1b3bfa8c76f2634f8741384b61674b9ec616813c
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / vcpe / CreateVcpeResCustServiceTest.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.assertTrue;
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDeleteAllottedResource;
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetAllottedResource;
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetCustomer;
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
29 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPatchAllottedResource;
31 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutAllottedResource;
32 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutServiceInstance;
33 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.MockGetServiceResourcesCatalogData;
34 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
35 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
36
37 import java.io.IOException;
38 import java.util.HashMap;
39 import java.util.Map;
40 import java.util.UUID;
41
42 import org.camunda.bpm.engine.test.Deployment;
43 import org.junit.Test;
44 import org.openecomp.mso.bpmn.common.BPMNUtil;
45 import org.openecomp.mso.bpmn.mock.FileUtil;
46
47 public class CreateVcpeResCustServiceTest extends AbstractTestBase {
48
49         private static final String PROCNAME = "CreateVcpeResCustService";
50         private static final String Prefix = "CVRCS_";
51         
52         private final CallbackSet callbacks = new CallbackSet();
53         private final String request;
54         
55         public CreateVcpeResCustServiceTest() throws IOException {
56                 callbacks.put("assign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyAssignCallback.xml"));
57                 callbacks.put("create", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyCreateCallback.xml"));
58                 callbacks.put("activate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyActivateCallback.xml"));
59                 callbacks.put("queryTXC", FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/SDNCTopologyQueryTXCCallback.xml"));
60                 callbacks.put("queryBRG", FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/SDNCTopologyQueryBRGCallback.xml"));
61                 callbacks.put("deactivate", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeactivateCallback.xml"));
62                 callbacks.put("delete", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyDeleteCallback.xml"));
63                 callbacks.put("unassign", FileUtil.readResourceFile("__files/VfModularity/SDNCTopologyUnassignCallback.xml"));
64                 
65                 request = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/requestNoSIName.json");
66         }
67         
68         @Test
69         @Deployment(resources = {
70                         "process/CreateVcpeResCustService.bpmn",
71                         "subprocess/SDNCAdapterV1.bpmn",
72                         "subprocess/FalloutHandler.bpmn",
73                         "subprocess/GenericGetService.bpmn",
74                         "subprocess/GenericPutService.bpmn",
75                         "subprocess/BuildingBlock/DecomposeService.bpmn",
76             "subprocess/DoCreateServiceInstance.bpmn",
77                         "subprocess/DoCreateAllottedResourceTXC.bpmn",
78                         "subprocess/DoCreateAllottedResourceBRG.bpmn",
79             "subprocess/CompleteMsoProcess.bpmn",
80
81             // stubs
82                         "VCPE/stubprocess/Homing.bpmn",
83             "VCPE/stubprocess/DoCreateVnfAndModules.bpmn"})
84         
85         public void testCreateVcpeResCustService_Success() throws Exception {
86
87                 System.out.println("starting:  testCreateVcpeResCustService_Success\n");
88                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "2", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
89                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
90                 MockGetCustomer(CUST, "VCPE/CreateVcpeResCustService/getCustomer.xml");
91                 
92                 // TODO: the SI should NOT have to be URL-encoded yet again!
93                 MockPutServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
94                 MockGetServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
95                 
96                 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
97                 MockNodeQueryServiceInstanceById(PARENT_INST, "GenericFlows/getParentSIUrlById.xml");           
98                 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
99                 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
100                 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
101                 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
102
103                 mockSDNCAdapter(200);
104                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
105                 
106                 Map<String, Object> variables = setupVariables();
107
108                 String businessKey = UUID.randomUUID().toString();
109                 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
110                 
111                 // for SI
112                 injectSDNCCallbacks(callbacks, "assign");
113                 
114                 // for TXC
115                 injectSDNCCallbacks(callbacks, "assign");
116                 injectSDNCCallbacks(callbacks, "create");
117                 injectSDNCCallbacks(callbacks, "activate");
118                 injectSDNCCallbacks(callbacks, "queryTXC");
119                 
120                 // for BRG
121                 injectSDNCCallbacks(callbacks, "assign");
122                 injectSDNCCallbacks(callbacks, "create");
123                 injectSDNCCallbacks(callbacks, "activate");
124                 injectSDNCCallbacks(callbacks, "queryBRG");
125                 
126                 waitForProcessEnd(businessKey, 10000);
127
128                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
129                 System.out.println("workflowException:\n" + workflowException);
130
131                 String completionReq = BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+VAR_COMP_REQ);
132                 System.out.println("completionReq:\n" + completionReq);
133                 
134                 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
135                 assertEquals("200", BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_RESP_CODE));
136                 assertEquals(null, workflowException);
137                 assertTrue(completionReq.contains("request-id>testRequestId<"));
138                 assertTrue(completionReq.contains("action>CREATE<"));
139                 assertTrue(completionReq.contains("source>VID<"));
140
141                 assertEquals("1", BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+"VnfsCreatedCount"));
142         }
143         
144         @Test
145         @Deployment(resources = {
146                         "process/CreateVcpeResCustService.bpmn",
147                         "subprocess/SDNCAdapterV1.bpmn",
148                         "subprocess/FalloutHandler.bpmn",
149                         "subprocess/GenericGetService.bpmn",
150                         "subprocess/GenericPutService.bpmn",
151                         "subprocess/BuildingBlock/DecomposeService.bpmn",
152             "subprocess/DoCreateServiceInstance.bpmn",
153                         "subprocess/DoCreateAllottedResourceTXC.bpmn",
154                         "subprocess/DoCreateAllottedResourceBRG.bpmn",
155             "subprocess/CompleteMsoProcess.bpmn",
156
157             // stubs
158                         "VCPE/stubprocess/Homing.bpmn",
159             "VCPE/stubprocess/DoCreateVnfAndModules.bpmn"})
160         
161         public void testCreateVcpeResCustService_NoParts() throws Exception {
162
163                 System.out.println("starting: testCreateVcpeResCustService_NoParts\n"  );
164                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "2", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesNoData.json");
165                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesNoData.json");
166                 MockGetCustomer(CUST, "VCPE/CreateVcpeResCustService/getCustomer.xml");
167                 
168                 // TODO: the SI should NOT have to be URL-encoded yet again!
169                 MockPutServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
170                 MockGetServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
171                 
172                 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");                
173                 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
174                 MockNodeQueryServiceInstanceById(PARENT_INST, "GenericFlows/getParentSIUrlById.xml");
175                 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
176                 
177                 // TODO: should these really be PARENT_INST, or should they be INST?
178                 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
179                 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
180
181                 mockSDNCAdapter(200);
182                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
183                 
184                 Map<String, Object> variables = setupVariables();
185
186                 String businessKey = UUID.randomUUID().toString();
187                 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
188                 
189                 // for SI
190                 injectSDNCCallbacks(callbacks, "assign");
191                 
192                 waitForProcessEnd(businessKey, 10000);
193
194                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
195                 System.out.println("workflowException:\n" + workflowException);
196
197                 String completionReq = BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+VAR_COMP_REQ);
198                 System.out.println("completionReq:\n" + completionReq);
199                 
200                 assertEquals("true", BPMNUtil.getVariable(processEngineRule, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
201                 assertEquals("200", BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_RESP_CODE));
202                 assertEquals(null, workflowException);
203                 assertTrue(completionReq.contains("request-id>testRequestId<"));
204                 assertTrue(completionReq.contains("action>CREATE<"));
205                 assertTrue(completionReq.contains("source>VID<"));
206
207                 assertEquals("0", BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+"VnfsCreatedCount"));
208         }
209         
210         @Test
211         @Deployment(resources = {
212                         "process/CreateVcpeResCustService.bpmn",
213                         "subprocess/SDNCAdapterV1.bpmn",
214                         "subprocess/FalloutHandler.bpmn",
215                         "subprocess/GenericGetService.bpmn",
216                         "subprocess/GenericPutService.bpmn",
217                         "subprocess/BuildingBlock/DecomposeService.bpmn",
218             "subprocess/DoCreateServiceInstance.bpmn",
219                         "subprocess/DoCreateAllottedResourceBRG.bpmn",
220             "subprocess/CompleteMsoProcess.bpmn",
221
222             // this stub will trigger a fault
223                         "VCPE/stubprocess/DoCreateAllottedResourceTXC.bpmn",
224
225             // stubs
226                         "VCPE/stubprocess/Homing.bpmn",
227             "VCPE/stubprocess/DoCreateVnfAndModules.bpmn"})
228         
229         public void testCreateVcpeResCustService_Fault_NoRollback() throws Exception {
230
231                 System.out.println("starting:  testCreateVcpeResCustService_Fault_NoRollback\n");
232                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "2", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
233                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
234                 MockGetCustomer(CUST, "VCPE/CreateVcpeResCustService/getCustomer.xml");
235                 
236                 // TODO: the SI should NOT have to be URL-encoded yet again!
237                 MockPutServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
238                 MockGetServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
239                 
240                 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
241                 MockNodeQueryServiceInstanceById(PARENT_INST, "GenericFlows/getParentSIUrlById.xml");           
242                 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
243                 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
244                 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
245                 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
246
247                 mockSDNCAdapter(200);
248                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
249                 
250                 Map<String, Object> variables = setupVariables();
251
252                 String req = FileUtil.readResourceFile("__files/VCPE/CreateVcpeResCustService/requestNoSINameNoRollback.json");
253                 
254                 String businessKey = UUID.randomUUID().toString();
255                 invokeAsyncProcess(PROCNAME, "v1", businessKey, req, variables);
256                 
257                 // for SI
258                 injectSDNCCallbacks(callbacks, "assign");
259                 
260                 waitForProcessEnd(businessKey, 10000);
261
262                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
263                 System.out.println("workflowException:\n" + workflowException);
264
265                 String completionReq = BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+VAR_COMP_REQ);
266                 System.out.println("completionReq:\n" + completionReq);
267                 
268                 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
269                 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_RESP_CODE));
270                 assertNotNull(workflowException);
271                 
272                 BPMNUtil.assertNoProcessInstance(processEngineRule, "DoCreateAllottedResourceBRGRollback");
273                 BPMNUtil.assertNoProcessInstance(processEngineRule, "DoCreateVnfAndModulesRollback");
274                 BPMNUtil.assertNoProcessInstance(processEngineRule, "DoCreateAllottedResourceTXCRollback");
275         }
276         
277         @Test
278         @Deployment(resources = {
279                         "process/CreateVcpeResCustService.bpmn",
280                         "subprocess/SDNCAdapterV1.bpmn",
281                         "subprocess/FalloutHandler.bpmn",
282                         "subprocess/GenericGetService.bpmn",
283                         "subprocess/GenericPutService.bpmn",
284                         "subprocess/BuildingBlock/DecomposeService.bpmn",
285             "subprocess/DoCreateServiceInstance.bpmn",
286                         "subprocess/DoCreateAllottedResourceTXC.bpmn",
287                         "subprocess/DoCreateAllottedResourceTXCRollback.bpmn",
288             "subprocess/CompleteMsoProcess.bpmn",
289
290             // this stub will trigger a fault
291                         "VCPE/stubprocess/DoCreateAllottedResourceBRG.bpmn",
292
293             // stubs
294                         "VCPE/stubprocess/DoCreateAllottedResourceBRGRollback.bpmn",
295                         "VCPE/stubprocess/DoCreateVnfAndModulesRollback.bpmn",
296             "VCPE/stubprocess/DoCreateServiceInstanceRollback.bpmn",
297                         "VCPE/stubprocess/Homing.bpmn",
298             "VCPE/stubprocess/DoCreateVnfAndModules.bpmn"})
299         
300         public void testCreateVcpeResCustService_Fault_Rollback() throws Exception {
301
302                 System.out.println("starting:  testCreateVcpeResCustService_Fault_Rollback\n");
303                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "2", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
304                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef", "VCPE/CreateVcpeResCustService/getCatalogServiceResourcesData.json");
305                 MockGetCustomer(CUST, "VCPE/CreateVcpeResCustService/getCustomer.xml");
306                 
307                 // TODO: the SI should NOT have to be URL-encoded yet again!
308                 MockPutServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
309                 MockGetServiceInstance(CUST, SVC, INST.replace("%", "%25"), "GenericFlows/getServiceInstance.xml");
310                 
311                 MockNodeQueryServiceInstanceById(INST, "GenericFlows/getSIUrlById.xml");
312                 MockNodeQueryServiceInstanceById(PARENT_INST, "GenericFlows/getParentSIUrlById.xml");           
313                 MockGetServiceInstance(CUST, SVC, INST, "GenericFlows/getServiceInstance.xml");
314                 MockGetServiceInstance(CUST, SVC, PARENT_INST, "GenericFlows/getParentServiceInstance.xml");
315                 MockGetAllottedResource(CUST, SVC, INST, ARID, "VCPE/CreateVcpeResCustService/arGetById.xml");
316                 MockGetAllottedResource(CUST, SVC, PARENT_INST, ARID, "VCPE/CreateVcpeResCustService/arGetById.xml");
317                 MockPutAllottedResource(CUST, SVC, PARENT_INST, ARID);
318                 MockPatchAllottedResource(CUST, SVC, PARENT_INST, ARID);
319                 MockDeleteAllottedResource(CUST, SVC, PARENT_INST, ARID, ARVERS);
320
321                 mockSDNCAdapter(200);
322                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
323                 
324                 Map<String, Object> variables = setupVariables();
325
326                 String businessKey = UUID.randomUUID().toString();
327                 invokeAsyncProcess(PROCNAME, "v1", businessKey, request, variables);
328                 
329                 // for SI
330                 injectSDNCCallbacks(callbacks, "assign");
331                 
332                 // for TXC
333                 injectSDNCCallbacks(callbacks, "assign");
334                 injectSDNCCallbacks(callbacks, "create");
335                 injectSDNCCallbacks(callbacks, "activate");
336                 injectSDNCCallbacks(callbacks, "queryTXC");
337                 
338                 // BRG is a stub so don't need SDNC callbacks
339                 
340                 // for TXC rollback
341                 injectSDNCCallbacks(callbacks, "deactivate");
342                 injectSDNCCallbacks(callbacks, "delete");
343                 injectSDNCCallbacks(callbacks, "unassign");
344                 
345                 waitForProcessEnd(businessKey, 10000);
346
347                 String workflowException = BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_WFEX);
348                 System.out.println("workflowException:\n" + workflowException);
349
350                 String completionReq = BPMNUtil.getVariable(processEngineRule, PROCNAME, Prefix+VAR_COMP_REQ);
351                 System.out.println("completionReq:\n" + completionReq);
352                 
353                 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, PROCNAME+VAR_SUCCESS_IND));
354                 assertEquals(null, BPMNUtil.getVariable(processEngineRule, PROCNAME, VAR_RESP_CODE));
355                 assertEquals(null, completionReq);
356                 assertNotNull(workflowException);
357                 
358                 BPMNUtil.assertAnyProcessInstanceFinished(processEngineRule, "DoCreateAllottedResourceBRGRollback");
359                 BPMNUtil.assertAnyProcessInstanceFinished(processEngineRule, "DoCreateVnfAndModulesRollback");
360                 BPMNUtil.assertAnyProcessInstanceFinished(processEngineRule, "DoCreateAllottedResourceTXCRollback");
361         }
362         
363         // *****************
364         // Utility Section
365         // *****************
366
367         // Success Scenario
368         private Map<String, Object> setupVariables() {
369                 Map<String, Object> variables = new HashMap<>();
370                 variables.put("requestId", "testRequestId");
371                 variables.put("request-id", "testRequestId");
372                 variables.put("serviceInstanceId", DEC_INST);
373                 variables.put("allottedResourceId", ARID);
374                 return variables;
375
376         }
377 }