use of org.kie.api.command.Command 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.kie.api.command.Command 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);
}
use of org.kie.api.command.Command 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.kie.api.command.Command 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.kie.api.command.Command in project drools by kiegroup.
the class EnableAuditLogCommandTest method testEnableAuditLogCommand.
@Test
public void testEnableAuditLogCommand() throws Exception {
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";
KieSession kSession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
List<Command> commands = new ArrayList<Command>();
commands.add(CommandFactory.newEnableAuditLog(auditFileDir, auditFileName));
commands.add(CommandFactory.newInsert(new Cheese()));
commands.add(CommandFactory.newFireAllRules());
kSession.execute(CommandFactory.newBatchExecution(commands));
kSession.dispose();
File file = new File(auditFileDir + File.separator + auditFileName + ".log");
assertTrue(file.exists());
}
Aggregations