Search in sources :

Example 71 with WorkItem

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);
}
Also used : HashMap(java.util.HashMap) IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) JbpmJUnitBaseTestCase(org.jbpm.test.JbpmJUnitBaseTestCase) KieSession(org.kie.api.runtime.KieSession) Person(org.jbpm.test.domain.Person) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 72 with WorkItem

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"));
}
Also used : TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 73 with WorkItem

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");
}
Also used : TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 74 with WorkItem

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);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) WorkItem(org.kie.api.runtime.process.WorkItem) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 75 with WorkItem

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);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) WorkItem(org.kie.api.runtime.process.WorkItem) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

WorkItem (org.kie.api.runtime.process.WorkItem)174 Test (org.junit.Test)139 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)127 KieBase (org.kie.api.KieBase)110 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)91 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)87 HashMap (java.util.HashMap)72 KieSession (org.kie.api.runtime.KieSession)48 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)33 ArrayList (java.util.ArrayList)29 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)27 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)26 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)22 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)20 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)14 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)13 Map (java.util.Map)11 StringReader (java.io.StringReader)10 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)10