use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class LiteralTest method testBigDecimalIntegerLiteral.
@Test
public void testBigDecimalIntegerLiteral() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("big_decimal_and_literal.drl"));
KieSession session = createKnowledgeSession(kbase);
final List list = new ArrayList();
session.setGlobal("list", list);
final PersonInterface bill = new Person("bill", null, 12);
bill.setBigDecimal(new BigDecimal("42"));
bill.setBigInteger(new BigInteger("42"));
session.insert(bill);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
assertEquals(6, ((List) session.getGlobal("list")).size());
}
use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class EvalTest method testPredicate.
@Test
public void testPredicate() throws Exception {
KieBase kbase = loadKnowledgeBase("predicate_rule_test.drl");
kbase = SerializationHelper.serializeObject(kbase);
KieSession ksession = kbase.newKieSession();
ksession.setGlobal("two", 2);
final List list = new ArrayList();
ksession.setGlobal("list", list);
final PersonInterface peter = new Person("peter", null, 12);
ksession.insert(peter);
final PersonInterface jane = new Person("jane", null, 10);
ksession.insert(jane);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.fireAllRules();
assertEquals(jane, ((List) ksession.getGlobal("list")).get(0));
assertEquals(peter, ((List) ksession.getGlobal("list")).get(1));
}
use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class MathTest method testAddition.
@Test
public void testAddition() throws Exception {
KieBase kbase = loadKnowledgeBase("returnvalue_rule_test.drl");
kbase = SerializationHelper.serializeObject(kbase);
KieSession ksession = kbase.newKieSession();
ksession.setGlobal("two", 2);
final List list = new ArrayList();
ksession.setGlobal("list", list);
final PersonInterface peter = new Person("peter", null, 12);
ksession.insert(peter);
final PersonInterface jane = new Person("jane", null, 10);
ksession.insert(jane);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.fireAllRules();
assertEquals(jane, ((List) ksession.getGlobal("list")).get(0));
assertEquals(peter, ((List) ksession.getGlobal("list")).get(1));
}
use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class ExecutionFlowControlTest method testSalienceIntegerAndLoadOrder.
@Test(timeout = 10000)
public void testSalienceIntegerAndLoadOrder() throws Exception {
KieBase kbase = loadKnowledgeBase("test_salienceIntegerRule.drl");
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final PersonInterface person = new Person("Edson", "cheese");
ksession.insert(person);
ksession.fireAllRules();
assertEquals("Three rules should have been fired", 3, list.size());
assertEquals("Rule 4 should have been fired first", "Rule 4", list.get(0));
assertEquals("Rule 2 should have been fired second", "Rule 2", list.get(1));
assertEquals("Rule 3 should have been fired third", "Rule 3", list.get(2));
}
use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class DynamicRulesTest method testDynamicRuleAdditions.
@Test(timeout = 10000)
public void testDynamicRuleAdditions() throws Exception {
InternalKnowledgeBase kbase = (InternalKnowledgeBase) SerializationHelper.serializeObject(loadKnowledgeBase("test_Dynamic1.drl"));
KieSession workingMemory = createKnowledgeSession(kbase);
workingMemory.setGlobal("total", new Integer(0));
final List<?> list = new ArrayList<Object>();
workingMemory.setGlobal("list", list);
// Adding person in advance. There is no Person() object
// type node in memory yet, but the rule engine is supposed
// to handle that correctly
final PersonInterface bob = new Person("bob", "stilton");
bob.setStatus("Not evaluated");
workingMemory.insert(bob);
final Cheese stilton = new Cheese("stilton", 5);
workingMemory.insert(stilton);
final Cheese cheddar = new Cheese("cheddar", 5);
workingMemory.insert(cheddar);
workingMemory.fireAllRules();
assertEquals(1, list.size());
assertEquals("stilton", list.get(0));
Collection<KiePackage> kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_Dynamic2.drl"));
kbase.addPackages(kpkgs);
workingMemory.fireAllRules();
assertEquals(5, list.size());
assertEquals("stilton", list.get(0));
assertTrue("cheddar".equals(list.get(1)) || "cheddar".equals(list.get(2)));
assertTrue("stilton".equals(list.get(1)) || "stilton".equals(list.get(2)));
list.clear();
kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_Dynamic3.drl"));
kbase.addPackages(kpkgs);
// Package 3 has a rule working on Person instances.
// As we added person instance in advance, rule should fire now
workingMemory.fireAllRules();
assertEquals("Rule from package 3 should have been fired", "match Person ok", bob.getStatus());
assertEquals(1, list.size());
assertEquals(bob, list.get(0));
kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_Dynamic4.drl"));
kbase.addPackages(kpkgs);
workingMemory.fireAllRules();
kbase = SerializationHelper.serializeObject(kbase);
assertEquals("Rule from package 4 should have been fired", "Who likes Stilton ok", bob.getStatus());
assertEquals(2, list.size());
assertEquals(bob, list.get(1));
}
Aggregations