2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.bpmn.process;
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;
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;
37 public class WorkflowActionBBTest extends BaseBPMNTest {
40 public void sunnyDaySuccessIsTopLevelFlow() throws InterruptedException, IOException {
41 variables.put("isTopLevelFlow", true);
42 variables.put("completed", true);
44 Map<String, String> map = new HashMap<>();
45 map.put("handlingCode", "Success");
46 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
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");
57 public void sunnyDaySuccessNotTopLevelFlow() throws InterruptedException, IOException {
58 variables.put("isTopLevelFlow", false);
59 variables.put("completed", true);
61 Map<String, String> map = new HashMap<>();
62 map.put("handlingCode", "Success");
63 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
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");
72 public void sunnyDayRollback() throws InterruptedException, IOException {
73 variables.put("isTopLevelFlow", false);
74 variables.put("isRollbackNeeded", false);
76 Map<String, String> map = new HashMap<>();
77 map.put("handlingCode", "Rollback");
78 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
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");
89 public void rainyDayAbort() throws Exception {
90 variables.put("isTopLevelFlow", true);
91 variables.put("completed", false);
93 Map<String, String> map = new HashMap<>();
94 map.put("handlingCode", "Abort");
96 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBFailure)
97 .abortCallErrorHandling(any(DelegateExecution.class));
98 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
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");
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");
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");
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");