Search in sources :

Example 1 with ExpressionLanguage

use of org.mule.runtime.api.el.ExpressionLanguage in project mule by mulesoft.

the class DataWeaveExpressionLanguageAdaptorTestCase method payloadExpressionShouldNotBeEvaluate.

@Test
public void payloadExpressionShouldNotBeEvaluate() throws MuleException {
    BindingContext bindingContext = BindingContext.builder().build();
    MuleContext muleContext = mock(MuleContext.class);
    DefaultExpressionLanguageFactoryService languageFactory = mock(DefaultExpressionLanguageFactoryService.class);
    ExpressionLanguage expressionLanguage = spy(ExpressionLanguage.class);
    when(languageFactory.create()).thenReturn(expressionLanguage);
    CoreEvent event = testEvent();
    new DataWeaveExpressionLanguageAdaptor(muleContext, registry, languageFactory).evaluate("#[payload]", event, bindingContext);
    verify(expressionLanguage, never()).evaluate(eq("payload"), any(BindingContext.class));
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) BindingContext(org.mule.runtime.api.el.BindingContext) ExpressionLanguage(org.mule.runtime.api.el.ExpressionLanguage) Test(org.junit.Test)

Example 2 with ExpressionLanguage

use of org.mule.runtime.api.el.ExpressionLanguage in project mule by mulesoft.

the class TestServicesConfigurationBuilder method doConfigure.

@Override
public void doConfigure(MuleContext muleContext) throws Exception {
    MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
    registry.registerObject(schedulerService.getName(), spy(schedulerService));
    registry.registerObject(OBJECT_SCHEDULER_BASE_CONFIG, config());
    if (mockExpressionExecutor) {
        DefaultExpressionLanguageFactoryService expressionExecutor = mock(DefaultExpressionLanguageFactoryService.class, RETURNS_DEEP_STUBS);
        registry.registerObject(MOCK_EXPR_EXECUTOR, expressionExecutor);
    } else {
        // Avoid doing the DW warm-up for every test, reusing the ExpressionLanguage implementation
        if (cachedExprLanguageFactory == null) {
            final DefaultExpressionLanguageFactoryService exprExecutor = new WeaveDefaultExpressionLanguageFactoryService();
            ExpressionLanguage exprLanguage = exprExecutor.create();
            // Force initialization of internal DataWeave stuff
            // This way we avoid doing some heavy initialization on the test itself,
            // which may cause trouble when evaluation expressions in places with small timeouts
            exprLanguage.evaluate("{dataWeave: 'is'} ++ {mule: 'default EL'}", NULL_BINDING_CONTEXT);
            cachedExprLanguageFactory = new DefaultExpressionLanguageFactoryService() {

                @Override
                public ExpressionLanguage create() {
                    return exprLanguage;
                }

                @Override
                public String getName() {
                    return exprExecutor.getName();
                }
            };
        }
        registry.registerObject(cachedExprLanguageFactory.getName(), cachedExprLanguageFactory);
    }
    if (mockHttpService) {
        registry.registerObject(MOCK_HTTP_SERVICE, mock(HttpService.class));
    }
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) HttpService(org.mule.runtime.http.api.HttpService) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) ExpressionLanguage(org.mule.runtime.api.el.ExpressionLanguage)

Example 3 with ExpressionLanguage

use of org.mule.runtime.api.el.ExpressionLanguage in project mule by mulesoft.

the class DefaultExpressionManagerTestCase method managedCursor.

@Test
public void managedCursor() throws Exception {
    final DefaultExpressionLanguageFactoryService mockFactory = mock(DefaultExpressionLanguageFactoryService.class, RETURNS_DEEP_STUBS);
    final ExpressionLanguage expressionLanguage = mock(ExpressionLanguage.class, RETURNS_DEEP_STUBS);
    final CursorProvider cursorProvider = mock(CursorProvider.class);
    Registry registry = mock(Registry.class);
    when(registry.lookupByType(DefaultExpressionLanguageFactoryService.class)).thenReturn(of(mockFactory));
    when(registry.lookupByName(OBJECT_EXPRESSION_LANGUAGE)).thenReturn(of(mock(MVELExpressionLanguage.class, RETURNS_DEEP_STUBS)));
    when(registry.lookupByName(COMPATIBILITY_PLUGIN_INSTALLED)).thenReturn(empty());
    TypedValue value = new TypedValue(cursorProvider, BYTE_ARRAY);
    when(expressionLanguage.evaluate(anyString(), any())).thenReturn(value);
    when(expressionLanguage.evaluate(anyString(), any(), any())).thenReturn(value);
    when(mockFactory.create()).thenReturn(expressionLanguage);
    expressionManager = new DefaultExpressionManager();
    ((DefaultExpressionManager) expressionManager).setRegistry(registry);
    ((DefaultExpressionManager) expressionManager).setStreamingManager(streamingManager);
    initialiseIfNeeded(expressionManager, false, muleContext);
    final CoreEvent event = testEvent();
    when(streamingManager.manage(cursorProvider, event)).thenReturn(cursorProvider);
    expressionManager.evaluate("someExpression", event);
    verify(streamingManager).manage(cursorProvider, event);
}
Also used : CursorProvider(org.mule.runtime.api.streaming.CursorProvider) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) Registry(org.mule.runtime.api.artifact.Registry) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ExpressionLanguage(org.mule.runtime.api.el.ExpressionLanguage) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Aggregations

DefaultExpressionLanguageFactoryService (org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService)3 ExpressionLanguage (org.mule.runtime.api.el.ExpressionLanguage)3 Test (org.junit.Test)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 Registry (org.mule.runtime.api.artifact.Registry)1 BindingContext (org.mule.runtime.api.el.BindingContext)1 TypedValue (org.mule.runtime.api.metadata.TypedValue)1 CursorProvider (org.mule.runtime.api.streaming.CursorProvider)1 MuleContext (org.mule.runtime.core.api.MuleContext)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)1 MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)1 HttpService (org.mule.runtime.http.api.HttpService)1 WeaveDefaultExpressionLanguageFactoryService (org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService)1