use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class DynamicRulesTest method testDynamicRuleRemovalsSubNetworkAndNot.
@Test(timeout = 10000)
public void testDynamicRuleRemovalsSubNetworkAndNot() throws Exception {
InternalKnowledgeBase kbase = (InternalKnowledgeBase) KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_DynamicRulesWithNotSubnetwork.drl");
KieSession ksession = kbase.newKieSession();
final AgendaEventListener alistener = mock(AgendaEventListener.class);
ksession.addEventListener(alistener);
// pattern does not match, so do not activate
ksession.insert(new Person("toni"));
ksession.fireAllRules();
verify(alistener, never()).matchCreated(any(org.kie.api.event.rule.MatchCreatedEvent.class));
// pattern matches, so create activation
ksession.insert(new Person("bob"));
ksession.fireAllRules();
verify(alistener, times(1)).matchCreated(any(org.kie.api.event.rule.MatchCreatedEvent.class));
// already active, so no new activation should be created
ksession.insert(new Person("mark"));
ksession.fireAllRules();
verify(alistener, times(1)).matchCreated(any(org.kie.api.event.rule.MatchCreatedEvent.class));
kbase.removeKiePackage("org.drools.mvel.compiler");
assertEquals(0, kbase.getKiePackages().size());
// lets re-compile and add it again
Collection<KiePackage> kpkgs = KieBaseUtil.getKieBaseFromClasspathResources("tmp", getClass(), kieBaseTestConfiguration, "test_DynamicRulesWithNotSubnetwork.drl").getKiePackages();
kbase.addPackages(kpkgs);
ksession.fireAllRules();
// rule should be reactivated, since data is still in the session
verify(alistener, times(2)).matchCreated(any(org.kie.api.event.rule.MatchCreatedEvent.class));
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class ExecutionFlowControlTest method testSalienceExpression.
@Test
public void testSalienceExpression() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "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.mvel.compiler.Person in project drools by kiegroup.
the class FirstOrderLogicTest method testFromWithOr.
@Test
public void testFromWithOr() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_FromWithOr.drl");
KieSession session = kbase.newKieSession();
final List<Address> results = new ArrayList<Address>();
session.setGlobal("results", results);
Address a1 = new Address();
a1.setZipCode("12345");
Address a2 = new Address();
a2.setZipCode("54321");
Address a3 = new Address();
a3.setZipCode("99999");
Person p = new Person();
p.addAddress(a1);
p.addAddress(a2);
p.addAddress(a3);
session.insert(p);
session.fireAllRules();
assertEquals(2, results.size());
assertTrue(results.contains(a1));
assertTrue(results.contains(a2));
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectWithNestedFromWithParams.
@Test
public void testCollectWithNestedFromWithParams() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CollectWithNestedFrom.drl");
KieSession workingMemory = kbase.newKieSession();
final List results = new ArrayList();
workingMemory.setGlobal("results", results);
final Person bob = new Person("bob", "stilton");
Cheesery cheesery = new Cheesery();
cheesery.addCheese(new Cheese("stilton", 10));
cheesery.addCheese(new Cheese("brie", 20));
cheesery.addCheese(new Cheese("muzzarela", 8));
cheesery.addCheese(new Cheese("stilton", 5));
cheesery.addCheese(new Cheese("provolone", 1));
workingMemory.insert(bob);
workingMemory.insert(cheesery);
workingMemory.fireAllRules();
assertEquals(1, results.size());
List cheeses = (List) results.get(0);
assertEquals(2, cheeses.size());
assertEquals(bob.getLikes(), ((Cheese) cheeses.get(0)).getType());
assertEquals(bob.getLikes(), ((Cheese) cheeses.get(1)).getType());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectFromMVELAfterOr.
@Test
public void testCollectFromMVELAfterOr() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CollectFromMVELAfterOr.drl");
KieSession wm = kbase.newKieSession();
List results = new ArrayList();
wm.setGlobal("results", results);
Person jill = new Person("jill");
Person bob = new Person("bob");
List addresses = new ArrayList();
addresses.add(new Address("a"));
addresses.add(new Address("b"));
addresses.add(new Address("c"));
bob.setAddresses(addresses);
wm.insert(jill);
wm.insert(bob);
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
wm.fireAllRules();
assertEquals(2, results.size());
assertEquals(3, ((Collection) results.get(0)).size());
}
Aggregations