Search in sources :

Example 11 with BindingContext

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

the class DefaultExpressionManagerTestCase method simpleCustomVariable.

@Test
@Description("Verifies that custom variables are considered.")
public void simpleCustomVariable() {
    Object object = new Object();
    BindingContext context = builder().addBinding(MY_VAR, new TypedValue(object, OBJECT)).build();
    assertThat(expressionManager.evaluate("#[myVar]", context).getValue(), equalTo(object));
}
Also used : BindingContext(org.mule.runtime.api.el.BindingContext) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 12 with BindingContext

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

the class DefaultExpressionModuleBuilderTestCase method shouldBeAddedToBindingContext.

@Test
public void shouldBeAddedToBindingContext() {
    BindingContext.Builder bindingContextBuilder = BindingContext.builder();
    ExpressionModule.Builder builder = ExpressionModule.builder(namespace);
    builder.addBinding("id", typedValue);
    ExpressionModule module = builder.build();
    bindingContextBuilder.addModule(module);
    BindingContext bindingContext = bindingContextBuilder.build();
    assertThat(bindingContext.modules(), hasSize(1));
    assertThat(bindingContext.modules(), hasItem(module));
}
Also used : ExpressionModule(org.mule.runtime.api.el.ExpressionModule) BindingContext(org.mule.runtime.api.el.BindingContext) Test(org.junit.Test)

Example 13 with BindingContext

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

the class ExtensionActivator method registerExpressionFunctions.

private void registerExpressionFunctions(ExtensionModel extensionModel) {
    if (extensionModel.getFunctionModels().isEmpty()) {
        return;
    }
    ExpressionModule.Builder moduleBuilder = new DefaultExpressionModuleBuilder(new ModuleNamespace(extensionModel.getXmlDslModel().getPrefix()));
    registerExpressionFunctions(extensionModel.getFunctionModels().stream(), moduleBuilder);
    try {
        final BindingContext bindingContext = new DefaultBindingContextBuilder().addModule(moduleBuilder.build()).build();
        registerObject(muleContext, extensionModel.getName() + "GlobalBindingContextProvider", (GlobalBindingContextProvider) () -> bindingContext);
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage(e.getMessage()), e);
    }
}
Also used : DefaultExpressionModuleBuilder(org.mule.runtime.core.internal.el.DefaultExpressionModuleBuilder) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultBindingContextBuilder(org.mule.runtime.core.internal.el.DefaultBindingContextBuilder) ExpressionModule(org.mule.runtime.api.el.ExpressionModule) ModuleNamespace(org.mule.runtime.api.el.ModuleNamespace) BindingContext(org.mule.runtime.api.el.BindingContext) MuleException(org.mule.runtime.api.exception.MuleException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Aggregations

BindingContext (org.mule.runtime.api.el.BindingContext)13 Test (org.junit.Test)9 TypedValue (org.mule.runtime.api.metadata.TypedValue)7 Description (io.qameta.allure.Description)4 ExpressionModule (org.mule.runtime.api.el.ExpressionModule)4 ExpressionFunction (org.mule.runtime.api.el.ExpressionFunction)3 DataType (org.mule.runtime.api.metadata.DataType)3 MuleContext (org.mule.runtime.core.api.MuleContext)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Pattern (java.util.regex.Pattern)1 Collectors.toMap (java.util.stream.Collectors.toMap)1