3ab1c76ee63a7a0e6f0b2c1e724df109557f28fc
[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
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                 
50                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
51                 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync",
52                                 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowCompleted", "Task_UpdateRequestComplete",
53                                 "End_WorkflowActionBB");
54         
55         }
56
57         @Test
58         public void sunnyDaySuccessNotTopLevelFlow() throws InterruptedException, IOException {
59                 variables.put("isTopLevelFlow", false);
60                 variables.put("completed", true);
61
62                 Map<String, String> map = new HashMap<>();
63                 map.put("handlingCode", "Success");
64                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
65                 
66                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
67                 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow",
68                                 "Task_SelectBB", "Call_ExecuteBB", "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", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow",
82                                 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "Task_RollbackExecutionPath", "Task_UpdateRequestToFailed", "End_RollbackFailed");
83                 
84         }
85         
86         @Test
87         public void rainyDayAbort() throws Exception {
88                 variables.put("isTopLevelFlow", true);
89                 variables.put("completed", false);
90
91                 Map<String, String> map = new HashMap<>();
92                 map.put("handlingCode", "Abort");
93                 
94                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBFailure).abortCallErrorHandling(any(DelegateExecution.class));
95                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
96                 
97                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
98                 assertThat(pi).isNotNull().isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow", "Task_SendSync",
99                                 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "ExclusiveGateway_isTopLevelFlowAbort", "Task_AbortAndCallErrorHandling", "ErrorStart",
100                                 "Task_UpdateDb", "ErrorEnd");
101
102         }
103         
104         @Test
105         public void retrieveBBExecutionListerrorHandling() throws Exception {
106                 variables.put("isTopLevelFlow", true);
107                 variables.put("sentSyncResponse", false);
108                 doThrow(new IllegalStateException("TESTING ERRORS")).when(workflowAction).selectExecutionList(any(DelegateExecution.class));
109                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
110                 assertThat(pi).isNotNull();
111                 assertThat(pi).isStarted().hasPassedInOrder("Start_WorkflowActionBB", "Task_RetrieveBBExectuionList", "StartEvent_runtimeError", "ServiceTask_HandleRuntimeError", "EndEvent__runtimeError", "SubProcess_0rze15o");
112
113         }
114         
115         @Test
116         public void errorCatchSubprocessHandlingTest() throws Exception {
117                 variables.put("isTopLevelFlow", true);
118                 variables.put("sentSyncResponse", false);
119                 doThrow(new IllegalStateException("TESTING ERRORS")).when(workflowAction).selectExecutionList(any(DelegateExecution.class));
120                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowAction).handleRuntimeException(any(DelegateExecution.class));
121                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
122                 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");
123
124         }
125         
126         @Test
127         public void errorCatchBpmnSubprocessHandlingTest() throws Exception {
128                 variables.put("isTopLevelFlow", true);
129                 variables.put("sentSyncResponse", false);
130                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBTasks).selectBB(any(DelegateExecution.class));
131                 ProcessInstance pi = runtimeService.startProcessInstanceByKey("WorkflowActionBB", variables);
132                 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");
133                 
134         }
135 }