use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class DataTest method testDataInputAssociationsWithStringWithoutQuotes.
@Test
public void testDataInputAssociationsWithStringWithoutQuotes() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-string-no-quotes.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {
public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
}
public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
assertEquals("hello", workItem.getParameter("coId"));
}
});
ProcessInstance processInstance = ksession.startProcess("process", null);
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class DataTest method testDataInputAssociationsWithLazyLoading.
/**
* TODO testDataInputAssociationsWithLazyLoading
*/
@Test
@Ignore
public void testDataInputAssociationsWithLazyLoading() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-lazy-creating.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WorkItemHandler() {
public void abortWorkItem(WorkItem manager, WorkItemManager mgr) {
}
public void executeWorkItem(WorkItem workItem, WorkItemManager mgr) {
Object coIdParamObj = workItem.getParameter("coId");
assertEquals("mydoc", ((Element) coIdParamObj).getNodeName());
assertEquals("mynode", ((Element) workItem.getParameter("coId")).getFirstChild().getNodeName());
assertEquals("user", ((Element) workItem.getParameter("coId")).getFirstChild().getFirstChild().getNodeName());
assertEquals("hello world", ((Element) workItem.getParameter("coId")).getFirstChild().getFirstChild().getAttributes().getNamedItem("hello").getNodeValue());
}
});
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream("<user hello='hello world' />".getBytes()));
Map<String, Object> params = new HashMap<String, Object>();
params.put("instanceMetadata", document.getFirstChild());
ProcessInstance processInstance = ksession.startProcess("process", params);
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ErrorEventTest method testCatchErrorBoundaryEventOnTask.
@Test
public void testCatchErrorBoundaryEventOnTask() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnTask.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
if (workItem.getParameter("ActorId").equals("mary")) {
throw new MyError();
}
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.abortWorkItem(workItem.getId());
}
});
ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnTask");
assertProcessInstanceActive(processInstance);
assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "User task error attached", "Script Task", "error1", "error2");
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ErrorEventTest method testErrorBoundaryEventOnExit.
@Test
public void testErrorBoundaryEventOnExit() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-BoundaryErrorEventCatchingOnExitException.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("BoundaryErrorEventOnExit");
assertProcessInstanceActive(processInstance.getId(), ksession);
WorkItem workItem = handler.getWorkItem();
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertEquals(1, handler.getWorkItems().size());
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class FlowTest method testInclusiveParallelExclusiveSplitNoLoop.
@Test
public void testInclusiveParallelExclusiveSplitNoLoop() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-InclusiveNestedInParallelNestedInExclusive.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("testWI", new SystemOutWorkItemHandler());
ksession.getWorkItemManager().registerWorkItemHandler("testWI2", new SystemOutWorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
Integer x = (Integer) workItem.getParameter("input1");
x++;
Map<String, Object> results = new HashMap<String, Object>();
results.put("output1", x);
manager.completeWorkItem(workItem.getId(), results);
}
});
final Map<String, Integer> nodeInstanceExecutionCounter = new HashMap<String, Integer>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.info(event.getNodeInstance().getNodeName());
Integer value = nodeInstanceExecutionCounter.get(event.getNodeInstance().getNodeName());
if (value == null) {
value = new Integer(0);
}
value++;
nodeInstanceExecutionCounter.put(event.getNodeInstance().getNodeName(), value);
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 0);
ProcessInstance processInstance = ksession.startProcess("Process_1", params);
assertProcessInstanceCompleted(processInstance);
assertEquals(12, nodeInstanceExecutionCounter.size());
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Start"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("XORGateway-converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("ANDGateway-diverging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("ORGateway-diverging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI3"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI2"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("ORGateway-converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("Script"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("XORGateway-diverging"));
assertEquals(2, (int) nodeInstanceExecutionCounter.get("ANDGateway-converging"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("testWI6"));
assertEquals(1, (int) nodeInstanceExecutionCounter.get("End"));
}
Aggregations