use of org.drools.compiler.OrderItem in project drools by kiegroup.
the class PatternTest method testSelfReference.
@Test
public void testSelfReference() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_SelfReference.drl"));
final KieSession ksession = createKnowledgeSession(kbase);
final List results = new ArrayList();
ksession.setGlobal("results", results);
final Order order = new Order(10, "Bob");
final OrderItem item1 = new OrderItem(order, 1);
final OrderItem item2 = new OrderItem(order, 2);
final OrderItem anotherItem1 = new OrderItem(null, 3);
final OrderItem anotherItem2 = new OrderItem(null, 4);
ksession.insert(order);
ksession.insert(item1);
ksession.insert(item2);
ksession.insert(anotherItem1);
ksession.insert(anotherItem2);
ksession.fireAllRules();
assertEquals(2, results.size());
assertTrue(results.contains(item1));
assertTrue(results.contains(item2));
}
use of org.drools.compiler.OrderItem in project drools by kiegroup.
the class EvalRewriteTest method testEvalRewrite.
@Test
public void testEvalRewrite() throws Exception {
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_EvalRewrite.drl"));
final KieSession ksession = createKnowledgeSession(kbase);
final List list = new ArrayList();
ksession.setGlobal("results", list);
final Order order1 = new Order(10, "Bob");
final OrderItem item11 = new OrderItem(order1, 1);
final OrderItem item12 = new OrderItem(order1, 2);
order1.addItem(item11);
order1.addItem(item12);
final Order order2 = new Order(11, "Bob");
final OrderItem item21 = new OrderItem(order2, 1);
final OrderItem item22 = new OrderItem(order2, 2);
order2.addItem(item21);
order2.addItem(item22);
final Order order3 = new Order(12, "Bob");
final OrderItem item31 = new OrderItem(order3, 1);
final OrderItem item32 = new OrderItem(order3, 2);
order3.addItem(item31);
order3.addItem(item32);
final Order order4 = new Order(13, "Bob");
final OrderItem item41 = new OrderItem(order4, 1);
final OrderItem item42 = new OrderItem(order4, 2);
order4.addItem(item41);
order4.addItem(item42);
ksession.insert(order1);
ksession.insert(item11);
ksession.insert(item12);
ksession.insert(order2);
ksession.insert(item21);
ksession.insert(item22);
ksession.insert(order3);
ksession.insert(item31);
ksession.insert(item32);
ksession.insert(order4);
ksession.insert(item41);
ksession.insert(item42);
ksession.fireAllRules();
assertEquals(5, list.size());
assertTrue(list.contains(item11));
assertTrue(list.contains(item12));
assertTrue(list.contains(item22));
assertTrue(list.contains(order3));
assertTrue(list.contains(order4));
}
use of org.drools.compiler.OrderItem in project drools by kiegroup.
the class OrTest method testOrWithFrom.
@Test
public void testOrWithFrom() {
// JBRULES-2274: Rule does not fire as expected using deep object model and nested 'or' clause
final String str = "package org.drools.compiler\n" + "rule NotContains\n" + "when\n" + " $oi1 : OrderItem( )\n" + " $o1 : Order(number == 1) from $oi1.order; \n" + " ( eval(true) or eval(true) )\n" + " $oi2 : OrderItem( )\n" + " $o2 : Order(number == 2) from $oi2.order; \n" + "then\n" + "end";
final KieBase kbase = loadKnowledgeBaseFromString(str);
final KieSession ksession = createKnowledgeSession(kbase);
final Order order1 = new Order(1, "XYZ");
final Order order2 = new Order(2, "ABC");
final OrderItem item11 = new OrderItem(order1, 1);
order1.addItem(item11);
final OrderItem item21 = new OrderItem(order2, 1);
order2.addItem(item21);
ksession.insert(order1);
ksession.insert(order2);
ksession.insert(item11);
ksession.insert(item21);
final int rules = ksession.fireAllRules();
assertEquals(2, rules);
}
Aggregations