Search in sources :

Example 16 with TestWorkItemHandler

use of io.automatiko.engine.workflow.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)

Example 17 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler 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();
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) InitialContext(javax.naming.InitialContext) Context(org.kie.api.runtime.Context) RegistryContext(org.kie.internal.command.RegistryContext) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) WorkItem(org.kie.api.runtime.process.WorkItem) 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) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) Test(org.junit.Test)

Example 18 with TestWorkItemHandler

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

the class ActivityTest method testAdHocSubProcessAutoComplete.

@Test
public void testAdHocSubProcessAutoComplete() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoComplete.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);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNull(workItem);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.fireAllRules();
    workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertEquals("Exit", getProcessVarValue(processInstance, "y"));
    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 19 with TestWorkItemHandler

use of io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler 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());
}
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) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 20 with TestWorkItemHandler

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

the class ActivityTest method testAdHocSubProcessAutoCompleteDynamicSubProcess.

@Test
public void testAdHocSubProcessAutoCompleteDynamicSubProcess() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-AdHocSubProcessAutoComplete.bpmn2", "BPMN2-AdHocSubProcess.drl", "BPMN2-MinimalProcess.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    TestWorkItemHandler workItemHandler2 = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("OtherTask", workItemHandler2);
    ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    ksession.fireAllRules();
    DynamicNodeInstance dynamicContext = (DynamicNodeInstance) ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next();
    DynamicUtils.addDynamicSubProcess(dynamicContext, ksession, "Minimal", new HashMap<String, Object>());
    ksession = restoreSession(ksession, true);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    // assertProcessInstanceActive(processInstance.getId(), ksession);
    // workItem = workItemHandler2.getWorkItem();
    // ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) 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)

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