Search in sources :

Example 81 with Task

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

the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOnUserTask_should_emmitEventsAndContinueOnceCompletionConditionIsReached.

@Test
public void processWithParallelMultiInstancesOnUserTask_should_emmitEventsAndContinueOnceCompletionConditionIsReached() {
    // when
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelUserTasksCompletionCondition");
    // then
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0", "My Task 1", "My Task 2", "My Task 3");
    assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 2", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 3", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 2", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 3", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    // given
    Task taskToComplete = tasks.get(0);
    // when first multi instance is completed: 3 remaining / completion condition not reached
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(taskToComplete);
    // then
    assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactly(tuple(taskToComplete.getName(), TaskRuntimeEvent.TaskEvents.TASK_COMPLETED));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
    // given
    taskToComplete = tasks.get(1);
    // when second multi instance is completed: 2 remaining / completion condition reached
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(taskToComplete);
    assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple(taskToComplete.getName(), TaskRuntimeEvent.TaskEvents.TASK_COMPLETED), tuple(tasks.get(2).getName(), TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple(tasks.get(3).getName(), TaskRuntimeEvent.TaskEvents.TASK_CANCELLED));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
    assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
    assertThat(localEventSource.getEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DummyBPMNTimerCancelledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerCancelledListener) ProcessRuntimeEvent(org.activiti.api.process.model.events.ProcessRuntimeEvent) Task(org.activiti.api.task.model.Task) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BPMNActivityStartedEvent(org.activiti.api.process.model.events.BPMNActivityStartedEvent) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) ProcessStartedEvent(org.activiti.api.process.runtime.events.ProcessStartedEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) ProcessCompletedEvent(org.activiti.api.process.runtime.events.ProcessCompletedEvent) ActiveProfiles(org.springframework.test.context.ActiveProfiles) DummyBPMNTimerScheduledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerScheduledListener) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) TaskCreatedEvent(org.activiti.api.task.runtime.events.TaskCreatedEvent) Arrays.asList(java.util.Arrays.asList) DummyBPMNTimerExecutedListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerExecutedListener) LocalEventSource(org.activiti.test.LocalEventSource) Collections.singletonMap(java.util.Collections.singletonMap) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) BPMNActivityCancelledEvent(org.activiti.api.process.model.events.BPMNActivityCancelledEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) BPMNActivityCompletedEvent(org.activiti.api.process.model.events.BPMNActivityCompletedEvent) Awaitility.await(org.awaitility.Awaitility.await) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TimerTestConfigurator(org.activiti.spring.boot.process.TimerTestConfigurator) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) BPMNActivityEvent(org.activiti.api.process.model.events.BPMNActivityEvent) Import(org.springframework.context.annotation.Import) Page(org.activiti.api.runtime.shared.query.Page) Collectors(java.util.stream.Collectors) TaskAssignedEvent(org.activiti.api.task.runtime.events.TaskAssignedEvent) DummyBPMNTimerFiredListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerFiredListener) Test(org.junit.jupiter.api.Test) ProcessRuntimeBPMNTimerIT(org.activiti.spring.boot.process.ProcessRuntimeBPMNTimerIT) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) ProcessBaseRuntime(org.activiti.spring.boot.process.ProcessBaseRuntime) 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 82 with Task

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

the class TaskRuntimeStandaloneTaskTest method createStandaloneTaskFailWithEmptyName.

@Test
public void createStandaloneTaskFailWithEmptyName() {
    securityUtil.logInAs("user");
    // when
    Throwable throwable = catchThrowable(() -> taskRuntime.create(TaskPayloadBuilder.create().withAssignee("user").build()));
    // then
    assertThat(throwable).isInstanceOf(IllegalStateException.class);
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 50));
    assertThat(tasks.getContent()).hasSize(0);
}
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 83 with Task

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

the class TaskRuntimeStandaloneTaskTest method should_throwExceptionOnUpdateVariable_when_charactersNotAllowedInVariableName.

@Test
public void should_throwExceptionOnUpdateVariable_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);
    Throwable throwable = catchThrowable(() -> taskRuntime.updateVariable(TaskPayloadBuilder.updateVariable().withTaskId(task.getId()).withVariable("!wrong_name", "value").build()));
    assertThat(throwable).isInstanceOf(IllegalStateException.class);
}
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 84 with Task

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

the class TaskRuntimeTaskForOtherTest method createStandaloneTaskWithNoCandidates.

@Test
public void createStandaloneTaskWithNoCandidates() {
    securityUtil.logInAs("garth");
    Task standAloneTask = taskRuntime.create(TaskPayloadBuilder.create().withName("task with no candidates besides owner").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("user");
    // Other users beside the owner shouldn't see the task
    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)

Example 85 with Task

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

the class TaskRuntimeVariableMappingIT method processTaskVarMapping.

@Test
public void processTaskVarMapping() {
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(TASK_VAR_MAPPING);
    Date date = dateFormatterProvider.parse("2019-09-01");
    Date datetime = dateFormatterProvider.parse("2019-09-01T10:20:30.000Z");
    Task task = checkTasks(processInstance.getId());
    assertThat(task.getName()).isEqualTo("testSimpleTask");
    List<VariableInstance> procVariables = processBaseRuntime.getProcessVariablesByProcessId(processInstance.getId());
    assertThat(procVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getType, VariableInstance::getValue).containsOnly(tuple("process_variable_unmapped_1", "string", "unmapped1Value"), tuple("process_variable_inputmap_1", "string", "inputmap1Value"), tuple("process_variable_outputmap_1", "string", "outputmap1Value"), tuple("process-variable-date", "date", date), tuple("process-variable-datetime", "date", datetime));
    List<VariableInstance> taskVariables = taskBaseRuntime.getTasksVariablesByTaskId(task.getId());
    assertThat(taskVariables).isNotNull().extracting(VariableInstance::getName, VariableInstance::getType, VariableInstance::getValue).containsOnly(tuple("task_input_variable_name_1", "string", "inputmap1Value"), tuple("task-variable-date", "date", date), tuple("task-variable-datetime", "date", datetime));
    Map<String, Object> variables = new HashMap<>();
    variables.put("task_input_variable_name_1", // This should not be set to 'process_variable_inputmap_1'
    "outputValue");
    variables.put("task_output_variable_name_1", // This should be set to 'process_variable_outputmap_1'
    "outputTaskValue");
    taskBaseRuntime.completeTask(task.getId(), variables);
    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", "outputTaskValue"), tuple("process-variable-date", date), tuple("process-variable-datetime", datetime));
    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) Date(java.util.Date) 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