use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorldUsingPackages.
@Test
public void testHelloWorldUsingPackages() throws Exception {
String drlDef = "package org.pkg1\n" + "import " + Message.class.getCanonicalName() + "\n" + "rule R_def when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0");
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/KBase1/r1_1.drl", drlDef).write("src/main/resources/KBase1/r1_2.drl", createDrl("org.pkg1", "R1")).write("src/main/resources/KBase1/r2.drl", createDrl("org.pkg2", "R2")).writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1").toXML());
KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
}
use of org.drools.mvel.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"));
KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
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.mvel.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])));
KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
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.mvel.compiler.Message in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorldUsingFolders.
@Test
public void testHelloWorldUsingFolders() throws Exception {
String drlDef = "package org.drools.mvel.integrationtests\n" + "import " + Message.class.getCanonicalName() + "\n" + "rule R_def when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0");
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/KBase1/org/pkg1/r1_1.drl", drlDef).write("src/main/resources/KBase1/org/pkg1/r1_2.drl", createDrl("R1")).write("src/main/resources/KBase1/org/pkg2/r2.drl", createDrl("R2")).writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1").setConfigurationProperty("drools.groupDRLsInKieBasesByFolder", "true").toXML());
KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
}
use of org.drools.mvel.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");
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/org/pkg1/test/r1.drl", createDrlWithGlobal("org.pkg1.test", "R1")).write("src/main/resources/org/pkg2/test/r2.drl", createDrlWithGlobal("org.pkg2.test", "R2")).writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1.*").toXML());
KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
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