use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testInstanceofWithPackageImport.
public void testInstanceofWithPackageImport() {
ParserConfiguration conf = new ParserConfiguration();
conf.addPackageImport("org.mvel2.tests.core");
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", Object.class);
Map vars = new HashMap() {
{
put("value", new CoreConfidenceTests());
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof CoreConfidenceTests", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof " + CoreConfidenceTests.class.getCanonicalName(), pctx), vars));
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMapAccessProperty.
public void testMapAccessProperty() {
String str = "map.key";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", POJO.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
POJO ctx = new POJO();
try {
MVEL.executeExpression(stmt, ctx);
fail("Expected PropertyAccessException");
} catch (PropertyAccessException ex) {
assertTrue(ex.getMessage().contains("could not access: key"));
}
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testStaticMethodInvocation.
public void testStaticMethodInvocation() {
ParserConfiguration conf = new ParserConfiguration();
conf.addImport(ARef.class);
conf.addImport(BRef.class);
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", String.class);
Map vars = new HashMap() {
{
put("value", "1234");
}
};
assertEquals(0, MVEL.executeExpression(MVEL.compileExpression("ARef.getSize(value)", pctx), vars));
assertEquals(4, MVEL.executeExpression(MVEL.compileExpression("BRef.getSize(value)", pctx), vars));
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMapAccessWithNestedProperty.
public void testMapAccessWithNestedProperty() {
String str = "map[key] == \"one\"";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", POJO.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
POJO ctx = new POJO();
ctx.getMap().put("1", "one");
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class ArithmeticTests method testStaticMathCeilWithJavaClassStyleLiterals.
public void testStaticMathCeilWithJavaClassStyleLiterals() {
MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;
try {
String str = "java.lang.Math.ceil( x/3.0 )";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("x", int.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Map vars = new HashMap();
vars.put("x", 4);
assertEquals(Math.ceil((double) 4 / 3), MVEL.executeExpression(stmt, vars));
} finally {
MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = false;
}
}
Aggregations