Search in sources :

Example 1 with ExpressionTransformer

use of org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer in project mule by mulesoft.

the class ExpressionTransformerTestCase method testNullPayloadIsConsideredAsNullResultEL.

@Test
public void testNullPayloadIsConsideredAsNullResultEL() throws Exception {
    ExpressionTransformer transformer = new ExpressionTransformer();
    transformer.setMuleContext(muleContext);
    transformer.setReturnSourceIfNull(true);
    // MVL doesn't return NullPayload but rather null. So 'optional' needs to be true.
    ExpressionArgument argument = new ExpressionArgument("test", "null", true);
    argument.setMuleContext(muleContext);
    transformer.addArgument(argument);
    Object result = transformer.transformMessage(testEvent(), null);
    assertTrue(result instanceof InternalMessage);
    InternalMessage transformedMessage = (InternalMessage) result;
    assertEquals(TEST_PAYLOAD, transformedMessage.getPayload().getValue());
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpressionTransformer(org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer) ExpressionArgument(org.mule.runtime.core.internal.transformer.expression.ExpressionArgument) Test(org.junit.Test)

Example 2 with ExpressionTransformer

use of org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer in project mule by mulesoft.

the class ExpressionTransformerTestCase method testExpressionEvaluationClassLoaderEL.

@Test
public void testExpressionEvaluationClassLoaderEL() throws ClassNotFoundException, TransformerException {
    ExpressionTransformer transformer = new ExpressionTransformer();
    transformer.setMuleContext(muleContext);
    ExpressionArgument argument = new ExpressionArgument("test", "mel:payload is org.MyClass", false);
    argument.setMuleContext(muleContext);
    transformer.addArgument(argument);
    withContextClassLoader(new MyClassClassLoader(), () -> {
        try {
            transformer.initialise();
        } catch (Exception e) {
            fail(e.getMessage());
        }
    });
    assertFalse((Boolean) transformer.transform("test"));
}
Also used : ExpressionTransformer(org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer) ExpressionArgument(org.mule.runtime.core.internal.transformer.expression.ExpressionArgument) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) Test(org.junit.Test)

Example 3 with ExpressionTransformer

use of org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer in project mule by mulesoft.

the class CoreComponentBuildingDefinitionProvider method getExpressionTransformerConfigurationFactory.

private ConfigurableInstanceFactory getExpressionTransformerConfigurationFactory() {
    return getAbstractTransformerConfigurationFactory(parameters -> {
        ExpressionTransformer expressionTransformer = new ExpressionTransformer();
        Boolean returnSourceIfNull = (Boolean) parameters.get("returnSourceIfNull");
        if (returnSourceIfNull != null) {
            expressionTransformer.setReturnSourceIfNull(returnSourceIfNull);
        }
        return expressionTransformer;
    });
}
Also used : AbstractExpressionTransformer(org.mule.runtime.core.internal.transformer.expression.AbstractExpressionTransformer) ExpressionTransformer(org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer) Boolean.parseBoolean(java.lang.Boolean.parseBoolean)

Aggregations

ExpressionTransformer (org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer)3 Test (org.junit.Test)2 ExpressionArgument (org.mule.runtime.core.internal.transformer.expression.ExpressionArgument)2 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)1 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)1 AbstractExpressionTransformer (org.mule.runtime.core.internal.transformer.expression.AbstractExpressionTransformer)1