Search in sources :

Example 1 with MVELExpressionLanguageContext

use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext in project mule by mulesoft.

the class MVELExpressionLanguageContextTestCase method testGetVariableResolver.

@Test
public void testGetVariableResolver() {
    MuleBaseVariableResolverFactory resoverFactory = new MVELExpressionLanguageContext(parserConfig, muleContext);
    resoverFactory.addResolver("foo", new SimpleValueResolver("val"));
    assertNotNull(resoverFactory.getVariableResolver("foo"));
    assertEquals("val", resoverFactory.getVariableResolver("foo").getValue());
    assertNull(resoverFactory.getVariableResolver("bar"));
}
Also used : MuleBaseVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.MuleBaseVariableResolverFactory) MVELExpressionLanguageContext(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext) SimpleValueResolver(org.mule.mvel2.integration.impl.SimpleValueResolver) Test(org.junit.Test)

Example 2 with MVELExpressionLanguageContext

use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext in project mule by mulesoft.

the class MVELExpressionLanguageContextTestCase method testGetVariableResolverNextFactory.

@Test
public void testGetVariableResolverNextFactory() {
    parserConfig.addImport(String.class);
    MuleBaseVariableResolverFactory resoverFactory = new MVELExpressionLanguageContext(parserConfig, muleContext);
    resoverFactory.setNextFactory(new MapVariableResolverFactory(Collections.singletonMap("foo", "val")));
    assertNotNull(resoverFactory.getVariableResolver("foo"));
    assertEquals("val", resoverFactory.getVariableResolver("foo").getValue());
    assertNull(resoverFactory.getVariableResolver("bar"));
}
Also used : MuleBaseVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.MuleBaseVariableResolverFactory) MVELExpressionLanguageContext(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext) MapVariableResolverFactory(org.mule.mvel2.integration.impl.MapVariableResolverFactory) Test(org.junit.Test)

Example 3 with MVELExpressionLanguageContext

use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext in project mule by mulesoft.

the class AbstractVarAssignmentDataTypePropagatorTestCase method createMvelExpressionLanguageContext.

protected MVELExpressionLanguageContext createMvelExpressionLanguageContext(PrivilegedEvent testEvent, PrivilegedEvent.Builder builder, ParserConfiguration parserConfiguration) {
    final MVELExpressionLanguageContext context = new MVELExpressionLanguageContext(parserConfiguration, muleContext);
    final StaticVariableResolverFactory staticContext = new StaticVariableResolverFactory(parserConfiguration, muleContext);
    final GlobalVariableResolverFactory globalContext = new GlobalVariableResolverFactory(emptyMap(), emptyMap(), parserConfiguration, muleContext);
    final DelegateVariableResolverFactory innerDelegate = new DelegateVariableResolverFactory(globalContext, new VariableVariableResolverFactory(parserConfiguration, muleContext, testEvent, builder));
    final DelegateVariableResolverFactory delegate = new DelegateVariableResolverFactory(staticContext, new MessageVariableResolverFactory(parserConfiguration, muleContext, testEvent, builder, innerDelegate));
    context.setNextFactory(new CachedMapVariableResolverFactory(emptyMap(), delegate));
    return context;
}
Also used : DelegateVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.DelegateVariableResolverFactory) MVELExpressionLanguageContext(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext) GlobalVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.GlobalVariableResolverFactory) MessageVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.MessageVariableResolverFactory) CachedMapVariableResolverFactory(org.mule.mvel2.integration.impl.CachedMapVariableResolverFactory) StaticVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.StaticVariableResolverFactory) VariableVariableResolverFactory(org.mule.runtime.core.internal.el.mvel.VariableVariableResolverFactory)

Example 4 with MVELExpressionLanguageContext

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

Example 5 with MVELExpressionLanguageContext

use of org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext in project mule by mulesoft.

the class DateTimeExpressionLanguageFunctionTestCase method setup.

@Before
public void setup() throws InitialisationException {
    ParserConfiguration parserConfiguration = new ParserConfiguration();
    expressionExecutor = new MVELExpressionExecutor(parserConfiguration);
    context = new MVELExpressionLanguageContext(parserConfiguration, Mockito.mock(MuleContext.class));
    dateTimeFunction = new DateTimeExpressionLanguageFuntion();
    context.declareFunction("dateTime", dateTimeFunction);
}
Also used : MVELExpressionExecutor(org.mule.runtime.core.internal.el.mvel.MVELExpressionExecutor) MVELExpressionLanguageContext(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext) ParserConfiguration(org.mule.mvel2.ParserConfiguration) Before(org.junit.Before)

Aggregations

MVELExpressionLanguageContext (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguageContext)9 ParserConfiguration (org.mule.mvel2.ParserConfiguration)5 Before (org.junit.Before)3 MVELExpressionExecutor (org.mule.runtime.core.internal.el.mvel.MVELExpressionExecutor)3 Test (org.junit.Test)2 ParserContext (org.mule.mvel2.ParserContext)2 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)2 CachedMapVariableResolverFactory (org.mule.mvel2.integration.impl.CachedMapVariableResolverFactory)2 MuleContext (org.mule.runtime.core.api.MuleContext)2 DelegateVariableResolverFactory (org.mule.runtime.core.internal.el.mvel.DelegateVariableResolverFactory)2 GlobalVariableResolverFactory (org.mule.runtime.core.internal.el.mvel.GlobalVariableResolverFactory)2 MessageVariableResolverFactory (org.mule.runtime.core.internal.el.mvel.MessageVariableResolverFactory)2 MuleBaseVariableResolverFactory (org.mule.runtime.core.internal.el.mvel.MuleBaseVariableResolverFactory)2 StaticVariableResolverFactory (org.mule.runtime.core.internal.el.mvel.StaticVariableResolverFactory)2 VariableVariableResolverFactory (org.mule.runtime.core.internal.el.mvel.VariableVariableResolverFactory)2 MapVariableResolverFactory (org.mule.mvel2.integration.impl.MapVariableResolverFactory)1 SimpleValueResolver (org.mule.mvel2.integration.impl.SimpleValueResolver)1 DataType (org.mule.runtime.api.metadata.DataType)1 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)1