use of org.activiti.api.task.model.Task 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.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeStandaloneTaskTest method createStandaloneTaskFailWithEmptyName.
@Test
public void createStandaloneTaskFailWithEmptyName() {
securityUtil.logInAs("user");
// when
Throwable throwable = catchThrowable(() -> taskRuntime.create(TaskPayloadBuilder.create().withAssignee("user").build()));
// then
assertThat(throwable).isInstanceOf(IllegalStateException.class);
Page<Task> 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 TaskRuntimeStandaloneTaskTest method should_throwExceptionOnUpdateVariable_when_charactersNotAllowedInVariableName.
@Test
public void should_throwExceptionOnUpdateVariable_when_charactersNotAllowedInVariableName() {
securityUtil.logInAs("user");
Task task = taskRuntime.create(TaskPayloadBuilder.create().withName("name").withAssignee("user").build());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getContent()).hasSize(1);
Throwable throwable = catchThrowable(() -> taskRuntime.updateVariable(TaskPayloadBuilder.updateVariable().withTaskId(task.getId()).withVariable("!wrong_name", "value").build()));
assertThat(throwable).isInstanceOf(IllegalStateException.class);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeTaskForOtherTest method createStandaloneTaskWithNoCandidates.
@Test
public void createStandaloneTaskWithNoCandidates() {
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("task with no candidates besides owner").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()).isNull();
assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
securityUtil.logInAs("user");
// Other users beside the owner shouldn't see the task
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 TaskRuntimeVariableMappingIT method processTaskVarMapping.
@Test
public void processTaskVarMapping() {
ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(TASK_VAR_MAPPING);
Date date = dateFormatterProvider.parse("2019-09-01");
Date datetime = dateFormatterProvider.parse("2019-09-01T10:20:30.000Z");
Task task = checkTasks(processInstance.getId());
assertThat(task.getName()).isEqualTo("testSimpleTask");
List<VariableInstance> procVariables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getType, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "string", "unmapped1Value"), tuple("process_variable_inputmap_1", "string", "inputmap1Value"), tuple("process_variable_outputmap_1", "string", "outputmap1Value"), tuple("process-variable-date", "date", date), tuple("process-variable-datetime", "date", datetime));
List<VariableInstance> taskVariables = taskBaseRuntime.getTasksVariablesByTaskId(task.getId());
assertThat(taskVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getType, VariableInstance::getValue).containsOnly(tuple("task_input_variable_name_1", "string", "inputmap1Value"), tuple("task-variable-date", "date", date), tuple("task-variable-datetime", "date", datetime));
Map<String, Object> variables = new HashMap<>();
variables.put("task_input_variable_name_1", // This should not be set to 'process_variable_inputmap_1'
"outputValue");
variables.put("task_output_variable_name_1", // This should be set to 'process_variable_outputmap_1'
"outputTaskValue");
taskBaseRuntime.completeTask(task.getId(), variables);
procVariables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "unmapped1Value"), tuple("process_variable_inputmap_1", "inputmap1Value"), tuple("process_variable_outputmap_1", "outputTaskValue"), tuple("process-variable-date", date), tuple("process-variable-datetime", datetime));
processBaseRuntime.delete(processInstance.getId());
}
Aggregations