use of org.drools.compiler.Message in project drools by kiegroup.
the class JBRULESTest method testJBRULES3326.
@Test
public void testJBRULES3326() throws Exception {
final StringBuilder rule = new StringBuilder();
rule.append("package org.drools.compiler\n");
rule.append("rule X\n");
rule.append("when\n");
rule.append(" Message(!!!false)\n");
rule.append("then\n");
rule.append("end\n");
// building stuff
final KieBase kbase = loadKnowledgeBaseFromString(rule.toString());
final KieSession ksession = createKnowledgeSession(kbase);
ksession.insert(new Message("test"));
final int rules = ksession.fireAllRules();
assertEquals(1, rules);
ksession.dispose();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieBuilderTest method testResourceInclusion.
@Test
public void testResourceInclusion() {
final String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
final String drl2 = "package org.drools.compiler\n" + "rule R2 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
final String drl3 = "package org.drools.compiler\n" + "rule R3 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
final String drl4 = "package org.drools.compiler\n" + "rule R4 when\n" + " $m : Message( message == \"Hello Earth\" )\n" + "then\n" + "end\n";
final String kmodule = "<kmodule xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + " <kbase name=\"kbase1\" default=\"true\" eventProcessingMode=\"stream\" equalsBehavior=\"identity\" scope=\"javax.enterprise.context.ApplicationScoped\">\n" + " <ksession name=\"ksession1\" type=\"stateful\" default=\"true\" clockType=\"realtime\" scope=\"javax.enterprise.context.ApplicationScoped\"/>\n" + " </kbase>\n" + "</kmodule>";
final KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
final Resource r1 = ResourceFactory.newByteArrayResource(drl1.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("kbase1/drl1.drl");
final Resource r2 = ResourceFactory.newByteArrayResource(drl2.getBytes()).setResourceType(ResourceType.GDRL).setSourcePath("kbase1/drl2.gdrl");
final Resource r3 = ResourceFactory.newByteArrayResource(drl3.getBytes()).setResourceType(ResourceType.RDRL).setSourcePath("kbase1/drl3.rdrl");
final Resource r4 = ResourceFactory.newByteArrayResource(drl4.getBytes()).setResourceType(ResourceType.TDRL).setSourcePath("kbase1/drl4.tdrl");
final KieModule km = createAndDeployJar(ks, kmodule, releaseId1, r1, r2, r3, r4);
final InternalKieModule ikm = (InternalKieModule) km;
assertNotNull(ikm.getResource(r1.getSourcePath()));
assertNotNull(ikm.getResource(r2.getSourcePath()));
assertNotNull(ikm.getResource(r3.getSourcePath()));
assertNotNull(ikm.getResource(r4.getSourcePath()));
// Create a session and fire rules
final KieContainer kc = ks.newKieContainer(km.getReleaseId());
final KieSession ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
ksession.dispose();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorldWithEmptyFile.
@Test
public void testHelloWorldWithEmptyFile() throws Exception {
String drl = createDrl("R1");
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl).write("src/main/resources/empty.drl", ks.getResources().newInputStreamResource(new ByteArrayInputStream(new byte[0])));
ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
ksession.insert(new Message("Hello World"));
int count = ksession.fireAllRules();
assertEquals(1, count);
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorld.
@Test
public void testHelloWorld() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", createDrl("R1"));
ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
ksession.insert(new Message("Hello World"));
int count = ksession.fireAllRules();
assertEquals(1, count);
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorldWithWildcardPackages.
@Test
public void testHelloWorldWithWildcardPackages() throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0-SNAPSHOT");
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/org/pkg1/test/r1.drl", createDrlWithGlobal("R1")).write("src/main/resources/org/pkg2/test/r2.drl", createDrlWithGlobal("R2")).writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1.*").toXML());
ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
ksession.insert(new Message("Hello World"));
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
assertEquals(1, ksession.fireAllRules());
assertEquals(1, list.size());
assertEquals("R1", list.get(0));
}
Aggregations