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.bpmn.BpmnAwareAssertions.assertThat;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.doAnswer;
27 import static org.mockito.Mockito.doThrow;
29 import java.util.List;
31 import org.camunda.bpm.engine.ManagementService;
32 import org.camunda.bpm.engine.TaskService;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.camunda.bpm.engine.delegate.DelegateExecution;
35 import org.camunda.bpm.engine.management.JobDefinition;
36 import org.camunda.bpm.engine.runtime.Job;
37 import org.camunda.bpm.engine.runtime.ProcessInstance;
38 import org.camunda.bpm.engine.task.Task;
39 import org.camunda.bpm.engine.test.ProcessEngineRule;
40 import org.junit.Ignore;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.mockito.invocation.InvocationOnMock;
44 import org.mockito.stubbing.Answer;
45 import org.onap.so.bpmn.BaseBPMNTest;
46 import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective;
47 import org.springframework.beans.factory.annotation.Autowired;
49 public class ExecuteBuildingBlockTest extends BaseBPMNTest {
51 private TaskService taskService;
53 private ManagementService managementService;
56 public void test_sunnyDayExecuteBuildingBlock_silentSuccess() throws Exception {
57 variables.put("orchestrationStatusValidationResult", OrchestrationStatusValidationDirective.SILENT_SUCCESS);
59 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
60 assertThat(pi).isNotNull();
61 assertThat(pi).isStarted()
62 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "StatusPolicy", "CheckOrchestrationStatusValidationResults","Task_setHandlingCodeSuccess", "End_ExecuteBuildingBlock")
63 .hasNotPassed("Call_BBToExecute", "ErrorStart", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_1aonzik", "ErrorEnd2", "Task_SetRetryTimer");
64 assertThat(pi).isEnded();
68 public void test_rainyDayExecuteBuildingBlock_rollbackOrAbort() throws Exception {
69 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
70 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
71 assertThat(pi).isNotNull();
72 assertThat(pi).isStarted()
73 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "BoundaryEvent_0i3q236", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ErrorEnd2")
74 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "ExclusiveGateway_0ey4zpt", "Task_SetRetryTimer");
75 assertThat(pi).isEnded();
79 public void test_rainyDayExecuteBuildingBlock_retryNoRetriesLeft() throws Exception {
80 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
82 variables.put("handlingCode", "Retry");
83 variables.put("RetryCount", 5);
85 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
86 assertThat(pi).isNotNull();
87 assertThat(pi).isStarted()
88 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "BoundaryEvent_0i3q236", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "ErrorEnd2")
89 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "Task_SetRetryTimer");
90 assertThat(pi).isEnded();
95 public void test_rainyDayExecuteBuildingBlock_retryRetriesLeft() throws Exception {
96 doThrow(new BpmnError("7000", "TESTING ERRORS")).when(bbInputSetup).execute(any(DelegateExecution.class));
98 variables.put("handlingCode", "Retry");
99 variables.put("RetryCount", 4);
100 variables.put("RetryDuration", "PT1S");
102 ProcessInstance pi = runtimeService.startProcessInstanceByKey("ExecuteBuildingBlock", variables);
103 assertThat(pi).isNotNull();
104 assertThat(pi).isStarted();
105 assertThat(pi).isWaitingAt("IntermediateCatchEvent_RetryTimer");
106 Job job = managementService.createJobQuery().activityId("IntermediateCatchEvent_RetryTimer").singleResult();
108 managementService.executeJob(job.getId());
109 assertThat(pi).isEnded()
110 .hasPassedInOrder("Start_ExecuteBuildingBlock", "Task_BBInputSetup", "BoundaryEvent_0i3q236", "Task_QueryRainyDayTable", "ExclusiveGateway_1aonzik", "ExclusiveGateway_0ey4zpt", "Task_SetRetryTimer", "EndEvent_1sez2lh")
111 .hasNotPassed("StatusPolicy", "CheckOrchestrationStatusValidationResults", "Task_setHandlingCodeSuccess","Call_BBToExecute", "End_ExecuteBuildingBlock", "ErrorEnd2");