Search in sources :

Example 26 with Task

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

the class TaskRuntimeIT method should_beAbleToAssignTaskToInitiatorEvenWhenInitiatorIsNotSetInStartEvent.

@Test
public void should_beAbleToAssignTaskToInitiatorEvenWhenInitiatorIsNotSetInStartEvent() {
    // given
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey("taskToInitiatorProcess").build());
    // when
    Page<Task> taskPage = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasksForProcess(processInstance).build());
    // then
    assertThat(taskPage.getContent()).extracting(Task::getName, Task::getAssignee).containsExactly(tuple("my-task", INITIATOR));
}
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 27 with Task

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

the class TaskRuntimeSaveTaskTest method createStandaloneTaskAndSaveWithUnAuthorizedUser.

@Test()
public void createStandaloneTaskAndSaveWithUnAuthorizedUser() {
    // given
    securityUtil.logInAs("garth");
    Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("simple task").withAssignee("garth").build());
    // Complete should fail with a different user
    securityUtil.logInAs("user");
    // when
    Throwable throwable = catchThrowable(() -> taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(standAloneTask.getId()).withVariable("name", "value").build()));
    // then
    assertThat(throwable).isInstanceOf(NotFoundException.class);
}
Also used : Task(org.activiti.api.task.model.Task) SaveTaskPayloadBuilder(org.activiti.api.task.model.builders.SaveTaskPayloadBuilder) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 28 with Task

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

the class TaskRuntimeSaveTaskTest method testSaveCompleteReviewOutcomeTasksProcessWithVariables.

@Test()
public void testSaveCompleteReviewOutcomeTasksProcessWithVariables() {
    // given
    securityUtil.logInAs("user");
    Map<String, Object> startVariables = new HashMap<>();
    startVariables.put("name", "");
    // when
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(COMPLETE_REVIEW_TASK_PROCESS).withVariables(startVariables).build());
    // complete task
    securityUtil.logInAs("garth");
    Task task1 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
    List<VariableInstance> variables = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build());
    assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", ""));
    taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task1.getId()).withVariable("name", "wrong").build());
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).build());
    // reject task
    securityUtil.logInAs("user");
    Task task2 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
    List<VariableInstance> variables1 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task2.getId()).build());
    assertThat(variables1).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("name", "wrong"));
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task2.getId()).withVariable("approved", false).build());
    // fix task
    securityUtil.logInAs("garth");
    Task task3 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
    taskRuntime.save(new SaveTaskPayloadBuilder().withTaskId(task3.getId()).withVariable("name", "correct").build());
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task3.getId()).build());
    // approve task
    securityUtil.logInAs("user");
    Task task4 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
    List<VariableInstance> variables2 = taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task4.getId()).build());
    assertThat(variables2).extracting(VariableInstance::getName, VariableInstance::getValue).contains(tuple("name", "correct"));
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task4.getId()).withVariable("approved", true).build());
    // then process completes
    Throwable throwable = catchThrowable(() -> assertThat(processRuntime.processInstance(processInstance.getId())).isNull());
    assertThat(throwable).isInstanceOf(NotFoundException.class);
}
Also used : Task(org.activiti.api.task.model.Task) HashMap(java.util.HashMap) SaveTaskPayloadBuilder(org.activiti.api.task.model.builders.SaveTaskPayloadBuilder) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) 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)

Example 29 with Task

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

the class TaskRuntimeCandidatesTest method should_addAndRemoveCandidateUser.

@Test
public void should_addAndRemoveCandidateUser() {
    RuntimeTestConfiguration.taskCandidateUserRemovedEvents.clear();
    RuntimeTestConfiguration.taskCandidateUserAddedEvents.clear();
    securityUtil.logInAs("garth");
    Task createTask = taskRuntime.create(TaskPayloadBuilder.create().withName("task for dean").withCandidateUsers("garth").withAssignee(// but he should still be assigned the task
    "dean").build());
    // Check the task should be visible for dean
    securityUtil.logInAs("dean");
    // the target user should be able to see the task as well
    TaskImpl task = (TaskImpl) taskRuntime.task(createTask.getId());
    assertThat(task.getAssignee()).isEqualTo("dean");
    assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    List<String> userCandidatesOnTask = task.getCandidateUsers();
    assertThat(userCandidatesOnTask).hasSize(1);
    List<String> userCandidates = taskRuntime.userCandidates(createTask.getId());
    assertThat(userCandidates).hasSize(1);
    taskRuntime.deleteCandidateUsers(TaskPayloadBuilder.deleteCandidateUsers().withTaskId(task.getId()).withCandidateUser("garth").build());
    assertThat(RuntimeTestConfiguration.taskCandidateUserRemovedEvents).hasSize(1);
    assertThat(RuntimeTestConfiguration.taskCandidateUserRemovedEvents).extracting(event -> event.getEntity().getUserId()).contains("garth");
    task = (TaskImpl) taskRuntime.task(createTask.getId());
    userCandidatesOnTask = task.getCandidateUsers();
    assertThat(userCandidatesOnTask).isEmpty();
    userCandidates = taskRuntime.userCandidates(createTask.getId());
    assertThat(userCandidates).isEmpty();
    taskRuntime.addCandidateUsers(TaskPayloadBuilder.addCandidateUsers().withTaskId(task.getId()).withCandidateUser("garth").build());
    assertThat(RuntimeTestConfiguration.taskCandidateUserAddedEvents).hasSize(2);
    assertThat(RuntimeTestConfiguration.taskCandidateUserAddedEvents).extracting(event -> event.getEntity().getUserId()).contains("garth", "garth");
    task = (TaskImpl) taskRuntime.task(createTask.getId());
    userCandidatesOnTask = task.getCandidateUsers();
    assertThat(userCandidatesOnTask).hasSize(1);
    userCandidates = taskRuntime.userCandidates(createTask.getId());
    assertThat(userCandidates).hasSize(1);
}
Also used : Task(org.activiti.api.task.model.Task) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) TaskAdminRuntime(org.activiti.api.task.runtime.TaskAdminRuntime) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) RuntimeTestConfiguration(org.activiti.spring.boot.RuntimeTestConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) TaskCleanUpUtil(org.activiti.spring.boot.test.util.TaskCleanUpUtil) Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 30 with Task

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

the class TaskRuntimeCandidatesTest method should_addAndRemoveCandidateGroup.

@Test
public void should_addAndRemoveCandidateGroup() {
    clearTaskCandidateEvents();
    securityUtil.logInAs("garth");
    Task createTask = taskRuntime.create(TaskPayloadBuilder.create().withName("task for dean").withAssignee("garth").build());
    taskRuntime.addCandidateGroups(TaskPayloadBuilder.addCandidateGroups().withTaskId(createTask.getId()).withCandidateGroup("test").build());
    assertThat(RuntimeTestConfiguration.taskCandidateGroupAddedEvents).hasSize(1);
    assertThat(RuntimeTestConfiguration.taskCandidateGroupAddedEvents).extracting(event -> event.getEntity().getGroupId()).contains("test");
    TaskImpl task = (TaskImpl) taskRuntime.task(createTask.getId());
    List<String> groupCandidatesOnTask = task.getCandidateGroups();
    assertThat(groupCandidatesOnTask).hasSize(1);
    List<String> groupCandidates = taskRuntime.groupCandidates(createTask.getId());
    assertThat(groupCandidates).hasSize(1);
    taskRuntime.deleteCandidateGroups(TaskPayloadBuilder.deleteCandidateGroups().withTaskId(task.getId()).withCandidateGroup("test").build());
    assertThat(RuntimeTestConfiguration.taskCandidateGroupRemovedEvents).hasSize(1);
    assertThat(RuntimeTestConfiguration.taskCandidateGroupRemovedEvents).extracting(event -> event.getEntity().getGroupId()).contains("test");
    task = (TaskImpl) taskRuntime.task(createTask.getId());
    groupCandidatesOnTask = task.getCandidateGroups();
    assertThat(groupCandidatesOnTask).isEmpty();
    groupCandidates = taskRuntime.groupCandidates(createTask.getId());
    assertThat(groupCandidates).isEmpty();
    taskRuntime.addCandidateGroups(TaskPayloadBuilder.addCandidateGroups().withTaskId(createTask.getId()).withCandidateGroup("test").build());
    task = (TaskImpl) taskRuntime.task(createTask.getId());
    groupCandidatesOnTask = task.getCandidateGroups();
    assertThat(groupCandidatesOnTask).hasSize(1);
    groupCandidates = taskRuntime.groupCandidates(createTask.getId());
    assertThat(groupCandidates).hasSize(1);
}
Also used : Task(org.activiti.api.task.model.Task) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) TaskAdminRuntime(org.activiti.api.task.runtime.TaskAdminRuntime) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) RuntimeTestConfiguration(org.activiti.spring.boot.RuntimeTestConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) TaskCleanUpUtil(org.activiti.spring.boot.test.util.TaskCleanUpUtil) Task(org.activiti.api.task.model.Task) TaskImpl(org.activiti.api.task.model.impl.TaskImpl) 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