use of org.drools.compiler.Message in project drools by kiegroup.
the class KieLoggersTest method testKieConsoleLoggerStateless.
@Test
public void testKieConsoleLoggerStateless() 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
StatelessKieSession ksession = getStatelessKieSession(dt);
KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newConsoleLogger(ksession);
AgendaEventListener ael = mock(AgendaEventListener.class);
ksession.addEventListener(ael);
ksession.execute(new Message("Hello World"));
verify(ael).afterMatchFired(any(AfterMatchFiredEvent.class));
logger.close();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieLoggersTest method testDeclarativeKieConsoleLoggerStateless.
@Test
public void testDeclarativeKieConsoleLoggerStateless() 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";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setType(KieSessionModel.KieSessionType.STATELESS).setConsoleLogger("logger");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
kfs.write("src/main/resources/KBase1/rule.drl", drl);
KieModule kieModule = ks.newKieBuilder(kfs).buildAll().getKieModule();
KieContainer kieContainer = ks.newKieContainer(kieModule.getReleaseId());
StatelessKieSession ksession = kieContainer.newStatelessKieSession("KSession1");
ksession.execute(new Message("Hello World"));
KieRuntimeLogger logger = ksession.getLogger();
assertNotNull(logger);
logger.close();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class KieRuntimeTest method testKieRuntimeAccess.
@Test
public void testKieRuntimeAccess() throws IOException, ClassNotFoundException {
String str = "";
str += "package org.drools.compiler.test\n";
str += "import " + Message.class.getName() + "\n";
str += "rule \"Hello World\"\n";
str += "when\n";
str += " Message( )\n";
str += "then\n";
str += " System.out.println( drools.getKieRuntime() );\n";
str += "end\n";
KieBase kbase = loadKnowledgeBaseFromString(str);
kbase = SerializationHelper.serializeObject(kbase);
final KieSession ksession = createKnowledgeSession(kbase);
ksession.insert(new Message("help"));
ksession.fireAllRules();
ksession.dispose();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class FirstOrderLogicTest method testOrs.
@Test
public void testOrs() throws Exception {
String str = "package org.drools.compiler.integrationtests\n" + "import " + Message.class.getName() + "\n" + "rule X\n" + " when\n" + " Message( message == 'test' )\n" + " Message( !fired ) or eval( !false )\n" + " then\n" + "end\n";
KieBase kbase = loadKnowledgeBaseFromString(str);
KieSession ksession = createKnowledgeSession(kbase);
ksession.insert(new Message("test"));
int rules = ksession.fireAllRules();
assertEquals(2, rules);
ksession.dispose();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class HelloWorldTest method testHelloWorldDebug.
@Test
public void testHelloWorldDebug() throws Exception {
final Set<String> knownVariables = new HashSet<String>();
MVELRuntime.resetDebugger();
MVELDebugHandler.setDebugMode(true);
MVELRuntime.setThreadDebugger(new Debugger() {
public int onBreak(Frame frame) {
System.out.println("onBreak");
for (String var : frame.getFactory().getKnownVariables()) {
knownVariables.add(var);
}
return 0;
}
});
String source = "org.drools.integrationtests.Rule_Hello_World";
MVELRuntime.registerBreakpoint(source, 1);
// load up the knowledge base
KieBase kbase = readKnowledgeBase();
KieSession ksession = createKnowledgeSession(kbase);
File testTmpDir = new File("target/test-tmp/");
testTmpDir.mkdirs();
KieRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "target/test-tmp/testHelloWorldDebug");
// go !
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
ksession.fireAllRules();
logger.close();
assertEquals(6, knownVariables.size());
assertTrue(knownVariables.contains("drools"));
assertTrue(knownVariables.contains("myMessage"));
assertTrue(knownVariables.contains("rule"));
assertTrue(knownVariables.contains("kcontext"));
assertTrue(knownVariables.contains("this"));
assertTrue(knownVariables.contains("m"));
assertTrue(knownVariables.contains("myMessage"));
}
Aggregations