use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOn_CallActivity_Boundary_Event.
@Test
public void processWithParallelMultiInstancesOn_CallActivity_Boundary_Event() {
ProcessInstance parentProcessInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelCallActivityBoundaryEvent");
final Page<ProcessInstance> childrenProcessInstances = processBaseRuntime.getChildrenProcessInstances(parentProcessInstance.getId());
assertThat(childrenProcessInstances.getContent()).hasSize(2);
assertThat(localEventSource.getEvents(ProcessStartedEvent.class)).extracting(RuntimeEvent::getEventType, event -> event.getEntity().getId(), event -> event.getEntity().getParentId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, parentProcessInstance.getId(), null), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, childrenProcessInstances.getContent().get(0).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, childrenProcessInstances.getContent().get(1).getId(), parentProcessInstance.getId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactlyInAnyOrder(tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", childrenProcessInstances.getContent().get(0).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", childrenProcessInstances.getContent().get(1).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", childrenProcessInstances.getContent().get(0).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", childrenProcessInstances.getContent().get(1).getId()));
assertThat(localEventSource.getEvents(ProcessCompletedEvent.class)).isEmpty();
// when
localEventSource.clearEvents();
processBaseRuntime.signal("goMiParallelCallActivityBoundaryEvent");
// then
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactlyInAnyOrder(tuple(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED, "User Task", childrenProcessInstances.getContent().get(0).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED, "User Task", childrenProcessInstances.getContent().get(1).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "Escalation Task", parentProcessInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "Escalation Task", parentProcessInstance.getId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED, childrenProcessInstances.getContent().get(0).getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED, childrenProcessInstances.getContent().get(1).getId()));
List<Task> tasks = taskBaseRuntime.getTasks(parentProcessInstance);
assertThat(tasks.size()).isEqualTo(1);
assertThat(tasks).extracting(Task::getName).contains("Escalation Task");
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertThat(taskBaseRuntime.getTasks(parentProcessInstance)).isEmpty();
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, parentProcessInstance.getId()));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithSequentialMultiInstancesOnCallActivity_should_emmit_EqualStartAndEndEvent.
@Test
public void processWithSequentialMultiInstancesOnCallActivity_should_emmit_EqualStartAndEndEvent() {
ProcessInstance parentProcessInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miSequentialCallActivity");
List<ProcessInstance> childrenProcessInstances = processBaseRuntime.getChildrenProcessInstances(parentProcessInstance.getId()).getContent();
assertThat(childrenProcessInstances).hasSize(1);
ProcessInstance firstChildProcInst = childrenProcessInstances.get(0);
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, firstChildProcInst.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, firstChildProcInst.getId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", firstChildProcInst.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", firstChildProcInst.getId()));
List<Task> tasks = taskBaseRuntime.getTasks(firstChildProcInst);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("User Task");
// complete first iteration, multi-instance should not complete yet
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, // second iteration was created
BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
childrenProcessInstances = processBaseRuntime.getChildrenProcessInstances(parentProcessInstance.getId()).getContent();
assertThat(childrenProcessInstances).hasSize(1);
ProcessInstance secondChildProcInst = childrenProcessInstances.get(0);
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "User Task", firstChildProcInst.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", secondChildProcInst.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", secondChildProcInst.getId()));
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, firstChildProcInst.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, secondChildProcInst.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, secondChildProcInst.getId()));
tasks = taskBaseRuntime.getTasks(secondChildProcInst);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("User Task");
// complete second iteration, multi-instance should not complete
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "User Task", secondChildProcInst.getId()));
assertThat(processBaseRuntime.getProcessInstances()).isEmpty();
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, secondChildProcInst.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, parentProcessInstance.getId()));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method verifyMultiInstanceStartAndEndEventCount.
private void verifyMultiInstanceStartAndEndEventCount(String processDefinitionKey, String elementId, Integer startCount, Integer completeCount) {
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(processDefinitionKey);
// testing the multi instance element start, complete, cancel events
verifyActivityStartedAndCompletedAreEmitted(elementId, startCount, completeCount);
assertThat(localEventSource.getEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOnUserTask_should_emmitEventsAndContinueOnceCompletionConditionIsReached.
@Test
public void processWithParallelMultiInstancesOnUserTask_should_emmitEventsAndContinueOnceCompletionConditionIsReached() {
// when
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelUserTasksCompletionCondition");
// then
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0", "My Task 1", "My Task 2", "My Task 3");
assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 2", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 3", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 2", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 3", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
// given
Task taskToComplete = tasks.get(0);
// when first multi instance is completed: 3 remaining / completion condition not reached
localEventSource.clearEvents();
taskBaseRuntime.completeTask(taskToComplete);
// then
assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactly(tuple(taskToComplete.getName(), TaskRuntimeEvent.TaskEvents.TASK_COMPLETED));
assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
// given
taskToComplete = tasks.get(1);
// when second multi instance is completed: 2 remaining / completion condition reached
localEventSource.clearEvents();
taskBaseRuntime.completeTask(taskToComplete);
assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple(taskToComplete.getName(), TaskRuntimeEvent.TaskEvents.TASK_COMPLETED), tuple(tasks.get(2).getName(), TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple(tasks.get(3).getName(), TaskRuntimeEvent.TaskEvents.TASK_CANCELLED));
assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
assertThat(localEventSource.getEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method verifyEventsOnAutomaticMultiInstanceWithCompletionCondition.
private void verifyEventsOnAutomaticMultiInstanceWithCompletionCondition(String processDefinitionKey, String elementId) {
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(processDefinitionKey);
List<BPMNActivityStartedEvent> startedEvents = localEventSource.getEvents(BPMNActivityStartedEvent.class).stream().filter(event -> elementId.equals(event.getEntity().getElementId())).collect(Collectors.toList());
List<BPMNActivityCompletedEvent> completedEvents = localEventSource.getEvents(BPMNActivityCompletedEvent.class).stream().filter(event -> elementId.equals(event.getEntity().getElementId())).collect(Collectors.toList());
List<BPMNActivityCancelledEvent> cancelledEvents = localEventSource.getEvents(BPMNActivityCancelledEvent.class).stream().filter(event -> elementId.equals(event.getEntity().getElementId())).collect(Collectors.toList());
// in some cases, the execution is scheduled in the agenda but it get cancelled even before starting
assertThat(startedEvents.size()).isGreaterThanOrEqualTo(2);
assertThat(completedEvents).hasSize(2);
assertThat(cancelledEvents).hasSize(2);
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, processInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, processInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
Aggregations