use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class EndEventTest method testMessageEndVerifyDeploymentId.
@Test
public void testMessageEndVerifyDeploymentId() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MessageEndEvent.bpmn2");
TestWorkItemHandler handler = new TestWorkItemHandler();
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Send Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "MyValue");
ProcessInstance processInstance = ksession.startProcess("MessageEndEvent", params);
assertProcessInstanceCompleted(processInstance);
WorkItem workItem = handler.getWorkItem();
assertNotNull(workItem);
assertTrue(workItem instanceof org.drools.core.process.instance.WorkItem);
long nodeInstanceId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId();
long nodeId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeId();
String deploymentId = ((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId();
assertNotNull(nodeId);
assertTrue(nodeId > 0);
assertNotNull(nodeInstanceId);
assertTrue(nodeInstanceId > 0);
assertNull(deploymentId);
// now set deployment id as part of ksession's env
ksession.getEnvironment().set("deploymentId", "testDeploymentId");
processInstance = ksession.startProcess("MessageEndEvent", params);
assertProcessInstanceCompleted(processInstance);
workItem = handler.getWorkItem();
assertNotNull(workItem);
assertTrue(workItem instanceof org.drools.core.process.instance.WorkItem);
nodeInstanceId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId();
nodeId = ((org.drools.core.process.instance.WorkItem) workItem).getNodeId();
deploymentId = ((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId();
assertNotNull(nodeId);
assertTrue(nodeId > 0);
assertNotNull(nodeInstanceId);
assertTrue(nodeInstanceId > 0);
assertNotNull(deploymentId);
assertEquals("testDeploymentId", deploymentId);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ErrorEventTest method testErrorBoundaryEventOnTask.
@Test
public void testErrorBoundaryEventOnTask() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnTask.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnTask");
List<WorkItem> workItems = handler.getWorkItems();
assertEquals(2, workItems.size());
WorkItem workItem = workItems.get(0);
if (!"john".equalsIgnoreCase((String) workItem.getParameter("ActorId"))) {
workItem = workItems.get(1);
}
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertProcessInstanceAborted(processInstance);
assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "User task error attached", "error end event");
assertNotNodeTriggered(processInstance.getId(), "Script Task", "error1", "error2");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ErrorEventTest method testEventSubprocessError.
@Test
public void testEventSubprocessError() 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);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessError");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "end", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertEquals(1, executednodes.size());
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ErrorEventTest method testErrorBoundaryEventOnEntry.
@Test
public void testErrorBoundaryEventOnEntry() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-BoundaryErrorEventCatchingOnEntryException.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("BoundaryErrorEventOnEntry");
assertProcessInstanceActive(processInstance.getId(), ksession);
assertEquals(1, handler.getWorkItems().size());
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ErrorEventTest method testErrorBoundaryEventOnServiceTask.
@Test
public void testErrorBoundaryEventOnServiceTask() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ErrorBoundaryEventOnServiceTask.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());
Map<String, Object> params = new HashMap<String, Object>();
params.put("s", "test");
ProcessInstance processInstance = ksession.startProcess("BPMN2-ErrorBoundaryEventOnServiceTask", params);
List<WorkItem> workItems = handler.getWorkItems();
assertEquals(1, workItems.size());
ksession.getWorkItemManager().completeWorkItem(workItems.get(0).getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "split", "User Task", "Service task error attached", "end0", "Script Task", "error2");
assertNotNodeTriggered(processInstance.getId(), "end");
}
Aggregations