use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class IntermediateEventTest method testEventBasedSplitWithCronTimerAndSignal.
@Test(timeout = 10000)
public void testEventBasedSplitWithCronTimerAndSignal() throws Exception {
System.setProperty("jbpm.enable.multi.con", "true");
try {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Request photos of order in use", 1);
NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("Request an online review", 1);
NodeLeftCountDownProcessEventListener countDownListener3 = new NodeLeftCountDownProcessEventListener("Send a thank you card", 1);
NodeLeftCountDownProcessEventListener countDownListener4 = new NodeLeftCountDownProcessEventListener("Request an online review", 1);
KieBase kbase = createKnowledgeBase("timer/BPMN2-CronTimerWithEventBasedGateway.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.addEventListener(countDownListener);
ksession.addEventListener(countDownListener2);
ksession.addEventListener(countDownListener3);
ksession.addEventListener(countDownListener4);
ProcessInstance processInstance = ksession.startProcess("timerWithEventBasedGateway");
assertProcessInstanceActive(processInstance.getId(), ksession);
countDownListener.waitTillCompleted();
logger.debug("First timer triggered");
countDownListener2.waitTillCompleted();
logger.debug("Second timer triggered");
countDownListener3.waitTillCompleted();
logger.debug("Third timer triggered");
countDownListener4.waitTillCompleted();
logger.debug("Fourth timer triggered");
List<WorkItem> wi = handler.getWorkItems();
assertThat(wi).isNotNull();
assertThat(wi.size()).isEqualTo(3);
ksession.abortProcessInstance(processInstance.getId());
} finally {
// clear property only as the only relevant value is when it's set to true
System.clearProperty("jbpm.enable.multi.con");
}
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class IntermediateEventTest method testIntermediateCatchEventTimerCycle1.
@Test(timeout = 10000)
public void testIntermediateCatchEventTimerCycle1() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerCycle1.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
assertProcessInstanceActive(processInstance);
// now wait for 1 second for timer to trigger
countDownListener.waitTillCompleted();
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class ProcessFactoryTest method testBoundaryTimerTimeCycle.
@Test(timeout = 10000)
public void testBoundaryTimerTimeCycle() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent", 1);
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task").actorId("john").taskName("MyTask").done().endNode(3).name("End1").terminate(false).done().boundaryEventNode(4).name("BoundaryTimerEvent").attachedTo(2).timeCycle("1s###5s").cancelActivity(false).done().endNode(5).name("End2").terminate(false).done().connection(1, 2).connection(2, 3).connection(4, 5);
RuleFlowProcess process = factory.validate().getProcess();
Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
// source path or target path must be set to be added into kbase
res.setSourcePath("/tmp/processFactory.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(res);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
ksession.addEventListener(countDownListener);
ProcessInstance pi = ksession.startProcess("org.jbpm.process");
assertProcessInstanceActive(pi);
// wait for boundary timer firing
countDownListener.waitTillCompleted();
assertNodeTriggered(pi.getId(), "End2");
// still active because CancelActivity = false
assertProcessInstanceActive(pi);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceCompleted(pi);
ksession.dispose();
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class ProcessFactoryTest method testBoundaryTimerTimeDuration.
@Test(timeout = 10000)
public void testBoundaryTimerTimeDuration() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent", 1);
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task").actorId("john").taskName("MyTask").done().endNode(3).name("End1").terminate(false).done().boundaryEventNode(4).name("BoundaryTimerEvent").attachedTo(2).timeDuration("1s").cancelActivity(false).done().endNode(5).name("End2").terminate(false).done().connection(1, 2).connection(2, 3).connection(4, 5);
RuleFlowProcess process = factory.validate().getProcess();
Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
// source path or target path must be set to be added into kbase
res.setSourcePath("/tmp/processFactory.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(res);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
ksession.addEventListener(countDownListener);
ProcessInstance pi = ksession.startProcess("org.jbpm.process");
assertProcessInstanceActive(pi);
// wait for boundary timer firing
countDownListener.waitTillCompleted();
assertNodeTriggered(pi.getId(), "End2");
// still active because CancelActivity = false
assertProcessInstanceActive(pi);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceCompleted(pi);
ksession.dispose();
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class StandaloneBPMNProcessTest method testTimerStart.
@Test(timeout = 10000)
public void testTimerStart() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5);
KieBase kbase = createKnowledgeBase("BPMN2-TimerStart.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
assertThat(list.size()).isEqualTo(0);
countDownListener.waitTillCompleted();
assertThat(list.size()).isEqualTo(5);
}
Aggregations