Search in sources :

Example 36 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testUserTaskWithSimData.

@Test
public void testUserTaskWithSimData() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSimulationMetaData.bpmn2");
    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("john", workItem.getParameter("ActorId"));
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 37 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testSubProcessInAdHocProcess.

@Test
public void testSubProcessInAdHocProcess() throws Exception {
    // JBPM-5374
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-SubProcessInAdHocProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    Map<String, Object> parameters = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("SubProcessInAdHocProcess", parameters);
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 38 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testCallActivityWithContantsAssignment.

@Test
public void testCallActivityWithContantsAssignment() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("subprocess/SingleTaskWithVarDef.bpmn2", "subprocess/InputMappingUsingValue.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("CustomTask", handler);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("defaultPackage.InputMappingUsingValue", params);
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    Object value = workItem.getParameter("TaskName");
    assertNotNull(value);
    assertEquals("test string", value);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceCompleted(processInstance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 39 with TestWorkItemHandler

use of org.jbpm.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();
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 40 with TestWorkItemHandler

use of org.jbpm.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testAdHocProcessDynamicTask.

@Test
public void testAdHocProcessDynamicTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-AdHocProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ProcessInstance processInstance = ksession.startProcess("AdHocProcess");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
    logger.debug("Triggering node");
    ksession.signalEvent("Task1", null, processInstance.getId());
    assertProcessInstanceActive(processInstance);
    TestWorkItemHandler workItemHandler2 = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("OtherTask", workItemHandler2);
    DynamicUtils.addDynamicWorkItem(processInstance, ksession, "OtherTask", new HashMap<String, Object>());
    WorkItem workItem = workItemHandler2.getWorkItem();
    assertNotNull(workItem);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    ksession.signalEvent("User1", null, processInstance.getId());
    assertProcessInstanceActive(processInstance);
    ksession.insert(new Person());
    ksession.signalEvent("Task3", null, processInstance.getId());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Person(org.jbpm.bpmn2.objects.Person) Test(org.junit.Test)

Aggregations

TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)141 Test (org.junit.Test)138 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)134 KieBase (org.kie.api.KieBase)131 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)96 WorkItem (org.kie.api.runtime.process.WorkItem)91 HashMap (java.util.HashMap)72 KieSession (org.kie.api.runtime.KieSession)37 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)27 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)23 ArrayList (java.util.ArrayList)21 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)14 StartEventTest (org.jbpm.bpmn2.StartEventTest)13 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)10 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)8 Person (org.jbpm.bpmn2.objects.Person)8 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)8 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)8 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)7 CountDownLatch (java.util.concurrent.CountDownLatch)6