Search in sources :

Example 1 with ReceiveTaskHandler

use of org.jbpm.bpmn2.handler.ReceiveTaskHandler in project jbpm by kiegroup.

the class IntermediateEventTest method testEventBasedSplit5.

@Test
public void testEventBasedSplit5() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit5.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ReceiveTaskHandler receiveTaskHandler = new ReceiveTaskHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    // Yes
    ProcessInstance processInstance = ksession.startProcess("com.sample.test");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    receiveTaskHandler.setKnowledgeRuntime(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    receiveTaskHandler.messageReceived("YesMessage", "YesValue");
    assertProcessInstanceFinished(processInstance, ksession);
    receiveTaskHandler.messageReceived("NoMessage", "NoValue");
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    receiveTaskHandler.setKnowledgeRuntime(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    // No
    processInstance = ksession.startProcess("com.sample.test");
    receiveTaskHandler.messageReceived("NoMessage", "NoValue");
    assertProcessInstanceFinished(processInstance, ksession);
    receiveTaskHandler.messageReceived("YesMessage", "YesValue");
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ReceiveTaskHandler(org.jbpm.bpmn2.handler.ReceiveTaskHandler) Test(org.junit.Test)

Example 2 with ReceiveTaskHandler

use of org.jbpm.bpmn2.handler.ReceiveTaskHandler in project jbpm by kiegroup.

the class ActivityTest method testReceiveTask.

@Test
public void testReceiveTask() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-ReceiveTask.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ReceiveTaskHandler receiveTaskHandler = new ReceiveTaskHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("ReceiveTask");
    assertProcessInstanceActive(processInstance);
    ksession = restoreSession(ksession, true);
    receiveTaskHandler.setKnowledgeRuntime(ksession);
    receiveTaskHandler.messageReceived("HelloMessage", "Hello john!");
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : KieBase(org.kie.api.KieBase) ReceiveTaskHandler(org.jbpm.bpmn2.handler.ReceiveTaskHandler) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 3 with ReceiveTaskHandler

use of org.jbpm.bpmn2.handler.ReceiveTaskHandler in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method testReceiveTask.

@Test
public void testReceiveTask() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-ReceiveTask.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ReceiveTaskHandler receiveTaskHandler = new ReceiveTaskHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("ReceiveTask");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession);
    receiveTaskHandler.messageReceived("HelloMessage", "Hello john!");
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
Also used : KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) ReceiveTaskHandler(org.jbpm.bpmn2.handler.ReceiveTaskHandler) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Test(org.junit.Test)

Example 4 with ReceiveTaskHandler

use of org.jbpm.bpmn2.handler.ReceiveTaskHandler in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method testEventBasedSplit5.

@Test
public void testEventBasedSplit5() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit5.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    ReceiveTaskHandler receiveTaskHandler = new ReceiveTaskHandler(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    // Yes
    ProcessInstance processInstance = ksession.startProcess("com.sample.test");
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    receiveTaskHandler.setKnowledgeRuntime(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    receiveTaskHandler.messageReceived("YesMessage", "YesValue");
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    receiveTaskHandler.messageReceived("NoMessage", "NoValue");
    ksession = restoreSession(ksession, true);
    ksession.getWorkItemManager().registerWorkItemHandler("Email1", new SystemOutWorkItemHandler());
    ksession.getWorkItemManager().registerWorkItemHandler("Email2", new SystemOutWorkItemHandler());
    receiveTaskHandler.setKnowledgeRuntime(ksession);
    ksession.getWorkItemManager().registerWorkItemHandler("Receive Task", receiveTaskHandler);
    // No
    processInstance = ksession.startProcess("com.sample.test");
    receiveTaskHandler.messageReceived("NoMessage", "NoValue");
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    receiveTaskHandler.messageReceived("YesMessage", "YesValue");
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ReceiveTaskHandler(org.jbpm.bpmn2.handler.ReceiveTaskHandler) Test(org.junit.Test)

Aggregations

ReceiveTaskHandler (org.jbpm.bpmn2.handler.ReceiveTaskHandler)4 Test (org.junit.Test)4 KieBase (org.kie.api.KieBase)4 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)4 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 KieSession (org.kie.api.runtime.KieSession)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2