use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class FlowTest method testMultiInstanceLoopCharacteristicsProcess2.
@Test
public void testMultiInstanceLoopCharacteristicsProcess2() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultiInstanceProcessWithOutputOnTask.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
List<String> myList = new ArrayList<String>();
List<String> myOutList = null;
myList.add("John");
myList.add("Mary");
params.put("miinput", myList);
ProcessInstance processInstance = ksession.startProcess("miprocess", params);
List<WorkItem> workItems = handler.getWorkItems();
assertNotNull(workItems);
assertEquals(2, workItems.size());
myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput"));
assertNull(myOutList);
Map<String, Object> results = new HashMap<String, Object>();
results.put("reply", "Hello John");
ksession.getWorkItemManager().completeWorkItem(workItems.get(0).getId(), results);
myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput"));
assertNull(myOutList);
results = new HashMap<String, Object>();
results.put("reply", "Hello Mary");
ksession.getWorkItemManager().completeWorkItem(workItems.get(1).getId(), results);
myOutList = (List<String>) ksession.execute(new GetProcessVariableCommand(processInstance.getId(), "mioutput"));
assertNotNull(myOutList);
assertEquals(2, myOutList.size());
assertTrue(myOutList.contains("Hello John"));
assertTrue(myOutList.contains("Hello Mary"));
ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ActivityTest method testUserTaskVerifyParameters.
@Test
public void testUserTaskVerifyParameters() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-UserTask.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
ksession.getEnvironment().set("deploymentId", "test-deployment-id");
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);
final WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
final long pId = processInstance.getId();
ksession.execute(new ExecutableCommand<Void>() {
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance processInstance = ksession.getProcessInstance(pId);
assertNotNull(processInstance);
NodeInstance nodeInstance = ((WorkflowProcessInstance) processInstance).getNodeInstance(((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId());
assertNotNull(nodeInstance);
assertTrue(nodeInstance instanceof WorkItemNodeInstance);
String deploymentId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getDeploymentId();
long nodeInstanceId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeInstanceId();
long nodeId = ((WorkItemNodeInstance) nodeInstance).getWorkItem().getNodeId();
assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId(), deploymentId);
assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getNodeId(), nodeId);
assertEquals(((org.drools.core.process.instance.WorkItem) workItem).getNodeInstanceId(), nodeInstanceId);
return null;
}
});
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 testCallActivitySkipAbortParent.
@Test
@RequirePersistence
public void testCallActivitySkipAbortParent() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-CallActivitySkipAbortParent.bpmn2", "BPMN2-UserTask.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "oldValue");
ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
long childPI = workItem.getProcessInstanceId();
assertNotEquals("Child process instance must be different", processInstance.getId(), childPI);
ksession.abortProcessInstance(childPI);
assertProcessInstanceFinished(processInstance, ksession);
ProcessInstanceLog log = logService.findProcessInstance(childPI);
assertNotNull(log);
assertEquals(ProcessInstance.STATE_ABORTED, log.getStatus().intValue());
// parent process instance should not be aborted
log = logService.findProcessInstance(processInstance.getId());
assertNotNull(log);
assertEquals("Parent process should be completed and not aborted", ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
}
use of org.kie.api.runtime.process.WorkItem 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 org.kie.api.runtime.process.WorkItem 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);
}
Aggregations