use of org.drools.compiler.Cheesery in project drools by kiegroup.
the class MVELTest method testMVELRewrite.
@Test
public void testMVELRewrite() throws Exception {
// read in the source
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_MVELrewrite.drl"));
KieSession ksession = createKnowledgeSession(kbase);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
final List results = new ArrayList();
ksession.setGlobal("results", results);
final Cheese brie = new Cheese("brie", 2);
final Cheese stilton = new Cheese("stilton", 2);
final Cheesery cheesery = new Cheesery();
cheesery.addCheese(brie);
cheesery.addCheese(stilton);
ksession.insert(cheesery);
ksession.fireAllRules();
assertEquals(1, results.size());
assertEquals(cheesery, results.get(0));
}
use of org.drools.compiler.Cheesery in project drools by kiegroup.
the class ImportsTest method testImportStaticClass.
@Test
public void testImportStaticClass() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_StaticField.drl"));
KieSession session = createKnowledgeSession(kbase);
// will test serialisation of int and typesafe enums tests
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
final List list = new ArrayList();
session.setGlobal("list", list);
final Cheesery cheesery1 = new Cheesery();
cheesery1.setStatus(Cheesery.SELLING_CHEESE);
cheesery1.setMaturity(Cheesery.Maturity.OLD);
session.insert(cheesery1);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
final Cheesery cheesery2 = new Cheesery();
cheesery2.setStatus(Cheesery.MAKING_CHEESE);
cheesery2.setMaturity(Cheesery.Maturity.YOUNG);
session.insert(cheesery2);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
assertEquals(2, list.size());
assertEquals(cheesery1, list.get(0));
assertEquals(cheesery2, list.get(1));
}
use of org.drools.compiler.Cheesery in project drools by kiegroup.
the class ContainsTest method testContainsCheese.
@Test
public void testContainsCheese() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_ContainsCheese.drl"));
final KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese stilton = new Cheese("stilton", 12);
ksession.insert(stilton);
final Cheese brie = new Cheese("brie", 10);
ksession.insert(brie);
final Cheesery cheesery = new Cheesery();
cheesery.getCheeses().add(stilton);
ksession.insert(cheesery);
ksession.fireAllRules();
assertEquals(2, list.size());
assertEquals(stilton, list.get(0));
assertEquals(brie, list.get(1));
}
use of org.drools.compiler.Cheesery in project drools by kiegroup.
the class FromTest method testFromDeclarationWithWorkingMemoryLogger.
/**
* JBRULES-1415 Certain uses of from causes NullPointerException in WorkingMemoryLogger
*/
@Test
public void testFromDeclarationWithWorkingMemoryLogger() throws Exception {
String rule = "package org.drools.compiler.test;\n";
rule += "import org.drools.compiler.Cheesery\n";
rule += "import org.drools.compiler.Cheese\n";
rule += "global java.util.List list\n";
rule += "rule \"Test Rule\"\n";
rule += "when\n";
rule += " $cheesery : Cheesery()\n";
rule += " Cheese( $type : type) from $cheesery.cheeses\n";
rule += "then\n";
rule += " list.add( $type );\n";
rule += "end";
final KieBase kbase = loadKnowledgeBaseFromString(rule);
final KieSession session = kbase.newKieSession();
final List list = new ArrayList();
session.setGlobal("list", list);
final Cheesery cheesery = new Cheesery();
cheesery.addCheese(new Cheese("stilton", 22));
session.insert(cheesery);
session.fireAllRules();
assertEquals(1, ((List) session.getGlobal("list")).size());
assertEquals("stilton", ((List) session.getGlobal("list")).get(0));
}
use of org.drools.compiler.Cheesery in project drools by kiegroup.
the class FromTest method testBasicFrom.
@Test
public void testBasicFrom() throws Exception {
KieBase kbase = loadKnowledgeBase("test_From.drl");
kbase = SerializationHelper.serializeObject(kbase);
KieSession ksession = createKnowledgeSession(kbase);
final List list1 = new ArrayList();
ksession.setGlobal("list1", list1);
final List list2 = new ArrayList();
ksession.setGlobal("list2", list2);
final List list3 = new ArrayList();
ksession.setGlobal("list3", list3);
final Cheesery cheesery = new Cheesery();
final Cheese stilton = new Cheese("stilton", 12);
final Cheese cheddar = new Cheese("cheddar", 15);
cheesery.addCheese(stilton);
cheesery.addCheese(cheddar);
ksession.setGlobal("cheesery", cheesery);
ksession.insert(cheesery);
final Person p = new Person("stilton");
ksession.insert(p);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.fireAllRules();
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.fireAllRules();
// from using a global
assertEquals(2, ((List) ksession.getGlobal("list1")).size());
assertEquals(cheddar, ((List) ksession.getGlobal("list1")).get(0));
assertEquals(stilton, ((List) ksession.getGlobal("list1")).get(1));
// from using a declaration
assertEquals(2, ((List) ksession.getGlobal("list2")).size());
assertEquals(cheddar, ((List) ksession.getGlobal("list2")).get(0));
assertEquals(stilton, ((List) ksession.getGlobal("list2")).get(1));
// from using a declaration
assertEquals(1, ((List) ksession.getGlobal("list3")).size());
assertEquals(stilton, ((List) ksession.getGlobal("list3")).get(0));
}
Aggregations