use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class DataTest method testDataInputAssociationsWithXMLLiteral.
@Test
public void testDataInputAssociationsWithXMLLiteral() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataInputAssociations-xml-literal.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("id", ((org.w3c.dom.Node) workItem.getParameter("coId")).getNodeName());
assertEquals("some text", ((org.w3c.dom.Node) workItem.getParameter("coId")).getFirstChild().getTextContent());
}
});
ProcessInstance processInstance = ksession.startProcess("process", null);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class DataTest method testDataInputAssociations.
@Test
public void testDataInputAssociations() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataInputAssociations.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 world", workItem.getParameter("coId"));
}
});
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.WorkItemManager in project jbpm by kiegroup.
the class ErrorEventTest method testEventSubprocessErrorThrowOnTask.
@Test
public void testEventSubprocessErrorThrowOnTask() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessError.bpmn2");
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("Script Task 1")) {
executednodes.add(event.getNodeInstance().getId());
}
}
};
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(listener);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
throw new MyError();
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.abortWorkItem(workItem.getId());
}
});
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessError");
assertProcessInstanceFinished(processInstance, ksession);
assertProcessInstanceAborted(processInstance);
assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertEquals(1, executednodes.size());
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class ActivityTest method testServiceTaskNoInterfaceName.
@Test
public void testServiceTaskNoInterfaceName() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ServiceTask-web-service.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new SystemOutWorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
assertEquals("SimpleService", workItem.getParameter("Interface"));
assertEquals("hello", workItem.getParameter("Operation"));
assertEquals("java.lang.String", workItem.getParameter("ParameterType"));
assertEquals("##WebService", workItem.getParameter("implementation"));
assertEquals("hello", workItem.getParameter("operationImplementationRef"));
assertEquals("SimpleService", workItem.getParameter("interfaceImplementationRef"));
super.executeWorkItem(workItem, manager);
}
});
Map<String, Object> params = new HashMap<String, Object>();
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("org.jboss.qa.jbpm.CallWS", params);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm-work-items by kiegroup.
the class JPAWorkItemHandlerTest method getAllProducts.
private List<Product> getAllProducts() throws Exception {
WorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter(JPAWorkItemHandler.P_ACTION, JPAWorkItemHandler.QUERY_ACTION);
workItem.setParameter(JPAWorkItemHandler.P_QUERY, "SELECT p FROM Product p");
UserTransaction ut = getUserTransaction();
ut.begin();
handler.executeWorkItem(workItem, manager);
ut.commit();
Map<String, Object> results = ((TestWorkItemManager) manager).getResults(workItem.getId());
@SuppressWarnings("unchecked") List<Product> products = (List<Product>) results.get(JPAWorkItemHandler.P_QUERY_RESULTS);
return products;
}
Aggregations