@Test public void testMVELDebugSymbols() throws DroolsParserException { MVELDebugHandler.setDebugMode(true); try { final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5); final PackageDescr pkgDescr = parser.parse(new InputStreamReader(getClass().getResourceAsStream("mvel_rule.drl"))); // just checking there is no parsing errors assertFalse(parser.getErrors().toString(), parser.hasErrors()); InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.drools"); final RuleDescr ruleDescr = pkgDescr.getRules().get(0); final RuleBuilder builder = new RuleBuilder(); final KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg); final KnowledgeBuilderConfigurationImpl conf = pkgBuilder.getBuilderConfiguration(); DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry(); Dialect dialect = dialectRegistry.getDialect("mvel"); RuleBuildContext context = new RuleBuildContext(pkgBuilder, ruleDescr, dialectRegistry, pkg, dialect); builder.build(context); assertTrue(context.getErrors().toString(), context.getErrors().isEmpty()); final RuleImpl rule = context.getRule(); MVELConsequence mvelCons = (MVELConsequence) rule.getConsequence(); mvelCons.compile( (MVELDialectRuntimeData) pkgBuilder .getPackageRegistry(pkg.getName()) .getDialectRuntimeRegistry() .getDialectData("mvel")); String s = DebugTools.decompile(mvelCons.getCompExpr()); int fromIndex = 0; int count = 0; while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) { count++; } assertEquals(4, count); } finally { MVELDebugHandler.setDebugMode(false); } }
@Test public void testDebug() throws Exception { String rule = "package com.sample; dialect \"mvel\" rule myRule when then\n System.out.println( \"test\" ); end"; PackageBuilder builder = new PackageBuilder(); DrlParser parser = new DrlParser(LanguageLevelOption.DRL5); PackageDescr packageDescr = parser.parse(rule); RuleDescr ruleDescr = packageDescr.getRules().get(0); builder = new PackageBuilder(); builder.addPackage(packageDescr); Package pkg = builder.getPackage(); MVELConsequence consequence = (MVELConsequence) pkg.getRule("myRule").getConsequence(); String sourceName = ((CompiledExpression) consequence.getCompExpr()).getSourceName(); System.out.println(sourceName); String ruleName = ruleDescr.getNamespace() + "." + ruleDescr.getClassName(); System.out.println(ruleName); assertEquals(sourceName, ruleName); }