Search in sources :

Example 6 with TrackingProcessEventListener

use of org.jbpm.test.container.listeners.TrackingProcessEventListener in project jbpm by kiegroup.

the class TransactionsTest method testRuleflowGroup.

@Test
public void testRuleflowGroup() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    TrackingAgendaEventListener agenda = new TrackingAgendaEventListener();
    KieSession ksession = createJPASession(getKnowledgeBase());
    ksession.addEventListener(process);
    ksession.addEventListener(agenda);
    long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS).getId();
    UserTransaction ut = getUserTransaction();
    ut.begin();
    ksession.signalEvent("start", "rfg", processId);
    Assertions.assertThat(process.wasNodeLeft("rfg")).isTrue();
    ut.rollback();
    Thread.sleep(600);
    process.clear();
    agenda.clear();
    ksession = reloadSession(ksession);
    ksession.addEventListener(process);
    ksession.addEventListener(agenda);
    ksession.fireAllRules();
    Assertions.assertThat(agenda.isRuleFired("dummyRule")).isFalse();
    agenda.clear();
    process.clear();
    ut = getUserTransaction();
    ut.begin();
    ksession.signalEvent("start", "rfg", processId);
    Thread.sleep(1000);
    ut.commit();
    Assertions.assertThat(process.wasNodeLeft("rfg")).isTrue();
    ksession.fireAllRules();
    ksession.signalEvent("finish", null, processId);
    Thread.sleep(1000);
    Assertions.assertThat(agenda.isRuleFired("dummyRule")).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(LocalTransactions.PROCESS_TRANSACTIONS)).isTrue();
}
Also used : UserTransaction(javax.transaction.UserTransaction) TrackingAgendaEventListener(org.jbpm.test.container.listeners.TrackingAgendaEventListener) TrackingProcessEventListener(org.jbpm.test.container.listeners.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Example 7 with TrackingProcessEventListener

use of org.jbpm.test.container.listeners.TrackingProcessEventListener in project jbpm by kiegroup.

the class TransactionsTest method testForloop.

@Test
public void testForloop() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    KieSession ksession = createJPASession(getKnowledgeBase());
    ksession.addEventListener(process);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("collection", Arrays.asList("hello world", "25", "false", "1234567891011121314151617181920", ""));
    long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS, params).getId();
    UserTransaction ut = getUserTransaction();
    ut.begin();
    ksession.signalEvent("start", "forloop", processId);
    Thread.sleep(1000);
    Assertions.assertThat(process.wasNodeLeft("forloop")).isTrue();
    ut.rollback();
    process.clear();
    ksession = reloadSession(ksession);
    ksession.addEventListener(process);
    ut = getUserTransaction();
    ut.begin();
    ksession.signalEvent("start", "forloop", processId);
    ut.commit();
    Thread.sleep(5000);
    Assertions.assertThat(process.wasNodeLeft("forloop")).isTrue();
    Assertions.assertThat(process.wasNodeLeft("Multiple Instances")).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(LocalTransactions.PROCESS_TRANSACTIONS)).isFalse();
}
Also used : UserTransaction(javax.transaction.UserTransaction) HashMap(java.util.HashMap) TrackingProcessEventListener(org.jbpm.test.container.listeners.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Example 8 with TrackingProcessEventListener

use of org.jbpm.test.container.listeners.TrackingProcessEventListener in project jbpm by kiegroup.

the class TransactionsTest method testEmbedded.

@Test
public void testEmbedded() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    KieSession ksession = createJPASession(getKnowledgeBase());
    ksession.addEventListener(process);
    long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS).getId();
    UserTransaction ut = getUserTransaction();
    ut.begin();
    ksession.signalEvent("start", "embedded", processId);
    Thread.sleep(1000);
    Assertions.assertThat(process.wasNodeLeft("embedded")).isTrue();
    ut.rollback();
    process.clear();
    ksession = reloadSession(ksession);
    ksession.addEventListener(process);
    ut = getUserTransaction();
    ut.begin();
    ksession.signalEvent("start", "embedded", processId);
    ut.commit();
    Thread.sleep(5000);
    Assertions.assertThat(process.wasNodeLeft("embedded")).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(LocalTransactions.PROCESS_TRANSACTIONS)).isFalse();
}
Also used : UserTransaction(javax.transaction.UserTransaction) TrackingProcessEventListener(org.jbpm.test.container.listeners.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Aggregations

TrackingProcessEventListener (org.jbpm.test.container.listeners.TrackingProcessEventListener)8 KieSession (org.kie.api.runtime.KieSession)8 UserTransaction (javax.transaction.UserTransaction)7 JbpmContainerTest (org.jbpm.test.container.JbpmContainerTest)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ProcessScenario (org.jbpm.test.container.archive.ejbtransactions.ProcessScenario)1 ListWorkItemHandler (org.jbpm.test.container.handlers.ListWorkItemHandler)1 TrackingAgendaEventListener (org.jbpm.test.container.listeners.TrackingAgendaEventListener)1