use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class IntermediateEventTest method runTestEventSubprocessSignal.
public void runTestEventSubprocessSignal(String processFile, String[] completedNodes) throws Exception {
KieBase kbase = createKnowledgeBase(processFile);
final List<Long> executednodes = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("sub-script")) {
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());
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
ksession.signalEvent("MySignal", null);
assertProcessInstanceActive(processInstance);
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
assertNodeTriggered(processInstance.getId(), completedNodes);
assertThat(executednodes.size()).isEqualTo(4);
}
use of org.kie.api.runtime.process.WorkItem 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.WorkItem in project jbpm by kiegroup.
the class IntermediateEventTest method testEventSubprocessTimer.
@Test(timeout = 10000)
public void testEventSubprocessTimer() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Script Task 1", 1);
KieBase kbase = createKnowledgeBase("BPMN2-EventSubprocessTimer.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("BPMN2-EventSubprocessTimer");
assertProcessInstanceActive(processInstance);
countDownListener.waitTillCompleted();
WorkItem workItem = workItemHandler.getWorkItem();
assertThat(workItem).isNotNull();
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");
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class IntermediateEventTest method testEventBasedSplitWithCronTimerAndSignal.
@Test(timeout = 10000)
public void testEventBasedSplitWithCronTimerAndSignal() throws Exception {
System.setProperty("jbpm.enable.multi.con", "true");
try {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Request photos of order in use", 1);
NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("Request an online review", 1);
NodeLeftCountDownProcessEventListener countDownListener3 = new NodeLeftCountDownProcessEventListener("Send a thank you card", 1);
NodeLeftCountDownProcessEventListener countDownListener4 = new NodeLeftCountDownProcessEventListener("Request an online review", 1);
KieBase kbase = createKnowledgeBase("timer/BPMN2-CronTimerWithEventBasedGateway.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ksession.addEventListener(countDownListener);
ksession.addEventListener(countDownListener2);
ksession.addEventListener(countDownListener3);
ksession.addEventListener(countDownListener4);
ProcessInstance processInstance = ksession.startProcess("timerWithEventBasedGateway");
assertProcessInstanceActive(processInstance.getId(), ksession);
countDownListener.waitTillCompleted();
logger.debug("First timer triggered");
countDownListener2.waitTillCompleted();
logger.debug("Second timer triggered");
countDownListener3.waitTillCompleted();
logger.debug("Third timer triggered");
countDownListener4.waitTillCompleted();
logger.debug("Fourth timer triggered");
List<WorkItem> wi = handler.getWorkItems();
assertThat(wi).isNotNull();
assertThat(wi.size()).isEqualTo(3);
ksession.abortProcessInstance(processInstance.getId());
} finally {
// clear property only as the only relevant value is when it's set to true
System.clearProperty("jbpm.enable.multi.con");
}
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class SLAComplianceTest method testSLAonUserTaskMet.
@Test
public void testSLAonUserTaskMet() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLAOnTask.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
processInstance = ksession.getProcessInstance(processInstance.getId());
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
Collection<NodeInstance> active = ((WorkflowProcessInstance) processInstance).getNodeInstances();
assertEquals(1, active.size());
NodeInstance userTaskNode = active.iterator().next();
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
assertEquals(ProcessInstance.SLA_NA, slaCompliance);
slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode);
assertEquals(ProcessInstance.SLA_MET, slaCompliance);
ksession.dispose();
}
Aggregations