use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class MutationsTests method testDeepAssignment2.
public void testDeepAssignment2() {
Map map = createTestMap();
ExpressionCompiler compiler = new ExpressionCompiler("foo.bar.age = 21");
ParserContext ctx = new ParserContext();
ctx.addInput("foo", Foo.class);
ctx.setStrongTyping(true);
CompiledExpression ce = compiler.compile(ctx);
executeExpression(ce, map);
assertEquals(((Foo) map.get("foo")).getBar().getAge(), 21);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class InlineCollectionsTests method testToListStrictMode.
@SuppressWarnings({ "UnnecessaryBoxing" })
public void testToListStrictMode() {
String text = "misc.toList(foo.bar.name, 'hello', 42, ['key1' : 'value1'," + " c : [ foo.bar.age, 'car', 42 ]], [42, [c : 'value1']] )";
ParserContext ctx = new ParserContext();
ctx.addInput("misc", MiscTestClass.class);
ctx.addInput("foo", Foo.class);
ctx.addInput("c", String.class);
ctx.setStrictTypeEnforcement(true);
ExpressionCompiler compiler = new ExpressionCompiler(text);
List list = (List) executeExpression(compiler.compile(ctx), createTestMap());
assertSame("dog", list.get(0));
assertEquals("hello", list.get(1));
assertEquals(new Integer(42), list.get(2));
Map map = (Map) list.get(3);
assertEquals("value1", map.get("key1"));
List nestedList = (List) map.get("cat");
assertEquals(14, nestedList.get(0));
assertEquals("car", nestedList.get(1));
assertEquals(42, nestedList.get(2));
nestedList = (List) list.get(4);
assertEquals(42, nestedList.get(0));
map = (Map) nestedList.get(1);
assertEquals("value1", map.get("cat"));
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testStrongTyping2.
public void testStrongTyping2() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("blah", String.class);
try {
new ExpressionCompiler("1-blah").compile(ctx);
} catch (Exception e) {
e.printStackTrace();
return;
}
assertTrue(false);
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testCompileTimeCoercion.
public void testCompileTimeCoercion() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("foo", Foo.class);
assertEquals(true, executeExpression(new ExpressionCompiler("foo.bar.woof == 'true'").compile(ctx), createTestMap()));
}
use of org.mule.mvel2.compiler.ExpressionCompiler in project mvel by mikebrock.
the class TypesAndInferenceTests method testParameterizedTypeInStrictMode2.
public void testParameterizedTypeInStrictMode2() {
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("ctx", Object.class);
ExpressionCompiler compiler = new ExpressionCompiler("org.mvel2.DataConversion.convert(ctx, String).toUpperCase()");
assertEquals(String.class, compiler.compile(ctx).getKnownEgressType());
}
Aggregations