use of org.drools.mvel.compiler.FactC 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));
}
use of org.drools.mvel.compiler.FactC 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));
}
use of org.drools.mvel.compiler.FactC in project drools by kiegroup.
the class SessionsPoolTest method createFactAndInsert.
private void createFactAndInsert(KieSession ksession) {
FactA factA = new FactA();
factA.setField1("code1");
ksession.insert(factA);
FactB factB = new FactB();
factB.setF2(1);
ksession.insert(factB);
FactC factC = new FactC();
factC.setF1("code3");
factC.setF2(2);
ksession.insert(factC);
}
use of org.drools.mvel.compiler.FactC in project drools by kiegroup.
the class MarshallingTest method testMultiRuleMultiJoinNodePatternsWithHalt.
@Test
public void testMultiRuleMultiJoinNodePatternsWithHalt() throws Exception {
String rule1 = "package org.drools.compiler.test;\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + Cheese.class.getCanonicalName() + "\n" + "global java.util.List list\n" + "rule \"Rule 1\"\n" + "when\n" + " $c : Cheese( ) \n" + " $p : Person( cheese == $c ) \n" + "then\n" + " list.add( $p );\n" + "end";
String rule2 = "package org.drools.compiler.test;\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + Cheese.class.getCanonicalName() + "\n" + "import " + Cell.class.getCanonicalName() + "\n" + "global java.util.List list\n" + "rule \"Rule 2\"\n" + "when\n" + " $c : Cheese( ) \n" + " $p : Person( cheese == $c ) \n" + " $x : Cell( value == $p.age ) \n" + "then\n" + " list.add( $x );\n" + "end";
String rule3 = "package org.drools.compiler.test;\n" + "import " + Person.class.getCanonicalName() + "\n" + "import " + FactA.class.getCanonicalName() + "\n" + "import " + FactB.class.getCanonicalName() + "\n" + "import " + FactC.class.getCanonicalName() + "\n" + "global java.util.List list\n" + "rule \"Rule 3\"\n" + "when\n" + " $a : FactA( field2 > 10 ) \n" + " $b : FactB( f2 >= $a.field2 ) \n" + " $p : Person( name == \"darth vadar\" ) \n" + " $c : FactC( f2 >= $b.f2 ) \n" + "then\n" + " list.add( $c );\n" + " drools.halt();\n" + "end";
KieBase kBase = loadKnowledgeBaseFromString(rule1, rule2, rule3);
KieSession session = kBase.newKieSession();
List list = new ArrayList();
session.setGlobal("list", list);
Cheese stilton = new Cheese("stilton", 25);
Cheese brie = new Cheese("brie", 49);
Person bobba = new Person("bobba fet", 30);
bobba.setCheese(stilton);
Person vadar = new Person("darth vadar", 38);
Person c3po = new Person("c3p0", 17);
c3po.setCheese(stilton);
Person r2d2 = new Person("r2d2", 58);
r2d2.setCheese(brie);
session.insert(stilton);
session.insert(bobba);
session.insert(vadar);
session.insert(brie);
session.insert(c3po);
session.insert(r2d2);
session = getSerialisedStatefulKnowledgeSession(session, kBase, true);
session.fireAllRules();
list = (List) session.getGlobal("list");
assertEquals(3, list.size());
assertTrue(list.contains(r2d2));
assertTrue(list.contains(c3po));
assertTrue(list.contains(bobba));
session = getSerialisedStatefulKnowledgeSession(session, kBase, true);
Cell cell30 = new Cell(30);
session.insert(cell30);
Cell cell58 = new Cell(58);
session.insert(cell58);
session = getSerialisedStatefulKnowledgeSession(session, kBase, true);
session.fireAllRules();
assertEquals(5, list.size());
assertTrue(list.contains(cell30));
assertTrue(list.contains(cell58));
session = getSerialisedStatefulKnowledgeSession(session, kBase, true);
session.insert(new FactA(15));
session.insert(new FactB(20));
FactC factC27 = new FactC(27);
session.insert(factC27);
FactC factC52 = new FactC(52);
session.insert(factC52);
session = getSerialisedStatefulKnowledgeSession(session, kBase, true);
session.fireAllRules();
session.fireAllRules();
assertEquals(7, list.size());
assertTrue(list.contains(factC52));
assertTrue(list.contains(factC27));
}
Aggregations