Search in sources :

Example 56 with ProcessInstance

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

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

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

Example 59 with ProcessInstance

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

the class ProcessRuntimeCallActivityMappingIT method getSubProcess.

private ProcessInstance getSubProcess(ProcessInstance processInstance) {
    List<ProcessInstance> subProcessInstanceList = processRuntime.processInstances(Pageable.of(0, 50), ProcessPayloadBuilder.processInstances().withParentProcessInstanceId(processInstance.getId()).build()).getContent();
    assertThat(subProcessInstanceList).isNotEmpty();
    ProcessInstance subProcessInstance = subProcessInstanceList.get(0);
    assertThat(subProcessInstance).isNotNull();
    assertThat(subProcessInstance.getParentId()).isEqualTo(processInstance.getId());
    return subProcessInstance;
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance)

Example 60 with ProcessInstance

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

the class ProcessRuntimeCallActivityMappingIT method basicCallActivityMappingTest.

@Test
public void basicCallActivityMappingTest() {
    securityUtil.logInAs("user");
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PARENT_PROCESS_CALL_ACTIVITY).build());
    assertThat(processInstance).isNotNull();
    ProcessInstance subProcessInstance = getSubProcess(processInstance);
    assertThat(subProcessInstance.getProcessDefinitionKey()).isEqualTo(SUB_PROCESS_CALL_ACTIVITY);
    Task task = getTask(subProcessInstance);
    taskRuntime.claim(TaskPayloadBuilder.claim().withTaskId(task.getId()).build());
    List<VariableInstance> subProcVariables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(subProcessInstance.getId()).build());
    assertThat(subProcVariables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("subprocess_input_var1", "inName"), tuple("subprocess_input_var2", 20), tuple("subprocess_input_var3", 5), tuple("input_static_value", "a static value"), tuple("subprocess_out_var1", "outValue"), tuple("subprocess_out_var2", 222), tuple("subprocess_static_value", "static some value"), tuple("var_not_exist_in_subprocess_extension_file", 20));
    assertThat("my-task-call-activity").isEqualTo(task.getName());
    Map<String, Object> variablesForTask = new HashMap<>();
    variablesForTask.put("input_variable_name_1", "fromSubprocessName");
    variablesForTask.put("input_variable_name_2", 39);
    variablesForTask.put("out_variable_name_1", 176);
    completeTask(task.getId(), variablesForTask);
    List<VariableInstance> parentVariables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstanceId(processInstance.getId()).build());
    assertThat(parentVariables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("name", "outValue"), tuple("age", 222), tuple("output_unmapped_variable_with_non_matching_connector_output_name", "default"), tuple("input_unmapped_variable_with_non_matching_connector_input_name", "inTest"));
    cleanUp();
}
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) 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