Search in sources :

Example 41 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class TransactionsTest method testRuleflowGroup.

@Test(timeout = 60000)
public void testRuleflowGroup() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener(false);
    TrackingAgendaEventListener agenda = new TrackingAgendaEventListener();
    ksession.addEventListener(process);
    ksession.addEventListener(agenda);
    long processId = startProcess(ksession);
    UserTransaction ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "rfg", processId);
        Assertions.assertThat(process.wasNodeLeft("rfg")).isTrue();
    } finally {
        ut.rollback();
    }
    Thread.sleep(600);
    process.clear();
    agenda.clear();
    ksession = restoreKSession(resources);
    ksession.addEventListener(process);
    ksession.addEventListener(agenda);
    ksession.fireAllRules();
    Assertions.assertThat(agenda.isRuleFired("dummyRule")).isFalse();
    agenda.clear();
    process.clear();
    String ruleFlowGroupNodeName = "rfg";
    ut = getUserTransaction();
    try {
        ut.begin();
        ksession.signalEvent("start", "rfg", processId);
        assertTrue("Node '" + ruleFlowGroupNodeName + "' was not left on time!", process.waitForNodeToBeLeft(ruleFlowGroupNodeName, 1000));
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    Assertions.assertThat(process.wasNodeLeft(ruleFlowGroupNodeName)).isTrue();
    ksession.signalEvent("finish", null, processId);
    ksession.fireAllRules();
    assertTrue("Process did not complete on time!", process.waitForProcessToComplete(1000));
    Assertions.assertThat(agenda.isRuleFired("dummyRule")).isTrue();
    assertProcessInstanceCompleted(processId);
}
Also used : UserTransaction(javax.transaction.UserTransaction) TrackingAgendaEventListener(org.jbpm.test.listener.TrackingAgendaEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) Test(org.junit.Test)

Example 42 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class EndEventTest method testEscalationEndEvent.

@BZ("1015221")
@Test(timeout = 30000)
public void testEscalationEndEvent() {
    KieSession ksession = createKSession(ESCALATION);
    IterableProcessEventListener events = new IterableProcessEventListener();
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(events);
    ksession.addEventListener(process);
    Command<?> cmd = getCommands().newStartProcess(ESCALATION_ID);
    ksession.execute(cmd);
    Assertions.assertThat(process.wasProcessStarted(ESCALATION_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(ESCALATION_ID)).isFalse();
    Assertions.assertThat(process.wasProcessAborted(ESCALATION_ID)).isTrue();
    assertProcessStarted(events, ESCALATION_ID);
    assertNextNode(events, "start");
    assertNextNode(events, "script");
    assertTriggered(events, "end");
    assertProcessCompleted(events, ESCALATION_ID);
    assertFalse(events.hasNext());
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) BZ(qa.tools.ikeeper.annotation.BZ)

Example 43 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class EndEventTest method testErrorEndEvent.

@Test(timeout = 30000)
public void testErrorEndEvent() {
    KieSession ksession = createKSession(ERROR);
    IterableProcessEventListener events = new IterableProcessEventListener();
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(events);
    ksession.addEventListener(process);
    Command<?> cmd = getCommands().newStartProcess(ERROR_ID);
    ksession.execute(cmd);
    Assertions.assertThat(process.wasProcessStarted(ERROR_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(ERROR_ID)).isFalse();
    Assertions.assertThat(process.wasProcessAborted(ERROR_ID)).isTrue();
    assertProcessStarted(events, ERROR_ID);
    assertNextNode(events, "start");
    assertNextNode(events, "script");
    assertTriggered(events, "end");
    assertProcessCompleted(events, ERROR_ID);
    Assertions.assertThat(events.hasNext()).isFalse();
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 44 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class EndEventTest method testTerminatingEndEvent.

@Test(timeout = 30000)
public void testTerminatingEndEvent() {
    KieSession ksession = createKSession(TERMINATING);
    IterableProcessEventListener events = new IterableProcessEventListener();
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(events);
    ksession.addEventListener(process);
    Command<?> cmd = getCommands().newStartProcess(TERMINATING_ID);
    ksession.execute(cmd);
    Assertions.assertThat(process.wasProcessStarted(TERMINATING_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(TERMINATING_ID)).isTrue();
    assertProcessStarted(events, TERMINATING_ID);
    assertNextNode(events, "start");
    assertNextNode(events, "script");
    assertNextNode(events, "end");
    assertProcessCompleted(events, TERMINATING_ID);
    Assertions.assertThat(events.hasNext()).isFalse();
}
Also used : IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 45 with TrackingProcessEventListener

use of org.jbpm.test.listener.TrackingProcessEventListener in project jbpm by kiegroup.

the class EndEventTest method testMessageEndEvent.

@Test(timeout = 30000)
public void testMessageEndEvent() {
    KieSession ksession = createKSession(MESSAGE);
    IterableProcessEventListener events = new IterableProcessEventListener();
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    ksession.addEventListener(events);
    ksession.addEventListener(process);
    RecordingHandler handler = new RecordingHandler();
    List<Command<?>> cmds = new ArrayList<Command<?>>();
    cmds.add(new RegisterWorkItemHandlerCommand("Send Task", handler));
    cmds.add(getCommands().newStartProcess(MESSAGE_ID));
    ksession.execute(getCommands().newBatchExecution(cmds, null));
    Assertions.assertThat(process.wasProcessStarted(MESSAGE_ID)).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(MESSAGE_ID)).isTrue();
    assertProcessStarted(events, MESSAGE_ID);
    assertNextNode(events, "start");
    assertNextNode(events, "script");
    assertNextNode(events, "end");
    assertProcessCompleted(events, MESSAGE_ID);
    Assertions.assertThat(events.hasNext()).isFalse();
    Assertions.assertThat(handler.item).isNotNull();
}
Also used : Command(org.kie.api.command.Command) RegisterWorkItemHandlerCommand(org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand) RegisterWorkItemHandlerCommand(org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand) IterableProcessEventListener(org.jbpm.test.listener.IterableProcessEventListener) TrackingProcessEventListener(org.jbpm.test.listener.TrackingProcessEventListener) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

TrackingProcessEventListener (org.jbpm.test.listener.TrackingProcessEventListener)51 Test (org.junit.Test)49 KieSession (org.kie.api.runtime.KieSession)25 IterableProcessEventListener (org.jbpm.test.listener.IterableProcessEventListener)17 Command (org.kie.api.command.Command)16 ArrayList (java.util.ArrayList)13 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)13 BZ (qa.tools.ikeeper.annotation.BZ)9 UserTransaction (javax.transaction.UserTransaction)7 RegisterWorkItemHandlerCommand (org.drools.core.command.runtime.process.RegisterWorkItemHandlerCommand)6 CompleteWorkItemCommand (org.drools.core.command.runtime.process.CompleteWorkItemCommand)5 HashMap (java.util.HashMap)3 TrackingAgendaEventListener (org.jbpm.test.listener.TrackingAgendaEventListener)2 WorkItem (org.kie.api.runtime.process.WorkItem)2 AsyncWorkItemHandler (org.jbpm.executor.impl.wih.AsyncWorkItemHandler)1 JbpmJUnitBaseTestCase (org.jbpm.test.JbpmJUnitBaseTestCase)1 TrackingRuleRuntimeEventListener (org.jbpm.test.listener.TrackingRuleRuntimeEventListener)1 ListWorkItemHandler (org.jbpm.test.wih.ListWorkItemHandler)1 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)1 Before (org.junit.Before)1