use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.
the class WithTests method testInlineWith4.
public void testInlineWith4() {
OptimizerFactory.setDefaultOptimizer("ASM");
ParserContext pCtx = new ParserContext();
pCtx.addImport(Foo.class);
ExpressionCompiler expr = new ExpressionCompiler("new Foo().{ name = 'bar' }", pCtx);
CompiledExpression c = expr.compile();
Foo f = (Foo) executeExpression(c);
assertEquals("bar", f.getName());
f = (Foo) executeExpression(c);
assertEquals("bar", f.getName());
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.
the class WithTests method testInlineWith3.
public void testInlineWith3() {
CompiledExpression expr = new ExpressionCompiler("foo.{name = 'poopy', aValue = 'bar', bar.{name = 'foobie'}, toUC('doopy')}").compile();
Foo f = (Foo) executeExpression(expr, createTestMap());
assertEquals("poopy", f.getName());
assertEquals("bar", f.aValue);
assertEquals("foobie", f.getBar().getName());
assertEquals("doopy", f.register);
}
use of org.mule.mvel2.compiler.CompiledExpression in project mvel by mvel.
the class ArithmeticTests method testStrongTypingModeComparison.
public void testStrongTypingModeComparison() {
ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true);
parserContext.addInput("a", Long.class);
CompiledExpression compiledExpression = new ExpressionCompiler("a==0", parserContext).compile();
HashMap<String, Object> variables = new HashMap<String, Object>();
variables.put("a", 0l);
MVEL.executeExpression(compiledExpression, variables);
}
use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.
the class AbstractVarAssignmentDataTypePropagatorTestCase method doAssignmentDataTypePropagationTest.
protected void doAssignmentDataTypePropagationTest(String expression) throws Exception {
DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
CompiledExpression compiledExpression = compileMelExpression(expression, (PrivilegedEvent) testEvent(), builder);
PrivilegedEvent event = builder.build();
dataTypePropagator.propagate(event, builder, new TypedValue<>(TEST_MESSAGE, expectedDataType), compiledExpression);
event = builder.build();
assertThat(getVariableDataType(event), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.mvel2.compiler.CompiledExpression in project mule by mulesoft.
the class AbstractVarExpressionDataTypeResolverTestCase method doVarDataTypeTest.
protected void doVarDataTypeTest(String expression) throws Exception {
DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
PrivilegedEvent event = setVariable((PrivilegedEvent) testEvent(), EXPRESSION_VALUE, expectedDataType);
final ParserConfiguration parserConfiguration = MVELExpressionLanguage.createParserConfiguration(Collections.EMPTY_MAP);
final MVELExpressionLanguageContext context = createMvelExpressionLanguageContext(event, parserConfiguration);
CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(parserConfiguration));
// Expression must be executed, otherwise the variable accessor is not properly configured
MVEL.executeExpression(compiledExpression, context);
assertThat(expressionDataTypeResolver.resolve(event, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
Aggregations