Search in sources :

Example 11 with MVELExpressionLanguage

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));
}
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) Test(org.junit.Test)

Example 12 with MVELExpressionLanguage

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));
}
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) Test(org.junit.Test)

Example 13 with MVELExpressionLanguage

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

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