use of org.kie.api.event.process.DefaultProcessEventListener 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.DefaultProcessEventListener in project jbpm by kiegroup.
the class ActivityTest method testSubProcessWithTerminateEndEventProcessScope.
@Test
public void testSubProcessWithTerminateEndEventProcessScope() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SubProcessWithTerminateEndEventProcessScope.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(5, list.size());
}
use of org.kie.api.event.process.DefaultProcessEventListener 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));
}
use of org.kie.api.event.process.DefaultProcessEventListener 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.DefaultProcessEventListener 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);
}
Aggregations