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