use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FireAllRulesCommandTest method infiniteLoopTerminatesAtMaxTest.
@Test
public void infiniteLoopTerminatesAtMaxTest() {
String str = "";
str += "package org.drools.compiler.integrationtests \n";
str += "import " + Cheese.class.getCanonicalName() + " \n";
str += "rule StringRule \n";
str += " when \n";
str += " $c : Cheese() \n";
str += " then \n";
str += " update($c); \n";
str += "end \n";
StatelessKieSession ksession = getSession(str);
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newInsert(new Cheese("stilton")));
FireAllRulesCommand farc = (FireAllRulesCommand) CommandFactory.newFireAllRules(10);
farc.setOutIdentifier("num-rules-fired");
commands.add(farc);
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(commands));
int fired = Integer.parseInt(results.getValue("num-rules-fired").toString());
assertEquals(10, fired);
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FireAllRulesCommandTest method oneRuleFiredWithDefinedMaxTest.
@Test
public void oneRuleFiredWithDefinedMaxTest() {
String str = "";
str += "package org.drools.compiler.integrationtests \n";
str += "import " + Cheese.class.getCanonicalName() + " \n";
str += "rule StringRule \n";
str += " when \n";
str += " $c : Cheese() \n";
str += " then \n";
str += " System.out.println($c); \n";
str += "end \n";
StatelessKieSession ksession = getSession(str);
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newInsert(new Cheese("stilton")));
FireAllRulesCommand farc = (FireAllRulesCommand) CommandFactory.newFireAllRules(10);
farc.setOutIdentifier("num-rules-fired");
commands.add(farc);
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(commands));
int fired = Integer.parseInt(results.getValue("num-rules-fired").toString());
assertEquals(1, fired);
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testOr.
@Test
public void testOr() throws Exception {
KieBase kbase = loadKnowledgeBase("test_OrNesting.drl");
KieSession workingMemory = createKnowledgeSession(kbase);
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.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testExistsWithBinding.
@Test
public void testExistsWithBinding() throws Exception {
KieBase kbase = loadKnowledgeBase("test_ExistsWithBindings.drl");
KieSession wm = createKnowledgeSession(kbase);
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());
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testCollect.
@Test
public void testCollect() throws Exception {
List results = new ArrayList();
KieBase kbase = loadKnowledgeBase("test_Collect.drl");
KieSession wm = createKnowledgeSession(kbase);
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());
}
Aggregations