use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method testReportFailingConstraintOnError.
@Test
public void testReportFailingConstraintOnError() {
// DROOLS-1071
String drl = "import " + Person.class.getCanonicalName() + "\n" + "rule R when\n" + " Person( name.startsWith(\"A\") )\n" + "then\n" + "end";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession kieSession = kbase.newKieSession();
for (int i = 0; i < 100; i++) {
kieSession.insert(new Person("A" + i));
}
kieSession.fireAllRules();
kieSession.insert(new Person(null));
try {
kieSession.fireAllRules();
fail("Evaluation with null must throw a NPE");
} catch (Exception e) {
assertTrue(e.getMessage().contains("name.startsWith(\"A\")"));
}
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method testDeletedRightTupleInChangedBucket.
@Test
public void testDeletedRightTupleInChangedBucket() {
// PLANNER-488
String drl = "import " + Person.class.getCanonicalName() + "\n" + "rule R when\n" + " Person( $name: name, $age: age )\n" + " not Person( happy, name == $name, age == $age-1 )\n" + "then\n" + "end";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession kieSession = kbase.newKieSession();
Person p1 = new Person("C", 1, true);
Person p2 = new Person("B", 1, true);
Person p3 = new Person("B", 2, true);
Person p4 = new Person("A", 2);
FactHandle fh1 = kieSession.insert(p1);
FactHandle fh2 = kieSession.insert(p2);
FactHandle fh3 = kieSession.insert(p3);
FactHandle fh4 = kieSession.insert(p4);
kieSession.fireAllRules();
p4.setName("B");
p4.setHappy(true);
kieSession.update(fh4, p4);
kieSession.fireAllRules();
p3.setName("A");
p3.setHappy(false);
kieSession.update(fh3, p3);
p1.setName("B");
kieSession.update(fh1, p1);
p2.setName("C");
kieSession.update(fh2, p2);
kieSession.fireAllRules();
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method testStringCoercionComparison.
@Test
public void testStringCoercionComparison() {
// DROOLS-167
String str = "import " + Person.class.getName() + ";\n" + "rule R1 when\n" + " $p : Person( name < \"90201304122000000000000017\" )\n" + "then end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
ksession.insert(new Person("90201304122000000000000015", 38));
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method testPhreakWith2Nots.
@Test
public void testPhreakWith2Nots() {
// DROOLS-7
String str = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list;\n" + "rule R when\n" + " Person( $age : age, $name : name )\n" + " not Person( name == $name, age == $age + 1 )\n" + " not Person( name == $name, age == $age - 1 )\n" + "then\n" + " list.add($age);\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
List<Integer> list = new ArrayList<>();
ksession.setGlobal("list", list);
Person p1 = new Person("AAA", 31);
Person p2 = new Person("AAA", 34);
Person p3 = new Person("AAA", 33);
FactHandle fh1 = ksession.insert(p1);
FactHandle fh3 = ksession.insert(p3);
FactHandle fh2 = ksession.insert(p2);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals(31, (int) list.get(0));
list.clear();
p1.setAge(35);
ksession.update(fh1, p1);
p3.setAge(31);
ksession.update(fh3, p3);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals(31, (int) list.get(0));
}
use of org.drools.mvel.compiler.Person in project drools by kiegroup.
the class Misc2Test method producePeopleInCity.
private Address producePeopleInCity(final KieSession ksession, final String city, final int countOfPeople) {
final Address address = new Address();
address.setCity(city);
ksession.insert(address);
for (int i = 0; i < countOfPeople; i++) {
final Person person = new Person();
person.setName("Inhabitant " + i);
person.setAddress(address);
ksession.insert(person);
}
return address;
}
Aggregations