use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage in project mule by mulesoft.
the class PropertyEnricherDataTypePropagatorTestCase method propagatesDataTypeForInlinedInvocationProperty.
@Test
public void propagatesDataTypeForInlinedInvocationProperty() throws Exception {
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression("foo = 'unused'", new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent testEvent = this.<PrivilegedEvent.Builder>getEventBuilder().message(of(TEST_MESSAGE)).addVariable("foo", "bar").build();
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent);
dataTypePropagator.propagate(testEvent, builder, new TypedValue<>(TEST_MESSAGE, expectedDataType), compiledExpression);
assertThat(builder.build().getVariables().get("foo").getDataType(), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage in project mule by mulesoft.
the class PropertyExpressionDataTypeResolverTestCase method returnsInlineSessionPropertyDataType.
@Test
public void returnsInlineSessionPropertyDataType() throws Exception {
final String expression = "foo";
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
((PrivilegedEvent) testEvent()).getSession().setProperty("foo", EXPRESSION_VALUE, expectedDataType);
assertThat(expressionDataTypeResolver.resolve((PrivilegedEvent) testEvent(), compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage in project mule by mulesoft.
the class MVELExpressionLanguageObjectFactory method doGetObject.
@Override
public MVELExpressionLanguage doGetObject() throws Exception {
MVELExpressionLanguage result = new MVELExpressionLanguage(muleContext);
result.setAutoResolveVariables(autoResolveVariables);
if (globalFunctions != null) {
result.setGlobalFunctionsFile(globalFunctions.getFile());
result.setGlobalFunctionsString(globalFunctions.getInlineScript());
}
if (aliases != null) {
Map<String, String> aliasesMap = new HashMap<>();
aliases.forEach(x -> aliasesMap.put(x.getKey(), x.getValue()));
result.setAliases(aliasesMap);
}
if (imports != null) {
Map<String, Class<?>> importsMap = new HashMap<>();
imports.forEach(x -> importsMap.put(x.getKey(), x.getValue()));
result.setImports(importsMap);
}
return result;
}
Aggregations