Search in sources :

Example 6 with MessageTransformerException

use of org.mule.runtime.core.api.transformer.MessageTransformerException in project mule by mulesoft.

the class TransformationServiceTestCase method failsOnConverterWhenSourceAndReturnTypeDoesNotMatchAndThereIsNoImplicitConversion2.

@Test
public void failsOnConverterWhenSourceAndReturnTypeDoesNotMatchAndThereIsNoImplicitConversion2() throws MuleException {
    // Converter(B->C), payload A: FAIL
    ByteArrayInputStream payload = new ByteArrayInputStream(TEST_PAYLOAD.getBytes());
    DataType originalSourceType = DataType.fromType(payload.getClass());
    Transformer converter1 = new MockConverterBuilder().from(originalSourceType).to(dataTypeC).build();
    A transformedPayload = new A();
    when(converter1.transform(any())).thenReturn(transformedPayload);
    Message message = of(payload);
    try {
        transformationService.applyTransformers(message, null, converter1);
        fail("Transformation is supposed to fail");
    } catch (MessageTransformerException expected) {
        assertThat(expected.getErrorMessage().getPayload().getValue(), is(transformedPayload));
    }
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Message(org.mule.runtime.api.message.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) DataType(org.mule.runtime.api.metadata.DataType) MessageTransformerException(org.mule.runtime.core.api.transformer.MessageTransformerException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

MessageTransformerException (org.mule.runtime.core.api.transformer.MessageTransformerException)6 Message (org.mule.runtime.api.message.Message)3 DataType (org.mule.runtime.api.metadata.DataType)3 Transformer (org.mule.runtime.core.api.transformer.Transformer)3 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 Test (org.junit.Test)1 Registry (org.mule.runtime.api.artifact.Registry)1 BindingContext (org.mule.runtime.api.el.BindingContext)1 MuleExpressionLanguage (org.mule.runtime.api.el.MuleExpressionLanguage)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)1 INPUT_STREAM (org.mule.runtime.api.metadata.DataType.INPUT_STREAM)1 TypedValue (org.mule.runtime.api.metadata.TypedValue)1 TransformationService (org.mule.runtime.api.transformation.TransformationService)1