Search in sources :

Example 1 with TriggerRulesEventListener

use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.

the class ActivityTest method testMultipleBusinessRuleTaskWithDataInputsWithPersistence.

@Test
public void testMultipleBusinessRuleTaskWithDataInputsWithPersistence() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-MultipleRuleTasksWithDataInput.bpmn2", "BPMN2-MultipleRuleTasks.drl");
    ksession = createKnowledgeSession(kbase);
    ksession.addEventListener(new TriggerRulesEventListener(ksession));
    List<String> listPerson = new ArrayList<String>();
    List<String> listAddress = new ArrayList<String>();
    ksession.setGlobal("listPerson", listPerson);
    ksession.setGlobal("listAddress", listAddress);
    Person person = new Person();
    person.setName("john");
    Address address = new Address();
    address.setStreet("5th avenue");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("person", person);
    params.put("address", address);
    ProcessInstance processInstance = ksession.startProcess("multiple-rule-tasks", params);
    assertEquals(1, listPerson.size());
    assertEquals(1, listAddress.size());
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : Address(org.jbpm.bpmn2.objects.Address) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) TriggerRulesEventListener(org.jbpm.process.instance.event.listeners.TriggerRulesEventListener) Person(org.jbpm.bpmn2.objects.Person) Test(org.junit.Test)

Example 2 with TriggerRulesEventListener

use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.

the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromClassPath.

@Test(timeout = 20000)
public void testStartTimerCycleFromClassPath() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
    KieBase kbase = createKnowledgeBase("BPMN2-StartTimerCycle.bpmn2");
    try {
        StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
        ksession.addEventListener(countDownListener);
        assertEquals(0, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
        long sessionId = ksession.getIdentifier();
        Environment env = ksession.getEnvironment();
        final List<Long> list = new ArrayList<Long>();
        ksession.addEventListener(new DefaultProcessEventListener() {

            public void beforeProcessStarted(ProcessStartedEvent event) {
                list.add(event.getProcessInstance().getId());
            }
        });
        ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
        countDownListener.waitTillCompleted();
        assertEquals(2, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
        logger.info("dispose");
        ksession.dispose();
        countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
        ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
        ksession.addEventListener(countDownListener);
        AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
        final List<Long> list2 = new ArrayList<Long>();
        ksession.addEventListener(new DefaultProcessEventListener() {

            public void beforeProcessStarted(ProcessStartedEvent event) {
                list2.add(event.getProcessInstance().getId());
            }
        });
        ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
        countDownListener.waitTillCompleted();
        ksession.dispose();
        assertEquals(4, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
    } finally {
        ksession = createKnowledgeSession(kbase);
        abortProcessInstances(ksession);
        ksession.dispose();
    }
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) Environment(org.kie.api.runtime.Environment) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) TriggerRulesEventListener(org.jbpm.process.instance.event.listeners.TriggerRulesEventListener) Test(org.junit.Test)

Example 3 with TriggerRulesEventListener

use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.

the class ActivityTest method testRuleTaskWithFactsWithPersistence.

@Test
@RequirePersistence
public void testRuleTaskWithFactsWithPersistence() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTaskWithFact.bpmn2", "BPMN2-RuleTask3.drl");
    ksession = createKnowledgeSession(kbase);
    ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
    ksession.addEventListener(new DebugAgendaEventListener());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    ProcessInstance processInstance = ksession.startProcess("RuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
    params = new HashMap<String, Object>();
    try {
        processInstance = ksession.startProcess("RuleTask", params);
        fail("Should fail");
    } catch (Exception e) {
        e.printStackTrace();
    }
    params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    processInstance = ksession.startProcess("RuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) TriggerRulesEventListener(org.jbpm.process.instance.event.listeners.TriggerRulesEventListener) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 4 with TriggerRulesEventListener

use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.

the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromDisc.

@Test(timeout = 20000)
public void testStartTimerCycleFromDisc() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
    KieBase kbase = createKnowledgeBaseFromDisc("BPMN2-StartTimerCycle.bpmn2");
    try {
        StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
        ksession.addEventListener(countDownListener);
        assertEquals(0, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
        long sessionId = ksession.getIdentifier();
        Environment env = ksession.getEnvironment();
        final List<Long> list = new ArrayList<Long>();
        ksession.addEventListener(new DefaultProcessEventListener() {

            public void beforeProcessStarted(ProcessStartedEvent event) {
                list.add(event.getProcessInstance().getId());
            }
        });
        ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
        countDownListener.waitTillCompleted();
        assertEquals(2, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
        logger.info("dispose");
        ksession.dispose();
        countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
        ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
        ksession.addEventListener(countDownListener);
        AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
        final List<Long> list2 = new ArrayList<Long>();
        ksession.addEventListener(new DefaultProcessEventListener() {

            public void beforeProcessStarted(ProcessStartedEvent event) {
                list2.add(event.getProcessInstance().getId());
            }
        });
        ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
        countDownListener.waitTillCompleted();
        assertEquals(4, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
        abortProcessInstances(ksession);
        ksession.dispose();
    } finally {
        ksession = createKnowledgeSession(kbase);
        abortProcessInstances(ksession);
        ksession.dispose();
    }
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) KieBase(org.kie.api.KieBase) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ArrayList(java.util.ArrayList) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) Environment(org.kie.api.runtime.Environment) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) TriggerRulesEventListener(org.jbpm.process.instance.event.listeners.TriggerRulesEventListener) Test(org.junit.Test)

Example 5 with TriggerRulesEventListener

use of org.jbpm.process.instance.event.listeners.TriggerRulesEventListener in project jbpm by kiegroup.

the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromDiscDRL.

@Test
@Ignore("beta4 phreak")
public void testStartTimerCycleFromDiscDRL() throws Exception {
    KieBase kbase = createKnowledgeBaseFromDisc("rules-timer.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    long sessionId = ksession.getIdentifier();
    Environment env = ksession.getEnvironment();
    final List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
    ksession.fireAllRules();
    Thread.sleep(5000);
    assertEquals(2, list.size());
    logger.info("dispose");
    ksession.dispose();
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
    AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
    final List<String> list2 = new ArrayList<String>();
    ksession.setGlobal("list", list2);
    ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
    ksession.fireAllRules();
    Thread.sleep(6000);
    assertEquals(3, list2.size());
}
Also used : KieBase(org.kie.api.KieBase) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ArrayList(java.util.ArrayList) Environment(org.kie.api.runtime.Environment) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) TriggerRulesEventListener(org.jbpm.process.instance.event.listeners.TriggerRulesEventListener) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TriggerRulesEventListener (org.jbpm.process.instance.event.listeners.TriggerRulesEventListener)6 Test (org.junit.Test)6 KieBase (org.kie.api.KieBase)6 ArrayList (java.util.ArrayList)5 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)5 Environment (org.kie.api.runtime.Environment)4 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)4 HashMap (java.util.HashMap)2 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)2 Ignore (org.junit.Ignore)2 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)2 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)2 Address (org.jbpm.bpmn2.objects.Address)1 Person (org.jbpm.bpmn2.objects.Person)1 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)1 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)1 DebugAgendaEventListener (org.kie.api.event.rule.DebugAgendaEventListener)1