use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class ProcessRuntimeBPMNMessageIT method should_not_cancelTask_when_nonInterruptedMessageReceived.
@Test
public void should_not_cancelTask_when_nonInterruptedMessageReceived() {
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withVariable("correlationKey", "correlationKey").withProcessDefinitionKey("messageNonInterruptingSubProcess").build());
List<Task> allTasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build()).getContent();
assertThat(allTasks.size()).isEqualTo(1);
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, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, allTasks.get(0).getName()));
// sending the Non Interrupted Start Message to process
processRuntime.receive(MessagePayloadBuilder.receive("nonInterruptedMessage").withCorrelationKey("correlationKey").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, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
assertThat(taskBaseRuntime.getTasksByProcessInstanceId(processInstance.getId()).size()).isEqualTo(1);
assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, allTasks.get(0).getName()));
localEventSource.clearEvents();
taskBaseRuntime.completeTask(allTasks.get(0).getId());
assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, allTasks.get(0).getName()));
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 UserTaskAssigneeDeleteRuntimeTest method shouldFailOnDeleteTask.
@Test
public void shouldFailOnDeleteTask() {
securityUtil.logInAs("user1");
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(processKey).withBusinessKey("my-business-key").withName("my-process-instance-name").build());
// then
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");
// I should be able to get the process instance from the Runtime because it is still running
ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId());
assertThat(processInstanceById).isEqualTo(processInstance);
// I should get a task for User1
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");
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeTaskAssigneeTest method aCreateStandaloneTaskForAnotherAssignee.
@Test
public void aCreateStandaloneTaskForAnotherAssignee() {
securityUtil.logInAs("garth");
taskRuntime.create(TaskPayloadBuilder.create().withName("task for dean").withAssignee(// but he should still be assigned the task
"dean").build());
// the owner should be able to see the created task
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getContent()).hasSize(1);
Task task = tasks.getContent().get(0);
assertThat(task.getAssignee()).isEqualTo("dean");
assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
// Now the task should be visible for dean
securityUtil.logInAs("dean");
// the target user should be able to see the task as well
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getContent()).hasSize(1);
task = tasks.getContent().get(0);
assertThat(task.getAssignee()).isEqualTo("dean");
assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
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 TaskRuntimeTerminateEndEventTest method should_ProcessesAndTasksDisappear_whenTerminateEventIsExecuted.
@Test
public void should_ProcessesAndTasksDisappear_whenTerminateEventIsExecuted() {
ProcessInstance process = processBaseRuntime.startProcessWithProcessDefinitionKey(TASK_PROCESS_TERMINATE_EVENT);
List<Task> taskList = taskBaseRuntime.getTasksByProcessInstanceId(process.getId());
assertThat(taskList).isNotEmpty();
assertThat(taskList).hasSize(2);
Task task1 = taskList.get(0);
taskBaseRuntime.completeTask(task1.getId());
List<Task> taskAfterCompleted = taskBaseRuntime.getTasksByProcessInstanceId(process.getId());
assertThat(taskAfterCompleted).hasSize(0);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeTerminateEndEventTest method should_CancelledTasksByTerminateEndEventHaveCancellationReasonSet.
@Test
public void should_CancelledTasksByTerminateEndEventHaveCancellationReasonSet() {
securityUtil.logInAs("user");
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(PROCESS_TERMINATE_EVENT);
assertThat(processInstance).isNotNull();
List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
assertThat(tasks).hasSize(2);
Task task2 = tasks.get(1);
taskBaseRuntime.completeTask(task2.getId());
List<Task> tasksAfterCompletion = taskBaseRuntime.getTasks(processInstance);
assertThat(tasksAfterCompletion).hasSize(0);
List<TaskCancelledEvent> taskCancelledEvents = localEventSource.getEvents(TaskCancelledEvent.class);
assertThat(taskCancelledEvents).hasSize(1);
assertThat(taskCancelledEvents.get(0).getReason()).contains("Terminated by end event");
}
Aggregations