use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class Misc2Test method testMultilineStatement.
@Test
public void testMultilineStatement() {
// BZ-1092502
String str = "rule \"test\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "System \n" + " .out \n" + " .println(\"hello\");\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertEquals(0, results.getMessages().size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class Misc2Test method testNestedNots1.
@Test
public void testNestedNots1() {
// DROOLS-444
String str = "package org.test; " + "rule negation_over_nested " + "when " + " not ( (String() and Integer()) " + " or " + " (String() and Integer())) " + "then " + " System.out.println(\"negation_over_nested\"); " + "end " + " " + "rule negation_distributed_partially_no_sharing " + "when " + " (not (String() and Long())) " + " and " + " (not (String() and Long())) " + "then " + " System.out.println(\"negation_distributed_partially_no_sharing\"); " + "end " + " " + "rule negation_distributed_partially_sharing " + "when " + " (not (String() and Integer())) " + " and " + " (not (String() and Integer())) " + "then " + " System.out.println(\"negation_distributed_partially_sharing\"); " + "end " + " " + "rule negation_distributed_fully " + "when " + " ((not String()) or (not Integer())) " + " and " + " ((not String()) or (not Integer())) " + "then " + " System.out.println(\"negation_distributed_fully\"); " + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
int n = ksession.fireAllRules();
assertEquals(7, n);
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class Misc2Test method testNPEOnMutableGlobal.
@Test
public void testNPEOnMutableGlobal() throws Exception {
// BZ-1019473
String str = "package org.drools.compiler\n" + "global java.util.List context\n" + "rule B\n" + " when\n" + " Message( message == \"b\" )\n" + " $s : String() from context\n" + " then\n" + " System.out.println($s);\n" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newByteArrayResource(str.getBytes()).setTargetPath("org/drools/compiler/rules.drl"));
KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();
assertEquals(0, kbuilder.getResults().getMessages().size());
ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).getKieBase();
KieSession ksession = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
assertNotNull(ksession);
List<String> context = new ArrayList<String>();
ksession.setGlobal("context", context);
FactHandle b = ksession.insert(new Message("b"));
ksession.delete(b);
int fired = ksession.fireAllRules(1);
assertEquals(0, fired);
ksession.dispose();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class Misc2Test method testTwoTimers.
@Test
public void testTwoTimers() {
// BZ-980385
String str = "import java.util.Date\n" + "import java.util.List\n" + "\n" + "global List dates\n" + "\n" + "rule \"intervalRule\"\n" + " timer(int: 200ms 100ms)\n" + "when\n" + " String(this == \"intervalRule\")\n" + "then\n" + " Date date = new Date();\n" + " dates.add(date);\n" + "end\n" + "\n" + "\n" + "// this rule stops timer\n" + "rule \"stopIntervalRule\"\n" + " timer(int: 320ms)\n" + "when\n" + " $s : String(this == \"intervalRule\")\n" + "then\n" + " delete($s);\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
assertEquals(0, ks.newKieBuilder(kfs).buildAll().getResults().getMessages().size());
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class ListenersTest method prepareKieModule.
/**
* Inserts a new KieModule containing single KieBase and a stateful and stateless KieSessions with listeners
* into KieRepository.
*
* @return created KIE module ReleaseId
*/
private ReleaseId prepareKieModule() {
final KieServices ks = KieServices.Factory.get();
KieModuleModel module = ks.newKieModuleModel();
KieBaseModel baseModel = module.newKieBaseModel("defaultKBase");
baseModel.setDefault(true);
baseModel.addPackage("*");
KieSessionModel sessionModel = baseModel.newKieSessionModel("defaultKSession");
sessionModel.setDefault(true);
sessionModel.setType(KieSessionModel.KieSessionType.STATEFUL);
sessionModel.newListenerModel(MarkingAgendaEventListener.class.getName(), ListenerModel.Kind.AGENDA_EVENT_LISTENER);
sessionModel.newListenerModel(MarkingRuntimeEventListener.class.getName(), ListenerModel.Kind.RULE_RUNTIME_EVENT_LISTENER);
KieSessionModel statelessSessionModel = baseModel.newKieSessionModel("defaultStatelessKSession");
statelessSessionModel.setDefault(true);
statelessSessionModel.setType(KieSessionModel.KieSessionType.STATELESS);
statelessSessionModel.newListenerModel(MarkingAgendaEventListener.class.getName(), ListenerModel.Kind.AGENDA_EVENT_LISTENER);
statelessSessionModel.newListenerModel(MarkingRuntimeEventListener.class.getName(), ListenerModel.Kind.RULE_RUNTIME_EVENT_LISTENER);
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(module.toXML());
kfs.generateAndWritePomXML(RELEASE_ID);
kfs.write("src/main/resources/" + PACKAGE_PATH + "/test.drl", ResourceFactory.newByteArrayResource(DRL.getBytes()));
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
assertEquals("Unexpected compilation errors", 0, builder.getResults().getMessages().size());
ks.getRepository().addKieModule(builder.getKieModule());
return RELEASE_ID;
}
Aggregations