ee02f293f77e04b04e0a844ebbe59d7d3b74c704
[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.bpmn.BpmnAwareAssertions.assertThat;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.doThrow;
26
27 import java.io.IOException;
28 import java.util.HashMap;
29 import java.util.Map;
30
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                 mockSubprocess("CompleteMsoProcess", "Mocked CompleteMsoProcess", "GenericStub");
50                 
51                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
52                 assertThat(pi).isNotNull();
53                 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync",
54                                 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowCompleted", "Task_SetupCompleteMsoProcess", "Call_CompleteMsoProcess",
55                                 "End_WorkflowActionBB");
56                 assertThat(pi).isEnded();
57         }
58
59         @Test
60         public void sunnyDaySuccessNotTopLevelFlow() throws InterruptedException, IOException {
61                 variables.put("isTopLevelFlow", false);
62                 variables.put("completed", true);
63
64                 Map<String, String> map = new HashMap<>();
65                 map.put("handlingCode", "Success");
66                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
67                 
68                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
69                 assertThat(pi).isNotNull();
70                 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow",
71                                 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowCompleted", "End_WorkflowActionBB");
72                 assertThat(pi).isEnded();
73         }
74         
75         @Test
76         public void sunnyDayRollback() throws InterruptedException, IOException {
77                 variables.put("isTopLevelFlow", false);
78                 variables.put("isRollbackNeeded", false);
79
80                 Map<String, String> map = new HashMap<>();
81                 map.put("handlingCode", "Rollback");
82                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
83                 
84                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
85                 assertThat(pi).isNotNull();
86                 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow",
87                                 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "Task_RollbackExecutionPath", "Task_UpdateRequestToFailed", "End_RollbackFailed");
88                 assertThat(pi).isEnded();
89         }
90         
91         @Test
92         public void rainyDayAbort() throws Exception {
93                 variables.put("isTopLevelFlow", true);
94                 variables.put("completed", false);
95
96                 Map<String, String> map = new HashMap<>();
97                 map.put("handlingCode", "Abort");
98                 
99                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBTasks).abortCallErrorHandling(any(DelegateExecution.class));
100                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
101                 
102                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
103                 assertThat(pi).isNotNull();
104                 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync",
105                                 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowAbort", "Task_AbortAndCallErrorHandling", "ErrorStart",
106                                 "Task_UpdateDb", "ErrorEnd");
107                 assertThat(pi).isEnded();
108         }
109         
110         @Test
111         public void retrieveBBExecutionListerrorHandling() throws Exception {
112                 variables.put("isTopLevelFlow", true);
113                 variables.put("sentSyncResponse", false);
114                 doThrow(new IllegalStateException("TESTING ERRORS")).when(workflowAction).selectExecutionList(any(DelegateExecution.class));
115                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
116                 assertThat(pi).isNotNull();
117                 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "StartEvent_runtimeError", "ServiceTask_HandleRuntimeError", "EndEvent__runtimeError", "SubProcess_0rze15o");
118                 assertThat(pi).isEnded();
119         }
120         
121         @Test
122         public void errorCatchSubprocessHandlingTest() throws Exception {
123                 variables.put("isTopLevelFlow", true);
124                 variables.put("sentSyncResponse", false);
125                 doThrow(new IllegalStateException("TESTING ERRORS")).when(workflowAction).selectExecutionList(any(DelegateExecution.class));
126                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowAction).handleRuntimeException(any(DelegateExecution.class));
127                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
128                 assertThat(pi).isNotNull();
129                 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "StartEvent_runtimeError", "ServiceTask_HandleRuntimeError", "SubProcess_0fuugr9", "ErrorStart", "ExclusiveGateway_10q79b6", "Task_SendSyncAckError", "Task_UpdateDb", "ErrorEnd", "SubProcess_18226x4");
130                 assertThat(pi).isEnded();
131         }
132         
133         @Test
134         public void errorCatchBpmnSubprocessHandlingTest() throws Exception {
135                 variables.put("isTopLevelFlow", true);
136                 variables.put("sentSyncResponse", false);
137                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBTasks).selectBB(any(DelegateExecution.class));
138                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
139                 assertThat(pi).isNotNull();
140                 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList","ExclusiveGateway_isTopLevelFlow","Task_SendSync","Task_SelectBB", "ErrorStart", "ExclusiveGateway_10q79b6", "Task_SendSyncAckError", "Task_UpdateDb", "ErrorEnd", "SubProcess_18226x4");
141                 assertThat(pi).isEnded();
142         }
143 }