use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class ActivityTest method testMinimalProcessMetaData.
@Test
public void testMinimalProcessMetaData() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MinimalProcessMetaData.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<String> list1 = new ArrayList<String>();
final List<String> list2 = new ArrayList<String>();
final List<String> list3 = new ArrayList<String>();
final List<String> list4 = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.debug("before node");
Map<String, Object> metaData = event.getNodeInstance().getNode().getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTag");
if (customTag != null) {
list1.add(customTag);
}
String customTag2 = (String) metaData.get("customTag2");
if (customTag2 != null) {
list2.add(customTag2);
}
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
logger.debug("after variable");
VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.impl.ProcessImpl) event.getProcessInstance().getProcess()).resolveContext(VariableScope.VARIABLE_SCOPE, event.getVariableId());
if (variableScope == null) {
return;
}
Map<String, Object> metaData = variableScope.findVariable(event.getVariableId()).getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTagVar");
if (customTag != null) {
list3.add(customTag);
}
}
public void afterProcessStarted(ProcessStartedEvent event) {
logger.debug("after process");
Map<String, Object> metaData = event.getProcessInstance().getProcess().getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTagProcess");
if (customTag != null) {
list4.add(customTag);
}
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "krisv");
ProcessInstance processInstance = ksession.startProcess("Minimal", params);
assertProcessInstanceCompleted(processInstance);
assertEquals(3, list1.size());
assertEquals(2, list2.size());
assertEquals(1, list3.size());
assertEquals(1, list4.size());
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testMultipleEventBasedStartEventsSignalStart.
@Test
public void testMultipleEventBasedStartEventsSignalStart() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MultipleEventBasedStartEventProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
ksession.signalEvent("startSignal", null);
assertThat(list.size()).isEqualTo(1);
WorkItem workItem = workItemHandler.getWorkItem();
long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
ksession = restoreSession(ksession, true);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testSignalStart.
@Test
public void testSignalStart() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
ksession.signalEvent("MySignal", "NewValue");
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testSignalToStartProcess.
@Test
public void testSignalToStartProcess() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2", "BPMN2-IntermediateThrowEventSignal.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
final List<String> startedProcesses = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
startedProcesses.add(event.getProcessInstance().getProcessId());
}
});
ProcessInstance processInstance = ksession.startProcess("SignalIntermediateEvent");
assertProcessInstanceFinished(processInstance, ksession);
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
assertThat(getNumberOfProcessInstances("SignalIntermediateEvent")).isEqualTo(1);
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromClassPath.
@Test(timeout = 20000)
public void testStartTimerCycleFromClassPath() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
KieBase kbase = createKnowledgeBase("BPMN2-StartTimerCycle.bpmn2");
try {
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
assertEquals(0, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
long sessionId = ksession.getIdentifier();
Environment env = ksession.getEnvironment();
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
assertEquals(2, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
logger.info("dispose");
ksession.dispose();
countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
ksession.addEventListener(countDownListener);
AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
final List<Long> list2 = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list2.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
ksession.dispose();
assertEquals(4, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
} finally {
ksession = createKnowledgeSession(kbase);
abortProcessInstances(ksession);
ksession.dispose();
}
}
Aggregations