use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class DataObjectTest method testDataObject.
/**
* DataObject is linked via association with Human Task. Work item should
* obtain this DataObject in parameters.
*/
@Test(timeout = 30000)
public void testDataObject() {
KieSession ksession = createKSession(PROCESS);
IterableProcessEventListener listener = new IterableProcessEventListener();
ksession.addEventListener(listener);
Map<String, Object> params = new HashMap<String, Object>();
Person mojmir = new Person("Mojmir");
params.put("person", mojmir);
JbpmJUnitBaseTestCase.TestWorkItemHandler wih = getTestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", wih);
StartProcessCommand spc = new StartProcessCommand();
spc.setProcessId(PROCESS_ID);
spc.setParameters(params);
ksession.execute(spc);
assertChangedVariable(listener, "person", null, mojmir);
assertProcessStarted(listener, PROCESS_ID);
assertNextNode(listener, "start");
assertTriggered(listener, "userTask");
WorkItem wi = wih.getWorkItem();
assertTrue(wi.getParameters().containsKey("PersonInput"));
Object param = wi.getParameter("PersonInput");
assertTrue(param instanceof Person);
Person userTaskInput = (Person) param;
assertEquals("Mojmir", userTaskInput.getName());
listener.clear();
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
assertLeft(listener, "userTask");
assertNextNode(listener, "end");
assertProcessCompleted(listener, PROCESS_ID);
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class FlexibleProcessTest method testFlexibleProcess.
/**
* Flexible process with four fragments. -default - with start node, without
* end event -two fragments which will be signaled -one fragment which won't
* be signaled - it should not be executed
*/
@Ignore
@Test(timeout = 30000)
public void testFlexibleProcess() throws Exception {
KieSession ksession = createKSession(PROCESS);
TrackingProcessEventListener tpel = new TrackingProcessEventListener();
ksession.addEventListener(tpel);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
ProcessInstance pi = ksession.startProcess(PROCESS_ID);
assertProcessStarted(tpel, PROCESS_ID);
assertTriggeredAndLeft(tpel, "start");
assertTriggered(tpel, "task1");
ksession.signalEvent("userTask", null, pi.getId());
assertTriggered(tpel, "userTask");
ksession = restoreKSession(PROCESS);
Assertions.assertThat(ksession.getProcessEventListeners()).isNotEmpty();
WorkItem item = handler.getWorkItem();
ksession.getWorkItemManager().completeWorkItem(item.getId(), null);
assertTriggered(tpel, "userTask2");
ksession.signalEvent("task21", null, pi.getId());
assertTriggeredAndLeft(tpel, "task21");
assertTriggeredAndLeft(tpel, "task22");
assertTriggeredAndLeft(tpel, "end1");
assertProcessCompleted(tpel, PROCESS_ID);
assertFalse(tpel.wasNodeTriggered("task3"));
assertFalse(tpel.wasNodeTriggered("end2"));
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class FlexibleProcessTest method testFlexibleProcessAddWorkItem.
/**
* Tests dynamic insertion of work item node into adhoc top-level process.
* DynamicUtils does not support adhoc processes yet, but there is improved
* version on jbpm master branch.
*/
@Test(timeout = 30000)
public void testFlexibleProcessAddWorkItem() {
KieSession ksession = createKSession(PROCESS);
TrackingProcessEventListener tpel = new TrackingProcessEventListener();
ksession.addEventListener(tpel);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("addedWorkItem", handler);
ProcessInstance pi = ksession.startProcess(PROCESS_ID);
assertProcessStarted(tpel, PROCESS_ID);
DynamicUtils.addDynamicWorkItem(pi, ksession, "addedWorkItem", Collections.<String, Object>emptyMap());
WorkItem wi = handler.getWorkItem();
ksession.getWorkItemManager().completeWorkItem(wi.getId(), new java.util.HashMap<String, Object>());
assertEquals(wi.getName(), "addedWorkItem");
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessServiceImplWithDeploymentIdTest method testStartProcessAndGetWorkItem.
@Test
public void testStartProcessAndGetWorkItem() {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
assertTrue(isDeployed);
assertNotNull(processService);
long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
assertNotNull(pi);
Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Write a Document", activeNodes.iterator().next().getName());
WorkItem wi = processService.getWorkItem(deploymentUnit.getIdentifier(), processInstanceId, activeNodes.iterator().next().getWorkItemId());
assertNotNull(wi);
assertEquals("Human Task", wi.getName());
assertEquals("Write a Document", wi.getParameter("NodeName"));
processService.abortProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), processInstanceId);
assertNull(pi);
}
use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.
the class ProcessServiceImplTest method testStartProcessAndGetWorkItems.
@Test
public void testStartProcessAndGetWorkItems() {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
assertTrue(isDeployed);
assertNotNull(processService);
long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance pi = processService.getProcessInstance(processInstanceId);
assertNotNull(pi);
Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Write a Document", activeNodes.iterator().next().getName());
List<WorkItem> wis = processService.getWorkItemByProcessInstance(processInstanceId);
assertNotNull(wis);
assertEquals(1, wis.size());
assertEquals("Human Task", wis.get(0).getName());
assertEquals("Write a Document", wis.get(0).getParameter("NodeName"));
processService.abortProcessInstance(processInstanceId);
pi = processService.getProcessInstance(processInstanceId);
assertNull(pi);
}
Aggregations