use of org.activiti.api.process.model.ProcessInstance 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.process.model.ProcessInstance 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");
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeIT method should_beAbleToAssignTaskToInitiatorEvenWhenInitiatorIsNotSetInStartEvent.
@Test
public void should_beAbleToAssignTaskToInitiatorEvenWhenInitiatorIsNotSetInStartEvent() {
// given
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey("taskToInitiatorProcess").build());
// when
Page<Task> taskPage = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasksForProcess(processInstance).build());
// then
assertThat(taskPage.getContent()).extracting(Task::getName, Task::getAssignee).containsExactly(tuple("my-task", INITIATOR));
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeSaveTaskTest method testSaveCompleteReviewOutcomeTasksProcessWithVariables.
@Test()
public void testSaveCompleteReviewOutcomeTasksProcessWithVariables() {
// given
securityUtil.logInAs("user");
Map<String, Object> startVariables = new HashMap<>();
startVariables.put("name", "");
// when
ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(COMPLETE_REVIEW_TASK_PROCESS).withVariables(startVariables).build());
// complete task
securityUtil.logInAs("garth");
Task task1 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", ""));
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task1.getId()).withVariable("name", "wrong").build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).build());
// reject task
securityUtil.logInAs("user");
Task task2 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables1 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task2.getId()).build());
assertThat(variables1).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", "wrong"));
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task2.getId()).withVariable("approved", false).build());
// fix task
securityUtil.logInAs("garth");
Task task3 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task3.getId()).withVariable("name", "correct").build());
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task3.getId()).build());
// approve task
securityUtil.logInAs("user");
Task task4 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
List<VariableInstance> variables2 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task4.getId()).build());
assertThat(variables2).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("name", "correct"));
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task4.getId()).withVariable("approved", true).build());
// then process completes
Throwable throwable = catchThrowable(() -> assertThat(processRuntime.processInstance(processInstance.getId())).isNull());
assertThat(throwable).isInstanceOf(NotFoundException.class);
}
use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.
the class TaskRuntimeClaimTaskFromProcessTest method claimTaskWithoutGroup.
@Test
public void claimTaskWithoutGroup() {
securityUtil.logInAs("user");
// when
ProcessInstance twoTaskInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(TWOTASK_PROCESS).build());
securityUtil.logInAs("dean");
Task task = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
// should still be in dean's list after claiming
task = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
assertThat(task).isNotNull();
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
}
Aggregations