use of org.kie.api.event.process.ProcessNodeTriggeredEvent in project jbpm by kiegroup.
the class FlowTest method testInclusiveSplitWithLoopInsideSubprocess.
@Test
public void testInclusiveSplitWithLoopInsideSubprocess() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithLoopInsideSubprocess.bpmn2");
ksession = createKnowledgeSession(kbase);
final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.info("{} {}", event.getNodeInstance().getNodeName(), ((NodeInstanceImpl) event.getNodeInstance()).getLevel());
Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
if (value == null) {
value = new Integer(0);
}
value++;
nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
}
});
TestWorkItemHandler handler = new TestWorkItemHandler();
TestWorkItemHandler handler2 = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("testWI", handler);
ksession.getWorkItemManager().registerWorkItemHandler("testWI2", handler2);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", -1);
ProcessInstance processInstance = ksession.startProcess("Process_1", params);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(2, workItems.size());
for (WorkItem wi : workItems) {
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
}
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceCompleted(processInstance);
assertEquals(13, nodeInstanceExecutionCounter.size());
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Sub Process 1"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("sb-start"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("sb-end"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("OR diverging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow2"));
assertEquals(3, (int) nodeInstanceExecutionCounter.get("OR converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow6"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("Script"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR diverging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
use of org.kie.api.event.process.ProcessNodeTriggeredEvent in project jbpm by kiegroup.
the class FlowTest method testInclusiveSplitWithLoopInside.
@Test
public void testInclusiveSplitWithLoopInside() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveGatewayWithLoopInside.bpmn2");
ksession = createKnowledgeSession(kbase);
final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.info("{} {}", event.getNodeInstance().getNodeName(), ((NodeInstanceImpl) event.getNodeInstance()).getLevel());
Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
if (value == null) {
value = new Integer(0);
}
value++;
nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
}
});
TestWorkItemHandler handler = new TestWorkItemHandler();
TestWorkItemHandler handler2 = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("testWI", handler);
ksession.getWorkItemManager().registerWorkItemHandler("testWI2", handler2);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", -1);
ProcessInstance processInstance = ksession.startProcess("Process_1", params);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(2, workItems.size());
for (WorkItem wi : workItems) {
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
}
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler2.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceCompleted(processInstance);
assertEquals(10, nodeInstanceExecutionCounter.size());
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("OR diverging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow2"));
assertEquals(3, (int) nodeInstanceExecutionCounter.get("OR converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("tareaWorkflow6"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("Script"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR diverging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("XOR converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
use of org.kie.api.event.process.ProcessNodeTriggeredEvent in project jbpm by kiegroup.
the class ActivityTest method testSubProcessWithTypeVariable.
@Test
public void testSubProcessWithTypeVariable() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("subprocess/BPMN2-SubProcessWithTypeVariable.bpmn2");
ksession = createKnowledgeSession(kbase);
final List<String> list = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("Read Map")) {
list.add(event.getNodeInstance().getNodeName());
}
}
});
ProcessInstance processInstance = ksession.startProcess("sub_variable.sub_variables");
assertProcessInstanceCompleted(processInstance);
assertEquals(2, list.size());
}
use of org.kie.api.event.process.ProcessNodeTriggeredEvent 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.ProcessNodeTriggeredEvent in project jbpm by kiegroup.
the class DynamicProcessTest method testDynamicProcess.
@Test
public void testDynamicProcess() throws Exception {
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
factory.name("HelloWorldProcess").version("1.0").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task1").actorId("krisv").taskName("MyTask").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
final RuleFlowProcess process = factory.validate().getProcess();
Resource resource = ResourceFactory.newByteArrayResource(XmlRuleFlowProcessDumper.INSTANCE.dump(process).getBytes());
// source path or target path must be set to be added into kbase
resource.setSourcePath("/tmp/dynamicProcess.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(resource);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
ksession.addEventListener(new ProcessEventListener() {
public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void beforeProcessStarted(ProcessStartedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
logger.info("{}", arg0);
}
public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void afterProcessStarted(ProcessStartedEvent arg0) {
}
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
}
public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
}
});
final ProcessInstanceImpl processInstance = (ProcessInstanceImpl) ksession.startProcess("org.jbpm.HelloWorld");
HumanTaskNode node = new HumanTaskNode();
node.setName("Task2");
node.setId(4);
insertNodeInBetween(process, 2, 3, node);
((CommandBasedStatefulKnowledgeSession) ksession).getRunner().execute(new ExecutableCommand<Void>() {
public Void execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
((ProcessInstanceImpl) ksession.getProcessInstance(processInstance.getId())).updateProcess(process);
return null;
}
});
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
Aggregations