use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testNestedClassWithNestedGenericsOnNakedMethod.
public void testNestedClassWithNestedGenericsOnNakedMethod() {
String str = "deliveries.size";
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Triangle.class);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertEquals(Integer.valueOf(0), (Integer) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
str = "deliveries.size == 0";
stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertTrue((Boolean) MVEL.executeExpression(stmt, new Triangle(), new HashMap()));
MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = false;
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testUnaryNegative.
public void testUnaryNegative() {
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 testBigDecimalOutput.
public void testBigDecimalOutput() {
String str = "import java.math.BigDecimal; BigDecimal test = new BigDecimal(\"50000\"); System.out.println(test / new BigDecimal(\"1.13\"));";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.setStrictTypeEnforcement(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 testNestedEnumFromJar.
public void testNestedEnumFromJar() throws ClassNotFoundException, SecurityException, NoSuchFieldException {
String expr = "EventRequest.Status.ACTIVE";
// creating a classloader for the jar
URL resource = getClass().getResource("/eventing-example.jar");
assertNotNull(resource);
URLClassLoader loader = new URLClassLoader(new URL[] { resource }, getClass().getClassLoader());
// loading the class to prove it works
Class<?> er = loader.loadClass("org.drools.examples.eventing.EventRequest");
assertNotNull(er);
assertEquals("org.drools.examples.eventing.EventRequest", er.getCanonicalName());
// getting the value of the enum to prove it works:
Class<?> st = er.getDeclaredClasses()[0];
assertNotNull(st);
Field active = st.getField("ACTIVE");
assertNotNull(active);
// now, trying with MVEL
ParserConfiguration pconf = new ParserConfiguration();
pconf.setClassLoader(loader);
pconf.addImport(er);
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
Serializable compiled = MVEL.compileExpression(expr, pctx);
Object result = MVEL.executeExpression(compiled);
assertNotNull(result);
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMapAccessWithNestedPropertyAO.
public void testMapAccessWithNestedPropertyAO() {
boolean allowCompilerOverride = MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING;
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
try {
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);
result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
} finally {
MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = allowCompilerOverride;
}
}
Aggregations