use of org.jbpm.test.listener.TrackingAgendaEventListener in project jbpm by kiegroup.
the class FireUntilHaltTest method testFireUntilHaltWithProcess.
@Test(timeout = 30000)
public void testFireUntilHaltWithProcess() throws Exception {
Map<String, ResourceType> res = new HashMap<String, ResourceType>();
res.put(PROCESS, ResourceType.BPMN2);
res.put(PROCESS_DRL, ResourceType.DRL);
final KieSession ksession = createKSession(res);
ksession.getEnvironment().set("org.jbpm.rule.task.waitstate", true);
TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
ksession.addEventListener(listener);
// thread for firing until halt
ExecutorService thread = Executors.newSingleThreadExecutor();
thread.submit(new Runnable() {
@Override
public void run() {
ksession.fireUntilHalt();
}
});
int wantedPersonsNum = 3;
int unwantedPersonsNum = 2;
Person p;
// insert 3 wanted persons
for (int i = 0; i < wantedPersonsNum; i++) {
p = new Person("wanted person");
p.setId(i);
ksession.insert(p);
}
// insert 2 unwanted persons
for (int i = 0; i < unwantedPersonsNum; i++) {
p = new Person("unwanted person");
p.setId(i);
ksession.insert(p);
}
// wait for rule to fire
Thread.sleep(100);
// 8 persons should be acknowledged - person detector rule fired
Assertions.assertThat(listener.ruleFiredCount("person detector")).isEqualTo(wantedPersonsNum + unwantedPersonsNum);
// we start defined process
ksession.startProcess(PROCESS_ID);
Thread.sleep(100);
Assertions.assertThat(listener.ruleFiredCount("initial actions")).isEqualTo(1);
Assertions.assertThat(listener.ruleFiredCount("wanted person detector")).isEqualTo(wantedPersonsNum);
Assertions.assertThat(listener.ruleFiredCount("change unwanted person to wanted")).isEqualTo(unwantedPersonsNum);
// 5 + 2 changed + 1 added
Assertions.assertThat(listener.ruleFiredCount("person detector")).isEqualTo(wantedPersonsNum * unwantedPersonsNum);
Assertions.assertThat(listener.ruleFiredCount("closing actions")).isEqualTo(1);
ksession.halt();
}
use of org.jbpm.test.listener.TrackingAgendaEventListener in project jbpm by kiegroup.
the class RuleTest method testNoOnEntryEvent.
@Test
@BZ("852095")
public void testNoOnEntryEvent() {
Map<String, ResourceType> res = new HashMap<String, ResourceType>();
res.put(ON_ENTRY_EVENT, ResourceType.BPMN2);
res.put(ON_ENTRY_EVENT_DRL, ResourceType.DRL);
KieSession ksession = createKSession(res);
List<Command<?>> commands = new ArrayList<Command<?>>();
TrackingAgendaEventListener agendaEvents = new TrackingAgendaEventListener();
TrackingProcessEventListener processEvents = new TrackingProcessEventListener();
TrackingRuleRuntimeEventListener ruleEvents = new TrackingRuleRuntimeEventListener();
ksession.addEventListener(agendaEvents);
ksession.addEventListener(processEvents);
ksession.addEventListener(ruleEvents);
commands.add(getCommands().newStartProcess(ON_ENTRY_EVENT_ID));
commands.add(getCommands().newFireAllRules());
ksession.execute(getCommands().newBatchExecution(commands, null));
Assertions.assertThat(processEvents.wasProcessStarted(ON_ENTRY_EVENT_ID)).isTrue();
Assertions.assertThat(processEvents.wasNodeTriggered("Rule")).isTrue();
Assertions.assertThat(ruleEvents.wasInserted("OnEntry")).isTrue();
Assertions.assertThat(agendaEvents.isRuleFired("dummyRule")).isTrue();
Assertions.assertThat(ruleEvents.wasInserted("OnExit")).isTrue();
Assertions.assertThat(processEvents.wasNodeLeft("Rule")).isTrue();
Assertions.assertThat(processEvents.wasProcessCompleted(ON_ENTRY_EVENT_ID)).isTrue();
}
use of org.jbpm.test.listener.TrackingAgendaEventListener in project jbpm by kiegroup.
the class TransactionsTest method testRuleflowGroup.
@Test(timeout = 60000)
public void testRuleflowGroup() throws Exception {
TrackingProcessEventListener process = new TrackingProcessEventListener(false);
TrackingAgendaEventListener agenda = new TrackingAgendaEventListener();
ksession.addEventListener(process);
ksession.addEventListener(agenda);
long processId = startProcess(ksession);
UserTransaction ut = getUserTransaction();
try {
ut.begin();
ksession.signalEvent("start", "rfg", processId);
Assertions.assertThat(process.wasNodeLeft("rfg")).isTrue();
} finally {
ut.rollback();
}
Thread.sleep(600);
process.clear();
agenda.clear();
ksession = restoreKSession(resources);
ksession.addEventListener(process);
ksession.addEventListener(agenda);
ksession.fireAllRules();
Assertions.assertThat(agenda.isRuleFired("dummyRule")).isFalse();
agenda.clear();
process.clear();
String ruleFlowGroupNodeName = "rfg";
ut = getUserTransaction();
try {
ut.begin();
ksession.signalEvent("start", "rfg", processId);
assertTrue("Node '" + ruleFlowGroupNodeName + "' was not left on time!", process.waitForNodeToBeLeft(ruleFlowGroupNodeName, 1000));
ut.commit();
} catch (Exception ex) {
ut.rollback();
throw ex;
}
Assertions.assertThat(process.wasNodeLeft(ruleFlowGroupNodeName)).isTrue();
ksession.signalEvent("finish", null, processId);
ksession.fireAllRules();
assertTrue("Process did not complete on time!", process.waitForProcessToComplete(1000));
Assertions.assertThat(agenda.isRuleFired("dummyRule")).isTrue();
assertProcessInstanceCompleted(processId);
}
Aggregations