Search in sources :

Example 61 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskBaseRuntime method completeTask.

public void completeTask(String taskId, Map<String, Object> variables) {
    Task completeTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskId).withVariables(variables).build());
    assertThat(completeTask).isNotNull();
    assertThat(completeTask.getStatus()).isEqualTo(TaskStatus.COMPLETED);
}
Also used : Task(org.activiti.api.task.model.Task)

Example 62 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeAppVersionIT method should_standaloneTaskAlwaysHaveAppVersion.

@Test
public void should_standaloneTaskAlwaysHaveAppVersion() {
    securityUtil.logInAs("user");
    taskRuntime.create(TaskPayloadBuilder.create().withName("new task").build());
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    Task result = tasks.getContent().get(0);
    assertThat(result.getName()).isEqualTo("new task");
    assertThat(result.getAppVersion()).isEqualTo("1");
}
Also used : Task(org.activiti.api.task.model.Task) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 63 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeClaimReleaseTest method should_throwIllegalStateException_when_releaseNotClaimedAndAssignedTask.

@Test
public void should_throwIllegalStateException_when_releaseNotClaimedAndAssignedTask() {
    securityUtil.logInAs("garth");
    Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("group task").withCandidateUsers("garth").withCandidateGroup("activitiTeam").build());
    assertThat(standAloneTask.getAssignee()).isNull();
    assertThat(standAloneTask.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
    Throwable thrown = catchThrowable(() -> {
        // UnAuthorized release, task is not assigned
        taskRuntime.release(TaskPayloadBuilder.release().withTaskId(standAloneTask.getId()).build());
    });
    assertThat(thrown).isInstanceOf(IllegalStateException.class).hasMessage("You cannot release a task that is not claimed");
    ;
}
Also used : Task(org.activiti.api.task.model.Task) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 64 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeClaimReleaseTest method should_claimAndRelease_when_userIsInCandidateGroup.

@Test
public void should_claimAndRelease_when_userIsInCandidateGroup() {
    securityUtil.logInAs("garth");
    Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("group 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 and Release
    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);
    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 65 with Task

use of org.activiti.api.task.model.Task in project Activiti by Activiti.

the class TaskRuntimeClaimReleaseTest method should_throwNotFoundException_when_releaseTaskNotAssignedToLoggedUser.

@Test
public void should_throwNotFoundException_when_releaseTaskNotAssignedToLoggedUser() {
    securityUtil.logInAs("garth");
    Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("group task").withCandidateGroup("activitiTeam").build());
    assertThat(standAloneTask.getAssignee()).isNull();
    assertThat(standAloneTask.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
    securityUtil.logInAs("user");
    // Claim task
    Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(standAloneTask.getId()).build());
    assertThat(claimedTask.getAssignee()).isEqualTo("user");
    assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    // UnAuthorized release, task is assigned not to you and hence not visible anymore
    securityUtil.logInAs("john");
    Throwable throwable = catchThrowable(() -> taskRuntime.release(TaskPayloadBuilder.release().withTaskId(standAloneTask.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])");
}
Also used : Task(org.activiti.api.task.model.Task) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) NotFoundException(org.activiti.api.runtime.shared.NotFoundException) 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