use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testStringConcatenation.
public void testStringConcatenation() {
// debugging MVEL code, it seems that MVEL 'thinks' that the result of the expression:
// "Drop +5%: "+$sb+" avg: $"+$av+" price: $"+$pr
// is a double, and as so, he looks for a method:
// Services.log( double );
// but finds only:
// Services.log( String );
// raising the error.
String ex = "services.log((String) \"Drop +5%: \"+$sb+\" avg: $\"+$av+\" price: $\"+$pr );";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("$sb", String.class);
ctx.addInput("$av", double.class);
ctx.addInput("$pr", double.class);
ctx.addInput("services", Services.class);
try {
ExpressionCompiler compiler = new ExpressionCompiler(ex);
compiler.compile(ctx);
} catch (Throwable e) {
e.printStackTrace();
fail("Should not raise exception: " + e.getMessage());
}
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testAssignmentRegression.
public void testAssignmentRegression() {
ExpressionCompiler compiler = new ExpressionCompiler("total = total + $cheese.price");
compiler.compile();
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testTypeRegression.
public void testTypeRegression() {
ExpressionCompiler compiler = new ExpressionCompiler("total = 0");
ParserContext ctx = new ParserContext();
ctx.setStrictTypeEnforcement(true);
compiler.compile(ctx);
assertEquals(Integer.class, compiler.getParserContextState().getVarOrInputType("total"));
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class CoreConfidenceTests method testListNestedInsideList.
public void testListNestedInsideList() {
ParserContext ctx = new ParserContext();
ctx.addImport("User", User.class);
ExpressionCompiler compiler = new ExpressionCompiler("users = [ new User('Darth', 'Vadar'), " + "new User('Bobba', 'Feta') ]; [ users.get( 0 ), users.get( 1 ) ]");
List list = (List) executeExpression(compiler.compile(ctx), new HashMap());
User user = (User) list.get(0);
assertEquals("Darth", user.getFirstName());
user = (User) list.get(1);
assertEquals("Bobba", user.getFirstName());
compiler = new ExpressionCompiler("users = [ new User('Darth', 'Vadar'), " + "new User('Bobba', 'Feta') ]; [ users[0], users[1] ]");
list = (List) executeExpression(compiler.compile(ctx), new HashMap());
user = (User) list.get(0);
assertEquals("Darth", user.getFirstName());
user = (User) list.get(1);
assertEquals("Bobba", user.getFirstName());
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
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);
Serializable s = compiler.compile(ctx);
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