use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FunctionsTest method testFunction.
@SuppressWarnings("unchecked")
@Test
public void testFunction() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "test_FunctionInConsequence.drl");
KieSession ksession = kbase.newKieSession();
final List<Integer> list = new ArrayList<Integer>();
ksession.setGlobal("list", list);
final Cheese stilton = new Cheese("stilton", 5);
ksession.insert(stilton);
ksession.fireAllRules();
assertEquals(new Integer(5), ((List<Integer>) ksession.getGlobal("list")).get(0));
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class IntegrationInterfacesTest method testGlobals2.
@SuppressWarnings("unchecked")
@Test
public void testGlobals2() throws Exception {
final KieBase kbase = getKnowledgeBase("test_globalsAsConstraints.drl");
KieSession ksession = kbase.newKieSession();
final List<Object> results = mock(List.class);
ksession.setGlobal("results", results);
final List<String> cheeseTypes = mock(List.class);
ksession.setGlobal("cheeseTypes", cheeseTypes);
when(cheeseTypes.contains("stilton")).thenReturn(Boolean.TRUE);
when(cheeseTypes.contains("muzzarela")).thenReturn(Boolean.TRUE);
final Cheese stilton = new Cheese("stilton", 5);
ksession.insert(stilton);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.fireAllRules();
verify(results, times(1)).add("memberOf");
final Cheese brie = new Cheese("brie", 5);
ksession.insert(brie);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.fireAllRules();
verify(results, times(1)).add("not memberOf");
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectResultConstraints.
@Test
public void testCollectResultConstraints() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CollectResultConstraints.drl");
KieSession wm = kbase.newKieSession();
List results = new ArrayList();
wm.setGlobal("results", results);
wm.insert(new Cheese("stilton", 10));
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
wm.fireAllRules();
assertEquals(1, results.size());
assertEquals(1, ((Collection) results.get(0)).size());
wm.insert(new Cheese("stilton", 7));
wm.insert(new Cheese("stilton", 8));
wm.fireAllRules();
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
assertEquals(1, results.size());
// It's 3 as while the rule does not fire, it does continue to evaluate and update the collection
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 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.Cheese 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