use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testDeepMethodNameResolution.
public void testDeepMethodNameResolution() {
String expression = "variables = [ \"symbol\" : \"RHT\" ]; \n" + "drools.getProcessManager().startProcess(\"id\", variables );";
// third pass
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("drools", KnowledgeRuntimeHelper.class);
Map vars = new HashMap();
vars.put("drools", new KnowledgeRuntimeHelper());
Serializable expr = MVEL.compileExpression(expression, ctx);
executeExpression(expr, vars);
}
use of org.mule.mvel2.ParserContext 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.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testTestIntToLong.
public void testTestIntToLong() {
String s = "1+(long)a";
ParserContext pc = new ParserContext();
pc.addInput("a", Integer.class);
ExpressionCompiler compiler = new ExpressionCompiler(s, pc);
CompiledExpression expr = compiler.compile();
Map vars = new HashMap();
vars.put("a", 1);
Object r = ((ExecutableStatement) expr).getValue(null, new MapVariableResolverFactory(vars));
assertEquals(new Long(2), r);
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testCovariance.
public void testCovariance() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrictTypeEnforcement(true);
parserContext.setStrongTyping(true);
parserContext.addInput("this", ImplementationA.class);
assertEquals(int.class, MVEL.analyze("b.value", parserContext));
assertEquals(42, MVEL.executeExpression(MVEL.compileExpression("b.value", parserContext), new ImplementationA()));
}
use of org.mule.mvel2.ParserContext in project mvel by mvel.
the class CoreConfidenceTests method testCompileWithNewInsideMethodCall.
public void testCompileWithNewInsideMethodCall() {
String expr = " p.name = \"goober\";\n" + " System.out.println(p.name);\n" + " drools.insert(new Address(\"Latona\"));\n";
ParserContext context = new ParserContext();
context.setStrictTypeEnforcement(false);
context.addImport("Person", Person.class);
context.addImport("Address", Address.class);
context.addInput("p", Person.class);
context.addInput("drools", Drools.class);
ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
compiler.compile();
}
Aggregations