Search in sources :

Example 6 with ProcessInstance

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

the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOnUserTask_Boundary_Event.

@Test
public void processWithParallelMultiInstancesOnUserTask_Boundary_Event() {
    // when
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelUserTaskBoundaryEvent");
    // then
    assertThat(taskBaseRuntime.getTasks(processInstance)).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0", "My Task 1");
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    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 0", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
    // when
    long waitTime = 1 * 60 * 1000;
    Date startTime = new Date();
    Date dueDate = new Date(startTime.getTime() + waitTime);
    // set the clock so the timer fires
    localEventSource.clearEvents();
    processEngineConfiguration.getClock().setCurrentTime(new Date(dueDate.getTime()));
    await().untilAsserted(() -> {
        assertThat(localEventSource.getEvents(BPMNTimerEvent.class)).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).containsExactly(tuple(BPMNTimerEvent.TimerEvents.TIMER_FIRED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"), tuple(BPMNTimerEvent.TimerEvents.TIMER_EXECUTED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
        assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("My Task 0", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("My Task 1", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
        assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
        // need to login again before getting the list of tasks
        // because Awaitility will run this inside another thread
        securityUtil.logInAs("user");
        List<Task> availableTasks = taskBaseRuntime.getTasks(processInstance);
        assertThat(availableTasks).extracting(Task::getName).containsExactly("Escalation Task");
        localEventSource.clearEvents();
        taskBaseRuntime.completeTask(availableTasks.get(0));
    });
    assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactly(tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_COMPLETED));
    assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
    assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(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) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ProcessInstance

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

the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOn_SubProcess_Boundary_Event.

@Test
public void processWithParallelMultiInstancesOn_SubProcess_Boundary_Event() {
    // when
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelSubProcessBoundaryEvent");
    // then
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("Task in sub-process 0", "Task in sub-process 1");
    assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("Task in sub-process 0", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Task in sub-process 1", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Task in sub-process 0", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED), tuple("Task in sub-process 1", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
    // send signal: boundary event should cancel multi-instance
    localEventSource.clearEvents();
    processBaseRuntime.signal("goMiParallelSubProcessBoundaryEvent");
    assertThat(localEventSource.getTaskEvents()).extracting(event -> ((Task) event.getEntity()).getName(), RuntimeEvent::getEventType).containsExactlyInAnyOrder(tuple("Task in sub-process 0", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("Task in sub-process 1", TaskRuntimeEvent.TaskEvents.TASK_CANCELLED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_CREATED), tuple("Escalation Task", TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED));
    assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED, BPMNActivityEvent.ActivityEvents.ACTIVITY_CANCELLED);
    tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks.size()).isEqualTo(1);
    assertThat(tasks).extracting(Task::getName).contains("Escalation Task");
    taskBaseRuntime.completeTask(tasks.get(0));
    assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
    assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(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 8 with ProcessInstance

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

the class TaskRuntimeMultiInstanceIT method processWithParallelMultiInstancesOnUserTask_should_emmit_EqualStartAndEndEvent.

@Test
public void processWithParallelMultiInstancesOnUserTask_should_emmit_EqualStartAndEndEvent() {
    // when
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miParallelUserTasks");
    // then
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0", "My Task 1");
    assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, processInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, processInstance.getId()));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED, BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactlyInAnyOrder(tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "My Task 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "My Task 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "My Task 1", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "My Task 1", processInstance.getId()));
    // complete first iteration: multi instance should not complete yet
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(tasks.get(0));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, tasks.get(0).getName(), processInstance.getId()));
    assertThat(localEventSource.getProcessInstanceEvents()).isEmpty();
    // complete second iteration: multi instance should complete
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(tasks.get(1));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, tasks.get(1).getName(), processInstance.getId()));
    assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
    assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
}
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 9 with ProcessInstance

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

the class TaskRuntimeMultiInstanceIT method processWithSequentialMultiInstancesOnUserTask_should_emmit_EqualStartAndEndEvent.

@Test
public void processWithSequentialMultiInstancesOnUserTask_should_emmit_EqualStartAndEndEvent() {
    // when
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miSequentialUserTasks");
    assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, processInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, processInstance.getId()));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "My Task 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "My Task 0", processInstance.getId()));
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("My Task 0");
    // complete first iteration, multi-instance should not complete yet
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(tasks.get(0));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, // second iteration was created
    BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "My Task 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "My Task 1", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "My Task 1", processInstance.getId()));
    tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("My Task 1");
    // complete second iteration, multi-instance should not complete
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(tasks.get(0));
    assertActivityEvents("miTasks", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "My Task 1", processInstance.getId()));
    assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
    assertThat(localEventSource.getProcessInstanceEvents()).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 10 with ProcessInstance

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

the class TaskRuntimeMultiInstanceIT method processWithSequentialMultiInstancesOnSubProcess_should_emmit_EqualStartAndEndEvent.

@Test
public void processWithSequentialMultiInstancesOnSubProcess_should_emmit_EqualStartAndEndEvent() {
    // when
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey("miSequentialSubprocess");
    assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, event -> ((ProcessInstance) event.getEntity()).getId()).containsExactlyInAnyOrder(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_CREATED, processInstance.getId()), tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_STARTED, processInstance.getId()));
    assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "Task in sub-process 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "Task in sub-process 0", processInstance.getId()));
    List<Task> tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("Task in sub-process 0");
    // complete first iteration, multi-instance should not complete yet
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(tasks.get(0));
    assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED, // second iteration was created
    BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "Task in sub-process 0", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_CREATED, "Task in sub-process 1", processInstance.getId()), tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, "Task in sub-process 1", processInstance.getId()));
    tasks = taskBaseRuntime.getTasks(processInstance);
    assertThat(tasks).extracting(Task::getName).containsExactlyInAnyOrder("Task in sub-process 1");
    // complete second iteration, multi-instance should not complete
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(tasks.get(0));
    assertActivityEvents("miSubProcess", BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED);
    assertThat(localEventSource.getTaskEvents()).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName(), event -> ((Task) event.getEntity()).getProcessInstanceId()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, "Task in sub-process 1", processInstance.getId()));
    assertThat(taskBaseRuntime.getTasks(processInstance)).isEmpty();
    assertThat(localEventSource.getProcessInstanceEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).containsExactly(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)

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