use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class CepEspTest method testStreamModeWithSubnetwork.
@Test
public void testStreamModeWithSubnetwork() {
// BZ-1009348
String drl = "package org.drools.compiler.integrationtests\n" + "\n" + "declare Event\n" + " @role(event)\n" + " name : String\n" + "end\n" + "\n" + "global java.util.List list\n" + "\n" + "rule \"firstRule\"\n" + "\n" + " when\n" + " not (\n" + " $e : Event() over window:length(3)\n" + " and Event( this == $e ) // test pass when you comment this line\n" + " )\n" + " then\n" + " list.add(\"firstRule\");\n" + "\n" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/notinfusion.drl", drl);
KieModuleModel kmoduleModel = ks.newKieModuleModel();
kmoduleModel.newKieBaseModel("KieBase").addPackage("*").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM).newKieSessionModel("KieSession").setDefault(true);
kfs.writeKModuleXML(kmoduleModel.toXML());
KieBuilder kbuilder = ks.newKieBuilder(kfs).buildAll();
List<org.kie.api.builder.Message> res = kbuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR);
assertEquals(res.toString(), 0, res.size());
KieSession ksession = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
ArrayList<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(1, list.size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class CepEspTest method testUpdateEventThroughEntryPoint.
@Test
public void testUpdateEventThroughEntryPoint() throws Exception {
String drl = "import org.drools.compiler.integrationtests.CepEspTest.TestEvent\n" + "\n" + "declare TestEvent\n" + " @role( event )\n" + " @expires( 4s )\n" + "end\n" + "\n" + "rule \"TestEventReceived\"\n" + " no-loop\n" + " when\n" + " $event : TestEvent ( name != null ) over window:time( 4s ) from entry-point EventStream\n" + " then\n" + " // insert( new Message( $event.getValue().toString() ) );\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kieModule = ks.newKieModuleModel();
kieModule.newKieBaseModel("KBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM).newKieSessionModel("KSession").setDefault(true);
kfs.writeKModuleXML(kieModule.toXML());
kfs.write("src/main/resources/lifecycle.drl", drl);
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, builder.getResults().getMessages().size());
KieSession kieSession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
EntryPoint entryPoint = kieSession.getEntryPoint("EventStream");
TestEvent event = new TestEvent("testEvent1");
FactHandle handle = entryPoint.insert(event);
TestEvent event2 = new TestEvent("testEvent2");
entryPoint.update(handle, event2);
// make sure the event is in the entry-point
assertFalse(entryPoint.getObjects().contains(event));
assertTrue(entryPoint.getObjects().contains(event2));
assertEquals(entryPoint.getObject(handle), event2);
kieSession.dispose();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class CepEspTest method testTemporalEvaluatorsUsingRawDateFields.
@Test
public void testTemporalEvaluatorsUsingRawDateFields() throws InterruptedException {
// DROOLS-421
String drl = "\n" + "import java.util.*; " + "global List list; " + "declare Delivery " + " effectiveDate : Date " + "end " + "declare Config " + " todate : Date " + "end " + "rule Control " + "when " + " $dpo: Delivery( $eff : effectiveDate ) " + " $gCfg: Config( todate == null || todate after[ 0d ] $eff ) " + "then " + " list.add( 0 ); " + "end " + "rule Init " + "when " + "then " + " Delivery dpo = new Delivery( new Date( 1000 ) ); " + " Config gCfg = new Config(); " + " gCfg.setTodate( new Date( 2000 ) ); " + " " + " insert( dpo ); " + " insert( gCfg ); " + "end " + "";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("rules.drl"));
KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();
assertEquals(0, kbuilder.getResults().getMessages().size());
KieSession ksession = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
assertNotNull(ksession);
List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(1, list.size());
ksession.dispose();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class CepEspTest method testTemporalEvaluatorsUsingSelfDates.
@Test
public void testTemporalEvaluatorsUsingSelfDates() throws InterruptedException {
// DROOLS-421
String drl = "\n" + "import java.util.*; " + "global List list; " + "declare Delivery " + " thisDate : Date " + " thatDate : Date " + "end " + "rule Init when then insert( new Delivery( new Date( 1000 ), new Date( 200 ) ) ); end " + "rule Control " + "when " + " Delivery( thisDate == null || thisDate after[ 0d ] thatDate ) " + "then " + " list.add( 0 ); " + "end " + "";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("rules.drl"));
KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();
assertEquals(0, kbuilder.getResults().getMessages().size());
KieSession ksession = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
assertNotNull(ksession);
List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(1, list.size());
ksession.dispose();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class CepEspTest method testTemporalEvaluatorsUsingRawDateFieldsFromFrom.
@Test
public void testTemporalEvaluatorsUsingRawDateFieldsFromFrom() throws InterruptedException {
// DROOLS-421
String drl = "\n" + "import java.util.*; " + "global List list; " + "declare Delivery " + " effectiveDate : Date " + "end " + "declare Config " + " todate : Date " + "end " + "rule Control " + "when " + " $dpo: Delivery( $eff : effectiveDate ) from new Delivery( new Date( 1000 ) ) " + " $gCfg: Config( todate == null || todate after[ 0d ] $eff ) from new Config( new Date( 2000 ) ) " + "then " + " list.add( 0 ); " + "end " + "";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("rules.drl"));
KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();
assertEquals(0, kbuilder.getResults().getMessages().size());
KieSession ksession = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
assertNotNull(ksession);
List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(1, list.size());
ksession.dispose();
}
Aggregations