use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ActivityTest method testAdHocSubProcessAutoCompleteDynamicSubProcess.
@Test
public void testAdHocSubProcessAutoCompleteDynamicSubProcess() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoComplete.bpmn2", "BPMN2-AdHocSubProcess.drl", "BPMN2-MinimalProcess.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
TestWorkItemHandler workItemHandler2 = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("OtherTask", workItemHandler2);
ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
ksession.fireAllRules();
DynamicNodeInstance dynamicContext = (DynamicNodeInstance) ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next();
DynamicUtils.addDynamicSubProcess(dynamicContext, ksession, "Minimal", new HashMap<String, Object>());
ksession = restoreSession(ksession, true);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
// assertProcessInstanceActive(processInstance.getId(), ksession);
// workItem = workItemHandler2.getWorkItem();
// ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ActivityTest method testAdHocSubProcessAutoComplete.
@Test
public void testAdHocSubProcessAutoComplete() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoComplete.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);
WorkItem workItem = workItemHandler.getWorkItem();
assertNull(workItem);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.fireAllRules();
workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertEquals("Exit", getProcessVarValue(processInstance, "y"));
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ActivityTest method testAdHocSubProcessAutoCompleteDynamicTask.
@Test
public void testAdHocSubProcessAutoCompleteDynamicTask() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoComplete.bpmn2", "BPMN2-AdHocSubProcess.drl");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
TestWorkItemHandler workItemHandler2 = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("OtherTask", workItemHandler2);
ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
DynamicNodeInstance dynamicContext = (DynamicNodeInstance) ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next();
DynamicUtils.addDynamicWorkItem(dynamicContext, ksession, "OtherTask", new HashMap<String, Object>());
WorkItem workItem = workItemHandler.getWorkItem();
assertNull(workItem);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.fireAllRules();
workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
ksession = restoreSession(ksession, true);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceActive(processInstance);
workItem = workItemHandler2.getWorkItem();
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ActivityTest method testUserTaskWithBooleanOutput.
@Test
public void testUserTaskWithBooleanOutput() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithBooleanOutput.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
ProcessInstance processInstance = ksession.startProcess("com.sample.boolean");
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
HashMap<String, Object> output = new HashMap<String, Object>();
output.put("isCheckedCheckbox", "true");
ksession.getWorkItemManager().completeWorkItem(workItem.getId(), output);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class CompensationTest method orderedCompensation.
@Test
public void orderedCompensation() throws Exception {
KieSession ksession = createKnowledgeSession("compensation/BPMN2-Compensation-ParallelOrderedCompensation-IntermediateThrowEvent.bpmn2");
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "");
ProcessInstance processInstance = ksession.startProcess("CompensateParallelOrdered", params);
List<WorkItem> workItems = workItemHandler.getWorkItems();
List<Long> workItemIds = new ArrayList<Long>();
for (WorkItem workItem : workItems) {
if ("Thr".equals(workItem.getParameter("NodeName"))) {
workItemIds.add(workItem.getId());
}
}
for (WorkItem workItem : workItems) {
if ("Two".equals(workItem.getParameter("NodeName"))) {
workItemIds.add(workItem.getId());
}
}
for (WorkItem workItem : workItems) {
if ("One".equals(workItem.getParameter("NodeName"))) {
workItemIds.add(workItem.getId());
}
}
for (Long id : workItemIds) {
ksession.getWorkItemManager().completeWorkItem(id, null);
}
// user task -> script task (associated with compensation) --> intermeidate throw compensation event
String xVal = getProcessVarValue(processInstance, "x");
// Compensation happens in the *REVERSE* order of completion
// Ex: if the order is 3, 17, 282, then compensation should happen in the order of 282, 17, 3
// Compensation did not fire in the same order as the associated activities completed.
Assertions.assertThat(xVal).isEqualTo("_171:_131:_141:_151:");
}
Aggregations