use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage in project mule by mulesoft.
the class ExpressionLanguageEnrichmentTestCase method setup.
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
expressionLanguage = new MVELExpressionLanguage(muleContext);
((MuleContextWithRegistries) muleContext).getRegistry().registerObject(OBJECT_EXPRESSION_LANGUAGE, expressionLanguage);
}
use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage in project mule by mulesoft.
the class PayloadEnricherDataTypePropagatorTestCase method doPayloadDataTypeTest.
private void doPayloadDataTypeTest(String expression) 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(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
dataTypePropagator.propagate((PrivilegedEvent) testEvent(), builder, new TypedValue<>(TEST_MESSAGE, expectedDataType), compiledExpression);
final CoreEvent event = builder.build();
assertThat(event.getMessage().getPayload().getDataType(), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage in project mule by mulesoft.
the class PayloadExpressionDataTypeResolverTestCase method doPayloadDataTypeTest.
private void doPayloadDataTypeTest(String expression) 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(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent event = PrivilegedEvent.builder(testEvent()).message(InternalMessage.builder(testEvent().getMessage()).value(TEST_MESSAGE).mediaType(expectedDataType.getMediaType()).build()).build();
assertThat(dataTypeResolver.resolve(event, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage in project mule by mulesoft.
the class DefaultExpressionManager method initialise.
@Override
public void initialise() throws InitialisationException {
if (!initialized.getAndSet(true)) {
final DataWeaveExpressionLanguageAdaptor dwExpressionLanguage = DataWeaveExpressionLanguageAdaptor.create(muleContext, registry);
MVELExpressionLanguage mvelExpressionLanguage = null;
if (registry.lookupByName(COMPATIBILITY_PLUGIN_INSTALLED).isPresent()) {
mvelExpressionLanguage = registry.<MVELExpressionLanguage>lookupByName(OBJECT_EXPRESSION_LANGUAGE).get();
}
this.expressionLanguage = new ExpressionLanguageAdaptorHandler(dwExpressionLanguage, mvelExpressionLanguage);
this.melDefault = expressionLanguage.isMelDefault();
Collection<GlobalBindingContextProvider> contextProviders = registry.lookupAllByType(GlobalBindingContextProvider.class);
contextProviders.stream().map(GlobalBindingContextProvider::getBindingContext).forEach(expressionLanguage::addGlobalBindings);
if (melDefault) {
LOGGER.warn("Using MEL as the default expression language.");
}
}
}
use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage in project mule by mulesoft.
the class PropertyEnricherDataTypePropagatorTestCase method propagatesDataTypeForInlinedSessionProperty.
@Test
public void propagatesDataTypeForInlinedSessionProperty() 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 event = (PrivilegedEvent) testEvent();
event.getSession().setProperty("foo", "bar");
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
dataTypePropagator.propagate((PrivilegedEvent) testEvent(), builder, new TypedValue(TEST_MESSAGE, expectedDataType), compiledExpression);
assertThat(builder.build().getSession().getPropertyDataType("foo"), like(String.class, JSON, CUSTOM_ENCODING));
}
Aggregations