use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class PassiveQueryTest method testPassiveQueryNodeSharing2.
@Test
public void testPassiveQueryNodeSharing2() throws Exception {
String str = "global java.util.List list\n" + "query Q (Integer i)\n" + " String( this == i.toString() )\n" + "end\n" + "rule R1a @Propagation(IMMEDIATE) when\n" + " $i : Integer()\n" + " ?Q( $i; )\n" + "then\n" + " list.add( \"R1a\" );\n" + "end\n" + "rule R1b @Propagation(IMMEDIATE) when\n" + " Long( $i : intValue )\n" + " ?Q( $i; )\n" + "then\n" + " list.add( \"R1b\" );\n" + "end\n" + "rule R2a when\n" + " $i : Integer()\n" + " ?Q( $i; )\n" + "then\n" + " list.add( \"R2a\" );\n" + "end\n" + "rule R2b when\n" + " Long( $i : intValue )\n" + " ?Q( $i; )\n" + "then\n" + " list.add( \"R2b\" );\n" + "end\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert(1);
ksession.insert(1L);
ksession.insert("1");
ksession.fireAllRules();
assertEquals(2, list.size());
assertTrue(list.containsAll(asList("R2a", "R2b")));
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class PassiveQueryTest method testReactiveQueryDataDriven.
@Test
public void testReactiveQueryDataDriven() throws Exception {
String str = "global java.util.List list\n" + "query Q (Integer i)\n" + " String( this == i.toString() )\n" + "end\n" + "rule R @Propagation(IMMEDIATE) when\n" + " $i : Integer()\n" + " Q( $i; )\n" + "then\n" + " list.add( $i );\n" + "end\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
List<Integer> list = new ArrayList<Integer>();
ksession.setGlobal("list", list);
ksession.insert(1);
ksession.insert("1");
ksession.fireAllRules();
assertEquals(1, list.size());
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class PassiveQueryTest method testPassiveQuery.
@Test
public void testPassiveQuery() throws Exception {
String str = "global java.util.List list\n" + "query Q (Integer i)\n" + " String( this == i.toString() )\n" + "end\n" + "rule R when\n" + " $i : Integer()\n" + " ?Q( $i; )\n" + "then\n" + " list.add( $i );\n" + "end\n";
KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession();
List<Integer> list = new ArrayList<Integer>();
ksession.setGlobal("list", list);
ksession.insert(1);
ksession.insert("2");
ksession.fireAllRules();
assertEquals(0, list.size());
ksession.insert("1");
ksession.fireAllRules();
assertEquals(0, list.size());
ksession.insert(2);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals(2, (int) list.get(0));
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class PolymorphismTest method testModifySubclassOverWindow.
@Test
public void testModifySubclassOverWindow() {
// DROOLS-1501
String drl = "declare Number @role( event ) end\n" + "declare Integer @role( event ) end\n" + "\n" + "rule R1 no-loop when\n" + " $i: Integer()\n" + "then\n" + " update($i);\n" + "end\n" + "rule R2 when\n" + " $n: Number() over window:length(1)\n" + "then\n" + "end";
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build(EventProcessingOption.STREAM).newKieSession();
ksession.insert(1);
ksession.fireAllRules();
}
use of org.kie.internal.utils.KieHelper in project drools by kiegroup.
the class PolymorphismTest method testModifySubclass2.
@Test
public void testModifySubclass2() {
// DROOLS-1501
String drl = "import " + A.class.getCanonicalName() + "\n;" + "import " + B.class.getCanonicalName() + "\n;" + "import " + C.class.getCanonicalName() + "\n;" + "import " + D.class.getCanonicalName() + "\n;" + "\n" + "rule Rd when\n" + " $a: D(id == 0)\n" + " $d: C($id : id == 0)\n" + "then\n" + " modify($d) { setId($id+1) };\n" + "end\n" + "rule Rc when\n" + " $a: D(id == 1)\n" + " $c: B($id : id == 1)\n" + "then\n" + " modify($c) { setId($id+1) };\n" + "end\n" + "rule Rb when\n" + " $a: D(id == 2)\n" + " $b: A($id : id == 2)\n" + "then\n" + " modify($b) { setId($id+1) };\n" + "end\n" + "rule Ra when\n" + " $a: D(id == 3)\n" + "then\n" + " delete($a);\n" + "end";
KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build(EventProcessingOption.STREAM).newKieSession();
FactHandle fh = ksession.insert(new D(0));
ksession.fireAllRules();
assertEquals(0, ksession.getObjects().size());
System.out.println(fh);
}
Aggregations