Search in sources :

Example 21 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class TimerEventTest method testIntermediateDurationTimerEvent.

@Test
public void testIntermediateDurationTimerEvent() throws Exception {
    Application app = generateCodeProcessesOnly("timer/IntermediateCatchEventTimerDurationISO.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().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(ProcessInstance.STATE_COMPLETED);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 22 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class TimerEventTest method testStartTimerEventTimeCycle.

@Test
public void testStartTimerEventTimeCycle() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerCycle.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 2);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(2);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.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(1, 10);
    assertThat(instances).hasSize(2);
    // clean up by aborting all instances
    instances.forEach(i -> ((ProcessInstance<?>) i).abort());
    instances = p.instances().values(1, 10);
    assertThat(instances).hasSize(0);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 23 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class TimerEventTest method testIntermediateCycleTimerCronEvent.

@Test
public void testIntermediateCycleTimerCronEvent() throws Exception {
    Application app = generateCodeProcessesOnly("timer/IntermediateCatchEventTimerCycleCron.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer", 3);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().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(ProcessInstance.STATE_ACTIVE);
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 24 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class TimerEventTest method testBoundaryCycleCronTimerEventOnTask.

@Test
public void testBoundaryCycleCronTimerEventOnTask() throws Exception {
    Application app = generateCodeProcessesOnly("timer/TimerBoundaryEventCycleCronOnTask.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().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(ProcessInstance.STATE_COMPLETED);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 25 with NodeLeftCountDownProcessEventListener

use of io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener in project automatiko-engine by automatiko-io.

the class TimerEventTest method testIntermediateDateTimerEvent.

@Test
public void testIntermediateDateTimerEvent() throws Exception {
    Application app = generateCodeProcessesOnly("timer/IntermediateCatchEventTimerDateISO.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer", 1);
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
    Process<? extends Model> p = app.processes().processById("IntermediateCatchEvent");
    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(ProcessInstance.STATE_COMPLETED);
}
Also used : NodeLeftCountDownProcessEventListener(io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener) HashMap(java.util.HashMap) OffsetDateTime(java.time.OffsetDateTime) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

Application (io.automatiko.engine.api.Application)26 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)26 NodeLeftCountDownProcessEventListener (io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener)26 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)25 Test (org.junit.jupiter.api.Test)25 Model (io.automatiko.engine.api.Model)23 HashMap (java.util.HashMap)22 Timeout (org.junit.jupiter.api.Timeout)7 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)4 OffsetDateTime (java.time.OffsetDateTime)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 WorkItem (io.automatiko.engine.api.workflow.WorkItem)1 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1