Search in sources :

Example 1 with BPMNTimerEvent

use of org.activiti.api.process.model.events.BPMNTimerEvent 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 2 with BPMNTimerEvent

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

the class ProcessRuntimeBPMNTimerIT method shouldGetTimerCanceledEventByProcessDelete.

@Test
public void shouldGetTimerCanceledEventByProcessDelete() {
    // GIVEN
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(PROCESS_TIMER_CANCELLED_EVENT);
    // WHEN
    processBaseRuntime.delete(processInstance.getId());
    // THEN
    List<BPMNTimerCancelledEvent> eventsCancelled = listenerCancelled.getEvents();
    assertThat(eventsCancelled).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_CANCELLED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) DummyBPMNTimerCancelledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerCancelledListener) Task(org.activiti.api.task.model.Task) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) DummyBPMNTimerExecutedListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerExecutedListener) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Awaitility.await(org.awaitility.Awaitility.await) Tuple(org.assertj.core.groups.Tuple) BPMNTimerCancelledEvent(org.activiti.api.process.model.events.BPMNTimerCancelledEvent) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) Import(org.springframework.context.annotation.Import) Page(org.activiti.api.runtime.shared.query.Page) BPMNTimerScheduledEvent(org.activiti.api.process.model.events.BPMNTimerScheduledEvent) DummyBPMNTimerFiredListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerFiredListener) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) ProcessInstance(org.activiti.api.process.model.ProcessInstance) BPMNTimerCancelledEvent(org.activiti.api.process.model.events.BPMNTimerCancelledEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with BPMNTimerEvent

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

the class ProcessRuntimeBPMNTimerIT method shouldGetTimerCanceledEventOnBoundaryEvent.

@Test
public void shouldGetTimerCanceledEventOnBoundaryEvent() {
    // given
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(PROCESS_TIMER_CANCELLED_EVENT);
    List<BPMNTimerScheduledEvent> eventsScheduled = listenerScheduled.getEvents();
    assertThat(eventsScheduled).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_SCHEDULED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
    clear();
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build());
    assertThat(tasks.getContent()).hasSize(1);
    Task task = tasks.getContent().get(0);
    taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(task.getId()).build());
    List<BPMNTimerCancelledEvent> eventsCanceled = listenerCancelled.getEvents();
    assertThat(eventsCanceled).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_CANCELLED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) DummyBPMNTimerCancelledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerCancelledListener) Task(org.activiti.api.task.model.Task) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) DummyBPMNTimerExecutedListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerExecutedListener) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Awaitility.await(org.awaitility.Awaitility.await) Tuple(org.assertj.core.groups.Tuple) BPMNTimerCancelledEvent(org.activiti.api.process.model.events.BPMNTimerCancelledEvent) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) Import(org.springframework.context.annotation.Import) Page(org.activiti.api.runtime.shared.query.Page) BPMNTimerScheduledEvent(org.activiti.api.process.model.events.BPMNTimerScheduledEvent) DummyBPMNTimerFiredListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerFiredListener) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Task(org.activiti.api.task.model.Task) BPMNTimerScheduledEvent(org.activiti.api.process.model.events.BPMNTimerScheduledEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) BPMNTimerCancelledEvent(org.activiti.api.process.model.events.BPMNTimerCancelledEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with BPMNTimerEvent

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

the class ProcessRuntimeBPMNTimerIT method shouldGetTimerFiredScheduledEventsForProcessWithTimer.

@Test
public void shouldGetTimerFiredScheduledEventsForProcessWithTimer() throws Exception {
    // given
    ProcessInstance processInstance = processBaseRuntime.startProcessWithProcessDefinitionKey(PROCESS_INTERMEDIATE_TIMER_EVENT);
    // when
    List<BPMNTimerScheduledEvent> eventsScheduled = listenerScheduled.getEvents();
    // then
    assertThat(eventsScheduled).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_SCHEDULED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
    assertThat(listenerFired.getEvents()).isEmpty();
    // when
    long waitTime = 10 * 60 * 1000;
    Date startTime = new Date();
    Date dueDate = new Date(startTime.getTime() + waitTime);
    // After setting the clock to time '5minutes and 5 seconds', the second timer should fire
    processEngineConfiguration.getClock().setCurrentTime(new Date(dueDate.getTime() + 5000));
    // then
    await().untilAsserted(() -> {
        assertThat(listenerFired.getEvents()).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_FIRED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
        assertThat(listenerExecuted.getEvents()).extracting(BPMNTimerEvent::getEventType, BPMNTimerEvent::getProcessDefinitionId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getElementId()).contains(Tuple.tuple(BPMNTimerEvent.TimerEvents.TIMER_EXECUTED, processInstance.getProcessDefinitionId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "timer"));
    });
    // then the execution reaches the task
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 10), TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build());
    assertThat(tasks.getContent()).hasSize(1);
    assertThat(tasks.getContent().get(0).getName()).isEqualTo("User Task");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) DummyBPMNTimerCancelledListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerCancelledListener) Task(org.activiti.api.task.model.Task) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) 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) DummyBPMNTimerExecutedListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerExecutedListener) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Awaitility.await(org.awaitility.Awaitility.await) Tuple(org.assertj.core.groups.Tuple) BPMNTimerCancelledEvent(org.activiti.api.process.model.events.BPMNTimerCancelledEvent) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) Import(org.springframework.context.annotation.Import) Page(org.activiti.api.runtime.shared.query.Page) BPMNTimerScheduledEvent(org.activiti.api.process.model.events.BPMNTimerScheduledEvent) DummyBPMNTimerFiredListener(org.activiti.spring.boot.process.listener.DummyBPMNTimerFiredListener) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Task(org.activiti.api.task.model.Task) BPMNTimerScheduledEvent(org.activiti.api.process.model.events.BPMNTimerScheduledEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Date (java.util.Date)4 List (java.util.List)4 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)4 ProcessInstance (org.activiti.api.process.model.ProcessInstance)4 BPMNTimerEvent (org.activiti.api.process.model.events.BPMNTimerEvent)4 Page (org.activiti.api.runtime.shared.query.Page)4 Task (org.activiti.api.task.model.Task)4 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)4 DummyBPMNTimerCancelledListener (org.activiti.spring.boot.process.listener.DummyBPMNTimerCancelledListener)4 DummyBPMNTimerExecutedListener (org.activiti.spring.boot.process.listener.DummyBPMNTimerExecutedListener)4 DummyBPMNTimerFiredListener (org.activiti.spring.boot.process.listener.DummyBPMNTimerFiredListener)4 DummyBPMNTimerScheduledListener (org.activiti.spring.boot.process.listener.DummyBPMNTimerScheduledListener)4 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)4 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.tuple (org.assertj.core.api.Assertions.tuple)4 Awaitility.await (org.awaitility.Awaitility.await)4 AfterEach (org.junit.jupiter.api.AfterEach)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Test (org.junit.jupiter.api.Test)4