use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class CoreConfidenceTests method testInterfaceMethodCallWithMacro.
@SuppressWarnings({ "unchecked" })
public void testInterfaceMethodCallWithMacro() {
Map macros = new HashMap(1);
macros.put("retract", new Macro() {
public String doMacro() {
return "drools.retract";
}
});
Map map = new HashMap();
DefaultKnowledgeHelper helper = new DefaultKnowledgeHelper();
map.put("drools", helper);
Cheese cheese = new Cheese("stilton", 15);
map.put("cheese", cheese);
executeExpression(compileExpression(parseMacros("retract(cheese)", macros)), map);
assertSame(cheese, helper.retracted.get(0));
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class CoreConfidenceTests method testStringConcatenation2.
public void testStringConcatenation2() {
String ex = "services.log( $cheese + \" some string \" );";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("$cheese", Cheese.class);
ctx.addInput("services", Services.class);
try {
ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx);
compiler.compile();
} catch (Throwable e) {
e.printStackTrace();
fail("Should not raise exception: " + e.getMessage());
}
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
the class CoreConfidenceTests method testIncrementAndAssignWithInputs.
public void testIncrementAndAssignWithInputs() {
ExpressionCompiler compiler = new ExpressionCompiler("total += cheese");
compiler.compile();
assertTrue(compiler.getParserContextState().getInputs().containsKey("total"));
assertTrue(compiler.getParserContextState().getInputs().containsKey("cheese"));
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
the class CoreConfidenceTests method testContextFieldNotFound.
public void testContextFieldNotFound() {
String str = "'stilton'.equals( type );";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Cheese.class);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
MVEL.executeExpression(stmt, new Cheese(), new HashMap());
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
the class DebuggerTests method testBreakpointsAcrossWith.
public void testBreakpointsAcrossWith() {
String line1 = "System.out.println( \"a1\" );\n";
String line2 = "c = new Cheese();\n";
String line3 = "with ( c ) { type = 'cheddar',\n" + " price = 10 };\n";
String line4 = "System.out.println( \"a1\" );\n";
String expr = line1 + line2 + line3 + line4;
System.out.println(expr);
ExpressionCompiler compiler = new ExpressionCompiler(expr);
ParserContext context = new ParserContext();
context.addImport("System", System.class);
context.addImport("Cheese", Cheese.class);
context.setStrictTypeEnforcement(true);
context.setDebugSymbols(true);
context.setSourceFile("mysource");
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile(context));
System.out.println("output: " + s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(5, count);
}
Aggregations