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