use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessSignalInterrupting.
@Test
public void testEventSubprocessSignalInterrupting() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessSignalInterrupting.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-EventSubprocessSignal");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
ksession.addEventListener(listener);
ksession.signalEvent("MySignal", null, processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), "start", "User Task 1", "Sub Process 1", "start-sub", "Script Task 1", "end-sub");
assertThat(executednodes.size()).isEqualTo(1);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testMessageIntermediateThrowVerifyWorkItemDataDeploymentId.
@Test
public void testMessageIntermediateThrowVerifyWorkItemDataDeploymentId() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateThrowEventMessage.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Send Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "MyValue");
ProcessInstance processInstance = ksession.startProcess("MessageIntermediateEvent", params);
assertProcessInstanceCompleted(processInstance);
WorkItem workItem = handler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem instanceof org.drools.core.process.instance.WorkItem).isTrue();
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();
assertThat(nodeId).isNotNull();
assertThat(nodeId > 0).isTrue();
assertThat(nodeInstanceId).isNotNull();
assertThat(nodeInstanceId > 0).isTrue();
assertThat(deploymentId).isNull();
// now set deployment id as part of ksession's env
ksession.getEnvironment().set("deploymentId", "testDeploymentId");
ksession.startProcess("MessageIntermediateEvent", params);
assertProcessInstanceCompleted(processInstance);
workItem = handler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem instanceof org.drools.core.process.instance.WorkItem).isTrue();
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();
assertThat(nodeId).isNotNull();
assertThat(nodeId > 0).isTrue();
assertThat(nodeInstanceId).isNotNull();
assertThat(nodeInstanceId > 0).isTrue();
assertThat(deploymentId).isNotNull();
assertThat(deploymentId).isEqualTo("testDeploymentId");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testThrowIntermediateSignalWithScope.
@Test
public void testThrowIntermediateSignalWithScope() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2IntermediateThrowEventScope.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = ksession.startProcess("intermediate-event-scope", params);
ProcessInstance processInstance2 = ksession.startProcess("intermediate-event-scope", params);
assertProcessInstanceActive(processInstance);
assertProcessInstanceActive(processInstance2);
assertNodeActive(processInstance.getId(), ksession, "Complete work", "Wait");
assertNodeActive(processInstance2.getId(), ksession, "Complete work", "Wait");
List<WorkItem> items = handler.getWorkItems();
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);
assertProcessInstanceActive(processInstance2);
assertNodeActive(processInstance2.getId(), ksession, "Complete work", "Wait");
wi = items.get(1);
ksession.getWorkItemManager().completeWorkItem(wi.getId(), result);
assertProcessInstanceCompleted(processInstance2);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testTimerBoundaryEventInterruptingOnTaskCancelTimer.
@Test
public void testTimerBoundaryEventInterruptingOnTaskCancelTimer() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-TimerBoundaryEventInterruptingOnTaskCancelTimer.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent");
assertProcessInstanceActive(processInstance);
Collection<TimerInstance> timers = getTimerManager(ksession).getTimers();
assertThat(timers.size()).isEqualTo(1);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
timers = getTimerManager(ksession).getTimers();
assertThat(timers.size()).isEqualTo(1);
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
timers = getTimerManager(ksession).getTimers();
assertThat(timers).isNullOrEmpty();
WorkItem workItem = handler.getWorkItem();
if (workItem != null) {
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
}
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class IntermediateEventTest method testTimerBoundaryEventInterruptingOnTask.
@Test(timeout = 10000)
public void testTimerBoundaryEventInterruptingOnTask() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 1);
KieBase kbase = createKnowledgeBase("BPMN2-TimerBoundaryEventInterruptingOnTask.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new TestWorkItemHandler());
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent");
assertProcessInstanceActive(processInstance);
countDownListener.waitTillCompleted();
ksession = restoreSession(ksession, true);
logger.debug("Firing timer");
assertProcessInstanceFinished(processInstance, ksession);
}
Aggregations