use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class ExecutionFlowControlTest method testSalienceExpression.
@Test
public void testSalienceExpression() throws Exception {
KieBase kbase = loadKnowledgeBase("test_salienceExpressionRule.drl");
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final PersonInterface person10 = new Person("bob", "cheese", 10);
ksession.insert(person10);
final PersonInterface person20 = new Person("mic", "cheese", 20);
ksession.insert(person20);
ksession.fireAllRules();
assertEquals("Two rules should have been fired", 2, list.size());
assertEquals("Rule 3 should have been fired first", "Rule 3", list.get(0));
assertEquals("Rule 2 should have been fired second", "Rule 2", list.get(1));
}
use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class FirstOrderLogicTest method testNotWithBindings.
@Test
public void testNotWithBindings() throws Exception {
KieBase kbase = loadKnowledgeBase("not_with_bindings_rule_test.drl");
KieSession wm = createKnowledgeSession(kbase);
final List list = new ArrayList();
wm.setGlobal("list", list);
final Cheese stilton = new Cheese("stilton", 5);
final FactHandle stiltonHandle = (FactHandle) wm.insert(stilton);
final Cheese cheddar = new Cheese("cheddar", 7);
final FactHandle cheddarHandle = (FactHandle) wm.insert(cheddar);
final PersonInterface paul = new Person("paul", "stilton", 12);
wm.insert(paul);
wm.fireAllRules();
assertEquals(0, list.size());
wm.retract(stiltonHandle);
wm.fireAllRules();
assertEquals(1, list.size());
}
use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class DynamicRulesTest method testDynamicRuleRemovals.
@Test(timeout = 10000)
public void testDynamicRuleRemovals() throws Exception {
InternalKnowledgeBase kbase = (InternalKnowledgeBase) SerializationHelper.serializeObject(loadKnowledgeBase("test_Dynamic1.drl", "test_Dynamic3.drl", "test_Dynamic4.drl"));
Collection<KiePackage> kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_Dynamic2.drl"));
kbase.addPackages(kpkgs);
KieSession wm = createKnowledgeSession(kbase);
// AgendaEventListener ael = mock( AgendaEventListener.class );
// wm.addEventListener( ael );
final List<?> list = new ArrayList<Object>();
wm.setGlobal("list", list);
final PersonInterface bob = new Person("bob", "stilton");
bob.setStatus("Not evaluated");
FactHandle fh0 = wm.insert(bob);
final Cheese stilton1 = new Cheese("stilton", 5);
FactHandle fh1 = wm.insert(stilton1);
final Cheese stilton2 = new Cheese("stilton", 3);
FactHandle fh2 = wm.insert(stilton2);
final Cheese stilton3 = new Cheese("stilton", 1);
FactHandle fh3 = wm.insert(stilton3);
final Cheese cheddar = new Cheese("cheddar", 5);
FactHandle fh4 = wm.insert(cheddar);
wm.fireAllRules();
assertEquals(15, list.size());
list.clear();
kbase.removeRule("org.drools.compiler.test", "Who likes Stilton");
wm.update(fh0, bob);
wm.update(fh1, stilton1);
wm.update(fh2, stilton2);
wm.update(fh3, stilton3);
wm.update(fh4, cheddar);
wm.fireAllRules();
assertEquals(12, list.size());
list.clear();
kbase.removeRule("org.drools.compiler.test", "like cheese");
wm.update(fh0, bob);
wm.update(fh1, stilton1);
wm.update(fh2, stilton2);
wm.update(fh3, stilton3);
wm.update(fh4, cheddar);
wm.fireAllRules();
assertEquals(8, list.size());
list.clear();
final Cheese muzzarela = new Cheese("muzzarela", 5);
wm.insert(muzzarela);
wm.fireAllRules();
assertEquals(1, list.size());
list.clear();
}
use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class NullTest method testNullValuesIndexing.
@Test
public void testNullValuesIndexing() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_NullValuesIndexing.drl"));
final KieSession ksession = kbase.newKieSession();
// Adding person with null name and likes attributes
final PersonInterface bob = new Person(null, null);
bob.setStatus("P1");
final PersonInterface pete = new Person(null, null);
bob.setStatus("P2");
ksession.insert(bob);
ksession.insert(pete);
ksession.fireAllRules();
assertEquals("Indexing with null values is not working correctly.", "OK", bob.getStatus());
assertEquals("Indexing with null values is not working correctly.", "OK", pete.getStatus());
}
use of org.drools.compiler.PersonInterface in project drools by kiegroup.
the class NullTest method testNullConstraint.
@Test
public void testNullConstraint() throws Exception {
final KieBase kbase = loadKnowledgeBase("null_constraint.drl");
KieSession session = kbase.newKieSession();
final List foo = new ArrayList();
session.setGlobal("messages", foo);
final PersonInterface p1 = new Person(null, "food", 40);
final Primitives p2 = new Primitives();
p2.setArrayAttribute(null);
session.insert(p1);
session.insert(p2);
session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
session.fireAllRules();
assertEquals(2, ((List) session.getGlobal("messages")).size());
}
Aggregations