use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class ArithmeticTests method testMathCeilWithDoubleCast.
public void testMathCeilWithDoubleCast() {
String str = "Math.ceil( (double) x / 3 )";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addImport("Math", Math.class);
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("x", Integer.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));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class TypesAndInferenceTests method testGenerics1.
public void testGenerics1() {
String str = "addresses[0] == new Address(\"s1\") && addresses[0].street == new Address(\"s1\").street";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", PersonAddresses.class);
pctx.addImport(Address.class);
pctx.addImport(PersonAddresses.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
PersonAddresses ctx = new PersonAddresses();
ctx.getAddresses().add(new Address("s1"));
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class TypesAndInferenceTests method testStaticMethodCallThrowsException.
public void testStaticMethodCallThrowsException() {
String text = " ( throwException( ) ) ";
ParserConfiguration pconf = new ParserConfiguration();
for (Method m : CoreConfidenceTests.StaticMethods.class.getMethods()) {
if (Modifier.isStatic(m.getModifiers())) {
pconf.addImport(m.getName(), m);
}
}
ParserContext pctx = new ParserContext(pconf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
Map<String, Object> vars = new HashMap<String, Object>();
Serializable expr = MVEL.compileExpression(text, pctx);
try {
MVEL.executeExpression(expr);
fail("this should throw an exception");
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class TypesAndInferenceTests method testStaticMethodsInInputsBug.
public void testStaticMethodsInInputsBug() {
String text = " getList( java.util.Formatter )";
ParserConfiguration pconf = new ParserConfiguration();
for (Method m : CoreConfidenceTests.StaticMethods.class.getMethods()) {
if (Modifier.isStatic(m.getModifiers())) {
pconf.addImport(m.getName(), m);
}
}
ParserContext pctx = new ParserContext(pconf);
pctx.setStrictTypeEnforcement(false);
pctx.setStrongTyping(false);
Map<String, Object> vars = new HashMap<String, Object>();
Serializable expr = MVEL.compileExpression(text, pctx);
List list = (List) MVEL.executeExpression(expr, null, vars);
assertEquals(Formatter.class, list.get(0));
assertEquals(0, pctx.getInputs().size());
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class AsmOptimizerOsgiTest method testCollectionAccessWithInvalidThreadClassLoader.
public void testCollectionAccessWithInvalidThreadClassLoader() {
String expression = "['A', 'B', 'C'] contains 'B'";
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setClassLoader(MVEL.class.getClassLoader());
Serializable compiledExpression = MVEL.compileExpression(expression, new ParserContext(parserConfiguration));
ClassLoader currentCl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(NO_MVEL_CL);
for (int i = 0; i <= DynamicOptimizer.tenuringThreshold; i++) {
Object result = MVEL.executeExpression(compiledExpression);
assertEquals(Boolean.TRUE, result);
}
} finally {
Thread.currentThread().setContextClassLoader(currentCl);
}
}
Aggregations