use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class StandaloneBPMNProcessTest method testEventBasedSplit2.
@Test(timeout = 10000)
public void testEventBasedSplit2() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit2.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
// Yes
ProcessInstance processInstance = ksession.startProcess("com.sample.test");
assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
ksession = restoreSession(ksession, true);
ksession.addEventListener(countDownListener);
ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
ksession.signalEvent("Yes", "YesValue", processInstance.getId());
assertProcessInstanceCompleted(processInstance.getId(), ksession);
ksession = restoreSession(ksession, true);
ksession.addEventListener(countDownListener);
ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
ksession = restoreSession(ksession, true);
ksession.addEventListener(countDownListener);
ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
// Timer
processInstance = ksession.startProcess("com.sample.test");
assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
countDownListener.waitTillCompleted();
ksession = restoreSession(ksession, true);
ksession.addEventListener(countDownListener);
ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testMultipleInOutgoingSequenceFlows.
@Test
public void testMultipleInOutgoingSequenceFlows() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
System.setProperty("jbpm.enable.multi.con", "true");
KieBase kbase = createKnowledgeBase("BPMN2-MultipleInOutgoingSequenceFlows.bpmn2");
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());
}
});
assertEquals(0, list.size());
countDownListener.waitTillCompleted();
assertEquals(1, list.size());
System.clearProperty("jbpm.enable.multi.con");
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testInclusiveSplitAndJoinWithTimer.
@Test(timeout = 10000)
public void testInclusiveSplitAndJoinWithTimer() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveSplitAndJoinWithTimer.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", 15);
ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
List<WorkItem> activeWorkItems = workItemHandler.getWorkItems();
assertEquals(1, activeWorkItems.size());
ksession.getWorkItemManager().completeWorkItem(activeWorkItems.get(0).getId(), null);
countDownListener.waitTillCompleted();
assertProcessInstanceActive(processInstance);
activeWorkItems = workItemHandler.getWorkItems();
assertEquals(2, activeWorkItems.size());
ksession.getWorkItemManager().completeWorkItem(activeWorkItems.get(0).getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(activeWorkItems.get(1).getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.test.listener.NodeLeftCountDownProcessEventListener in project jbpm by kiegroup.
the class FlowTest method testTimerAndGateway.
@Test
public void testTimerAndGateway() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
KieBase kbase = createKnowledgeBase("timer/BPMN2-ParallelSplitWithTimerProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
TestWorkItemHandler handler1 = new TestWorkItemHandler();
TestWorkItemHandler handler2 = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("task1", handler1);
ksession.getWorkItemManager().registerWorkItemHandler("task2", handler2);
ProcessInstance instance = ksession.createProcessInstance("timer-process", new HashMap<String, Object>());
ksession.startProcessInstance(instance.getId());
WorkItem workItem1 = handler1.getWorkItem();
assertNotNull(workItem1);
assertNull(handler1.getWorkItem());
// first safe state: task1 completed
ksession.getWorkItemManager().completeWorkItem(workItem1.getId(), null);
ksession = restoreSession(ksession, true);
ksession.addEventListener(countDownListener);
ksession.getWorkItemManager().registerWorkItemHandler("task1", handler1);
ksession.getWorkItemManager().registerWorkItemHandler("task2", handler2);
// second safe state: timer completed, waiting on task2
countDownListener.waitTillCompleted();
WorkItem workItem2 = handler2.getWorkItem();
// Both sides of the join are completed. But on the process instance, there are two
// JoinInstance for the same Join, and since it is an AND join, it never reaches task2
// It fails after the next assertion
assertNotNull(workItem2);
assertNull(handler2.getWorkItem());
ksession.getWorkItemManager().completeWorkItem(workItem2.getId(), null);
assertProcessInstanceCompleted(instance);
}
use of org.jbpm.test.listener.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");
}
Aggregations