use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOnSubProcess_should_emmitEventsAndContinueOnceCompletionConditionIsReached.
@Test
public void processWithParallelMultiInstancesOnSubProcess_should_emmitEventsAndContinueOnceCompletionConditionIsReached() {
// when
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelSubprocessCompletionCondition");
// then
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("Task in sub-process 0", "Task in sub-process 1", "Task in sub-process 2", "Task in sub-process 3");
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 2", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Task in sub-process 3", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Task in sub-process 0", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("Task in sub-process 1", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("Task in sub-process 2", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("Task in sub-process 3", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
assertActivityEvents("miSubProcess", 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("miSubProcess", 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);
// then
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("miSubProcess", 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.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesCallActivity_should_emmitEventsAndContinueOnceCompletionConditionIsReached.
@Test
public void processWithParallelMultiInstancesCallActivity_should_emmitEventsAndContinueOnceCompletionConditionIsReached() {
ProcessInstance parentProcessInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelCallActivityCompletionCondition");
List<ProcessInstance> childrenProcess = processBaseRuntime.getChildrenProcessInstances(parentProcessInstance.getId()).getContent();
assertThat(childrenProcess).hasSize(4);
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId(), event -> ((ProcessInstance) event.getEntity()).getParentId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, parentProcessInstance.getId(), null), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, parentProcessInstance.getId(), null), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, childrenProcess.get(0).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, childrenProcess.get(0).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, childrenProcess.get(1).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, childrenProcess.get(1).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, childrenProcess.get(2).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, childrenProcess.get(2).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, childrenProcess.get(3).getId(), parentProcessInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, childrenProcess.get(3).getId(), parentProcessInstance.getId()));
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactlyInAnyOrder(tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", childrenProcess.get(0).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", childrenProcess.get(1).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", childrenProcess.get(2).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "User Task", childrenProcess.get(3).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", childrenProcess.get(0).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", childrenProcess.get(1).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", childrenProcess.get(2).getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "User Task", childrenProcess.get(3).getId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
// first multi instance is completed: 3 remaining / completion condition not reached
List<TaskAssignedEvent> assignedTasksEvents = localEventSource.getEvents(TaskAssignedEvent.class);
TaskAssignedEvent taskAssignedEvent = assignedTasksEvents.get(0);
localEventSource.clearEvents();
taskBaseRuntime.completeTask(taskAssignedEvent.getEntity().getId());
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId(), event -> ((ProcessInstance) event.getEntity()).getParentId()).containsExactly(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, taskAssignedEvent.getEntity().getProcessInstanceId(), parentProcessInstance.getId()));
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "User Task", taskAssignedEvent.getEntity().getProcessInstanceId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
// second multi instance is completed: 2 remaining / completion condition reached
taskAssignedEvent = assignedTasksEvents.get(1);
localEventSource.clearEvents();
taskBaseRuntime.completeTask(taskAssignedEvent.getEntity().getId());
assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, taskAssignedEvent.getEntity().getProcessInstanceId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED, assignedTasksEvents.get(2).getEntity().getProcessInstanceId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CANCELLED, assignedTasksEvents.get(3).getEntity().getProcessInstanceId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, parentProcessInstance.getId()));
assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactlyInAnyOrder(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "User Task", taskAssignedEvent.getEntity().getProcessInstanceId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED, "User Task", assignedTasksEvents.get(2).getEntity().getProcessInstanceId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CANCELLED, "User Task", assignedTasksEvents.get(3).getEntity().getProcessInstanceId()));
assertActivityEvents("miCallActivity", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
assertThat(processBaseRuntime.getProcessInstances()).isEmpty();
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeStandaloneTaskTest method createStandaloneTaskForUser.
@Test
public void createStandaloneTaskForUser() {
securityUtil.logInAs("user");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("cure Skipper").withAssignee("user").build());
assertThat(RuntimeTestConfiguration.createdTasks).contains(standAloneTask.getId());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getContent()).hasSize(1);
Task task = tasks.getContent().get(0);
assertThat(task.getAssignee()).isEqualTo("user");
assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
assertThat(task.isStandalone()).isTrue();
Task deletedTask = taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).withReason("test clean up").build());
assertThat(deletedTask).isNotNull();
assertThat(deletedTask.getStatus()).isEqualTo(Task.TaskStatus.CANCELLED);
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getContent()).hasSize(0);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class DemoApplication method checkAndWorkOnTasksWhenAvailable.
@Scheduled(initialDelay = 1000, fixedDelay = 5000)
public void checkAndWorkOnTasksWhenAvailable() {
securityUtil.logInAs("bob");
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10));
if (tasks.getTotalItems() > 0) {
for (Task t : tasks.getContent()) {
logger.info("> Claiming task: " + t.getId());
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(t.getId()).build());
List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(t.getId()).build());
VariableInstance variableInstance = variables.get(0);
if (variableInstance.getName().equals("content")) {
LinkedHashMap contentToProcess = objectMapper.convertValue(variableInstance.getValue(), LinkedHashMap.class);
logger.info("> Content received inside the task to approve: " + contentToProcess);
if (contentToProcess.get("body").toString().contains("activiti")) {
logger.info("> User Approving content");
contentToProcess.put("approved", true);
} else {
logger.info("> User Discarding content");
contentToProcess.put("approved", false);
}
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(t.getId()).withVariable("content", contentToProcess).build());
}
}
} else {
logger.info("> There are no task for me to work on.");
}
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class ProcessRuntimeBPMNMessageIT method shouldTestCatchMessageExpressionWithVariableMappingExtensions.
@Test
public void shouldTestCatchMessageExpressionWithVariableMappingExtensions() {
// when
ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withProcessDefinitionKey("testCatchMessageExpression").build());
// then
List<VariableInstance> variables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(process).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("intermediate_var", ""), tuple("inter_message_var", "check2"));
// when
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(process.getId()).build());
// then
assertThat(tasks.getContent()).hasSize(1);
String taskId = tasks.getContent().get(0).getId();
// when
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskId).withVariable("Text0739ze", "foo").build());
// then
variables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(process).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("intermediate_var", "foo"), tuple("inter_message_var", "check2"));
// when
processRuntime.receive(MessagePayloadBuilder.receive("intermediate-catch-message-check2").withCorrelationKey("foo").build());
// then
tasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(process.getId()).build());
assertThat(tasks.getContent()).hasSize(1);
taskId = tasks.getContent().get(0).getId();
// then
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskId).build());
// then
assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "intermediate-catch-message-check2", "foo", process.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "intermediate-catch-message-check2", "foo", process.getBusinessKey(), null));
}
Aggregations