use of org.drools.compiler.Message in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorldWithWildcardPackagesComplex.
@Test
public void testHelloWorldWithWildcardPackagesComplex() throws Exception {
// BZ-1174563
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/rules/rules.drl", createDrlWithGlobal("R1")).write("src/main/resources/rules/tests/tests.drl", createDrlWithGlobal("R2")).write("src/main/resources/aaarules/aaarules.drl", createDrlWithGlobal("R3")).write("src/main/resources/sample/brms601_1310778/rules/rules.drl", createDrlWithGlobal("R4")).write("src/main/resources/sample/brms601_1310778/tests/tests.drl", createDrlWithGlobal("R5")).write("src/main/resources/tests/tests.drl", createDrlWithGlobal("R6")).write("src/main/resources/rules2/rules2.drl", createDrlWithGlobal("R7")).writeKModuleXML(createKieProjectWithPackages(ks, "rules.*").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(2, ksession.fireAllRules());
assertTrue(list.contains("R1"));
assertTrue(list.contains("R2"));
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorldUsingPackages.
@Test
public void testHelloWorldUsingPackages() throws Exception {
String drlDef = "package org.drools.compiler.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-SNAPSHOT");
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").toXML());
ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieLoggersTest method testKieConsoleLogger.
@Test
public void testKieConsoleLogger() throws Exception {
String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + " when\n" + " m : Message( myMessage : message )\n" + " then\n" + "end";
// get the resource
Resource dt = ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/integrationtests/hello.drl");
// create the builder
KieSession ksession = getKieSession(dt);
KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newConsoleLogger(ksession);
ksession.insert(new Message("Hello World"));
int fired = ksession.fireAllRules();
assertEquals(1, fired);
logger.close();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieLoggersTest method testKieFileLogger.
@Test
public void testKieFileLogger() throws Exception {
String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + " when\n" + " m : Message( myMessage : message )\n" + " then\n" + "end";
// get the resource
Resource dt = ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/integrationtests/hello.drl");
// create the builder
KieSession ksession = getKieSession(dt);
String fileName = "target/testKieFileLogger";
File file = new File(fileName + ".log");
if (file.exists()) {
file.delete();
}
KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newFileLogger(ksession, fileName);
ksession.insert(new Message("Hello World"));
int fired = ksession.fireAllRules();
assertEquals(1, fired);
logger.close();
file = new File(fileName + ".log");
assertTrue(file.exists());
assertTrue(file.length() > 0);
file.delete();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class ExecutionFlowControlTest method testDateEffective.
@Test
public void testDateEffective() throws Exception {
// read in the source
KieBase kbase = loadKnowledgeBase("test_EffectiveDate.drl");
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
// go !
final Message message = new Message("hola");
ksession.insert(message);
ksession.fireAllRules();
assertFalse(message.isFired());
}
Aggregations