Search in sources :

Example 26 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.

the class TaskRuntimeTerminateEndEventTest method should_ProcessesAndTasksDisappear_whenTerminateEventIsExecuted.

@Test
public void should_ProcessesAndTasksDisappear_whenTerminateEventIsExecuted() {
    ProcessInstance process = processBaseRuntime.startProcessWithProcessDefinitionKey(TASK_PROCESS_TERMINATE_EVENT);
    List<Task> taskList = taskBaseRuntime.getTasksByProcessInstanceId(process.getId());
    assertThat(taskList).isNotEmpty();
    assertThat(taskList).hasSize(2);
    Task task1 = taskList.get(0);
    taskBaseRuntime.completeTask(task1.getId());
    List<Task> taskAfterCompleted = taskBaseRuntime.getTasksByProcessInstanceId(process.getId());
    assertThat(taskAfterCompleted).hasSize(0);
}
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 ProcessInstance

use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.

the class TaskRuntimeTerminateEndEventTest method should_CancelledTasksByTerminateEndEventHaveCancellationReasonSet.

@Test
public void should_CancelledTasksByTerminateEndEventHaveCancellationReasonSet() {
    securityUtil.logInAs("user");
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(PROCESS_TERMINATE_EVENT);
    assertThat(processInstance).isNotNull();
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).hasSize(2);
    Task task2 = tasks.get(1);
    taskBaseRuntime.completeTask(task2.getId());
    List<Task> tasksAfterCompletion = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasksAfterCompletion).hasSize(0);
    List<TaskCancelledEvent> taskCancelledEvents = localEventSource.getEvents(TaskCancelledEvent.class);
    assertThat(taskCancelledEvents).hasSize(1);
    assertThat(taskCancelledEvents.get(0).getReason()).contains("Terminated by end event");
}
Also used : Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) TaskCancelledEvent(org.activiti.api.task.runtime.events.TaskCancelledEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 28 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance 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 29 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance 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 30 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.

the class TaskRuntimeClaimTaskFromProcessTest method claimTaskWithoutGroup.

@Test
public void claimTaskWithoutGroup() {
    securityUtil.logInAs("user");
    // when
    ProcessInstance twoTaskInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(TWOTASK_PROCESS).build());
    securityUtil.logInAs("dean");
    Task task = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
    taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    // should still be in dean's list after claiming
    task = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().build()).getContent().get(0);
    assertThat(task).isNotNull();
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
}
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

ProcessInstance (org.activiti.api.process.model.ProcessInstance)154 Test (org.junit.jupiter.api.Test)123 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)116 Task (org.activiti.api.task.model.Task)73 AfterEach (org.junit.jupiter.api.AfterEach)57 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)54 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)39 Autowired (org.springframework.beans.factory.annotation.Autowired)39 BeforeEach (org.junit.jupiter.api.BeforeEach)38 Page (org.activiti.api.runtime.shared.query.Page)37 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)37 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)37 Import (org.springframework.context.annotation.Import)35 List (java.util.List)33 Assertions.tuple (org.assertj.core.api.Assertions.tuple)33 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)31 LocalEventSource (org.activiti.test.LocalEventSource)30 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)29 ProcessRuntimeEvent (org.activiti.api.process.model.events.ProcessRuntimeEvent)29 TaskRuntimeEvent (org.activiti.api.task.model.events.TaskRuntimeEvent)29