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;
27 import java.io.IOException;
28 import java.util.HashMap;
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;
39 public class WorkflowActionBBTest extends BaseBPMNTest {
42 public void sunnyDaySuccessIsTopLevelFlow() throws InterruptedException, IOException {
43 variables.put("isTopLevelFlow", true);
44 variables.put("completed", true);
46 Map<String, String> map = new HashMap<>();
47 map.put("handlingCode", "Success");
48 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
49 mockSubprocess("CompleteMsoProcess", "Mocked CompleteMsoProcess", "GenericStub");
51 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
52 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync",
53 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowCompleted", "Task_SetupCompleteMsoProcess", "Call_CompleteMsoProcess",
54 "End_WorkflowActionBB");
59 public void sunnyDaySuccessNotTopLevelFlow() throws InterruptedException, IOException {
60 variables.put("isTopLevelFlow", false);
61 variables.put("completed", true);
63 Map<String, String> map = new HashMap<>();
64 map.put("handlingCode", "Success");
65 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
67 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
68 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow",
69 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowCompleted", "End_WorkflowActionBB");
73 public void sunnyDayRollback() throws InterruptedException, IOException {
74 variables.put("isTopLevelFlow", false);
75 variables.put("isRollbackNeeded", false);
77 Map<String, String> map = new HashMap<>();
78 map.put("handlingCode", "Rollback");
79 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
81 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
82 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow",
83 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "Task_RollbackExecutionPath", "Task_UpdateRequestToFailed", "End_RollbackFailed");
88 public void rainyDayAbort() throws Exception {
89 variables.put("isTopLevelFlow", true);
90 variables.put("completed", false);
92 Map<String, String> map = new HashMap<>();
93 map.put("handlingCode", "Abort");
95 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBTasks).abortCallErrorHandling(any(DelegateExecution.class));
96 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
98 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
99 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync",
100 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowAbort", "Task_AbortAndCallErrorHandling", "ErrorStart",
101 "Task_UpdateDb", "ErrorEnd");
106 public void retrieveBBExecutionListerrorHandling() throws Exception {
107 variables.put("isTopLevelFlow", true);
108 variables.put("sentSyncResponse", false);
109 doThrow(new IllegalStateException("TESTING ERRORS")).when(workflowAction).selectExecutionList(any(DelegateExecution.class));
110 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
111 assertThat(pi).isNotNull();
112 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "StartEvent_runtimeError", "ServiceTask_HandleRuntimeError", "EndEvent__runtimeError", "SubProcess_0rze15o");
117 public void errorCatchSubprocessHandlingTest() throws Exception {
118 variables.put("isTopLevelFlow", true);
119 variables.put("sentSyncResponse", false);
120 doThrow(new IllegalStateException("TESTING ERRORS")).when(workflowAction).selectExecutionList(any(DelegateExecution.class));
121 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowAction).handleRuntimeException(any(DelegateExecution.class));
122 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
123 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "StartEvent_runtimeError", "ServiceTask_HandleRuntimeError", "SubProcess_0fuugr9", "ErrorStart", "ExclusiveGateway_10q79b6", "Task_SendSyncAckError", "Task_UpdateDb", "ErrorEnd", "SubProcess_18226x4");
128 public void errorCatchBpmnSubprocessHandlingTest() throws Exception {
129 variables.put("isTopLevelFlow", true);
130 variables.put("sentSyncResponse", false);
131 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBTasks).selectBB(any(DelegateExecution.class));
132 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
133 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList","ExclusiveGateway_isTopLevelFlow","Task_SendSync","Task_SelectBB", "ErrorStart", "ExclusiveGateway_10q79b6", "Task_SendSyncAckError", "Task_UpdateDb", "ErrorEnd", "SubProcess_18226x4");