use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class AlphaNodeTest method testAlphaModify.
@Test
public void testAlphaModify() {
String str = "import " + Person.class.getCanonicalName() + "\n" + "rule R1 when\n" + " $p : Person(name == \"Mario\")\n" + "then\n" + " modify($p) { setName(\"Mark\")}" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
ksession.insert(new Person("Mario"));
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method testJittedConstraintStringAndLong.
@Test
public void testJittedConstraintStringAndLong() {
// DROOLS-740
String drl = " import org.drools.mvel.compiler.Person; " + " rule 'hello person' " + " when " + " Person( name == \"Elizabeth\" + new Long(2L) ) " + " then " + " end " + "\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
ksession.insert(new org.drools.mvel.compiler.Person("Elizabeth2", 88));
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method testWrongNodeSharingWithSameHashCode.
@Test
public void testWrongNodeSharingWithSameHashCode() throws IllegalAccessException, InstantiationException {
String drl = "import " + Person.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " String()\n" + " $p: Person( name == \"ATL\", name != null)\n" + "then \n" + " $p.setHappy(true);\n" + "end\n" + "rule R2 when\n" + " String()\n" + " $p: Person( name == \"B5L\", name != null)\n" + "then \n" + " $p.setHappy(true);\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession kieSession = kbase.newKieSession();
kieSession.insert("test");
Person b5L = new Person("B5L");
kieSession.insert(b5L);
assertFalse(b5L.isHappy());
kieSession.fireAllRules();
assertTrue(b5L.isHappy());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method testReuseAgendaAfterException.
@Test
public void testReuseAgendaAfterException() throws Exception {
// JBRULES-3677
String str = "import org.drools.mvel.compiler.Person;\n" + "global java.util.List results;" + "rule R1\n" + "ruleflow-group \"test\"\n" + "when\n" + " Person( $age : age ) \n" + "then\n" + " if ($age > 40) throw new RuntimeException(\"Too old\");\n" + " results.add(\"OK\");" + "end";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
List<String> res = new ArrayList<>();
ksession.setGlobal("results", res);
AgendaEventListener agendaEventListener = new AgendaEventListener() {
public void matchCreated(org.kie.api.event.rule.MatchCreatedEvent event) {
}
public void matchCancelled(org.kie.api.event.rule.MatchCancelledEvent event) {
}
public void beforeMatchFired(org.kie.api.event.rule.BeforeMatchFiredEvent event) {
}
public void afterMatchFired(org.kie.api.event.rule.AfterMatchFiredEvent event) {
}
public void agendaGroupPopped(org.kie.api.event.rule.AgendaGroupPoppedEvent event) {
}
public void agendaGroupPushed(org.kie.api.event.rule.AgendaGroupPushedEvent event) {
}
public void beforeRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent event) {
}
public void afterRuleFlowGroupActivated(org.kie.api.event.rule.RuleFlowGroupActivatedEvent event) {
ksession.fireAllRules();
}
public void beforeRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent event) {
}
public void afterRuleFlowGroupDeactivated(org.kie.api.event.rule.RuleFlowGroupDeactivatedEvent event) {
}
};
ksession.addEventListener(agendaEventListener);
FactHandle fact1 = ksession.insert(new Person("Mario", 38));
((InternalAgenda) ksession.getAgenda()).activateRuleFlowGroup("test");
ksession.fireAllRules();
assertEquals(1, res.size());
res.clear();
ksession.delete(fact1);
FactHandle fact2 = ksession.insert(new Person("Mario", 48));
try {
((InternalAgenda) ksession.getAgenda()).activateRuleFlowGroup("test");
ksession.fireAllRules();
fail("should throw an Exception");
} catch (Exception e) {
}
ksession.delete(fact2);
assertEquals(0, res.size());
// try to reuse the ksession after the Exception
FactHandle fact3 = ksession.insert(new Person("Mario", 38));
((InternalAgenda) ksession.getAgenda()).activateRuleFlowGroup("test");
ksession.fireAllRules();
assertEquals(1, res.size());
ksession.delete(fact3);
ksession.dispose();
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method testBigDecimalComparison.
@Test
public void testBigDecimalComparison() throws Exception {
// JBRULES-3715
String str = "import org.drools.mvel.compiler.Person;\n" + "rule \"Big Decimal Comparison\"\n" + " dialect \"mvel\"\n" + "when\n" + " Person( bigDecimal == 0.0B )\n" + "then\n" + "end";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
Person p = new Person("Mario", 38);
p.setBigDecimal(new BigDecimal("0"));
ksession.insert(p);
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
}
Aggregations