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.subprocess;
22 import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
23 import static org.junit.Assert.assertNotNull;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doAnswer;
26 import static org.mockito.Mockito.doThrow;
28 import java.util.List;
30 import org.camunda.bpm.engine.ManagementService;
31 import org.camunda.bpm.engine.TaskService;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.camunda.bpm.engine.delegate.DelegateExecution;
34 import org.camunda.bpm.engine.management.JobDefinition;
35 import org.camunda.bpm.engine.runtime.Job;
36 import org.camunda.bpm.engine.runtime.ProcessInstance;
37 import org.camunda.bpm.engine.task.Task;
38 import org.camunda.bpm.engine.test.ProcessEngineRule;
39 import org.junit.Ignore;
40 import org.junit.Rule;
41 import org.junit.Test;
42 import org.mockito.invocation.InvocationOnMock;
43 import org.mockito.stubbing.Answer;
44 import org.onap.so.bpmn.BaseBPMNTest;
45 import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective;
46 import org.springframework.beans.factory.annotation.Autowired;
48 public class ExecuteBuildingBlockTest extends BaseBPMNTest {
50 private TaskService taskService;
52 private ManagementService managementService;
55 public void runExecuteFlowTest() {
57 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.CONTINUE);
58 variables.put("flowToBeCalled", "MockFlow");
60 mockSubprocess("MockFlow", "My Mock Process Name", "GenericStub");
62 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
64 assertThat(pi).isNotNull();
65 assertThat(pi).isStarted()
66 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_PreValidate", "Call_BBToExecute", "Task_PostValidate", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock");
67 assertThat(pi).isEnded();
72 public void test_sunnyDayExecuteBuildingBlock_silentSuccess() throws Exception {
73 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS);
75 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
76 assertThat(pi).isNotNull();
77 assertThat(pi).isStarted()
78 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy", "CheckOrchestrationStatusValidationResults","Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock")
79 .hasNotPassed("Call_BBToExecute", "ErrorStart", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_1aonzik", "ErrorEnd2", "Task_SetRetryTimer");
80 assertThat(pi).isEnded();
85 public void test_rainyDayExecuteBuildingBlock_rollbackOrAbort() throws Exception {
86 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
87 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
88 assertThat(pi).isNotNull();
89 assertThat(pi).isStarted()
90 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "EndEvent_0mvmk3i", "SubProcess_0tv8zda")
91 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "ExclusiveGateway_0ey4zpt", "Task_SetRetryTimer");
92 assertThat(pi).isEnded();
97 public void test_rainyDayExecuteBuildingBlock_retryNoRetriesLeft() throws Exception {
98 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
100 variables.put("handlingCode", "Retry");
101 variables.put("RetryCount", 5);
103 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
104 assertThat(pi).isNotNull();
105 assertThat(pi).isStarted()
106 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "ErrorEnd2")
107 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "Task_SetRetryTimer");
108 assertThat(pi).isEnded();
113 public void test_rainyDayExecuteBuildingBlock_retryRetriesLeft() throws Exception {
114 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
116 variables.put("handlingCode", "Retry");
117 variables.put("RetryCount", 4);
118 variables.put("RetryDuration", "PT1S");
120 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
121 assertThat(pi).isNotNull();
122 assertThat(pi).isStarted();
123 assertThat(pi).isWaitingAt("IntermediateCatchEvent_RetryTimer");
124 Job job = managementService.createJobQuery().activityId("IntermediateCatchEvent_RetryTimer").singleResult();
126 managementService.executeJob(job.getId());
127 assertThat(pi).isEnded()
128 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "BoundaryEvent_0i3q236", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "Task_SetRetryTimer", "EndEvent_1sez2lh")
129 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "ErrorEnd2");