Search in sources :

Example 41 with Task

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

the class TaskVariablesLocalCopiesTest method processInstanceVariablesCopiedIntoTasksByDefault.

@Test
public void processInstanceVariablesCopiedIntoTasksByDefault() {
    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());
    assertThat(processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(twoTaskInstance).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
    // both tasks should have the process variables
    Task task1 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
    assertThat(taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
    securityUtil.logInAs("garth");
    Task task2 = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
    assertThat(taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task2.getId()).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
    securityUtil.logInAs("user");
    taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task1.getId()).build());
    // if one modifies, the other should not see the modification
    taskRuntime.updateVariable(TaskPayloadBuilder.updateVariable().withTaskId(task1.getId()).withVariable("start1", "modifiedstart1").build());
    // the task where it was modified should reflect the modification
    assertThat(taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task1.getId()).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "modifiedstart1"), tuple("start2", "start2"));
    securityUtil.logInAs("garth");
    // other does not see
    assertThat(taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task2.getId()).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
    securityUtil.logInAs("user");
    // complete and change var again
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task1.getId()).withVariable("start1", "modagainstart1").build());
    // after completion the process variable should be updated but only the one that was modified
    assertThat(processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(twoTaskInstance).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "modagainstart1"), tuple("start2", "start2"));
    securityUtil.logInAs("garth");
    // and task2 should not see the change
    assertThat(taskRuntime.variables(TaskPayloadBuilder.variables().withTaskId(task2.getId()).build())).extracting(VariableInstance::getName, VariableInstance::getValue).containsExactly(tuple("start1", "start1"), tuple("start2", "start2"));
}
Also used : Task(org.activiti.api.task.model.Task) HashMap(java.util.HashMap) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with Task

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

the class BasicExclusiveGatewayTest method shouldCreateAndCompleteATaskAndDontSeeNext.

@Test
public void shouldCreateAndCompleteATaskAndDontSeeNext() {
    securityUtil.logInAs("user1");
    // given
    ProcessInstance processInstance = processOperations.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PROCESS_KEY).withBusinessKey("my-business-key").withName("my-process-instance-name").build()).expectFields(processInstance().status(ProcessInstance.ProcessInstanceStatus.RUNNING), processInstance().name("my-process-instance-name"), processInstance().businessKey("my-business-key")).expect(processInstance().hasTask("Task 1 User 1", Task.TaskStatus.ASSIGNED, withAssignee("user1"))).expectEvents(processInstance().hasBeenStarted(), startEvent("StartEvent_1").hasBeenStarted(), startEvent("StartEvent_1").hasBeenCompleted(), sequenceFlow("SequenceFlow_1035s34").hasBeenTaken(), taskWithName("Task 1 User 1").hasBeenCreated(), taskWithName("Task 1 User 1").hasBeenAssigned()).andReturn();
    // 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);
    assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    assertThat(task.getAssignee()).isEqualTo("user1");
    // given
    taskOperations.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build()).expectEvents(task().hasBeenCompleted(), sequenceFlow("SequenceFlow_0pdm5j0").hasBeenTaken(), exclusiveGateway("ExclusiveGateway_1ri35t5").hasBeenStarted(), exclusiveGateway("ExclusiveGateway_1ri35t5").hasBeenCompleted(), sequenceFlow("SequenceFlow_1tut9mk").hasBeenTaken(), taskWithName("Task 2 User 1").hasBeenCreated(), taskWithName("Task 2 User 1").hasBeenAssigned()).expect(processInstance().hasTask("Task 2 User 1", Task.TaskStatus.ASSIGNED, withAssignee("user1")));
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    task = tasks.getContent().get(0);
    assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    assertThat(task.getAssignee()).isEqualTo("user1");
}
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 43 with Task

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

the class BasicParallelGatewayGroupAssignmentsTest method shouldCheckThatParallelGatewayCreateBothTasksForGroups.

@Test
public void shouldCheckThatParallelGatewayCreateBothTasksForGroups() {
    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.ASSIGNED);
    assertThat(task).isEqualTo(taskById);
    assertThat(task.getAssignee()).isEqualTo("user1");
    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, TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED);
    clearEvents();
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
    assertThat(RuntimeTestConfiguration.collectedEvents).extracting(RuntimeEvent::getEventType).contains(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED, BPMNSequenceFlowTakenEvent.SequenceFlowEvents.SEQUENCE_FLOW_TAKEN, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, TaskRuntimeEvent.TaskEvents.TASK_CREATED);
    clearEvents();
    // User 1 is a candidate for a task
    securityUtil.logInAs("user1");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    task = tasks.getContent().get(0);
    taskById = taskRuntime.task(task.getId());
    assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
    assertThat(task).isEqualTo(taskById);
    assertThat(task.getAssignee()).isNull();
    // User 2 is a candidate for a task
    securityUtil.logInAs("user2");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(1);
    task = tasks.getContent().get(0);
    taskById = taskRuntime.task(task.getId());
    assertThat(taskById.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
    assertThat(task).isEqualTo(taskById);
    assertThat(task.getAssignee()).isNull();
    // User 3 is a candidate for both tasks
    securityUtil.logInAs("user3");
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getTotalItems()).isEqualTo(2);
}
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 44 with Task

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

the class TaskRuntimeStandaloneTaskTest method should_throwExceptionOnTaskSave_when_charactersNotAllowedInVariableName.

@Test
public void should_throwExceptionOnTaskSave_when_charactersNotAllowedInVariableName() {
    securityUtil.logInAs("user");
    Task task = taskRuntime.create(TaskPayloadBuilder.create().withName("name").withAssignee("user").build());
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    Map<String, Object> variables = new HashMap<>();
    variables.put("var_name1", "good_value");
    variables.put("!wrong_name", "!any_value>");
    Throwable throwable = catchThrowable(() -> taskRuntime.save(TaskPayloadBuilder.save().withTaskId(task.getId()).withVariables(variables).build()));
    assertThat(throwable).isInstanceOf(IllegalStateException.class);
}
Also used : Task(org.activiti.api.task.model.Task) HashMap(java.util.HashMap) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 45 with Task

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

the class TaskRuntimeStandaloneTaskTest method createStandaloneTaskForGroup.

@Test
public void createStandaloneTaskForGroup() {
    securityUtil.logInAs("garth");
    Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("find Lucien Sanchez").withCandidateGroup("doctor").build());
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(1);
    Task task = tasks.getContent().get(0);
    assertThat(task.getId()).isEqualTo(standAloneTask.getId());
    assertThat(task.getAssignee()).isNull();
    assertThat(task.getStatus()).isEqualTo(Task.TaskStatus.CREATED);
    assertThat(task.isStandalone()).isTrue();
    Task claimedTask = taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    assertThat(claimedTask.getAssignee()).isEqualTo("garth");
    assertThat(claimedTask.getStatus()).isEqualTo(Task.TaskStatus.ASSIGNED);
    Task deletedTask = taskRuntime.delete(TaskPayloadBuilder.delete().withTaskId(task.getId()).withReason("test clean up").build());
    assertThat(deletedTask).isNotNull();
    assertThat(deletedTask.getStatus()).isEqualTo(Task.TaskStatus.CANCELLED);
    tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(0);
}
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