use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class MacroProcessorTest method testMacroSupport.
public void testMacroSupport() {
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("foo", new Foo());
Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>();
Map<String, Macro> macros = new HashMap<String, Macro>();
interceptors.put("Modify", new Interceptor() {
public int doBefore(ASTNode node, VariableResolverFactory factory) {
((WithNode) node).getNestedStatement().getValue(null, factory);
factory.createVariable("mod", "FOOBAR!");
return 0;
}
public int doAfter(Object val, ASTNode node, VariableResolverFactory factory) {
return 0;
}
});
macros.put("modify", new Macro() {
public String doMacro() {
return "@Modify with";
}
});
ExpressionCompiler compiler = new ExpressionCompiler(parseMacros("modify (foo) { aValue = 'poo = poo', bValue = 'poo, poo' }; mod", macros));
ParserContext ctx = new ParserContext(null, interceptors, null);
ctx.setSourceFile("test.mv");
ctx.setDebugSymbols(true);
assertEquals("FOOBAR!", executeExpression(compiler.compile(ctx), null, vars));
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class MacroProcessorTest method testMacroSupportWithStrings.
public void testMacroSupportWithStrings() {
Map<String, Object> vars = new HashMap<String, Object>();
Foo foo = new Foo();
vars.put("foo", foo);
Map<String, Macro> macros = new HashMap<String, Macro>();
macros.put("modify", new Macro() {
public String doMacro() {
return "drools.modify";
}
});
assertEquals("", foo.aValue);
ExpressionCompiler compiler = new ExpressionCompiler(parseMacros("\"This is an modify()\"", macros));
ParserContext ctx = new ParserContext(null, null, null);
ctx.setSourceFile("test.mv");
ctx.setDebugSymbols(true);
assertEquals("This is an modify()", executeExpression(compiler.compile(ctx), null, vars));
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class MutationsTests method testDeepAssignment2.
public void testDeepAssignment2() {
Map map = createTestMap();
ExpressionCompiler compiler = new ExpressionCompiler("foo.bar.age = 21");
ParserContext ctx = new ParserContext();
ctx.addInput("foo", Foo.class);
ctx.setStrongTyping(true);
CompiledExpression ce = compiler.compile(ctx);
executeExpression(ce, map);
assertEquals(((Foo) map.get("foo")).getBar().getAge(), 21);
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class ProjectionsTests method testProjectionSupport3.
public void testProjectionSupport3() {
String ex = "(toUpperCase() in ['bar', 'foo'])[1]";
Map vars = createTestMap();
assertEquals("FOO", MVEL.eval(ex, new Base(), vars));
assertEquals("FOO", test("(toUpperCase() in ['bar', 'foo'])[1]"));
}
use of org.mvel2.tests.core.res.Foo in project mvel by mikebrock.
the class PropertyAccessTests method testDynamicDeop.
public void testDynamicDeop() {
Serializable s = compileExpression("name");
assertEquals("dog", executeExpression(s, new Foo()));
assertEquals("dog", executeExpression(s, new Foo().getBar()));
}
Aggregations