Search in sources :

Example 6 with DebugAgendaEventListener

use of org.kie.api.event.rule.DebugAgendaEventListener in project drools by kiegroup.

the class Misc2Test method testLockOnActiveWithModifyNoEager.

@Test
public void testLockOnActiveWithModifyNoEager() {
    // DROOLS-280
    String drl = "" + "package org.drools.test; \n" + "import org.drools.compiler.Person; \n" + "" + "rule \"Rule1\" \n" + "salience 1 \n" + "lock-on-active true\n" + "when\n" + "  $p: Person()\n" + "then\n" + "  System.out.println( \"Rule1\" ); \n" + "  modify( $p ) { setAge( 44 ); }\n" + "end;\n" + "\n" + "rule \"Rule2\"\n" + "lock-on-active true\n" + "when\n" + "  $p: Person() \n" + "  String() from $p.getName() \n" + "then\n" + "  System.out.println( \"Rule2\" + $p ); " + "  modify ( $p ) { setName( \"john\" ); } \n" + "end";
    KieBase kb = loadKnowledgeBaseFromString(drl);
    KieSession ks = kb.newKieSession();
    ks.addEventListener(new DebugAgendaEventListener());
    ks.fireAllRules();
    Person p = new Person("mark", 76);
    ks.insert(p);
    ks.fireAllRules();
    assertEquals(44, p.getAge());
    assertEquals("john", p.getName());
}
Also used : DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) Person(org.drools.compiler.Person) Test(org.junit.Test)

Example 7 with DebugAgendaEventListener

use of org.kie.api.event.rule.DebugAgendaEventListener 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)

Aggregations

DebugAgendaEventListener (org.kie.api.event.rule.DebugAgendaEventListener)7 Test (org.junit.Test)6 KieSession (org.kie.api.runtime.KieSession)6 KieBase (org.kie.api.KieBase)4 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)3 ArrayList (java.util.ArrayList)2 Person (org.drools.compiler.Person)2 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 StockTick (org.drools.compiler.StockTick)1 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)1 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)1 DebugProcessEventListener (org.drools.core.event.DebugProcessEventListener)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)1 TriggerRulesEventListener (org.jbpm.process.instance.event.listeners.TriggerRulesEventListener)1 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)1 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)1