use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class IntermediateEventTest method testMessageIntermediateThrowWithTransformation.
@Test
public void testMessageIntermediateThrowWithTransformation() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-IntermediateThrowEventMessageWithTransformation.bpmn2");
ksession = createKnowledgeSession(kbase);
final StringBuffer messageContent = new StringBuffer();
ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
// collect message content for verification
messageContent.append(workItem.getParameter("Message"));
super.executeWorkItem(workItem, manager);
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "MyValue");
ProcessInstance processInstance = ksession.startProcess("MessageIntermediateEvent", params);
assertProcessInstanceCompleted(processInstance);
assertThat(messageContent.toString()).isEqualTo("MYVALUE");
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class IntermediateEventTest method testThrowIntermediateSignalWithExternalScope.
@Test
public void testThrowIntermediateSignalWithExternalScope() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateThrowEventExternalScope.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
WorkItemHandler externalHandler = new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
String signal = (String) workItem.getParameter("Signal");
ksession.signalEvent(signal, null);
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
}
};
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.getWorkItemManager().registerWorkItemHandler("External Send Task", externalHandler);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = ksession.startProcess("intermediate-event-scope", params);
assertProcessInstanceActive(processInstance);
assertNodeActive(processInstance.getId(), ksession, "Complete work", "Wait");
List<WorkItem> items = handler.getWorkItems();
assertThat(items.size()).isEqualTo(1);
WorkItem wi = items.get(0);
Map<String, Object> result = new HashMap<String, Object>();
result.put("_output", "sending event");
ksession.getWorkItemManager().completeWorkItem(wi.getId(), result);
assertProcessInstanceCompleted(processInstance);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class DataTest method testDataInputAssociationsWithStringObject.
@Test
public void testDataInputAssociationsWithStringObject() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataInputAssociations-string-object.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"));
}
});
Map<String, Object> params = new HashMap<String, Object>();
params.put("instanceMetadata", "hello");
ProcessInstance processInstance = ksession.startProcess("process", params);
}
use of org.kie.api.runtime.process.WorkItemManager in project jbpm by kiegroup.
the class DataTest method testDataInputAssociationsWithString.
@Test
public void testDataInputAssociationsWithString() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-DataInputAssociations-string.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.WorkItemManager in project jbpm by kiegroup.
the class DataTest method testDataOutputAssociationsforHumanTask.
@Test
public void testDataOutputAssociationsforHumanTask() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-DataOutputAssociations-HumanTask.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) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
final Map<String, Object> results = new HashMap<String, Object>();
// process metadata
org.w3c.dom.Document processMetadaDoc = builder.newDocument();
org.w3c.dom.Element processMetadata = processMetadaDoc.createElement("previoustasksowner");
processMetadaDoc.appendChild(processMetadata);
// org.w3c.dom.Element procElement =
// processMetadaDoc.createElement("previoustasksowner");
processMetadata.setAttribute("primaryname", "my_result");
// processMetadata.appendChild(procElement);
results.put("output", processMetadata);
mgr.completeWorkItem(workItem.getId(), results);
}
});
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = ksession.startProcess("process", params);
}
Aggregations