Search in sources :

Example 11 with Debugger

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"));
}
Also used : Debugger(org.mvel2.debug.Debugger) Frame(org.mvel2.debug.Frame) KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) Message(org.drools.compiler.Message) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CompiledExpression (org.mvel2.compiler.CompiledExpression)9 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)9 Debugger (org.mvel2.debug.Debugger)9 Frame (org.mvel2.debug.Frame)9 ParserContext (org.mvel2.ParserContext)8 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)8 HashSet (java.util.HashSet)6 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)4 HashMap (java.util.HashMap)3 ASTNode (org.mvel2.ast.ASTNode)3 Interceptor (org.mvel2.integration.Interceptor)3 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)3 Macro (org.mvel2.Macro)2 WithNode (org.mvel2.ast.WithNode)2 File (java.io.File)1 Message (org.drools.compiler.Message)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KieRuntimeLogger (org.kie.api.logger.KieRuntimeLogger)1 KieSession (org.kie.api.runtime.KieSession)1