use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testRemoveIdentitiesSubNetwork.
@Test
public void testRemoveIdentitiesSubNetwork() throws Exception {
KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
conf.setOption(RemoveIdentitiesOption.YES);
KieBase kbase = loadKnowledgeBase(conf, "test_removeIdentitiesSubNetwork.drl");
KieSession workingMemory = createKnowledgeSession(kbase);
final List list = new ArrayList();
workingMemory.setGlobal("results", list);
final Person bob = new Person("bob", "stilton");
workingMemory.insert(bob);
final Person mark = new Person("mark", "stilton");
workingMemory.insert(mark);
final Cheese stilton1 = new Cheese("stilton", 6);
final FactHandle stilton1Handle = (FactHandle) workingMemory.insert(stilton1);
final Cheese stilton2 = new Cheese("stilton", 7);
final FactHandle stilton2Handle = (FactHandle) workingMemory.insert(stilton2);
workingMemory.fireAllRules();
assertEquals(0, list.size());
workingMemory.retract(stilton1Handle);
workingMemory.fireAllRules();
assertEquals(1, list.size());
assertEquals(mark, list.get(0));
workingMemory.retract(stilton2Handle);
workingMemory.fireAllRules();
assertEquals(2, list.size());
assertEquals(bob, list.get(1));
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testExists2.
@Test
public void testExists2() throws Exception {
KieBase kbase = loadKnowledgeBase("test_exists.drl");
KieSession workingMemory = createKnowledgeSession(kbase);
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.compiler.Cheese in project drools by kiegroup.
the class FunctionsTest method testFunctionException.
@Test
public void testFunctionException() throws Exception {
KieBase kbase = loadKnowledgeBase("test_FunctionException.drl");
KieSession ksession = createKnowledgeSession(kbase);
final Cheese brie = new Cheese("brie", 12);
ksession.insert(brie);
try {
ksession.fireAllRules();
fail("Should throw an Exception from the Function");
} catch (final Exception e) {
assertEquals("this should throw an exception", e.getCause().getMessage());
}
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FunctionsTest method testFunction.
@SuppressWarnings("unchecked")
@Test
public void testFunction() throws Exception {
KieBase kbase = loadKnowledgeBase("test_FunctionInConsequence.drl");
KieSession ksession = createKnowledgeSession(kbase);
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.compiler.Cheese in project drools by kiegroup.
the class MVELTest method testMVELSoundexNoCharParam.
@Test
public void testMVELSoundexNoCharParam() throws Exception {
// read in the source
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("MVEL_soundexNPE2500.drl"));
KieSession ksession = createKnowledgeSession(kbase);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
final Cheese foobarCheese = new Cheese("foobar", 2);
final Cheese nullCheese = new Cheese(null, 2);
final Cheese starCheese = new Cheese("*", 2);
ksession.insert(foobarCheese);
ksession.insert(nullCheese);
ksession.insert(starCheese);
ksession.fireAllRules();
assertEquals(42, foobarCheese.getPrice());
assertEquals(2, nullCheese.getPrice());
assertEquals(2, starCheese.getPrice());
}
Aggregations