use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class UpdateTest method noDormantCheckOnModifies.
@Test
public void noDormantCheckOnModifies() throws Exception {
// Test case for BZ 862325
final String str = "package org.drools.mvel.compiler;\n" + " rule R1\n" + " salience 10\n" + " when\n" + " $c : Cheese( price == 10 ) \n" + " $p : Person( ) \n" + " then \n" + " modify($c) { setPrice( 5 ) }\n" + " modify($p) { setAge( 20 ) }\n" + "end\n" + "rule R2\n" + " when\n" + " $p : Person( )" + " then \n" + " // noop\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
final org.kie.api.event.rule.AgendaEventListener ael = mock(org.kie.api.event.rule.AgendaEventListener.class);
ksession.addEventListener(ael);
ksession.insert(new Person("Bob", 19));
ksession.insert(new Cheese("brie", 10));
ksession.fireAllRules();
// both rules should fire exactly once
verify(ael, times(2)).afterMatchFired(any(org.kie.api.event.rule.AfterMatchFiredEvent.class));
// no cancellations should have happened
verify(ael, never()).matchCancelled(any(org.kie.api.event.rule.MatchCancelledEvent.class));
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class SequentialTest method testSalience.
@Test
public void testSalience() throws Exception {
final KieModule kieModule = KieUtil.getKieModuleFromClasspathResources("test", getClass(), kieBaseTestConfiguration, "simpleSalience.drl");
final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, SequentialOption.YES);
StatelessKieSession ksession = kbase.newStatelessKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.execute(new Person("pob"));
assertEquals(3, list.size());
assertEquals("rule 3", list.get(0));
assertEquals("rule 2", list.get(1));
assertEquals("rule 1", list.get(2));
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class SequentialTest method testBasicOperation.
@Test
public void testBasicOperation() throws Exception {
final KieModule kieModule = KieUtil.getKieModuleFromClasspathResources("test", getClass(), kieBaseTestConfiguration, "simpleSequential.drl");
final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, SequentialOption.YES);
StatelessKieSession ksession = kbase.newStatelessKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Person p1 = new Person("p1", "stilton");
final Person p2 = new Person("p2", "cheddar");
final Person p3 = new Person("p3", "stilton");
final Cheese stilton = new Cheese("stilton", 15);
final Cheese cheddar = new Cheese("cheddar", 15);
ksession.execute(CommandFactory.newInsertElements(Arrays.asList(new Object[] { p1, stilton, p2, cheddar, p3 })));
assertEquals(3, list.size());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class SequentialTest method testSequentialWithRulebaseUpdate.
// JBRULES-1567 - ArrayIndexOutOfBoundsException in sequential execution after calling RuleBase.addPackage(..)
@Test
public void testSequentialWithRulebaseUpdate() throws Exception {
final KieModule kieModule = KieUtil.getKieModuleFromClasspathResources("test", getClass(), kieBaseTestConfiguration, "simpleSalience.drl");
final InternalKnowledgeBase kbase = (InternalKnowledgeBase) KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, SequentialOption.YES);
StatelessKieSession ksession = kbase.newStatelessKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.execute(new Person("pob"));
Collection<KiePackage> kpkgs = KieBaseUtil.getKieBaseFromClasspathResources("tmp", DynamicRulesTest.class, kieBaseTestConfiguration, "test_Dynamic3.drl").getKiePackages();
kbase.addPackages(kpkgs);
ksession = kbase.newStatelessKieSession();
ksession.setGlobal("list", list);
Person person = new Person("bop");
ksession.execute(person);
assertEquals(7, list.size());
assertEquals("rule 3", list.get(0));
assertEquals("rule 2", list.get(1));
assertEquals("rule 1", list.get(2));
assertEquals("rule 3", list.get(3));
assertEquals("rule 2", list.get(4));
assertEquals("rule 1", list.get(5));
assertEquals(person, list.get(6));
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class FieldAccessTest method testGenericsOption.
@Test
public void testGenericsOption() throws Exception {
// JBRULES-3579
final String str = "import org.drools.mvel.compiler.*;\n" + "rule R1 when\n" + " $c : Cheese( $type: type )\n" + " $p : Person( $name : name, addressOption.get.street == $type )\n" + "then\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
final Person p = new Person("x");
p.setAddress(new Address("x", "x", "x"));
ksession.insert(p);
ksession.insert(new Cheese("x"));
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
}
Aggregations