Search in sources :

Example 86 with Task

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

the class TaskRuntimeVariableMappingIT method allVariablesShouldBePassedWhenThereIsNoMapping.

@Test
public void allVariablesShouldBePassedWhenThereIsNoMapping() {
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(TASK_VAR_NO_MAPPING);
    Task task = checkTasks(processInstance.getId());
    assertThat(task.getName()).isEqualTo("testSimpleTask");
    List<VariableInstance> procVariables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
    assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "unmapped1Value"), tuple("process_variable_inputmap_1", "inputmap1Value"), tuple("process_variable_outputmap_1", "outputmap1Value"));
    List<VariableInstance> taskVariables = taskBaseRuntime.getTasksVariablesByTaskId(task.getId());
    assertThat(taskVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "unmapped1Value"), tuple("process_variable_inputmap_1", "inputmap1Value"), tuple("process_variable_outputmap_1", "outputmap1Value"));
    Map<String, Object> variables = new HashMap<>();
    variables.put("task_input_variable_name_1", "outputValue");
    variables.put("task_output_variable_name_1", "outputTaskValue");
    taskBaseRuntime.completeTask(task.getId(), variables);
    procVariables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
    assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getValue).containsExactlyInAnyOrder(tuple("process_variable_unmapped_1", "unmapped1Value"), tuple("process_variable_inputmap_1", "inputmap1Value"), tuple("process_variable_outputmap_1", "outputmap1Value"), tuple("task_input_variable_name_1", "outputValue"), tuple("task_output_variable_name_1", "outputTaskValue"));
    processBaseRuntime.delete(processInstance.getId());
}
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)

Example 87 with Task

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

the class TaskRuntimeVariableMappingIT method taskShouldHaveNoVariablesWhenMappingIsEmpty.

@Test
public void taskShouldHaveNoVariablesWhenMappingIsEmpty() {
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(TASK_EMPTY_VAR_MAPPING);
    List<Task> tasks = taskBaseRuntime.getTasksByProcessInstanceId(processInstance.getId());
    assertThat(tasks).isNotEmpty();
    assertThat(tasks).hasSize(1);
    Task task = tasks.get(0);
    assertThat(task.getName()).isEqualTo("testSimpleTask");
    List<VariableInstance> procVariables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
    assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "unmapped1Value"), tuple("process_variable_inputmap_1", "inputmap1Value"), tuple("process_variable_outputmap_1", "outputmap1Value"));
    List<VariableInstance> taskVariables = taskBaseRuntime.getTasksVariablesByTaskId(task.getId());
    assertThat(taskVariables).isEmpty();
    Map<String, Object> variables = new HashMap<>();
    variables.put("task_input_variable_name_1", "outputValue");
    variables.put("task_output_variable_name_1", "outputTaskValue");
    taskBaseRuntime.completeTask(task.getId(), variables);
    assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "unmapped1Value"), tuple("process_variable_inputmap_1", "inputmap1Value"), tuple("process_variable_outputmap_1", "outputmap1Value"));
    processBaseRuntime.delete(processInstance.getId());
}
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)

Example 88 with Task

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

the class TaskRuntimeTaskAssigneeTest method createStandaloneTaskForGroupAndAdminAssignUser.

@Test
public void createStandaloneTaskForGroupAndAdminAssignUser() {
    securityUtil.logInAs("garth");
    taskRuntime.create(TaskPayloadBuilder.create().withName("group task").withCandidateGroup("doctor").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);
    securityUtil.logInAs("admin");
    Task assignedTask = taskAdminRuntime.assign(TaskPayloadBuilder.assign().withTaskId(task.getId()).withAssignee("garth").build());
    assertThat(assignedTask.getAssignee()).isEqualTo("garth");
    assertThat(assignedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    securityUtil.logInAs("garth");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    task = tasks.getContent().get(0);
    assertThat(task.getAssignee()).isEqualTo("garth");
    taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).withReason("test clean up").build());
}
Also used : Task(org.activiti.api.task.model.Task) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 89 with Task

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

the class TaskRuntimeTaskAssigneeTest method createStandaloneTaskForUsersAndAdminReassignUser.

@Test
public void createStandaloneTaskForUsersAndAdminReassignUser() {
    securityUtil.logInAs("garth");
    taskRuntime.create(TaskPayloadBuilder.create().withName("group task").withCandidateUsers("dean").withCandidateUsers("garth").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);
    // Check that admin may assign a user to the task without assignee
    securityUtil.logInAs("admin");
    Task assignedTask = taskAdminRuntime.assign(TaskPayloadBuilder.assign().withTaskId(task.getId()).withAssignee("garth").build());
    assertThat(assignedTask.getAssignee()).isEqualTo("garth");
    assertThat(assignedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    // Check that admin may reassign a user to the task when assignee is present
    assignedTask = taskAdminRuntime.assign(TaskPayloadBuilder.assign().withTaskId(task.getId()).withAssignee("dean").build());
    assertThat(assignedTask.getAssignee()).isEqualTo("dean");
    assertThat(assignedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    securityUtil.logInAs("dean");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    task = tasks.getContent().get(0);
    assertThat(task.getAssignee()).isEqualTo("dean");
    taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).withReason("test clean up").build());
}
Also used : Task(org.activiti.api.task.model.Task) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 90 with Task

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

the class TaskRuntimeTaskAssigneeTest method createStandaloneTaskForGroupAndClaim.

@Test
public void createStandaloneTaskForGroupAndClaim() {
    securityUtil.logInAs("garth");
    Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("group task").withCandidateGroup("doctor").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);
    Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    assertThat(claimedTask.getAssignee()).isEqualTo("garth");
    assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
}
Also used : Task(org.activiti.api.task.model.Task) 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