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;
23 import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.doAnswer;
27 import static org.mockito.Mockito.doThrow;
28 import java.util.List;
29 import org.camunda.bpm.engine.ManagementService;
30 import org.camunda.bpm.engine.TaskService;
31 import org.camunda.bpm.engine.delegate.BpmnError;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.camunda.bpm.engine.management.JobDefinition;
34 import org.camunda.bpm.engine.runtime.Job;
35 import org.camunda.bpm.engine.runtime.ProcessInstance;
36 import org.camunda.bpm.engine.task.Task;
37 import org.camunda.bpm.engine.test.ProcessEngineRule;
38 import org.junit.Ignore;
39 import org.junit.Rule;
40 import org.junit.Test;
41 import org.mockito.invocation.InvocationOnMock;
42 import org.mockito.stubbing.Answer;
43 import org.onap.so.bpmn.BaseBPMNTest;
44 import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective;
45 import org.springframework.beans.factory.annotation.Autowired;
47 public class ExecuteBuildingBlockTest extends BaseBPMNTest {
49 private TaskService taskService;
51 private ManagementService managementService;
54 public void runExecuteFlowTest() {
56 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.CONTINUE);
57 variables.put("flowToBeCalled", "MockFlow");
59 mockSubprocess("MockFlow", "My Mock Process Name", "GenericStub");
61 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
63 assertThat(pi).isNotNull();
64 assertThat(pi).isStarted().hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy",
65 "CheckOrchestrationStatusValidationResults", "Task_PreValidate", "Call_BBToExecute",
66 "Task_PostValidate", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock");
67 assertThat(pi).isEnded();
73 public void test_sunnyDayExecuteBuildingBlock_silentSuccess() throws Exception {
74 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS);
76 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
77 assertThat(pi).isNotNull();
78 assertThat(pi).isStarted().hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy",
79 "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock")
80 .hasNotPassed("Call_BBToExecute", "ErrorStart", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik",
81 "ExclusiveGateway_1aonzik", "ErrorEnd2", "Task_SetRetryTimer");
82 assertThat(pi).isEnded();
87 public void test_rainyDayExecuteBuildingBlock_rollbackOrAbort() throws Exception {
88 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
89 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
90 assertThat(pi).isNotNull();
91 assertThat(pi).isStarted()
92 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g",
93 "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "EndEvent_0mvmk3i", "SubProcess_0tv8zda")
94 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
95 "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock",
96 "ExclusiveGateway_0ey4zpt", "Task_SetRetryTimer");
97 assertThat(pi).isEnded();
102 public void test_rainyDayExecuteBuildingBlock_retryNoRetriesLeft() throws Exception {
103 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
105 variables.put("handlingCode", "Retry");
106 variables.put("RetryCount", 5);
108 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
109 assertThat(pi).isNotNull();
110 assertThat(pi).isStarted()
111 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g",
112 "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "ErrorEnd2")
113 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
114 "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock",
115 "Task_SetRetryTimer");
116 assertThat(pi).isEnded();
121 public void test_rainyDayExecuteBuildingBlock_retryRetriesLeft() throws Exception {
122 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
124 variables.put("handlingCode", "Retry");
125 variables.put("RetryCount", 4);
126 variables.put("RetryDuration", "PT1S");
128 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
129 assertThat(pi).isNotNull();
130 assertThat(pi).isStarted();
131 assertThat(pi).isWaitingAt("IntermediateCatchEvent_RetryTimer");
132 Job job = managementService.createJobQuery().activityId("IntermediateCatchEvent_RetryTimer").singleResult();
134 managementService.executeJob(job.getId());
135 assertThat(pi).isEnded()
136 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "BoundaryEvent_0i3q236",
137 "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt",
138 "Task_SetRetryTimer", "EndEvent_1sez2lh")
139 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
140 "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock", "ErrorEnd2");