use of org.kie.api.runtime.process.WorkItem 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.kie.api.runtime.process.WorkItem 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.kie.api.runtime.process.WorkItem 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.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class OneProcessPerThreadTest method testMultiThreadProcessInstanceWorkItem.
@Test
public void testMultiThreadProcessInstanceWorkItem() throws Exception {
final ConcurrentHashMap<Long, Long> workItems = new ConcurrentHashMap<Long, Long>();
try {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("BPMN2-MultiThreadServiceProcess.bpmn"), ResourceType.BPMN2);
KieBase kbase = kbuilder.newKieBase();
KieSession ksession = createStatefulKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Log", new WorkItemHandler() {
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
Long threadId = (Long) workItem.getParameter("id");
workItems.put(workItem.getProcessInstanceId(), threadId);
}
public void abortWorkItem(WorkItem arg0, WorkItemManager arg1) {
}
});
startThreads(ksession);
assertEquals(THREAD_COUNT, workItems.size());
} catch (Throwable t) {
t.printStackTrace();
fail("Should not raise any exception: " + t.getMessage());
}
int i = 0;
while (started.get() > done.get()) {
logger.info("{} > {}", started, done);
Thread.sleep(10 * 1000);
if (++i > 10) {
fail("Not all threads completed.");
}
}
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class HumanTaskHandler method select.
private void select() {
WorkItem workItem = getSelectedWorkItem();
if (workItem != null) {
HumanTaskDialog dialog = new HumanTaskDialog(HumanTaskHandler.this, workItem);
dialog.setVisible(true);
}
}
Aggregations