use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectAfterOrCE.
@Test
public void testCollectAfterOrCE() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_OrCEFollowedByCollect.drl");
KieSession session = kbase.newKieSession();
// Set up facts
final Cheesery bonFromage = new Cheesery();
bonFromage.addCheese(new Cheese("cheddar"));
bonFromage.addCheese(new Cheese("cheddar"));
session.insert(bonFromage);
int rules = session.fireAllRules();
assertEquals(2, rules);
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testExists2.
@Test
public void testExists2() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_exists.drl");
KieSession workingMemory = kbase.newKieSession();
final List list = new ArrayList();
workingMemory.setGlobal("list", list);
final Cheese cheddar = new Cheese("cheddar", 7);
final Cheese provolone = new Cheese("provolone", 5);
final Person edson = new Person("Edson", "cheddar");
final Person bob = new Person("Bob", "muzzarela");
workingMemory.insert(cheddar);
workingMemory.fireAllRules();
assertEquals(0, list.size());
workingMemory.insert(provolone);
workingMemory.fireAllRules();
assertEquals(0, list.size());
workingMemory.insert(edson);
workingMemory.fireAllRules();
assertEquals(1, list.size());
workingMemory.insert(bob);
workingMemory.fireAllRules();
assertEquals(1, list.size());
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testNot.
@Test
public void testNot() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "not_rule_test.drl");
KieSession wm = kbase.newKieSession();
final List list = new ArrayList();
wm.setGlobal("list", list);
final Cheese stilton = new Cheese("stilton", 5);
final FactHandle stiltonHandle = (FactHandle) wm.insert(stilton);
final Cheese cheddar = new Cheese("cheddar", 7);
final FactHandle cheddarHandle = (FactHandle) wm.insert(cheddar);
wm.fireAllRules();
assertEquals(0, list.size());
wm.retract(stiltonHandle);
wm.fireAllRules();
assertEquals(4, list.size());
assertTrue(list.contains(new Integer(5)));
assertTrue(list.contains(new Integer(6)));
assertTrue(list.contains(new Integer(7)));
assertTrue(list.contains(new Integer(8)));
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testCollect.
@Test
public void testCollect() throws Exception {
List results = new ArrayList();
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_Collect.drl");
KieSession wm = kbase.newKieSession();
wm.setGlobal("results", results);
wm.insert(new Cheese("stilton", 10));
wm.insert(new Cheese("stilton", 7));
wm.insert(new Cheese("stilton", 8));
wm.insert(new Cheese("brie", 5));
wm.insert(new Cheese("provolone", 150));
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
wm.insert(new Cheese("provolone", 20));
wm.insert(new Person("Bob", "stilton"));
wm.insert(new Person("Mark", "provolone"));
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
wm.fireAllRules();
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
assertEquals(1, results.size());
assertEquals(3, ((Collection) results.get(0)).size());
assertEquals(ArrayList.class.getName(), results.get(0).getClass().getName());
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testExistsWithBinding.
@Test
public void testExistsWithBinding() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_ExistsWithBindings.drl");
KieSession wm = kbase.newKieSession();
final List list = new ArrayList();
wm.setGlobal("results", list);
final Cheese c = new Cheese("stilton", 10);
final Person p = new Person("Mark", "stilton");
wm.insert(c);
wm.insert(p);
wm.fireAllRules();
assertTrue(list.contains(c.getType()));
assertEquals(1, list.size());
}
Aggregations