use of org.activiti.api.task.model.Task 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());
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeDeleteTaskTest method should_ownerDeleteItsTask_when_aTaskIsAssignedToSomeOneElse.
@Test
public void should_ownerDeleteItsTask_when_aTaskIsAssignedToSomeOneElse() {
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("simple task").withCandidateGroup("activitiTeam").build());
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);
// Claim a task created for a group
securityUtil.logInAs("user");
Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
assertThat(claimedTask.getAssignee()).isEqualTo("user");
assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
// Try to delete a task where the user is the owner
securityUtil.logInAs("garth");
assertThat(taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).build())).isNotNull();
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeDeleteTaskTest method createStandaloneGroupTaskClaimAndDeleteFail.
@Test
public void createStandaloneGroupTaskClaimAndDeleteFail() {
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("simple task").withCandidateGroup("activitiTeam").build());
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);
// Before claim 'john' can view the task because it is in activitiTeam group
securityUtil.logInAs("john");
assertThat(taskRuntime.task(task.getId())).isNotNull();
// Claim a task created for a group
securityUtil.logInAs("user");
Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
assertThat(claimedTask.getAssignee()).isEqualTo("user");
assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
// Try to delete a task that you cannot see because it was assigned
securityUtil.logInAs("john");
// when
Throwable throwable = catchThrowable(() -> taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).build()));
// then
assertThat(throwable).isInstanceOf(NotFoundException.class).hasMessage("Unable to find task for the given id: " + standAloneTask.getId() + " for user: john (with groups: [activitiTeam] & with roles: [ACTIVITI_USER])");
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeFormKeyTest method processTaskHasFormKeyAndTaskDefinitionKey.
@Test
public void processTaskHasFormKeyAndTaskDefinitionKey() {
securityUtil.logInAs("garth");
ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(SINGLE_TASK_PROCESS).build());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getContent()).hasSize(1);
Task task = tasks.getContent().get(0);
assertThat(task.getFormKey()).isEqualTo("taskForm");
assertThat(task.getTaskDefinitionKey()).isEqualTo("Task_03l0zc2");
processRuntime.delete(ProcessPayloadBuilder.delete().withProcessInstance(process).build());
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class UserTaskAssigneeRuntimeTest method shouldStartAProcessCreateAndCompleteAssignedTask.
@Test
public void shouldStartAProcessCreateAndCompleteAssignedTask() {
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");
// Check with user2
securityUtil.logInAs("user2");
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(0);
Throwable throwable = catchThrowable(() -> taskRuntime.task(task.getId()));
assertThat(throwable).isInstanceOf(NotFoundException.class);
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();
// complete with user1
securityUtil.logInAs("user1");
Task completedTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
assertThat(completedTask.getStatus()).isEqualTo(Task.TaskStatus.COMPLETED);
assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED);
}
Aggregations