use of org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class ActivityTest method testProcesWithHumanTaskWithTimer.
@Test(timeout = 10000)
@RequirePersistence
public void testProcesWithHumanTaskWithTimer() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Timer", 1);
KieBase kbase = createKnowledgeBase("BPMN2-SubProcessWithTimer.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = ksession.startProcess("subproc", params);
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
long sessionId = ksession.getIdentifier();
Environment env = ksession.getEnvironment();
ksession.dispose();
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
ksession.addEventListener(countDownListener);
countDownListener.waitTillCompleted();
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class ActivityTest method testCallActivityWithBoundaryEvent.
@Test
public void testCallActivityWithBoundaryEvent() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Boundary event", 1);
KieBase kbase = createKnowledgeBase("BPMN2-CallActivityWithBoundaryEvent.bpmn2", "BPMN2-CallActivitySubProcessWithBoundaryEvent.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "oldValue");
ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
countDownListener.waitTillCompleted();
assertProcessInstanceFinished(processInstance, ksession);
// assertEquals("new timer value",
// ((WorkflowProcessInstance) processInstance).getVariable("y"));
// first check the parent process executed nodes
assertNodeTriggered(processInstance.getId(), "StartProcess", "CallActivity", "Boundary event", "Script Task", "end");
// then check child process executed nodes - is there better way to get child process id than simply increment?
assertNodeTriggered(processInstance.getId() + 1, "StartProcess2", "User Task");
}
use of org.jbpm.test.listener.process.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.process.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.process.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class StartEventTest method testTimerCycle.
@Test(timeout = 10000)
public void testTimerCycle() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 5);
KieBase kbase = createKnowledgeBase("timer/BPMN2-StartTimerCycle.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
StartCountingListener listener = new StartCountingListener();
ksession.addEventListener(listener);
countDownListener.waitTillCompleted();
assertThat(listener.getCount("start.cycle")).isEqualTo(5);
}
Aggregations