use of org.mvel2.debug.Debugger 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