use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method compensationViaIntermediateThrowEventProcess.
/**
* TESTS
*/
@Test
public void compensationViaIntermediateThrowEventProcess() throws Exception {
KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-IntermediateThrowEvent.bpmn2");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "0");
ProcessInstance processInstance = ksession.startProcess("CompensateIntermediateThrowEvent", params);
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItem().getId(), null);
// compensation activity (assoc. with script task) signaled *after* script task
assertProcessInstanceCompleted(processInstance.getId(), ksession);
assertProcessVarValue(processInstance, "x", "1");
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class StandaloneBPMNProcessTest method testAdHocSubProcess.
@Test
@Ignore("Process does not complete.")
public void testAdHocSubProcess() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-AdHocSubProcess.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNull();
ksession = restoreSession(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.fireAllRules();
ksession.signalEvent("Hello2", null, processInstance.getId());
workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
ksession = restoreSession(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class StartEventTest method testMultipleEventBasedStartEventsSignalStart.
@Test
public void testMultipleEventBasedStartEventsSignalStart() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MultipleEventBasedStartEventProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
ksession.signalEvent("startSignal", null);
assertThat(list.size()).isEqualTo(1);
WorkItem workItem = workItemHandler.getWorkItem();
long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
ksession = restoreSession(ksession, true);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class StartEventTest method testMultipleStartEventsRegularStart.
@Test
public void testMultipleStartEventsRegularStart() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MultipleStartEventProcessLongInterval.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("MultipleStartEvents");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class StartEventTest method testSignalToStartProcess.
@Test
public void testSignalToStartProcess() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2", "BPMN2-IntermediateThrowEventSignal.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
final List<String> startedProcesses = new ArrayList<String>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
startedProcesses.add(event.getProcessInstance().getProcessId());
}
});
ProcessInstance processInstance = ksession.startProcess("SignalIntermediateEvent");
assertProcessInstanceFinished(processInstance, ksession);
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1);
assertThat(getNumberOfProcessInstances("SignalIntermediateEvent")).isEqualTo(1);
}
Aggregations