Search in sources :

Example 11 with DebugAgendaEventListener

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

the class RuleTest method testCheck.

@Test
public void testCheck() {
    String drl = "package i.p;\n" + "import " + LongHolder.class.getCanonicalName() + "\n" + "import " + WeirdObject.class.getCanonicalName() + "\n" + "import " + TestObjectEnum.class.getCanonicalName() + "\n" + "rule fileArule1 when\n" + "  $t : LongHolder()\n" + "  WeirdObject(added == $t.value, status == TestObjectEnum.ONE.getValue() )\n" + "then\n" + "end\n" + "rule fileArule2 when\n" + "  $t : LongHolder()\n" + "  WeirdObject(nested.id == $t.value, status == 0 )\n" + "then\n" + "end\n";
    String drl2 = "package c.t.p;\n" + "import " + WeirdObject.class.getCanonicalName() + "\n" + "import " + TestObjectEnum.class.getCanonicalName() + "\n" + "rule fileBrule1 when\n" + "  WeirdObject(status == 1)\n" + "then\n" + "end\n";
    KieSession kieSession = new KieHelper().addContent(drl2, ResourceType.DRL).addContent(drl, ResourceType.DRL).build().newKieSession();
    ReteDiagram.newInstance().diagramRete(kieSession);
    kieSession.addEventListener(new DebugAgendaEventListener());
    kieSession.insert(new LongHolder(12345L));
    kieSession.insert(new WeirdObject(1, new WeirdNested(12345L)));
    kieSession.fireAllRules();
}
Also used : DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 12 with DebugAgendaEventListener

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

the class TraitTest method testTraitDonLegacyClassWithoutEmptyConstructor.

@Test
public void testTraitDonLegacyClassWithoutEmptyConstructor() {
    String drl = "package org.drools.compiler.trait.test;\n" + "\n" + "import " + TraitableFoo.class.getCanonicalName() + ";" + "import org.drools.core.factmodel.traits.Traitable;\n" + "\n" + "" + "declare trait Bar\n" + "end\n" + "\n" + "rule \"Don\"\n" + "no-loop \n" + "when\n" + " $f : TraitableFoo( )\n" + "then\n" + "  Bar b = don( $f, Bar.class );\n" + "end";
    KieSession ksession = getSessionFromString(drl);
    TraitFactoryImpl.setMode(mode, ksession.getKieBase());
    ksession.addEventListener(new DebugAgendaEventListener());
    ksession.insert(new TraitableFoo("xx", 0, null));
    ksession.fireAllRules();
    for (Object o : ksession.getObjects()) {
        System.out.println(o);
    }
    assertEquals(2, ksession.getObjects().size());
}
Also used : DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) CommonTraitTest(org.drools.traits.compiler.CommonTraitTest) Test(org.junit.Test)

Example 13 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)13 KieSession (org.kie.api.runtime.KieSession)12 Test (org.junit.Test)11 KieBase (org.kie.api.KieBase)7 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)6 ArrayList (java.util.ArrayList)2 Person (org.drools.compiler.Person)2 Person (org.drools.mvel.compiler.Person)2 FactWithString (org.drools.mvel.integrationtests.facts.FactWithString)2 DebugRuleRuntimeEventListener (org.kie.api.event.rule.DebugRuleRuntimeEventListener)2 KieHelper (org.kie.internal.utils.KieHelper)2 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)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 DefaultAgenda (org.drools.kiesession.agenda.DefaultAgenda)1 StockTick (org.drools.testcoverage.common.model.StockTick)1