Search in sources :

Example 1 with ExpressionArgument

use of org.mule.runtime.core.internal.transformer.expression.ExpressionArgument 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 ExpressionArgument

use of org.mule.runtime.core.internal.transformer.expression.ExpressionArgument 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)

Aggregations

Test (org.junit.Test)2 ExpressionArgument (org.mule.runtime.core.internal.transformer.expression.ExpressionArgument)2 ExpressionTransformer (org.mule.runtime.core.internal.transformer.expression.ExpressionTransformer)2 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)1 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)1