use of org.kie.api.runtime.ExecutionResults in project drools by kiegroup.
the class SimpleBatchExecutionTest method testSetGlobalCommand.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testSetGlobalCommand() throws Exception {
ksession.insert(new Integer(5));
ksession.insert(new Integer(7));
ksession.fireAllRules();
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newSetGlobal("globalCheeseCountry", "France", true));
Command cmds = CommandFactory.newBatchExecution(commands);
ExecutionResults result = (ExecutionResults) ksession.execute(cmds);
assertNotNull(result);
Object global = result.getValue("globalCheeseCountry");
assertNotNull(global);
assertEquals("France", global);
}
use of org.kie.api.runtime.ExecutionResults in project drools by kiegroup.
the class SimpleBatchExecutionTest method testInsertObjectCommand.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testInsertObjectCommand() throws Exception {
String expected_1 = "expected_1";
String expected_2 = "expected_2";
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newInsert(expected_1, "out_1"));
commands.add(CommandFactory.newInsert(expected_2, "out_2"));
Command cmds = CommandFactory.newBatchExecution(commands);
ExecutionResults result = (ExecutionResults) ksession.execute(cmds);
Object fact_1 = result.getValue("out_1");
assertNotNull(fact_1);
Object fact_2 = result.getValue("out_2");
assertNotNull(fact_2);
ksession.fireAllRules();
Object[] expectedArr = { expected_1, expected_2 };
List<Object> expectedList = new ArrayList<Object>(Arrays.asList(expectedArr));
Collection<? extends Object> factList = ksession.getObjects();
assertTrue("Expected " + expectedList.size() + " objects but retrieved " + factList.size(), factList.size() == expectedList.size());
for (Object fact : factList) {
if (expectedList.contains(fact)) {
expectedList.remove(fact);
}
}
assertTrue("Retrieved object list did not contain expected objects.", expectedList.isEmpty());
}
use of org.kie.api.runtime.ExecutionResults in project drools by kiegroup.
the class SimpleBatchExecutionTest method testGetObjectCommand.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testGetObjectCommand() throws Exception {
String expected_1 = "expected_1";
String expected_2 = "expected_2";
FactHandle handle_1 = ksession.insert(expected_1);
FactHandle handle_2 = ksession.insert(expected_2);
ksession.fireAllRules();
Object fact = ksession.getObject(handle_1);
assertNotNull(fact);
assertEquals(expected_1, fact);
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newGetObject(handle_1, "out_1"));
commands.add(CommandFactory.newGetObject(handle_2, "out_2"));
Command cmds = CommandFactory.newBatchExecution(commands);
ExecutionResults result = (ExecutionResults) ksession.execute(cmds);
assertNotNull("GetObjectCommand result is null!", result);
assertEquals(expected_1, result.getValue("out_1"));
assertEquals(expected_2, result.getValue("out_2"));
}
use of org.kie.api.runtime.ExecutionResults in project drools by kiegroup.
the class FireAllRulesCommandTest method oneRuleFiredTest.
@Test
public void oneRuleFiredTest() {
String str = "";
str += "package org.drools.mvel.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.runtime.ExecutionResults in project drools by kiegroup.
the class FireAllRulesCommandTest method zeroRulesFiredTest.
@Test
public void zeroRulesFiredTest() {
String str = "";
str += "package org.drools.mvel.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);
}
Aggregations