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);
 
  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");
 
  58         public void sunnyDaySuccessNotTopLevelFlow() throws InterruptedException, IOException {
 
  59                 variables.put("isTopLevelFlow", false);
 
  60                 variables.put("completed", true);
 
  62                 Map<String, String> map = new HashMap<>();
 
  63                 map.put("handlingCode", "Success");
 
  64                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
 
  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");
 
  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", "Task_RetrieveBBExectuionList", "ExclusiveGateway_isTopLevelFlow",
 
  82                                 "Task_SelectBB", "Call_ExecuteBB", "ExclusiveGateway_Finished", "Task_RollbackExecutionPath", "Task_UpdateRequestToFailed", "End_RollbackFailed");
 
  87         public void rainyDayAbort() throws Exception {
 
  88                 variables.put("isTopLevelFlow", true);
 
  89                 variables.put("completed", false);
 
  91                 Map<String, String> map = new HashMap<>();
 
  92                 map.put("handlingCode", "Abort");
 
  94                 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(workflowActionBBFailure).abortCallErrorHandling(any(DelegateExecution.class));
 
  95                 mockSubprocess("ExecuteBuildingBlock", "Mocked ExecuteBuildingBlock", "GenericStub", map);
 
  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");
 
 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");
 
 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");
 
 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");