use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ActivityTest method testAdHocSubProcessAutoCompleteExpression.
@Test
public void testAdHocSubProcessAutoCompleteExpression() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoCompleteExpression.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("counter", new Integer(2));
ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess", params);
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
WorkItem workItem = workItemHandler.getWorkItem();
assertNull(workItem);
ksession.signalEvent("Hello1", null, processInstance.getId());
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
Map<String, Object> results = new HashMap<String, Object>();
results.put("testHT", new Integer(1));
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), results);
assertProcessInstanceActive(processInstance.getId(), ksession);
ksession.signalEvent("Hello1", null, processInstance.getId());
workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
results = new HashMap<String, Object>();
results.put("testHT", new Integer(0));
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), results);
assertProcessInstanceFinished(processInstance, ksession);
}
use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ActivityTest method testScriptTaskFEEL.
@Test
public void testScriptTaskFEEL() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ScriptTaskFEEL.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("name", "krisv");
Person person = new Person();
person.setName("krisv");
params.put("person", person);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("ScriptTask", params);
assertEquals("Entry", processInstance.getVariable("x"));
assertNull(processInstance.getVariable("y"));
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertEquals("Exit", getProcessVarValue(processInstance, "y"));
assertEquals("tester", processInstance.getVariable("surname"));
assertNodeTriggered(processInstance.getId(), "Script1");
}
use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ActivityTest method testUserTaskParametrizedInput.
@Test
public void testUserTaskParametrizedInput() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithParametrizedInput.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);
ksession = restoreSession(ksession, true);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("Executing task of process instance " + processInstance.getId() + " as work item with Hello", workItem.getParameter("Description").toString().trim());
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ActivityTest method testAdHocSubProcess.
@Test
public void testAdHocSubProcess() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcess.bpmn2", "BPMN2-AdHocSubProcess.drl");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
assertEquals("Entry", ((WorkflowProcessInstance) processInstance).getVariable("x"));
WorkItem workItem = workItemHandler.getWorkItem();
assertNull(workItem);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.fireAllRules();
logger.debug("Signaling Hello2");
ksession.signalEvent("Hello2", null, processInstance.getId());
workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
}
use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.
the class ActivityTest method testCallActivityMISequential.
@Test
public void testCallActivityMISequential() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityMISequential.bpmn2", "BPMN2-UserTask.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
final List<Long> subprocessStarted = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
if (event.getProcessInstance().getProcessId().equals("UserTask")) {
subprocessStarted.add(event.getProcessInstance().getId());
}
}
});
List<String> list = new ArrayList<String>();
list.add("first");
list.add("second");
List<String> listOut = new ArrayList<String>();
Map<String, Object> params = new HashMap<String, Object>();
params.put("list", list);
params.put("listOut", listOut);
ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
List<WorkItem> tasks = workItemHandler.getWorkItems();
assertEquals("There should be only one task assigned", 1, tasks.size());
ksession.getWorkItemManager().completeWorkItem(tasks.get(0).getId(), null);
tasks = workItemHandler.getWorkItems();
assertEquals("There should be only one task assigned", 1, tasks.size());
ksession.getWorkItemManager().completeWorkItem(tasks.get(0).getId(), null);
assertProcessInstanceCompleted(processInstance);
assertEquals(2, subprocessStarted.size());
}
Aggregations