Source:
public void shouldFailOnDeleteTask() { securityUtil.logInAs("user1"); ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder .start() .withProcessDefinitionKey(processKey) .withBusinessKey("my-business-key") .withName("my-process-instance-name") .build()); assertThat(processInstance).isNotNull(); assertThat(processInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING); assertThat(processInstance.getBusinessKey()).isEqualTo("my-business-key"); assertThat(processInstance.getName()).isEqualTo("my-process-instance-name"); ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId()); assertThat(processInstanceById).isEqualTo(processInstance); Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50)); assertThat(tasks.getTotalItems()).isEqualTo(1); Task task = tasks.getContent().get(0); Task taskById = taskRuntime.task(task.getId()); assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED); assertThat(task).isEqualTo(taskById); assertThat(task.getAssignee()).isEqualTo("user1"); assertThat(RuntimeTestConfiguration.collectedEvents) .extracting(RuntimeEvent::getEventType) .containsExactly( ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED, TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED); cleanUp(); Throwable throwable = catchThrowable(() -> taskRuntime.delete(TaskPayloadBuilder.delete() .withTaskId(task.getId()) .withReason("I don't want this task anymore").build())); assertThat(throwable) .isInstanceOf(ActivitiException.class) .hasMessage("The task cannot be deleted because is part of a running process"); }

Target:
public void shouldFailOnDeleteTask() { securityUtil.logInAs("user1"); ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder .start() .withProcessDefinitionKey(processKey) .withBusinessKey("my-business-key") .withName("my-process-instance-name") .build()); assertThat(processInstance).isNotNull(); assertThat(processInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING); assertThat(processInstance.getBusinessKey()).isEqualTo("my-business-key"); assertThat(processInstance.getName()).isEqualTo("my-process-instance-name"); ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId()); assertThat(processInstanceById).isEqualTo(processInstance); Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50)); assertThat(tasks.getTotalItems()).isEqualTo(1); Task task = tasks.getContent().get(0); Task taskById = taskRuntime.task(task.getId()); assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED); assertThat(task).isEqualTo(taskById); assertThat(task.getAssignee()).isEqualTo("user1"); assertThat(RuntimeTestConfiguration.collectedEvents) .extracting(RuntimeEvent::getEventType) .containsExactly( ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED, TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED); clearEvents(); Throwable throwable = catchThrowable(() -> taskRuntime.delete(TaskPayloadBuilder.delete() .withTaskId(task.getId()) .withReason("I don't want this task anymore").build())); assertThat(throwable) .isInstanceOf(ActivitiException.class) .hasMessage("The task cannot be deleted because is part of a running process"); }