use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOnUserTask_Boundary_Event.
@Test
public void processWithParallelMultiInstancesOnUserTask_Boundary_Event() {
// when
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelUserTaskBoundaryEvent");
// then
assertThat(taskBaseRuntime.getTasks(processInstance)).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0", "My Task 1");
assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
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 0", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
// when
long waitTime = 1 * 60 * 1000;
Date startTime = new Date();
Date dueDate = new Date(startTime.getTime() + waitTime);
// set the clock so the timer fires
localEventSource.clearEvents();
processEngineConfiguration.getClock().setCurrentTime(new Date(dueDate.getTime()));
await().untilAsserted(() -> {
assertThat(localEventSource.getEvents(BPMNTimerEvent.class)).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).containsExactly(tuple(BPMNTimerEvent.TimerEvents.TIMER_FIRED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"), tuple(BPMNTimerEvent.TimerEvents.TIMER_EXECUTED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
// need to login again before getting the list of tasks
// because Awaitility will run this inside another thread
securityUtil.logInAs("user");
List<Task> availableTasks = taskBaseRuntime.getTasks(processInstance);
assertThat(availableTasks).extracting(Task::getName).containsExactly("Escalation Task");
localEventSource.clearEvents();
taskBaseRuntime.completeTask(availableTasks.get(0));
});
assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactly(tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_COMPLETED));
assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOn_SubProcess_Boundary_Event.
@Test
public void processWithParallelMultiInstancesOn_SubProcess_Boundary_Event() {
// when
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelSubProcessBoundaryEvent");
// then
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("Task in sub-process 0", "Task in sub-process 1");
assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("Task in sub-process 0", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Task in sub-process 1", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Task in sub-process 0", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("Task in sub-process 1", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
// send signal: boundary event should cancel multi-instance
localEventSource.clearEvents();
processBaseRuntime.signal("goMiParallelSubProcessBoundaryEvent");
assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("Task in sub-process 0", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("Task in sub-process 1", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks.size()).isEqualTo(1);
assertThat(tasks).extracting(Task::getName).contains("Escalation Task");
taskBaseRuntime.completeTask(tasks.get(0));
assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(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_emmit_EqualStartAndEndEvent.
@Test
public void processWithParallelMultiInstancesOnUserTask_should_emmit_EqualStartAndEndEvent() {
// when
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelUserTasks");
// then
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0", "My Task 1");
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()));
assertActivityEvents("miTasks", 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, "My Task 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "My Task 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "My Task 1", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "My Task 1", processInstance.getId()));
// complete first iteration: multi instance should not complete yet
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miTasks", 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, tasks.get(0).getName(), processInstance.getId()));
assertThat(localEventSource.getProcessInstanceEvents()).isEmpty();
// complete second iteration: multi instance should complete
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(1));
assertActivityEvents("miTasks", 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, tasks.get(1).getName(), processInstance.getId()));
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithSequentialMultiInstancesOnUserTask_should_emmit_EqualStartAndEndEvent.
@Test
public void processWithSequentialMultiInstancesOnUserTask_should_emmit_EqualStartAndEndEvent() {
// when
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miSequentialUserTasks");
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()));
assertActivityEvents("miTasks", 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, "My Task 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "My Task 0", processInstance.getId()));
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0");
// complete first iteration, multi-instance should not complete yet
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, // second iteration was created
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_COMPLETED, "My Task 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "My Task 1", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "My Task 1", processInstance.getId()));
tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("My Task 1");
// complete second iteration, multi-instance should not complete
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miTasks", 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, "My Task 1", processInstance.getId()));
assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
assertThat(localEventSource.getProcessInstanceEvents()).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 processWithSequentialMultiInstancesOnSubProcess_should_emmit_EqualStartAndEndEvent.
@Test
public void processWithSequentialMultiInstancesOnSubProcess_should_emmit_EqualStartAndEndEvent() {
// when
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miSequentialSubprocess");
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()));
assertActivityEvents("miSubProcess", 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, "Task in sub-process 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "Task in sub-process 0", processInstance.getId()));
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("Task in sub-process 0");
// complete first iteration, multi-instance should not complete yet
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, // second iteration was created
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_COMPLETED, "Task in sub-process 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "Task in sub-process 1", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "Task in sub-process 1", processInstance.getId()));
tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("Task in sub-process 1");
// complete second iteration, multi-instance should not complete
localEventSource.clearEvents();
taskBaseRuntime.completeTask(tasks.get(0));
assertActivityEvents("miSubProcess", 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, "Task in sub-process 1", processInstance.getId()));
assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
Aggregations