use of org.kie.internal.utils.KieHelper 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";
KieSession kieSession = new KieHelper().addContent(drl, ResourceType.DRL).build().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.kie.internal.utils.KieHelper in project drools by kiegroup.
the class Misc2Test method checkJava8InRhs.
private void checkJava8InRhs(String expr) {
assumeTrue(System.getProperty("java.version").startsWith("1.8"));
// BZ-1199965
String drl = "global java.util.List list;\n" + "rule \"Example with Lambda expression\"\n" + " when\n" + " then\n" + " java.util.List<Integer> $list = java.util.Arrays.asList(1, 2, 3, 4);\n" + " $list.forEach(" + expr + ");\n" + "end\n";
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
List<Integer> list = new ArrayList<Integer>();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(4, list.size());
assertTrue(list.containsAll(Arrays.asList(1, 2, 3, 4)));
}
use of org.kie.internal.utils.KieHelper 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";
KieSession kieSession = new KieHelper().addContent(drl, ResourceType.DRL).build().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.kie.internal.utils.KieHelper in project drools by kiegroup.
the class Misc2Test method testDoubleNestedClass.
@Test
public void testDoubleNestedClass() {
// DROOLS-815
String drl = "import " + $X.$Y.class.getCanonicalName() + ";\n" + "global java.util.List list\n" + "rule R when\n" + " $X.$Y($v : value)\n" + "then\n" + " list.add($v);\n" + "end";
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert(new $X.$Y(42));
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals(42, list.get(0));
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class Misc2Test method testBitwiseOperator.
@Test
public void testBitwiseOperator() {
// DROOLS-585
String drl = "global java.util.List list;\n" + "\n" + "rule R when\n" + " $i : Integer( (intValue() & 5) != 0 )\n" + "then\n" + " list.add($i);\n" + "end";
KieHelper helper = new KieHelper();
helper.addContent(drl, ResourceType.DRL);
KieSession kieSession = helper.build().newKieSession();
List<Integer> list = new ArrayList<Integer>();
kieSession.setGlobal("list", list);
kieSession.insert(3);
kieSession.insert(2);
kieSession.insert(6);
kieSession.fireAllRules();
assertEquals(2, list.size());
assertTrue(list.containsAll(asList(3, 6)));
}
Aggregations