use of org.drools.mvel.integrationtests.facts.FactWithList in project drools by kiegroup.
the class Misc2Test method testCollectWithEagerActivation.
@Test
public void testCollectWithEagerActivation() {
// DROOLS-4468
String drl = "import java.util.ArrayList\n" + "import " + FactWithList.class.getCanonicalName() + "\n" + "import " + FactWithString.class.getCanonicalName() + "\n" + "\n" + "dialect \"mvel\"\n" + "global java.util.List list; \n" + "\n" + " rule \"Init\"\n" + " when\n" + " $fl: FactWithList(items.size()==0)\n" + " then\n" + " $fl.getItems().add(\"A\");\n" + " $fl.getItems().add(\"B\");\n" + " update($fl);\n" + " end\n" + "\n" + " rule \"R1\"\n" + " when\n" + " $fl: FactWithList($itemList : items)\n" + " $l: java.util.List(size > 0) from collect(FactWithString($itemList contains stringValue));\n" + " then\n" + " list.add(\"R1\"); \n" + " end\n" + "\n" + " rule \"R2\"\n" + " when\n" + " $fl: FactWithList($itemList : items)\n" + " not( FactWithString($itemList contains stringValue) )\n" + " then\n" + " list.add(\"R2\"); \n" + " end";
KieSessionConfiguration config = KieServices.Factory.get().newKieSessionConfiguration(null);
config.setOption(ForceEagerActivationOption.YES);
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession(config, null);
List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.insert(new FactWithString("A"));
ksession.insert(new FactWithList());
ksession.fireAllRules();
assertEquals(1, list.size());
assertTrue(list.contains("R1"));
}
Aggregations