use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class FirstOrderLogicTest method testMVELCollect.
@Test
public void testMVELCollect() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_MVELCollect.drl");
KieSession wm = kbase.newKieSession();
final List results = new ArrayList();
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.insert(new Cheese("provolone", 20));
wm.insert(new Person("Bob", "stilton"));
wm.insert(new Person("Mark", "provolone"));
wm.fireAllRules();
assertEquals(1, results.size());
assertEquals(6, ((List) results.get(0)).size());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class FirstOrderLogicTest method testNotWithBindings.
@Test
public void testNotWithBindings() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "not_with_bindings_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);
final PersonInterface paul = new Person("paul", "stilton", 12);
wm.insert(paul);
wm.fireAllRules();
assertEquals(0, list.size());
wm.retract(stiltonHandle);
wm.fireAllRules();
assertEquals(1, list.size());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class FirstOrderLogicTest method testForall2.
@Test
public void testForall2() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_Forall2.drl");
KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("results", list);
final State state = new State("SP");
ksession.insert(state);
final Person bob = new Person("Bob");
bob.setStatus(state.getState());
bob.setAlive(true);
ksession.insert(bob);
ksession.fireAllRules();
assertEquals(0, list.size());
final State qc = new State("QC");
ksession.insert(qc);
final Person john = new Person("John");
john.setStatus(qc.getState());
john.setAlive(false);
ksession.insert(john);
ksession.fireAllRules();
assertEquals(1, list.size());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class FirstOrderLogicTest method testOr.
@Test
public void testOr() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_OrNesting.drl");
KieSession workingMemory = kbase.newKieSession();
final List list = new ArrayList();
workingMemory.setGlobal("results", list);
final Cheese cheddar = new Cheese("cheddar", 7);
final Cheese provolone = new Cheese("provolone", 5);
final Cheese brie = new Cheese("brie", 15);
final Person mark = new Person("mark", "stilton");
FactHandle ch = (FactHandle) workingMemory.insert(cheddar);
FactHandle ph = (FactHandle) workingMemory.insert(provolone);
FactHandle bh = (FactHandle) workingMemory.insert(brie);
FactHandle markh = (FactHandle) workingMemory.insert(mark);
workingMemory.fireAllRules();
assertEquals(1, list.size());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class FirstOrderLogicTest method testForall.
@Test
public void testForall() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_Forall.drl");
KieSession workingMemory = kbase.newKieSession();
final List list = new ArrayList();
workingMemory.setGlobal("results", list);
final State state = new State("SP");
workingMemory.insert(state);
final Person bob = new Person("Bob");
bob.setStatus(state.getState());
bob.setLikes("stilton");
workingMemory.insert(bob);
workingMemory.fireAllRules();
assertEquals(0, list.size());
workingMemory.insert(new Cheese(bob.getLikes(), 10));
workingMemory.fireAllRules();
assertEquals(1, list.size());
}
Aggregations