Search in sources :

Example 1 with DefaultExpressionLanguageFactoryService

use of org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService 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 DefaultExpressionLanguageFactoryService

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

the class GlobalBindingContextProviderTestCase method getStartUpRegistryObjects.

@Override
protected Map<String, Object> getStartUpRegistryObjects() {
    Map<String, Object> objects = new HashMap<>();
    DefaultExpressionLanguageFactoryService weaveExpressionExecutor = new WeaveDefaultExpressionLanguageFactoryService();
    objects.put(weaveExpressionExecutor.getName(), weaveExpressionExecutor);
    objects.put(KEY, new TestGlobalBindingContextProvider());
    return objects;
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) HashMap(java.util.HashMap) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService)

Example 3 with DefaultExpressionLanguageFactoryService

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

the class BasicRuntimeServicesConfigurationBuilder method doConfigure.

@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
    new SpiServiceRegistry().lookupProviders(Service.class, BasicRuntimeServicesConfigurationBuilder.class.getClassLoader()).forEach(service -> {
        try {
            startIfNeeded(service);
            registerObject(muleContext, service.getName(), service);
        } catch (MuleException e) {
            throw new MuleRuntimeException(e);
        }
    });
    DefaultExpressionLanguageFactoryService weaveExpressionExecutor = new WeaveDefaultExpressionLanguageFactoryService();
    registerObject(muleContext, weaveExpressionExecutor.getName(), weaveExpressionExecutor);
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) Service(org.mule.runtime.api.service.Service) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) MuleException(org.mule.runtime.api.exception.MuleException)

Example 4 with DefaultExpressionLanguageFactoryService

use of org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService 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 5 with DefaultExpressionLanguageFactoryService

use of org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService 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)5 ExpressionLanguage (org.mule.runtime.api.el.ExpressionLanguage)3 WeaveDefaultExpressionLanguageFactoryService (org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService)3 Test (org.junit.Test)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 HashMap (java.util.HashMap)1 Registry (org.mule.runtime.api.artifact.Registry)1 BindingContext (org.mule.runtime.api.el.BindingContext)1 MuleException (org.mule.runtime.api.exception.MuleException)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 TypedValue (org.mule.runtime.api.metadata.TypedValue)1 Service (org.mule.runtime.api.service.Service)1 CursorProvider (org.mule.runtime.api.streaming.CursorProvider)1 MuleContext (org.mule.runtime.core.api.MuleContext)1 SpiServiceRegistry (org.mule.runtime.core.api.registry.SpiServiceRegistry)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