f492326b0c9a22a3e8185e47e70ba7477e2246d4
[so.git] / bpmn / so-bpmn-building-blocks / src / test / java / org / onap / so / bpmn / infrastructure / bpmn / process / WorkflowActionBBTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.infrastructure.bpmn.process;
24
25 import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.assertThat;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.Mockito.doThrow;
28 import java.io.IOException;
29 import java.util.HashMap;
30 import java.util.Map;
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.camunda.bpm.engine.runtime.ProcessInstance;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.onap.so.bpmn.BaseBPMNTest;
37
38 @Ignore
39 public class WorkflowActionBBTest extends BaseBPMNTest {
40
41     @Test
42     public void sunnyDaySuccessIsTopLevelFlow() throws InterruptedException, IOException {
43         variables.put("isTopLevelFlow", true);
44         variables.put("completed", true);
45
46         Map<String, String> map = new HashMap<>();
47         map.put("handlingCode", "Success");
48         mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
49
50         ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
51         assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB",
52                 "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync", "Task_SelectBB",
53                 "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowCompleted",
54                 "Task_UpdateRequestComplete", "End_WorkflowActionBB");
55
56     }
57
58     @Test
59     public void sunnyDaySuccessNotTopLevelFlow() throws InterruptedException, IOException {
60         variables.put("isTopLevelFlow", false);
61         variables.put("completed", true);
62
63         Map<String, String> map = new HashMap<>();
64         map.put("handlingCode", "Success");
65         mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
66
67         ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
68         assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB",
69                 "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SelectBB", "Call_ExecuteBB",
70                 "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowCompleted", "End_WorkflowActionBB");
71     }
72
73     @Test
74     public void sunnyDayRollback() throws InterruptedException, IOException {
75         variables.put("isTopLevelFlow", false);
76         variables.put("isRollbackNeeded", false);
77
78         Map<String, String> map = new HashMap<>();
79         map.put("handlingCode", "Rollback");
80         mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
81
82         ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
83         assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB",
84                 "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SelectBB", "Call_ExecuteBB",
85                 "ExclusiveGateway_Finished", "Task_RollbackExecutionPath", "Task_UpdateRequestToFailed",
86                 "End_RollbackFailed");
87
88     }
89
90     @Test
91     public void rainyDayAbort() throws Exception {
92         variables.put("isTopLevelFlow", true);
93         variables.put("completed", false);
94
95         Map<String, String> map = new HashMap<>();
96         map.put("handlingCode", "Abort");
97
98         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBFailure).abortCallErrorHandling();
99         mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
100
101         ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
102         assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB",
103                 "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync", "Task_SelectBB",
104                 "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowAbort",
105                 "Task_AbortAndCallErrorHandling", "ErrorStart", "Task_UpdateDb", "ErrorEnd");
106
107     }
108
109     @Test
110     public void retrieveBBExecutionListerrorHandling() throws Exception {
111         variables.put("isTopLevelFlow", true);
112         variables.put("sentSyncResponse", false);
113         doThrow(new IllegalStateException("TESTING ERRORS")).when(workflowAction)
114                 .selectExecutionList(any(DelegateExecution.class));
115         ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
116         assertThat(pi).isNotNull();
117         assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList",
118                 "StartEvent_runtimeError", "ServiceTask_HandleRuntimeError", "EndEvent__runtimeError",
119                 "SubProcess_0rze15o");
120
121     }
122
123     @Test
124     public void errorCatchSubprocessHandlingTest() throws Exception {
125         variables.put("isTopLevelFlow", true);
126         variables.put("sentSyncResponse", false);
127         doThrow(new IllegalStateException("TESTING ERRORS")).when(workflowAction)
128                 .selectExecutionList(any(DelegateExecution.class));
129         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowAction)
130                 .handleRuntimeException(any(DelegateExecution.class));
131         ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
132         assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB",
133                 "Task_RetrieveBBExectuionList", "StartEvent_runtimeError", "ServiceTask_HandleRuntimeError",
134                 "SubProcess_0fuugr9", "ErrorStart", "ExclusiveGateway_10q79b6", "Task_SendSyncAckError",
135                 "Task_UpdateDb", "ErrorEnd", "SubProcess_18226x4");
136
137     }
138
139     @Test
140     public void errorCatchBpmnSubprocessHandlingTest() throws Exception {
141         variables.put("isTopLevelFlow", true);
142         variables.put("sentSyncResponse", false);
143         doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBTasks)
144                 .selectBB(any(DelegateExecution.class));
145         ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
146         assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB",
147                 "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync", "Task_SelectBB",
148                 "ErrorStart", "ExclusiveGateway_10q79b6", "Task_SendSyncAckError", "Task_UpdateDb", "ErrorEnd",
149                 "SubProcess_18226x4");
150
151     }
152 }