use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testDynamicImportsWithNullConstructorParamWithStrongType.
public void testDynamicImportsWithNullConstructorParamWithStrongType() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addPackageImport("org.mvel2.tests.core.res");
ExpressionCompiler compiler = new ExpressionCompiler("new Cheesery(\"bobbo\", null)", ctx);
Cheesery p1 = new Cheesery("bobbo", null);
Cheesery p2 = (Cheesery) executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory());
assertEquals(p1, p2);
}
use of org.mule.mvel2.ParserContext 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.mule.mvel2.ParserContext 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.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testJIRA155.
public void testJIRA155() {
ParserContext pctx = new ParserContext();
pctx.addImport("returnTrue", MVEL.getStaticMethod(CoreConfidenceTests.class, "returnTrue", new Class[0]));
assertEquals(true, executeExpression(MVEL.compileExpression("!true || returnTrue()", pctx)));
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testComaProblemStrikesBack.
public void testComaProblemStrikesBack() {
String ex = "a.explanation = \"There is a coma, in here\"";
ParserContext ctx = new ParserContext();
ExpressionCompiler compiler = new ExpressionCompiler(ex, ctx);
Serializable s = compiler.compile();
Base a = new Base();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("a", a);
executeExpression(s, variables);
assertEquals("There is a coma, in here", a.data);
}
Aggregations