Search in sources :

Example 91 with Task

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);
}
Also used : Task(org.activiti.api.task.model.Task) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 92 with Task

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()));
}
Also used : Task(org.activiti.api.task.model.Task) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 93 with Task

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()));
}
Also used : Task(org.activiti.api.task.model.Task) UpdateTaskPayload(org.activiti.api.task.model.payloads.UpdateTaskPayload) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 94 with Task

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);
}
Also used : Task(org.activiti.api.task.model.Task) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 95 with Task

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"));
}
Also used : Task(org.activiti.api.task.model.Task) HashMap(java.util.HashMap) ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Task (org.activiti.api.task.model.Task)115 Test (org.junit.jupiter.api.Test)99 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)95 ProcessInstance (org.activiti.api.process.model.ProcessInstance)59 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)29 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)25 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)23 AfterEach (org.junit.jupiter.api.AfterEach)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)22 Page (org.activiti.api.runtime.shared.query.Page)21 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)20 BeforeEach (org.junit.jupiter.api.BeforeEach)20 Import (org.springframework.context.annotation.Import)20 Date (java.util.Date)19 List (java.util.List)19 Collections.singletonMap (java.util.Collections.singletonMap)15 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)15 ProcessRuntimeEvent (org.activiti.api.process.model.events.ProcessRuntimeEvent)15 TaskRuntimeEvent (org.activiti.api.task.model.events.TaskRuntimeEvent)15