use of org.drools.compiler.Cheese in project drools by kiegroup.
the class ExecutionFlowControlTest method testInsertRetractNoloop.
@Test
public void testInsertRetractNoloop() throws Exception {
// read in the source
KieBase kbase = loadKnowledgeBase("test_Insert_Retract_Noloop.drl");
KieSession ksession = kbase.newKieSession();
ksession.insert(new Cheese("stilton", 15));
ksession.fireAllRules();
assertEquals(0, ksession.getObjects().size());
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class ExecutionFlowControlTest method testNoLoopWithModify.
@Test
public void testNoLoopWithModify() throws Exception {
KieBase kbase = loadKnowledgeBase("no-loop_with_modify.drl");
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese brie = new Cheese("brie", 12);
ksession.insert(brie);
ksession.fireAllRules();
assertEquals("Should not loop and thus size should be 1", 1, list.size());
assertEquals(50, brie.getPrice());
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FireAllRulesCommandTest method zeroRulesFiredTest.
@Test
public void zeroRulesFiredTest() {
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("not cheese"));
commands.add(CommandFactory.newFireAllRules("num-rules-fired"));
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(commands));
int fired = Integer.parseInt(results.getValue("num-rules-fired").toString());
assertEquals(0, fired);
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FireAllRulesCommandTest method fiveRulesFiredTest.
@Test
public void fiveRulesFiredTest() {
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")));
commands.add(CommandFactory.newInsert(new Cheese("gruyere")));
commands.add(CommandFactory.newInsert(new Cheese("cheddar")));
commands.add(CommandFactory.newInsert(new Cheese("stinky")));
commands.add(CommandFactory.newInsert(new Cheese("limburger")));
commands.add(CommandFactory.newFireAllRules("num-rules-fired"));
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(commands));
int fired = Integer.parseInt(results.getValue("num-rules-fired").toString());
assertEquals(5, fired);
}
use of org.drools.compiler.Cheese in project drools by kiegroup.
the class FireAllRulesCommandTest method oneRuleFiredTest.
@Test
public void oneRuleFiredTest() {
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")));
commands.add(CommandFactory.newFireAllRules("num-rules-fired"));
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(commands));
int fired = Integer.parseInt(results.getValue("num-rules-fired").toString());
assertEquals(1, fired);
}
Aggregations