use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class RequestUI method createKieSession.
private KieSession createKieSession() {
try {
final KieSession ksession = getKieSession();
KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
UIWorkItemHandler handler = new UIWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
handler.setVisible(true);
ksession.getWorkItemManager().registerWorkItemHandler("Email", new WorkItemHandler() {
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println("Sending email ...");
manager.completeWorkItem(workItem.getId(), null);
}
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
});
Person person = new Person("john", "John Doe");
person.setAge(40);
ksession.insert(person);
person = new Person("krisv", "Kris Verlaenen");
person.setAge(30);
ksession.insert(person);
person = new Person("baby", "Baby");
person.setAge(1);
ksession.insert(person);
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
ksession.insert(event);
}
});
return ksession;
} catch (Throwable t) {
throw new RuntimeException("Could not initialize session!", t);
}
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StandaloneBPMNProcessTest method testTimerStart.
@Test(timeout = 10000)
public void testTimerStart() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5);
KieBase kbase = createKnowledgeBase("BPMN2-TimerStart.bpmn2");
KieSession 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());
}
});
assertThat(list.size()).isEqualTo(0);
countDownListener.waitTillCompleted();
assertThat(list.size()).isEqualTo(5);
}
use of org.kie.api.event.process.ProcessStartedEvent 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.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class ActivityTest method testCallActivityWithTransformation.
@Test
public void testCallActivityWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityWithTransformation.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<ProcessInstance> instances = new ArrayList<ProcessInstance>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
instances.add(event.getProcessInstance());
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "oldValue");
ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
assertProcessInstanceCompleted(processInstance);
assertEquals(2, instances.size());
// assert variables of parent process, first in start (input transformation, then on end output transformation)
assertEquals("oldValue", ((WorkflowProcessInstance) instances.get(0)).getVariable("x"));
assertEquals("NEW VALUE", ((WorkflowProcessInstance) instances.get(0)).getVariable("y"));
// assert variables of subprocess, first in start (input transformation, then on end output transformation)
assertEquals("OLDVALUE", ((WorkflowProcessInstance) instances.get(1)).getVariable("subX"));
assertEquals("new value", ((WorkflowProcessInstance) instances.get(1)).getVariable("subY"));
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class ActivityTest method testCallActivityMI.
@Test
public void testCallActivityMI() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityMI.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<Long> subprocessStarted = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
if (event.getProcessInstance().getProcessId().equals("SubProcess")) {
subprocessStarted.add(event.getProcessInstance().getId());
}
}
});
List<String> list = new ArrayList<String>();
list.add("first");
list.add("second");
List<String> listOut = new ArrayList<String>();
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "oldValue");
params.put("list", list);
params.put("listOut", listOut);
ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
assertProcessInstanceCompleted(processInstance);
assertEquals(2, subprocessStarted.size());
listOut = (List) ((WorkflowProcessInstance) processInstance).getVariable("listOut");
assertNotNull(listOut);
assertEquals(2, listOut.size());
assertEquals("new value", listOut.get(0));
assertEquals("new value", listOut.get(1));
}
Aggregations