use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testStaticMethodsInvocationWithNullArg.
public void testStaticMethodsInvocationWithNullArg() {
String str = "org.mvel2.tests.core.CoreConfidenceTests$MyObj.doSomething(null, \"abc\")";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
assertEquals(null + "abc", MVEL.executeExpression(MVEL.compileExpression(str, pctx)));
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testUnaryNegativeWithSpace.
public void testUnaryNegativeWithSpace() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", int.class);
Map vars = new HashMap() {
{
put("value", 42);
}
};
assertEquals(-42, MVEL.executeExpression(MVEL.compileExpression("- value", pctx), vars));
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testPackageImportEnum.
// public void testSysoutNullVariable() {
// // Create our root Map object
// Map<String, String> map = new HashMap<String, String>();
// map.put("foo", null);
//
// VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
// factory.createVariable("this", map);
//
// org.mvel2.MVEL.executeExpression(org.mvel2.MVEL.compileExpression("System.out.println(foo);"), map, factory);
// }
public void testPackageImportEnum() {
String str = "new Status( START )";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addPackageImport("org.mvel2.tests.core.res");
pconf.addPackageImport("org.mvel2.tests.core.res.Status");
ParserContext context = new ParserContext(pconf);
context.setStrongTyping(true);
Serializable s = MVEL.compileExpression(str.trim(), context);
assertEquals(new Status(Status.START), MVEL.executeExpression(s));
assertFalse(new Status(Status.STOP).equals(MVEL.executeExpression(s)));
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testArrays.
public void testArrays() {
String str = "Object[] a = new Object[3]; a[0] = \"a\"; a[1] = \"b\"; a[2] = \"c\"; System.out.println(java.util.Arrays.toString(a));";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
MVEL.executeExpression(stmt, new HashMap());
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testInlineConstructor.
public void testInlineConstructor() {
String str = "cheese = new Cheese().{ type = $c.type };";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("$c", Cheese.class);
pctx.addImport(Cheese.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Cheese $c = new Cheese();
$c.setType("stilton");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("$c", $c);
Cheese cheese = (Cheese) MVEL.executeExpression(stmt, vars);
assertEquals("stilton", cheese.getType());
}
Aggregations