use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeCompleteTaskTest method createStandaloneTaskAndComplete.
@Test
public void createStandaloneTaskAndComplete() {
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("simple task").withAssignee("garth").build());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getContent()).hasSize(1);
Task task = tasks.getContent().get(0);
assertThat(task.getAssignee()).isEqualTo("garth");
assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
Task completedTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
assertThat(completedTask.getStatus()).isEqualTo(Task.TaskStatus.COMPLETED);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeCompleteTaskTest method createStandaloneTaskandCompleteWithUnAuthorizedUser.
@Test
public void createStandaloneTaskandCompleteWithUnAuthorizedUser() {
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("simple task").withAssignee("garth").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("garth");
assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
// Complete should fail with a different user
securityUtil.logInAs("user");
// when
// then
assertThatExceptionOfType(NotFoundException.class).isThrownBy(() -> taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()));
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class BasicExclusiveGatewayErrorTest method shouldFailOnExpressionError.
@Test
public void shouldFailOnExpressionError() {
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.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()));
// @TODO: this is leaking ActivitiException.class we should validate expressions before running the process
// https://github.com/Activiti/Activiti/issues/2328
assertThat(throwable).isInstanceOf(ActivitiException.class).hasMessageContaining("condition expression returns non-Boolean");
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class BasicInclusiveGatewayTest method testProcessExecutionWithInclusiveGateway.
@Test
public void testProcessExecutionWithInclusiveGateway() {
// given
securityUtil.logInAs("user1");
// given
ProcessInstance processInstance = processOperations.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PROCESS_KEY).withBusinessKey("my-business-key").withName("my-process-instance-name").withVariable("input", 1).build()).expectFields(processInstance().status(ProcessInstance.ProcessInstanceStatus.RUNNING), processInstance().name("my-process-instance-name"), processInstance().businessKey("my-business-key")).expect(processInstance().hasTask("Start Process", Task.TaskStatus.ASSIGNED, withAssignee("user1"))).expectEvents(processInstance().hasBeenStarted(), startEvent("theStart").hasBeenStarted(), startEvent("theStart").hasBeenCompleted(), sequenceFlow("flow1").hasBeenTaken(), taskWithName("Start Process").hasBeenCreated(), taskWithName("Start Process").hasBeenAssigned()).andReturn();
// I should be able to get the process instance from the Runtime
ProcessInstance processInstanceById = processRuntime.processInstance(processInstance.getId());
assertThat(processInstanceById).isEqualTo(processInstance);
// I should get a task for User1
GetTasksPayload processInstanceTasksPayload = TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build();
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50), processInstanceTasksPayload);
assertThat(tasks.getTotalItems()).isEqualTo(1);
Task task = tasks.getContent().get(0);
// given
taskOperations.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()).expectEvents(task().hasBeenCompleted(), sequenceFlow("flow2").hasBeenTaken(), inclusiveGateway("inclusiveGateway").hasBeenStarted(), inclusiveGateway("inclusiveGateway").hasBeenCompleted(), sequenceFlow("flow3").hasBeenTaken(), taskWithName("Send e-mail").hasBeenCreated(), sequenceFlow("flow4").hasBeenTaken(), taskWithName("Check account").hasBeenCreated()).expect(processInstance().hasTask("Send e-mail", Task.TaskStatus.ASSIGNED), processInstance().hasTask("Check account", Task.TaskStatus.ASSIGNED));
// then - two tasks should be available
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(2);
Task task1 = tasks.getContent().get(0);
Task task2 = tasks.getContent().get(1);
// given
taskOperations.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).build()).expectEvents(task().hasBeenCompleted(), inclusiveGateway("inclusiveGatewayEnd").hasBeenStarted()).expect(processInstance().hasTask(task2.getName(), task2.getStatus()));
// then - only second task should be available
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
assertThat(tasks.getContent()).extracting(Task::getStatus, Task::getName).contains(tuple(task2.getStatus(), task2.getName()));
// complete second task
taskOperations.complete(TaskPayloadBuilder.complete().withTaskId(task2.getId()).build()).expectEvents(task().hasBeenCompleted(), inclusiveGateway("inclusiveGatewayEnd").hasBeenCompleted(), endEvent("theEnd").hasBeenStarted(), endEvent("theEnd").hasBeenCompleted());
// No tasks should be available
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(0);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class BasicParallelGatewayTest method shouldCheckThatParallelGatewayCreateTwoAssignedTasks.
@Test
public void shouldCheckThatParallelGatewayCreateTwoAssignedTasks() {
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();
taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).contains(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, 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, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED, TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED);
clearEvents();
// User 1 has his/her task
securityUtil.logInAs("user1");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
task = tasks.getContent().get(0);
taskById = taskRuntime.task(task.getId());
assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
assertThat(task).isEqualTo(taskById);
assertThat(task.getAssignee()).isEqualTo("user1");
// User 2 has his/her task
securityUtil.logInAs("user2");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
task = tasks.getContent().get(0);
taskById = taskRuntime.task(task.getId());
assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
assertThat(task).isEqualTo(taskById);
assertThat(task.getAssignee()).isEqualTo("user2");
}
Aggregations