use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class PropertyHandlerTests method testNullPropertyHandler2.
public void testNullPropertyHandler2() {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
OptimizerFactory.setDefaultOptimizer("reflective");
PropertyHandlerFactory.setNullPropertyHandler(new PropertyHandler() {
public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) {
return "NULL";
}
public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
return "NULL";
}
});
Foo foo = new Foo();
Bar bar = foo.getBar();
foo.setBar(null);
Map map = new HashMap();
map.put("foo", foo);
Serializable s = MVEL.compileExpression("foo.bar");
assertEquals("NULL", MVEL.executeExpression(s, map));
assertEquals("NULL", MVEL.executeExpression(s, map));
foo.setBar(bar);
assertEquals(bar, MVEL.executeExpression(s, map));
}
use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class PropertyHandlerTests method testNullPropertyHandler.
public void testNullPropertyHandler() {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
OptimizerFactory.setDefaultOptimizer("ASM");
PropertyHandlerFactory.setNullPropertyHandler(new PropertyHandler() {
public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) {
return "NULL";
}
public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
return "NULL";
}
});
Foo foo = new Foo();
Bar bar = foo.getBar();
foo.setBar(null);
Map map = new HashMap();
map.put("foo", foo);
Serializable s = MVEL.compileExpression("foo.bar");
assertEquals("NULL", MVEL.executeExpression(s, map));
assertEquals("NULL", MVEL.executeExpression(s, map));
foo.setBar(bar);
assertEquals(bar, MVEL.executeExpression(s, map));
}
use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class WithTests method testNewUsingWith.
public void testNewUsingWith() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addImport(Foo.class);
ctx.addImport(Bar.class);
Serializable s = compileExpression("[ 'foo' : (with ( new Foo() )" + " { bar = with ( new Bar() ) { name = 'ziggy' } }) ]", ctx);
OptimizerFactory.setDefaultOptimizer("reflective");
assertEquals("ziggy", (((Foo) ((Map) executeExpression(s)).get("foo")).getBar().getName()));
}
use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class WithTests method testInlineWith3.
public void testInlineWith3() {
CompiledExpression expr = new ExpressionCompiler("foo.{name = 'poopy', aValue = 'bar', bar.{name = 'foobie'}, toUC('doopy')}").compile();
Foo f = (Foo) executeExpression(expr, createTestMap());
assertEquals("poopy", f.getName());
assertEquals("bar", f.aValue);
assertEquals("foobie", f.getBar().getName());
assertEquals("doopy", f.register);
}
use of org.mvel2.tests.core.res.Bar in project mvel by mikebrock.
the class WithTests method testInlineWith5.
public void testInlineWith5() {
OptimizerFactory.setDefaultOptimizer("ASM");
ParserContext pCtx = new ParserContext();
pCtx.setStrongTyping(true);
pCtx.addInput("foo", Foo.class);
CompiledExpression expr = new ExpressionCompiler("foo.{name='poopy', aValue='bar'}").compile(pCtx);
Foo f = (Foo) executeExpression(expr, createTestMap());
assertEquals("poopy", f.getName());
assertEquals("bar", f.aValue);
}
Aggregations