Search in sources :

Example 1 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.util.NodeLeftCountDownProcessEventListener in project kogito-runtimes by kiegroup.

the class TimerEventIT method testBoundaryDateTimerEventOnTask.

@Test
void testBoundaryDateTimerEventOnTask() throws Exception {
    Application app = generateCodeProcessesOnly("timer/TimerBoundaryEventDateISOOnTask.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
    Process<? extends Model> p = app.get(Processes.class).processById("TimerBoundaryEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
    parameters.put("date", plusTwoSeconds.toString());
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED);
}
Also used : ProcessConfig(org.kie.kogito.process.ProcessConfig) HashMap(java.util.HashMap) Processes(org.kie.kogito.process.Processes) NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) OffsetDateTime(java.time.OffsetDateTime) Model(org.kie.kogito.Model) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 2 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.util.NodeLeftCountDownProcessEventListener in project kogito-runtimes by kiegroup.

the class TimerEventIT method testStartTimerEventTimeCycle.

@Test
void testStartTimerEventTimeCycle() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerCycle.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 2);
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
    Process<? extends Model> p = app.get(Processes.class).processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
    assertThat(instances).hasSize(2);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
    // deactivate to cancel timer, so there should be no more timers fired
    p.deactivate();
    // reset the listener to make sure nothing more is triggered
    listener.reset(1);
    completed = listener.waitTillCompleted(3000);
    assertThat(completed).isFalse();
    // same amount of instances should be active as before deactivation
    instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
    assertThat(instances).hasSize(2);
    // clean up by aborting all instances
    instances.forEach(i -> ((ProcessInstance<?>) i).abort());
    assertThat(p.instances().size()).isZero();
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) ProcessConfig(org.kie.kogito.process.ProcessConfig) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessInstance(org.kie.kogito.process.ProcessInstance) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 3 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.util.NodeLeftCountDownProcessEventListener in project kogito-runtimes by kiegroup.

the class TimerEventIT method testBoundaryDurationTimerEventOnSubProcess.

@Test
void testBoundaryDurationTimerEventOnSubProcess() throws Exception {
    Application app = generateCodeProcessesOnly("timer/TimerBoundaryEventDurationISO.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
    Process<? extends Model> p = app.get(Processes.class).processById("TimerBoundaryEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_COMPLETED);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) ProcessConfig(org.kie.kogito.process.ProcessConfig) HashMap(java.util.HashMap) Model(org.kie.kogito.Model) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 4 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.util.NodeLeftCountDownProcessEventListener in project kogito-runtimes by kiegroup.

the class TimerEventIT method testIntermediateCycleTimerEvent.

@Test
void testIntermediateCycleTimerEvent() throws Exception {
    Application app = generateCodeProcessesOnly("timer/IntermediateCatchEventTimerCycleISO.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer", 3);
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
    Process<? extends Model> p = app.get(Processes.class).processById("IntermediateCatchEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ABORTED);
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) ProcessConfig(org.kie.kogito.process.ProcessConfig) HashMap(java.util.HashMap) Model(org.kie.kogito.Model) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 5 with NodeLeftCountDownProcessEventListener

use of org.jbpm.test.util.NodeLeftCountDownProcessEventListener in project kogito-runtimes by kiegroup.

the class TimerEventIT method testStartTimerEvent.

@Test
void testStartTimerEvent() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerDuration.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 1);
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
    Process<? extends Model> p = app.get(Processes.class).processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
    assertThat(instances).hasSize(1);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ABORTED);
    assertThat(p.instances().size()).isZero();
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) ProcessConfig(org.kie.kogito.process.ProcessConfig) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessInstance(org.kie.kogito.process.ProcessInstance) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Aggregations

NodeLeftCountDownProcessEventListener (org.jbpm.test.util.NodeLeftCountDownProcessEventListener)56 Test (org.junit.jupiter.api.Test)55 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)46 Timeout (org.junit.jupiter.api.Timeout)43 HashMap (java.util.HashMap)19 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)18 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)16 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)13 ArrayList (java.util.ArrayList)12 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)12 Application (org.kie.kogito.Application)10 ProcessConfig (org.kie.kogito.process.ProcessConfig)10 Processes (org.kie.kogito.process.Processes)10 Model (org.kie.kogito.Model)8 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)8 OffsetDateTime (java.time.OffsetDateTime)6 Map (java.util.Map)6 EventDescription (org.kie.kogito.process.EventDescription)5 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)5 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)4