Search in sources :

Example 66 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method testAdHocSubProcess.

@Test
@Ignore("Process does not complete.")
public void testAdHocSubProcess() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-AdHocSubProcess.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("AdHocSubProcess");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNull();
    ksession = restoreSession(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.fireAllRules();
    ksession.signalEvent("Hello2", null, processInstance.getId());
    workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession = restoreSession(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 67 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class StartEventTest method testMultipleEventBasedStartEventsSignalStart.

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

        public void afterProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
        }
    });
    ksession.signalEvent("startSignal", null);
    assertThat(list.size()).isEqualTo(1);
    WorkItem workItem = workItemHandler.getWorkItem();
    long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    ksession = restoreSession(ksession, true);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 68 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class StartEventTest method testMultipleStartEventsRegularStart.

@Test
public void testMultipleStartEventsRegularStart() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-MultipleStartEventProcessLongInterval.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    ProcessInstance processInstance = ksession.startProcess("MultipleStartEvents");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameter("ActorId")).isEqualTo("john");
    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) WorkItem(org.kie.api.runtime.process.WorkItem) Test(org.junit.Test)

Example 69 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class OneProcessPerThreadTest method testMultiThreadProcessInstanceWorkItem.

@Test
public void testMultiThreadProcessInstanceWorkItem() throws Exception {
    final ConcurrentHashMap<Long, Long> workItems = new ConcurrentHashMap<Long, Long>();
    try {
        final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kbuilder.add(ResourceFactory.newClassPathResource("BPMN2-MultiThreadServiceProcess.bpmn"), ResourceType.BPMN2);
        KieBase kbase = kbuilder.newKieBase();
        KieSession ksession = createStatefulKnowledgeSession(kbase);
        ksession.getWorkItemManager().registerWorkItemHandler("Log", new WorkItemHandler() {

            public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
                Long threadId = (Long) workItem.getParameter("id");
                workItems.put(workItem.getProcessInstanceId(), threadId);
            }

            public void abortWorkItem(WorkItem arg0, WorkItemManager arg1) {
            }
        });
        startThreads(ksession);
        assertEquals(THREAD_COUNT, workItems.size());
    } catch (Throwable t) {
        t.printStackTrace();
        fail("Should not raise any exception: " + t.getMessage());
    }
    int i = 0;
    while (started.get() > done.get()) {
        logger.info("{} > {}", started, done);
        Thread.sleep(10 * 1000);
        if (++i > 10) {
            fail("Not all threads completed.");
        }
    }
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 70 with WorkItem

use of org.kie.api.runtime.process.WorkItem in project jbpm by kiegroup.

the class HumanTaskHandler method select.

private void select() {
    WorkItem workItem = getSelectedWorkItem();
    if (workItem != null) {
        HumanTaskDialog dialog = new HumanTaskDialog(HumanTaskHandler.this, workItem);
        dialog.setVisible(true);
    }
}
Also used : WorkItem(org.kie.api.runtime.process.WorkItem)

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