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 org.camunda.bpm.engine.ManagementService;
24 import org.camunda.bpm.engine.TaskService;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.camunda.bpm.engine.runtime.Job;
28 import org.camunda.bpm.engine.runtime.ProcessInstance;
29 import org.junit.Ignore;
30 import org.junit.Test;
31 import org.onap.so.bpmn.BaseBPMNTest;
32 import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat;
35 import static org.junit.Assert.assertNotNull;
36 import static org.mockito.ArgumentMatchers.any;
37 import static org.mockito.Mockito.doThrow;
39 public class ExecuteBuildingBlockTest extends BaseBPMNTest {
41 private TaskService taskService;
43 private ManagementService managementService;
46 public void runExecuteFlowTest() {
48 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.CONTINUE);
49 variables.put("flowToBeCalled", "MockFlow");
50 variables.put("homing", false);
52 mockSubprocess("MockFlow", "My Mock Process Name", "GenericStub");
54 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
56 assertThat(pi).isNotNull();
57 assertThat(pi).isStarted().hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy",
58 "CheckOrchestrationStatusValidationResults", "Task_PreValidate", "Call_BBToExecute",
59 "Task_PostValidate", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock");
60 assertThat(pi).isEnded();
66 public void test_sunnyDayExecuteBuildingBlock_silentSuccess() throws Exception {
67 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS);
68 variables.put("homing", false);
70 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
71 assertThat(pi).isNotNull();
72 assertThat(pi).isStarted().hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy",
73 "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock")
74 .hasNotPassed("Call_BBToExecute", "ErrorStart", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik",
75 "ExclusiveGateway_1aonzik", "ErrorEnd2", "Task_SetRetryTimer");
76 assertThat(pi).isEnded();
81 public void test_rainyDayExecuteBuildingBlock_rollbackOrAbort() throws Exception {
82 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
83 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
84 variables.put("homing", false);
85 assertThat(pi).isNotNull();
86 assertThat(pi).isStarted()
87 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g",
88 "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "EndEvent_0mvmk3i", "SubProcess_0tv8zda")
89 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
90 "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock",
91 "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);
102 variables.put("homing", false);
104 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
105 assertThat(pi).isNotNull();
106 assertThat(pi).isStarted()
107 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StartEvent_0tmcs9g",
108 "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "ErrorEnd2")
109 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
110 "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock",
111 "Task_SetRetryTimer");
112 assertThat(pi).isEnded();
117 public void test_rainyDayExecuteBuildingBlock_retryRetriesLeft() throws Exception {
118 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
120 variables.put("handlingCode", "Retry");
121 variables.put("RetryCount", 4);
122 variables.put("RetryDuration", "PT1S");
123 variables.put("homing", false);
125 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
126 assertThat(pi).isNotNull();
127 assertThat(pi).isStarted();
128 assertThat(pi).isWaitingAt("IntermediateCatchEvent_RetryTimer");
129 Job job = managementService.createJobQuery().activityId("IntermediateCatchEvent_RetryTimer").singleResult();
131 managementService.executeJob(job.getId());
132 assertThat(pi).isEnded()
133 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "BoundaryEvent_0i3q236",
134 "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt",
135 "Task_SetRetryTimer", "EndEvent_1sez2lh")
136 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults",
137 "Task_setHandlingCodeSuccess", "Call_BBToExecute", "End_ExecuteBuildingBlock", "ErrorEnd2");