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);
}
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();
}
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);
}
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);
}
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();
}
Aggregations