use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class FlowTest method testMultipleGatewaysProcess.
@Test
public void testMultipleGatewaysProcess() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultipleGatewaysProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(new DefaultProcessEventListener() {
ProcessInstance pi;
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("CreateAgent")) {
pi.signalEvent("Signal_1", null);
}
}
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.info("Before Node triggered event received for node: {}", event.getNodeInstance().getNodeName());
}
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
pi = event.getProcessInstance();
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("action", "CreateAgent");
ProcessInstance processInstance = ksession.startProcess("multiplegateways", params);
assertProcessInstanceCompleted(processInstance);
}
use of org.kie.api.event.process.ProcessStartedEvent 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.ProcessStartedEvent 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.ProcessStartedEvent 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.ProcessStartedEvent 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