use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class ActivityTest method testSubProcess.
@Test
public void testSubProcess() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SubProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
logger.debug(event.toString());
}
public void beforeVariableChanged(ProcessVariableChangedEvent event) {
logger.debug(event.toString());
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
logger.debug(event.toString());
}
});
ProcessInstance processInstance = ksession.startProcess("SubProcess");
assertProcessInstanceCompleted(processInstance);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class ActivityTest method testSubProcessWithTerminateEndEvent.
@Test
public void testSubProcessWithTerminateEndEvent() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SubProcessWithTerminateEndEvent.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<String> list = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
list.add(event.getNodeInstance().getNodeName());
}
});
ProcessInstance processInstance = ksession.startProcess("SubProcessTerminate");
assertProcessInstanceCompleted(processInstance);
assertEquals(7, list.size());
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class StandaloneBPMNProcessTest method testMessageStart.
@Test
public void testMessageStart() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MessageStart.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
ksession.signalEvent("Message-HelloMessage", "NewValue");
assertThat(list.size()).isEqualTo(1);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class StartEventTest method testMultipleEventBasedStartEventsStartOnTimer.
@Test(timeout = 10000)
public void testMultipleEventBasedStartEventsStartOnTimer() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartTimer", 2);
KieBase kbase = createKnowledgeBase("BPMN2-MultipleEventBasedStartEventProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
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);
// Timer in the process takes 500ms, so after 1 second, there should be 2 process IDs in the list.
countDownListener.waitTillCompleted();
assertThat(getNumberOfProcessInstances("MultipleStartEvents")).isEqualTo(2);
}
use of org.kie.api.event.process.DefaultProcessEventListener in project jbpm by kiegroup.
the class StartEventTest method testSignalStartDynamic.
@Test
public void testSignalStartDynamic() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2");
ksession = createKnowledgeSession(kbase);
// create KieContainer after session was created to make sure no runtime data
// will be used during serialization (deep clone)
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
kContainer.getKieBase();
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
logger.info("{}", event.getProcessInstance().getId());
list.add(event.getProcessInstance().getId());
}
});
ksession.signalEvent("MySignal", "NewValue");
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
// now remove the process from kbase to make sure runtime based listeners are removed from signal manager
kbase.removeProcess("Minimal");
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
ksession.signalEvent("MySignal", "NewValue");
}).withMessageContaining("Unknown process ID: Minimal");
// must be still one as the process was removed
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
}
Aggregations