use of org.drools.mvel.compiler.OrderItem in project drools by kiegroup.
the class DynamicRulesTest method testRemovePackageSubNetwork.
@Test(timeout = 10000)
public void testRemovePackageSubNetwork() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_DynamicRulesWithSubnetwork.drl");
String packageName = kbase.getKiePackages().iterator().next().getName();
KieSession workingMemory = kbase.newKieSession();
List<?> results = new ArrayList<Object>();
workingMemory.setGlobal("results", results);
Order order = new Order();
OrderItem item1 = new OrderItem(order, 1, "Adventure Guide Brazil", OrderItem.TYPE_BOOK, 24);
OrderItem item2 = new OrderItem(order, 2, "Prehistoric Britain", OrderItem.TYPE_BOOK, 15);
OrderItem item3 = new OrderItem(order, 3, "Holiday Music", OrderItem.TYPE_CD, 9);
OrderItem item4 = new OrderItem(order, 4, "Very Best of Mick Jagger", OrderItem.TYPE_CD, 11);
OrderItem item5 = new OrderItem(order, 5, "The Master and Margarita", OrderItem.TYPE_BOOK, 29);
order.addItem(item1);
order.addItem(item2);
order.addItem(item3);
order.addItem(item4);
order.addItem(item5);
workingMemory.insert(order);
workingMemory.fireAllRules();
assertEquals(1, results.size());
assertEquals(3, ((List) results.get(0)).size());
results.clear();
InternalKnowledgeBase ruleBaseWM = (InternalKnowledgeBase) workingMemory.getKieBase();
ruleBaseWM.removeKiePackage(packageName);
Collection<KiePackage> kpkgs = KieBaseUtil.getKieBaseFromClasspathResources("tmp", getClass(), kieBaseTestConfiguration, "test_DynamicRulesWithSubnetwork.drl").getKiePackages();
ruleBaseWM.addPackages(kpkgs);
workingMemory.fireAllRules();
results = (List) workingMemory.getGlobal("results");
assertEquals(1, results.size());
assertEquals(3, ((List) results.get(0)).size());
results.clear();
ruleBaseWM.removeKiePackage(packageName);
ruleBaseWM.addPackages(kpkgs);
workingMemory.fireAllRules();
assertEquals(1, results.size());
assertEquals(3, ((List) results.get(0)).size());
results.clear();
ruleBaseWM.removeKiePackage(packageName);
ruleBaseWM.addPackages(kpkgs);
workingMemory.fireAllRules();
assertEquals(1, results.size());
assertEquals(3, ((List) results.get(0)).size());
results.clear();
}
use of org.drools.mvel.compiler.OrderItem in project drools by kiegroup.
the class Query2Test method testEvalRewrite.
@Test
public void testEvalRewrite() throws Exception {
String str = "" + "package org.drools.mvel.compiler;\n" + "global java.util.List results;\n" + "rule \"eval rewrite\"\n" + " when\n" + " $o1 : OrderItem( order.number == 11, $seq : seq == 1 )\n" + // " $o2 : OrderItem( order.number == $o1.order.number, seq != $seq )\n" +
" $o2 : Order( items[(Integer) 1] == $o1 ) \n" + " then\n" + " System.out.println( $o1 + \":\" + $o2 );\n" + "end \n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
final Order order1 = new Order(11, "Bob");
final OrderItem item11 = new OrderItem(order1, 1);
final OrderItem item12 = new OrderItem(order1, 2);
ksession.insert(order1);
ksession.insert(item11);
ksession.insert(item12);
ksession.fireAllRules();
}
use of org.drools.mvel.compiler.OrderItem in project drools by kiegroup.
the class DynamicRulesTest method testDynamicRuleRemovalsSubNetwork.
@Test(timeout = 10000)
public void testDynamicRuleRemovalsSubNetwork() throws Exception {
Collection<KiePackage> kpkgs = KieBaseUtil.getKieBaseFromClasspathResources("tmp", getClass(), kieBaseTestConfiguration, "test_DynamicRulesWithSubnetwork1.drl", "test_DynamicRulesWithSubnetwork.drl").getKiePackages();
InternalKnowledgeBase kbase = (InternalKnowledgeBase) KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration);
kbase.addPackages(kpkgs);
kpkgs = KieBaseUtil.getKieBaseFromClasspathResources("tmp", getClass(), kieBaseTestConfiguration, "test_DynamicRulesWithSubnetwork2.drl").getKiePackages();
kbase.addPackages(kpkgs);
KieSession session = kbase.newKieSession();
final List<?> list = new ArrayList<Object>();
session.setGlobal("results", list);
Order order = new Order();
OrderItem item1 = new OrderItem(order, 1, "Adventure Guide Brazil", OrderItem.TYPE_BOOK, 24);
order.addItem(item1);
FactHandle item1Fh = session.insert(item1);
OrderItem item2 = new OrderItem(order, 2, "Prehistoric Britain", OrderItem.TYPE_BOOK, 15);
order.addItem(item2);
FactHandle item2Fh = session.insert(item2);
OrderItem item3 = new OrderItem(order, 3, "Holiday Music", OrderItem.TYPE_CD, 9);
order.addItem(item3);
FactHandle item3Fh = session.insert(item3);
OrderItem item4 = new OrderItem(order, 4, "Very Best of Mick Jagger", OrderItem.TYPE_CD, 11);
order.addItem(item4);
FactHandle item4Fh = session.insert(item4);
session.insert(order);
session.fireAllRules();
assertEquals(11, list.size());
kbase.removeRule("org.drools.mvel.compiler", "Apply Discount on all books");
list.clear();
session.update(item1Fh, item1);
session.update(item2Fh, item2);
session.update(item3Fh, item3);
session.update(item4Fh, item4);
session.fireAllRules();
assertEquals(10, list.size());
kbase.removeRule("org.drools.mvel.compiler", "like book");
list.clear();
session.update(item1Fh, item1);
session.update(item2Fh, item2);
session.update(item3Fh, item3);
session.update(item4Fh, item4);
session.fireAllRules();
assertEquals(8, list.size());
final OrderItem item5 = new OrderItem(order, 5, "Sinatra : Vegas", OrderItem.TYPE_CD, 5);
FactHandle item5Fh = session.insert(item5);
session.fireAllRules();
assertEquals(10, list.size());
kbase.removeKiePackage("org.drools.mvel.compiler");
list.clear();
session.update(item1Fh, item1);
session.update(item2Fh, item2);
session.update(item3Fh, item3);
session.update(item4Fh, item4);
session.update(item5Fh, item5);
session.fireAllRules();
assertEquals(0, list.size());
}
use of org.drools.mvel.compiler.OrderItem in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectWithContainsOperators.
@Test
public void testCollectWithContainsOperators() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CollectContainsOperator.drl");
KieSession workingMemory = kbase.newKieSession();
final List list = new ArrayList();
workingMemory.setGlobal("results", list);
final Order order1 = new Order(1, "bob");
final OrderItem item11 = new OrderItem(order1, 1);
final OrderItem item12 = new OrderItem(order1, 2);
final Order order2 = new Order(2, "mark");
final OrderItem item21 = new OrderItem(order2, 1);
final OrderItem item22 = new OrderItem(order2, 2);
workingMemory.insert(order1);
workingMemory.insert(item11);
workingMemory.insert(item12);
workingMemory.insert(order2);
workingMemory.insert(item21);
workingMemory.insert(item22);
workingMemory.fireAllRules();
int index = 0;
assertEquals(8, list.size());
assertSame(order1, list.get(index++));
assertSame(item11, list.get(index++));
assertSame(order2, list.get(index++));
assertSame(item21, list.get(index++));
assertSame(order1, list.get(index++));
assertSame(item11, list.get(index++));
assertSame(order2, list.get(index++));
assertSame(item21, list.get(index++));
}
use of org.drools.mvel.compiler.OrderItem in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectWithMemberOfOperators.
@Test
public void testCollectWithMemberOfOperators() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CollectMemberOfOperator.drl");
KieSession workingMemory = kbase.newKieSession();
final List list = new ArrayList();
workingMemory.setGlobal("results", list);
final Order order1 = new Order(1, "bob");
final OrderItem item11 = new OrderItem(order1, 1);
final OrderItem item12 = new OrderItem(order1, 2);
final Order order2 = new Order(2, "mark");
final OrderItem item21 = new OrderItem(order2, 1);
final OrderItem item22 = new OrderItem(order2, 2);
workingMemory.insert(order1);
workingMemory.insert(item11);
workingMemory.insert(item12);
workingMemory.insert(order2);
workingMemory.insert(item21);
workingMemory.insert(item22);
workingMemory.fireAllRules();
int index = 0;
assertEquals(8, list.size());
assertSame(order1, list.get(index++));
assertSame(item11, list.get(index++));
assertSame(order2, list.get(index++));
assertSame(item21, list.get(index++));
assertSame(order1, list.get(index++));
assertSame(item11, list.get(index++));
assertSame(order2, list.get(index++));
assertSame(item21, list.get(index++));
}
Aggregations