Search in sources :

Example 1 with WorkItemHandler

use of org.drools.core.process.instance.WorkItemHandler in project jbpm by kiegroup.

the class IntermediateEventTest method testThrowIntermediateSignalWithExternalScope.

@Test
public void testThrowIntermediateSignalWithExternalScope() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateThrowEventExternalScope.bpmn2");
    ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    WorkItemHandler externalHandler = new WorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            String signal = (String) workItem.getParameter("Signal");
            ksession.signalEvent(signal, null);
            manager.completeWorkItem(workItem.getId(), null);
        }

        @Override
        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
        }
    };
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ksession.getWorkItemManager().registerWorkItemHandler("External Send Task", externalHandler);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = ksession.startProcess("intermediate-event-scope", params);
    assertProcessInstanceActive(processInstance);
    assertNodeActive(processInstance.getId(), ksession, "Complete work", "Wait");
    List<WorkItem> items = handler.getWorkItems();
    assertThat(items.size()).isEqualTo(1);
    WorkItem wi = items.get(0);
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("_output", "sending event");
    ksession.getWorkItemManager().completeWorkItem(wi.getId(), result);
    assertProcessInstanceCompleted(processInstance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) WorkItemHandler(org.drools.core.process.instance.WorkItemHandler) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) 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) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 WorkItemHandler (org.drools.core.process.instance.WorkItemHandler)1 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)1 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)1 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkItem (org.kie.api.runtime.process.WorkItem)1 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1