use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testEmpty.
public void testEmpty() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
Serializable s = compileExpression("list = new java.util.ArrayList(); list == empty", ctx);
Map vars = new HashMap();
Boolean x = (Boolean) executeExpression(s, vars);
assertNotNull(x);
assertTrue(x.booleanValue());
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testNestedNumInMapKey.
public void testNestedNumInMapKey() {
String str = "objectKeyMaptributes[Triangle.Foo.OBTUSE]";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addImport("Triangle", Triangle.class);
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Person.class);
pctx.setStrongTyping(true);
Foo foo = new Foo();
Person p = new Person();
Map<Object, Foo> map = new HashMap<Object, Foo>();
map.put(Triangle.Foo.OBTUSE, foo);
p.setObjectKeyMaptributes(map);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Object o = MVEL.executeExpression(stmt, p, new HashMap());
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method ctxJIRA170.
private ParserContext ctxJIRA170(boolean strictTypeEnforcement, boolean strongTyping) {
ParserContext ctx = new ParserContext();
// ctx.setStrictTypeEnforcement(strictTypeEnforcement);
ctx.setStrongTyping(strongTyping);
ctx.addInput("x", Collection.class, new Class[] { Integer.class });
ctx.addInput("y", Integer.class);
return ctx;
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testMVEL190.
public void testMVEL190() {
ParserContext context = new ParserContext();
context.addImport(Ship.class);
context.addImport(MapObject.class);
context.addInput("obj", MapObject.class);
Object compiled = MVEL.compileExpression("((Ship) obj).getName()", context);
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("obj", new Ship());
VariableResolverFactory varsResolver = new MapVariableResolverFactory(vars);
System.out.println(executeExpression(compiled, varsResolver));
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testMethodCallWithSpaces.
public void testMethodCallWithSpaces() {
String[] str = new String[] { "Foo f = new Foo(); f.setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f . setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f. setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f .setBoolTest( true ) ; f.isBoolTest()", "Foo f = new Foo(); f.boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f . boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f. boolTest = true ; f.isBoolTest()", "Foo f = new Foo(); f .boolTest = true ; f.isBoolTest()" };
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", Bar.class);
pctx.addImport(Foo.class);
List<String> errors = new ArrayList<String>();
for (String s : str) {
try {
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(s, pctx);
Bar ctx = new Bar();
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx, new HashMap());
assertTrue(result);
} catch (Exception e) {
e.printStackTrace();
errors.add("**** Error on expression: " + s + "\n" + e.getMessage());
}
}
assertTrue(errors.toString(), errors.isEmpty());
}
Aggregations