use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeUpdateTaskTest method createAndUpdateStandaloneTaskForUser.
@Test
public void createAndUpdateStandaloneTaskForUser() {
securityUtil.logInAs("garth");
Task standaloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("test task update").withDescription("test task update description").withDueDate(new Date()).withPriority(50).withAssignee("garth").build());
assertThat(RuntimeTestConfiguration.createdTasks).contains(standaloneTask.getId());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getContent()).containsOnly(standaloneTask).extracting("status", "assignee").contains(tuple(Task.TaskStatus.ASSIGNED, "garth"));
final Task updatedTask = taskRuntime.update(TaskPayloadBuilder.update().withTaskId(standaloneTask.getId()).withName(standaloneTask.getName() + " [UPDATED]").withPriority(60).withDueDate(new Date()).withDescription(standaloneTask.getDescription() + " [UPDATED]").build());
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(RuntimeTestConfiguration.updatedTasks).contains(updatedTask.getId());
assertThat(tasks.getTotalItems()).isEqualTo(1);
assertThat(tasks.getContent()).filteredOn("status", Task.TaskStatus.ASSIGNED).containsOnly(updatedTask);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeUpdateTaskTest method createClaimAndUpdateStandaloneTask.
@Test
public void createClaimAndUpdateStandaloneTask() {
securityUtil.logInAs("garth");
// create
Task standaloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("test task update").withDescription("test task update description").withDueDate(new Date()).withPriority(50).withCandidateUsers("garth").build());
assertThat(RuntimeTestConfiguration.createdTasks).contains(standaloneTask.getId());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
assertThat(tasks.getContent()).extracting("status", "id").contains(tuple(Task.TaskStatus.CREATED, standaloneTask.getId()));
final UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId(standaloneTask.getId()).withName(standaloneTask.getName() + " [UPDATED]").withPriority(60).withDueDate(new Date()).withDescription(standaloneTask.getDescription() + " [UPDATED]").build();
// try update
// task should be claimed before be updated
Throwable thrown = catchThrowable(() -> taskRuntime.update(updateTaskPayload));
assertThat(thrown).isInstanceOf(IllegalStateException.class).hasMessage("You cannot update a task where you are not the assignee");
// claim
taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(standaloneTask.getId()).build());
// update
final Task updatedTask = taskRuntime.update(updateTaskPayload);
tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(RuntimeTestConfiguration.updatedTasks).contains(updatedTask.getId());
assertThat(tasks.getContent()).extracting("status", "id").contains(tuple(Task.TaskStatus.ASSIGNED, standaloneTask.getId()));
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeUpdateTaskTest method createClaimAndAdminUpdateStandaloneTask.
@Test
public void createClaimAndAdminUpdateStandaloneTask() {
securityUtil.logInAs("garth");
// create
Task standaloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("test task update").withDescription("test task update description").withDueDate(new Date()).withPriority(50).build());
assertThat(RuntimeTestConfiguration.createdTasks).contains(standaloneTask.getId());
Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
assertThat(tasks.getTotalItems()).isEqualTo(1);
assertThat(tasks.getContent()).extracting("status", "id").contains(tuple(Task.TaskStatus.CREATED, standaloneTask.getId()));
final UpdateTaskPayload updateTaskPayload = TaskPayloadBuilder.update().withTaskId(standaloneTask.getId()).withName(standaloneTask.getName() + " [UPDATED]").withPriority(60).withDueDate(new Date()).withDescription(standaloneTask.getDescription() + " [UPDATED]").build();
// admin should update a task
securityUtil.logInAs("admin");
final Task updatedTask = taskAdminRuntime.update(updateTaskPayload);
tasks = taskAdminRuntime.tasks(Pageable.of(0, 50));
assertThat(RuntimeTestConfiguration.updatedTasks).contains(updatedTask.getId());
assertThat(tasks.getContent()).extracting("id", "name", "description", "priority").contains(tuple(standaloneTask.getId(), updateTaskPayload.getName(), updateTaskPayload.getDescription(), updateTaskPayload.getPriority()));
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeClaimReleaseTest method should_ownerClaimATask_when_taskHasNotAssignOrCandidates.
@Test
public void should_ownerClaimATask_when_taskHasNotAssignOrCandidates() {
securityUtil.logInAs("garth");
Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("group task").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);
assertThat(task.getAssignee()).isNull();
assertThat(task.getCandidateUsers()).isNullOrEmpty();
assertThat(task.getCandidateGroups()).isNullOrEmpty();
Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
assertThat(claimedTask.getAssignee()).isEqualTo("garth");
assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
assertThat(claimedTask.getTaskDefinitionKey()).isNull();
Task releasedTask = taskRuntime.release(TaskPayloadBuilder.release().withTaskId(claimedTask.getId()).build());
assertThat(releasedTask.getAssignee()).isNull();
assertThat(releasedTask.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
}
use of org.activiti.api.task.model.Task in project Activiti by Activiti.
the class TaskRuntimeCompleteTaskTest method completeProcessTaskAndCheckReturnedTaskAndVariables.
@Test
public void completeProcessTaskAndCheckReturnedTaskAndVariables() {
securityUtil.logInAs("user");
Map<String, Object> startVariables = new HashMap<>();
startVariables.put("start1", "start1");
startVariables.put("start2", "start2");
// when
ProcessInstance twoTaskInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(TWOTASK_PROCESS).withVariables(startVariables).build());
// both tasks should have same variables
List<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent();
List<VariableInstance> variables;
for (Task task : tasks) {
variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task.getId()).build());
assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
}
Task task = tasks.get(0);
// claim task
Task claimTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
assertThat(claimTask).extracting(Task::getStatus, Task::getOwner, Task::getAssignee, Task::getName, Task::getDescription, Task::getCreatedDate, Task::getDueDate, Task::getPriority, Task::getProcessDefinitionId, Task::getProcessInstanceId, Task::getParentTaskId, Task::getFormKey, Task::getProcessDefinitionVersion).containsExactly(TaskStatus.ASSIGNED, task.getOwner(), "user", task.getName(), task.getDescription(), task.getCreatedDate(), task.getDueDate(), task.getPriority(), task.getProcessDefinitionId(), task.getProcessInstanceId(), task.getParentTaskId(), task.getFormKey(), task.getProcessDefinitionVersion());
// complete one task and change var
Task completeTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).withVariable("start1", "modagainstart1").build());
assertThat(completeTask).isNotNull().extracting(Task::getStatus, Task::getOwner, Task::getAssignee, Task::getName, Task::getDescription, Task::getCreatedDate, Task::getDueDate, Task::getClaimedDate, Task::getPriority, Task::getProcessDefinitionId, Task::getProcessInstanceId, Task::getParentTaskId, Task::getFormKey, Task::getProcessDefinitionVersion).containsExactly(TaskStatus.COMPLETED, task.getOwner(), claimTask.getAssignee(), task.getName(), task.getDescription(), task.getCreatedDate(), task.getDueDate(), claimTask.getClaimedDate(), task.getPriority(), task.getProcessDefinitionId(), task.getProcessInstanceId(), task.getParentTaskId(), task.getFormKey(), task.getProcessDefinitionVersion());
// after completion of the process variable start1 should updated
assertThat(processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(twoTaskInstance).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "modagainstart1"), tuple("start2", "start2"));
}
Aggregations