use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class NegativePatternsTest method prepareKieSession.
@Before
public void prepareKieSession() {
String drl = "package org.drools.compiler.integrationtests\n" + "\n" + "import org.drools.compiler.integrationtests.NegativePatternsTest.TestEvent\n" + "\n" + "declare TestEvent\n" + " @role( event )\n" + " @expires( 22ms )\n" + "end\n" + "\n" + "rule \"SingleAbsence\"\n" + " duration( 18ms )\n" + " when\n" + " not ( TestEvent ( ) from entry-point EventStream )\n" + " then\n" + " // consequence\n" + "end\n" + "\n" + "rule \"SingleConstrained\"\n" + " duration( 18ms )\n" + " when\n" + " not ( TestEvent ( name == \"EventA\" ) from entry-point EventStream )\n" + " then\n" + " // consequence\n" + "end\n" + "\n" + "rule \"MultipleEvents\"\n" + " duration( 18ms )\n" + " when\n" + " TestEvent ( name == \"EventA\" ) over window:time( 22ms ) from entry-point EventStream\n" + " not ( TestEvent ( name == \"EventB\" ) over window:time( 22ms ) from entry-point EventStream )\n" + " then\n" + " // consequence\n" + "end\n" + "\n" + "rule \"MultipleEntryPoints\"\n" + " duration( 18ms )\n" + " when\n" + " not (\n" + " TestEvent( name == \"EventA\" ) from entry-point EventStream\n" + " )\n" + " not (\n" + " TestEvent( name == \"EventB\" ) from entry-point OtherStream\n" + " )\n" + " then\n" + " // consequence\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieModuleModel kieModule = ks.newKieModuleModel();
KieBaseModel defaultBase = kieModule.newKieBaseModel("defaultKBase").setDefault(true).addPackage("*").setEventProcessingMode(EventProcessingOption.STREAM);
defaultBase.newKieSessionModel(DEFAULT_SESSION_NAME).setClockType(ClockTypeOption.get("pseudo")).setDefault(true);
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
kfs.writeKModuleXML(kieModule.toXML());
KieModule builtModule = ks.newKieBuilder(kfs).buildAll().getKieModule();
ks.getRepository().addKieModule(builtModule);
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession(DEFAULT_SESSION_NAME);
firedRulesListener = new TrackingAgendaEventListener();
ksession.addEventListener(firedRulesListener);
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class QueryCepFireUntilHaltTest method prepare.
@Before
public void prepare() {
String drl = "package org.drools.compiler.integrationtests\n" + "import " + TestEvent.class.getCanonicalName() + "\n" + "declare TestEvent\n" + " @role( event )\n" + "end\n" + "query EventsFromStream\n" + " $event : TestEvent() from entry-point FirstStream\n" + "end\n" + "query ZeroToNineteenSeconds\n" + " $event : TestEvent() from entry-point FirstStream\n" + " $result : TestEvent ( this after [0s, 19s] $event) from entry-point SecondStream\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
baseModel.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmodule.toXML());
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/compiler/integrationtests/queries.drl"));
assertTrue(ks.newKieBuilder(kfs).buildAll().getResults().getMessages().isEmpty());
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
firstEntryPoint = ksession.getEntryPoint("FirstStream");
secondEntryPoint = ksession.getEntryPoint("SecondStream");
clock = ksession.getSessionClock();
this.startEngine();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class QueryInRHSCepTest method prepare1.
private void prepare1() {
String drl = "package org.drools.compiler.integrationtests\n" + "import " + SolicitFirePojo.class.getCanonicalName() + "\n" + "import " + QueryItemPojo.class.getCanonicalName() + "\n" + "global java.util.List myGlobal \n" + "declare SolicitFirePojo\n" + " @role( event )\n" + "end\n" + "query \"myQuery\"\n" + " $r : QueryItemPojo()\n" + "end\n" + "rule \"drools-usage/WLHxG8S\"\n" + " no-loop\n" + " when\n" + " SolicitFirePojo()\n" + " then\n" + " myGlobal.add(drools.getKieRuntime().getQueryResults(\"myQuery\"));\n" + " end\n";
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
baseModel.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmodule.toXML());
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/compiler/integrationtests/" + this.getClass().getName() + ".drl"));
assertTrue(ks.newKieBuilder(kfs).buildAll().getResults().getMessages().isEmpty());
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
clock = ksession.getSessionClock();
myGlobal = new ArrayList<>();
ksession.setGlobal("myGlobal", myGlobal);
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class QueryCepTest method prepare.
@Before
public void prepare() {
String drl = "package org.drools.compiler.integrationtests\n" + "import " + TestEvent.class.getCanonicalName() + "\n" + "declare TestEvent\n" + " @role( event )\n" + "end\n" + "query EventsFromStream\n" + " $event : TestEvent() from entry-point FirstStream\n" + "end\n" + "query ZeroToNineteenSeconds\n" + " $event : TestEvent() from entry-point FirstStream\n" + " $result : TestEvent ( this after [0s, 19s] $event) from entry-point SecondStream\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
baseModel.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmodule.toXML());
kfs.write(ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/compiler/integrationtests/queries.drl"));
assertTrue(ks.newKieBuilder(kfs).buildAll().getResults().getMessages().isEmpty());
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
firstEntryPoint = ksession.getEntryPoint("FirstStream");
secondEntryPoint = ksession.getEntryPoint("SecondStream");
clock = ksession.getSessionClock();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class KieBaseIncludesTest method testKieBaseIncludesCrossKJarDifferentPackageNames.
/**
* Test the inclusion of a KieBase defined in one KJAR into the KieBase of another KJAR.
* <p/>
* The 2 KieBases use different package names for the rules (i.e. "rules" and "rules2").
*/
@Test
public void testKieBaseIncludesCrossKJarDifferentPackageNames() {
// @formatter:off
String pomContent1 = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "<modelVersion>4.0.0</modelVersion>\n" + "<groupId>org.kie</groupId>\n" + "<artifactId>rules-1</artifactId>\n" + "<version>1.0.0</version>\n" + "<packaging>jar</packaging>\n" + "<dependencies>\n" + "<dependency>\n" + "<groupId>org.kie</groupId>\n" + "<artifactId>rules-2</artifactId>\n" + "<version>1.0.0</version>\n" + "</dependency>\n" + "</dependencies>\n" + "</project>\n";
String kmoduleContent1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://jboss.org/kie/6.0.0/kmodule\">\n" + "<kbase name=\"kbase1\" equalsBehavior=\"equality\" default=\"true\" packages=\"rules\" includes=\"kbase2\">\n" + "<ksession name=\"ksession1\" default=\"true\" type=\"stateful\"/>\n" + "</kbase>\n" + "</kmodule>";
String drl1 = "package org.jboss.ddoyle.drools.rules1\n" + "\n" + "rule \"Rule in KieBase 1\"\n" + "when\n" + "then\n" + "System.out.println(\"Rule in KieBase1\");\n" + "end";
String kmoduleContent2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://jboss.org/kie/6.0.0/kmodule\">\n" + "<kbase name=\"kbase2\" equalsBehavior=\"equality\" default=\"false\" packages=\"rules2\">\n" + "<ksession name=\"ksession2\" default=\"false\" type=\"stateful\"/>\n" + "</kbase>\n" + "</kmodule>";
String drl2 = "package org.jboss.ddoyle.drools.rules2\n" + "\n" + "rule \"Rule in KieBase 2\"\n" + "when\n" + "then\n" + "System.out.println(\"Rule in KieBase2\");\n" + "end";
// @formatter:on
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "rules-1", "1.0.0");
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "rules-2", "1.0.0");
// First deploy the second KJAR on which the first one depends.
KieFileSystem kfs2 = ks.newKieFileSystem().generateAndWritePomXML(releaseId2).write("src/main/resources/rules2/rules.drl", drl2).writeKModuleXML(kmoduleContent2);
ks.newKieBuilder(kfs2).buildAll();
KieFileSystem kfs1 = ks.newKieFileSystem().writePomXML(pomContent1).write("src/main/resources/rules/rules.drl", drl1).writeKModuleXML(kmoduleContent1);
ks.newKieBuilder(kfs1).buildAll();
KieContainer kc = ks.newKieContainer(releaseId1);
KieBase kieBase = kc.getKieBase();
// Assert the number of rules in the KieBase.
long nrOfRules = getNumberOfRules(kieBase);
// We should have 2 rules in our KieBase. One from our own DRL and one from the DRL in the KieBase we've included.
assertEquals(2, nrOfRules);
}
Aggregations