Search in sources :

Example 1 with MVELExpressionLanguage

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);
}
Also used : MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) Before(org.junit.Before)

Example 2 with MVELExpressionLanguage

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression)

Example 3 with MVELExpressionLanguage

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression)

Example 4 with MVELExpressionLanguage

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.");
        }
    }
}
Also used : GlobalBindingContextProvider(org.mule.runtime.core.privileged.el.GlobalBindingContextProvider) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) DataWeaveExpressionLanguageAdaptor(org.mule.runtime.core.internal.el.dataweave.DataWeaveExpressionLanguageAdaptor)

Example 5 with MVELExpressionLanguage

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Aggregations

MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)13 Test (org.junit.Test)6 ParserContext (org.mule.mvel2.ParserContext)6 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)6 DataType (org.mule.runtime.api.metadata.DataType)6 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)6 DefaultExpressionManager (org.mule.runtime.core.internal.el.DefaultExpressionManager)3 Before (org.junit.Before)2 FlowConstruct (org.mule.runtime.core.api.construct.FlowConstruct)2 SmallTest (org.mule.tck.size.SmallTest)2 WeaveDefaultExpressionLanguageFactoryService (org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService)2 HashMap (java.util.HashMap)1 Component (org.mule.runtime.api.component.Component)1 ComponentInitialStateManager (org.mule.runtime.api.deployment.management.ComponentInitialStateManager)1 TypedValue (org.mule.runtime.api.metadata.TypedValue)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 NoRetryPolicyTemplate (org.mule.runtime.core.api.retry.policy.NoRetryPolicyTemplate)1 DefaultStreamingManager (org.mule.runtime.core.api.streaming.DefaultStreamingManager)1 StreamingManager (org.mule.runtime.core.api.streaming.StreamingManager)1 SimpleRegistryBootstrap (org.mule.runtime.core.internal.config.bootstrap.SimpleRegistryBootstrap)1