Search in sources :

Example 11 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler 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);
}
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 12 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testScriptTaskFEEL.

@Test
public void testScriptTaskFEEL() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ScriptTaskFEEL.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("name", "krisv");
    Person person = new Person();
    person.setName("krisv");
    params.put("person", person);
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("ScriptTask", params);
    assertEquals("Entry", processInstance.getVariable("x"));
    assertNull(processInstance.getVariable("y"));
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
    assertEquals("Exit", getProcessVarValue(processInstance, "y"));
    assertEquals("tester", processInstance.getVariable("surname"));
    assertNodeTriggered(processInstance.getId(), "Script1");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) Person(org.jbpm.bpmn2.objects.Person) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 13 with TestWorkItemHandler

use of io.automatiko.engine.workflow.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 14 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler 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);
}
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 15 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler in project jbpm by kiegroup.

the class ActivityTest method testCallActivityMISequential.

@Test
public void testCallActivityMISequential() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-CallActivityMISequential.bpmn2", "BPMN2-UserTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    final List<Long> subprocessStarted = new ArrayList<Long>();
    ksession.addEventListener(new DefaultProcessEventListener() {

        @Override
        public void beforeProcessStarted(ProcessStartedEvent event) {
            if (event.getProcessInstance().getProcessId().equals("UserTask")) {
                subprocessStarted.add(event.getProcessInstance().getId());
            }
        }
    });
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("list", list);
    params.put("listOut", listOut);
    ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
    List<WorkItem> tasks = workItemHandler.getWorkItems();
    assertEquals("There should be only one task assigned", 1, tasks.size());
    ksession.getWorkItemManager().completeWorkItem(tasks.get(0).getId(), null);
    tasks = workItemHandler.getWorkItems();
    assertEquals("There should be only one task assigned", 1, tasks.size());
    ksession.getWorkItemManager().completeWorkItem(tasks.get(0).getId(), null);
    assertProcessInstanceCompleted(processInstance);
    assertEquals(2, subprocessStarted.size());
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) WorkItem(org.kie.api.runtime.process.WorkItem) KieBase(org.kie.api.KieBase) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)307 HashMap (java.util.HashMap)172 Test (org.junit.Test)154 Test (org.junit.jupiter.api.Test)151 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)149 KieBase (org.kie.api.KieBase)147 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)139 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)108 WorkItem (org.kie.api.runtime.process.WorkItem)103 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)94 ArrayList (java.util.ArrayList)54 KieSession (org.kie.api.runtime.KieSession)43 DefaultKogitoProcessEventListener (org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener)34 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)32 InternalKogitoWorkItem (org.kie.kogito.process.workitems.InternalKogitoWorkItem)25 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener)24 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)23 Person (org.jbpm.bpmn2.objects.Person)21 Disabled (org.junit.jupiter.api.Disabled)20 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)18