45dafbe606883737137b1b0c9a451745a7f58440
[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                 mockSubprocess("CompleteMsoProcess", "Mocked CompleteMsoProcess", "GenericStub");
50                 
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");
55         
56         }
57
58         @Test
59         public void sunnyDaySuccessNotTopLevelFlow() throws InterruptedException, IOException {
60                 variables.put("isTopLevelFlow", false);
61                 variables.put("completed", true);
62
63                 Map<String, String> map = new HashMap<>();
64                 map.put("handlingCode", "Success");
65                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
66                 
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");
70         }
71         
72         @Test
73         public void sunnyDayRollback() throws InterruptedException, IOException {
74                 variables.put("isTopLevelFlow", false);
75                 variables.put("isRollbackNeeded", false);
76
77                 Map<String, String> map = new HashMap<>();
78                 map.put("handlingCode", "Rollback");
79                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
80                 
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");
84                 
85         }
86         
87         @Test
88         public void rainyDayAbort() throws Exception {
89                 variables.put("isTopLevelFlow", true);
90                 variables.put("completed", false);
91
92                 Map<String, String> map = new HashMap<>();
93                 map.put("handlingCode", "Abort");
94                 
95                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBFailure).abortCallErrorHandling(any(DelegateExecution.class));
96                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
97                 
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");
102
103         }
104         
105         @Test
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");
113
114         }
115         
116         @Test
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");
124
125         }
126         
127         @Test
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");
134                 
135         }
136 }