Search in sources :

Example 1 with FactB

use of org.drools.mvel.compiler.FactB in project drools by kiegroup.

the class JBRULESTest method testJBRules2369.

@Test
public void testJBRules2369() {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "test_JBRules2369.drl");
    KieSession ksession = kbase.newKieSession();
    final List<String> results = new ArrayList<String>();
    ksession.setGlobal("results", results);
    final FactA a = new FactA();
    final FactB b = new FactB(Integer.valueOf(0));
    final FactHandle aHandle = ksession.insert(a);
    final FactHandle bHandle = ksession.insert(b);
    ksession.fireAllRules();
    assertEquals(1, results.size());
    ksession.update(aHandle, a);
    ksession.fireAllRules();
    assertEquals(2, results.size());
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) FactA(org.drools.mvel.compiler.FactA) FactB(org.drools.mvel.compiler.FactB) Test(org.junit.Test)

Example 2 with FactB

use of org.drools.mvel.compiler.FactB in project drools by kiegroup.

the class FirstOrderLogicTest method testOrWithVariableResolution2.

// JBRULES-2526
@Test
public void testOrWithVariableResolution2() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_OrCEFollowedByMultipleEval2.drl");
    KieSession ksession = kbase.newKieSession();
    final AgendaEventListener al = mock(AgendaEventListener.class);
    ksession.addEventListener(al);
    ksession.insert(new FactA("a"));
    ksession.insert(new FactB("b"));
    ksession.insert(new FactC("c"));
    ksession.fireAllRules();
    verify(al, times(8)).afterMatchFired(any(AfterMatchFiredEvent.class));
}
Also used : KieBase(org.kie.api.KieBase) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) KieSession(org.kie.api.runtime.KieSession) FactA(org.drools.mvel.compiler.FactA) FactB(org.drools.mvel.compiler.FactB) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) FactC(org.drools.mvel.compiler.FactC) Test(org.junit.Test)

Example 3 with FactB

use of org.drools.mvel.compiler.FactB in project drools by kiegroup.

the class FirstOrderLogicTest method testOrWithVariableResolution.

// JBRULES-2482
@Test
public void testOrWithVariableResolution() throws Exception {
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_OrCEFollowedByMultipleEval.drl");
    KieSession ksession = kbase.newKieSession();
    final AgendaEventListener al = mock(AgendaEventListener.class);
    ksession.addEventListener(al);
    ksession.insert(new FactA("a"));
    ksession.insert(new FactB("b"));
    ksession.insert(new FactC("c"));
    ksession.fireAllRules();
    verify(al, times(6)).afterMatchFired(any(AfterMatchFiredEvent.class));
}
Also used : KieBase(org.kie.api.KieBase) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) KieSession(org.kie.api.runtime.KieSession) FactA(org.drools.mvel.compiler.FactA) FactB(org.drools.mvel.compiler.FactB) AfterMatchFiredEvent(org.kie.api.event.rule.AfterMatchFiredEvent) FactC(org.drools.mvel.compiler.FactC) Test(org.junit.Test)

Example 4 with FactB

use of org.drools.mvel.compiler.FactB in project drools by kiegroup.

the class SessionsPoolTest method testSegmentMemoriesResetWithNotNodeInTheMiddle.

@Test
public void testSegmentMemoriesResetWithNotNodeInTheMiddle() {
    String drl = "import " + FactA.class.getCanonicalName() + ";\n" + "import " + FactB.class.getCanonicalName() + ";\n" + "import " + FactC.class.getCanonicalName() + ";\n" + "rule R1\n" + "when\n" + "  $factA : FactA( field1 == \"code1\")\n" + "  not FactC( f2 == 1 && f1 == \"code1\")\n" + "  $factB : FactB( f2 == 1 )\n" + "then\n" + "end\n" + "rule R2\n" + "when\n" + "  $factA : FactA( field1 == \"code1\")\n" + "  not FactC( f2 == 1 && f1 == \"code1\")\n" + "  $factB : FactB( f2 == 3 )\n" + "then\n" + "end\n" + "rule R3\n" + "when\n" + "  $factA: FactA( field1 == \"code1\")\n" + "  $factC: FactC( f1 == \"code1\")\n" + "then\n" + "end";
    final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, drl);
    KieContainer kcontainer = KieServices.get().newKieContainer(kieModule.getReleaseId());
    KieSessionsPool pool = kcontainer.newKieSessionsPool(1);
    KieSession ksession = pool.newKieSession();
    try {
        createFactAndInsert(ksession);
        // R1 is fired
        assertEquals(1, ksession.fireAllRules());
    } finally {
        ksession.dispose();
    }
    ksession = pool.newKieSession();
    try {
        createFactAndInsert(ksession);
        assertEquals(1, ksession.fireAllRules());
    } finally {
        ksession.dispose();
    }
    pool.shutdown();
}
Also used : StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) FactB(org.drools.mvel.compiler.FactB) KieModule(org.kie.api.builder.KieModule) KieSessionsPool(org.kie.api.runtime.KieSessionsPool) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 5 with FactB

use of org.drools.mvel.compiler.FactB in project drools by kiegroup.

the class SessionsPoolTest method testSegmentMemoriesResetWithNotNodeInTheMiddle2.

@Test
public void testSegmentMemoriesResetWithNotNodeInTheMiddle2() {
    // FactB constrains in R1 and R2 are different from testSegmentMemoriesResetWithNotNodeInTheMiddle()
    String drl = "import " + FactA.class.getCanonicalName() + ";\n" + "import " + FactB.class.getCanonicalName() + ";\n" + "import " + FactC.class.getCanonicalName() + ";\n" + "rule R1\n" + "when\n" + "  $factA : FactA( field1 == \"code1\")\n" + "  not FactC( f2 == 1 && f1 == \"code1\")\n" + "  $factB : FactB( f2 == 3 )\n" + "then\n" + "end\n" + "rule R2\n" + "when\n" + "  $factA : FactA( field1 == \"code1\")\n" + "  not FactC( f2 == 1 && f1 == \"code1\")\n" + "  $factB : FactB( f2 == 1 )\n" + "then\n" + "end\n" + "rule R3\n" + "when\n" + "  $factA: FactA( field1 == \"code1\")\n" + "  $factC: FactC( f1 == \"code1\")\n" + "then\n" + "end";
    final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, drl);
    KieContainer kcontainer = KieServices.get().newKieContainer(kieModule.getReleaseId());
    KieSessionsPool pool = kcontainer.newKieSessionsPool(1);
    KieSession ksession = pool.newKieSession();
    try {
        createFactAndInsert(ksession);
        // R2 is fired
        assertEquals(1, ksession.fireAllRules());
    } finally {
        ksession.dispose();
    }
    ksession = pool.newKieSession();
    try {
        createFactAndInsert(ksession);
        assertEquals(1, ksession.fireAllRules());
    } finally {
        ksession.dispose();
    }
    pool.shutdown();
}
Also used : StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) FactB(org.drools.mvel.compiler.FactB) KieModule(org.kie.api.builder.KieModule) KieSessionsPool(org.kie.api.runtime.KieSessionsPool) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

FactB (org.drools.mvel.compiler.FactB)8 Test (org.junit.Test)7 KieSession (org.kie.api.runtime.KieSession)7 FactA (org.drools.mvel.compiler.FactA)6 FactC (org.drools.mvel.compiler.FactC)4 KieBase (org.kie.api.KieBase)4 ArrayList (java.util.ArrayList)2 KieModule (org.kie.api.builder.KieModule)2 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)2 AgendaEventListener (org.kie.api.event.rule.AgendaEventListener)2 KieContainer (org.kie.api.runtime.KieContainer)2 KieSessionsPool (org.kie.api.runtime.KieSessionsPool)2 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)2 List (java.util.List)1 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)1 Cell (org.drools.mvel.compiler.Cell)1 Cheese (org.drools.mvel.compiler.Cheese)1 Person (org.drools.mvel.compiler.Person)1 IteratorToList (org.drools.mvel.integrationtests.IteratorToList)1 KiePackage (org.kie.api.definition.KiePackage)1