Search in sources :

Example 66 with Task

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

the class TaskRuntimeClaimReleaseTest method should_userViewATaskByCandidateGroup_when_itIsNotAssigned.

@Test
public void should_userViewATaskByCandidateGroup_when_itIsNotAssigned() {
    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");
    assertThat(taskRuntime.task(standAloneTask.getId())).isNotNull();
    securityUtil.logInAs("john");
    assertThat(taskRuntime.task(standAloneTask.getId())).isNotNull();
    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.task(standAloneTask.getId()));
    // 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)

Example 67 with Task

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

the class TaskRuntimeClaimReleaseTest method should_throwIllegalStateException_when_ownerTryToReleaseATaskAssignedToSomeOneElse.

@Test
public void should_throwIllegalStateException_when_ownerTryToReleaseATaskAssignedToSomeOneElse() {
    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("garth");
    Throwable throwable = catchThrowable(() -> taskRuntime.release(TaskPayloadBuilder.release().withTaskId(standAloneTask.getId()).build()));
    // then
    assertThat(throwable).isInstanceOf(IllegalStateException.class).hasMessage("You cannot release a task where you are not the assignee");
    ;
}
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 68 with Task

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

the class UserTaskCandidateGroupRuntimeTest method shouldCreateClaimAndCompleteTask.

@Test
public void shouldCreateClaimAndCompleteTask() {
    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.CREATED);
    assertThat(task).isEqualTo(taskById);
    assertThat(task.getAssignee()).isNull();
    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);
    clearEvents();
    // 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);
    // Check with user3
    securityUtil.logInAs("user3");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    // Try to complete without claim should error
    securityUtil.logInAs("user1");
    throwable = catchThrowable(() -> taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()));
    assertThat(throwable).isInstanceOf(IllegalStateException.class);
    // Claim should be allowed
    Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    assertThat(claimedTask.getAssignee()).isEqualTo("user1");
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, TaskRuntimeEvent.TaskEvents.TASK_UPDATED);
    clearEvents();
    // complete task now should work
    Task completedTask = taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(claimedTask.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);
}
Also used : Task(org.activiti.api.task.model.Task) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 69 with Task

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

the class UserTaskCandidateGroupRuntimeTest method shouldCreateClaimAndReleaseTask.

@Test
public void shouldCreateClaimAndReleaseTask() {
    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);
    // 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.CREATED);
    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);
    clearEvents();
    // Check with user3
    securityUtil.logInAs("user3");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    // Claim with User 1
    securityUtil.logInAs("user1");
    Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    assertThat(claimedTask.getAssignee()).isEqualTo("user1");
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, TaskRuntimeEvent.TaskEvents.TASK_UPDATED);
    clearEvents();
    // Check with user3, he/she shouldn't see any task now that the task was assigned
    securityUtil.logInAs("user3");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(0);
    // Release with User 1
    securityUtil.logInAs("user1");
    Task releasedTask = taskRuntime.release(TaskPayloadBuilder.release().withTaskId(task.getId()).build());
    assertThat(releasedTask.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
    assertThat(releasedTask.getAssignee()).isNull();
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).containsExactly(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, TaskRuntimeEvent.TaskEvents.TASK_UPDATED);
    clearEvents();
    // User 1 should be able to see the task to claim now
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    // User 3 also should be able to see the task now
    // Check with user3
    securityUtil.logInAs("user3");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
}
Also used : Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 70 with Task

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

the class UserTaskNoCandidateRuntimeTest method shouldNotSeeTaskWithoutCandidateOrAssignee.

@Test
public void shouldNotSeeTaskWithoutCandidateOrAssignee() {
    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 shouldn't get a task for User1
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(0);
    securityUtil.logInAs("user2");
    // I shouldn't get a task for User2
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(0);
    // I should get a task for Admin
    securityUtil.logInAs("admin");
    tasks = taskAdminRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
}
Also used : Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) 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