|
| 1 | +/* Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | + * you may not use this file except in compliance with the License. |
| 3 | + * You may obtain a copy of the License at |
| 4 | + * |
| 5 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | + * limitations under the License. |
| 12 | + */ |
| 13 | +package org.flowable.engine.test.api.deletereason; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Assertions.assertThat; |
| 16 | + |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | +import org.flowable.engine.history.DeleteReason; |
| 20 | +import org.flowable.engine.history.HistoricActivityInstance; |
| 21 | +import org.flowable.engine.impl.test.PluggableFlowableTestCase; |
| 22 | +import org.flowable.engine.runtime.ProcessInstance; |
| 23 | +import org.flowable.engine.test.Deployment; |
| 24 | +import org.flowable.task.api.Task; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +/** |
| 28 | + * Companion to {@link DeleteReasonTest#testInterruptingBoundaryEvent()}, for the |
| 29 | + * interrupting error event sub-process. |
| 30 | + * |
| 31 | + * An activity terminated by an interrupting start event is recorded with |
| 32 | + * DeleteReason.EVENT_SUBPROCESS_INTERRUPTING, so history can tell it apart from |
| 33 | + * one that completed normally. |
| 34 | + */ |
| 35 | +public class ErrorEventSubProcessDeleteReasonTest extends PluggableFlowableTestCase { |
| 36 | + |
| 37 | + /** |
| 38 | + * A forked process: one branch parks on a user task inside a call activity, |
| 39 | + * the other throws a BpmnError from a start execution listener. The |
| 40 | + * interrupting error event sub-process catches it and terminates the whole |
| 41 | + * scope, including the parked branch. |
| 42 | + */ |
| 43 | + @Test |
| 44 | + @Deployment(resources = "org/flowable/engine/test/api/deletereason/ErrorEventSubProcessDeleteReasonTest.bpmn20.xml") |
| 45 | + public void testInterruptingErrorEventSubProcess() { |
| 46 | + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("errorEventSubProcessDeleteReason"); |
| 47 | + |
| 48 | + waitForHistoryJobExecutorToProcessAllJobs(7000, 100); |
| 49 | + |
| 50 | + // The parked branch's user task was destroyed by the interruption. |
| 51 | + assertThat(taskService.createTaskQuery().processInstanceId(processInstance.getId()).count()).isZero(); |
| 52 | + assertThat(runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).count()).isZero(); |
| 53 | + |
| 54 | + HistoricActivityInstance parkedBranch = historicActivity(processInstance.getId(), "waitingCall"); |
| 55 | + |
| 56 | + // An end time and a called process instance are also what a call |
| 57 | + // activity that ran to completion records, so the delete reason is the |
| 58 | + // only thing separating the two. |
| 59 | + assertThat(parkedBranch.getEndTime()).isNotNull(); |
| 60 | + assertThat(parkedBranch.getCalledProcessInstanceId()).isNotNull(); |
| 61 | + |
| 62 | + assertThat(parkedBranch.getDeleteReason()) |
| 63 | + .as("delete reason on an activity terminated by the interrupting error event sub-process") |
| 64 | + .isEqualTo(DeleteReason.EVENT_SUBPROCESS_INTERRUPTING + "(errorHandlerStart)"); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * The same BpmnError caught by an interrupting boundary event instead, which |
| 69 | + * records DeleteReason.BOUNDARY_EVENT_INTERRUPTING. The two paths differ only |
| 70 | + * in which vehicle catches the error. |
| 71 | + */ |
| 72 | + @Test |
| 73 | + @Deployment(resources = "org/flowable/engine/test/api/deletereason/ErrorEventSubProcessDeleteReasonTest.boundary.bpmn20.xml") |
| 74 | + public void testInterruptingBoundaryEvent() { |
| 75 | + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("boundaryDeleteReason"); |
| 76 | + |
| 77 | + Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); |
| 78 | + assertThat(task).isNotNull(); |
| 79 | + taskService.complete(task.getId()); |
| 80 | + |
| 81 | + waitForHistoryJobExecutorToProcessAllJobs(7000, 100); |
| 82 | + |
| 83 | + HistoricActivityInstance subProcess = historicActivity(processInstance.getId(), "theSubProcess"); |
| 84 | + assertThat(subProcess.getDeleteReason()).contains(DeleteReason.BOUNDARY_EVENT_INTERRUPTING); |
| 85 | + } |
| 86 | + |
| 87 | + private HistoricActivityInstance historicActivity(String processInstanceId, String activityId) { |
| 88 | + List<HistoricActivityInstance> instances = historyService.createHistoricActivityInstanceQuery() |
| 89 | + .processInstanceId(processInstanceId) |
| 90 | + .activityId(activityId) |
| 91 | + .list(); |
| 92 | + assertThat(instances).hasSize(1); |
| 93 | + return instances.get(0); |
| 94 | + } |
| 95 | + |
| 96 | +} |
0 commit comments