Search in sources :

Example 36 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class TransformationServiceTestCase method skipsConverterFailsOnTransformerWhenOriginalPayloadMatchesExpectedOutputType.

@Test
public void skipsConverterFailsOnTransformerWhenOriginalPayloadMatchesExpectedOutputType() throws MuleException {
    // Converter(B -> D) Transformer(C->D), payload D: FAIL
    Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeD).build();
    Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new D());
    try {
        transformationService.applyTransformers(message, null, converter1, transformer2);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerNotExecuted(converter1);
    verifyTransformerNotExecuted(transformer2);
}
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) MockTransformerBuilder(org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 37 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class TransformationServiceTestCase method failsTransformationUsingConverterWhenSourceAndReturnTypeDoesNotMatch2.

@Test
public void failsTransformationUsingConverterWhenSourceAndReturnTypeDoesNotMatch2() throws MuleException {
    // Converter(B -> C) Converter(C->D), payload A: FAIL
    Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).build();
    Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new A());
    try {
        transformationService.applyTransformers(message, null, converter1, converter2);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerNotExecuted(converter1);
    verifyTransformerNotExecuted(converter2);
}
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) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 38 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class TransformationServiceTestCase method failsTransformerIgnoringMatchingConverter.

@Test
public void failsTransformerIgnoringMatchingConverter() throws MuleException {
    // Transformer(B -> D) Converter(C->D), payload C: FAIL
    Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).build();
    Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new C());
    try {
        transformationService.applyTransformers(message, null, transformer1, converter2);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerNotExecuted(transformer1);
    verifyTransformerNotExecuted(converter2);
}
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) MockTransformerBuilder(org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 39 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class TransformationServiceTestCase method failsTransformerIgnoringNonMatchingConverter.

@Test
public void failsTransformerIgnoringNonMatchingConverter() throws MuleException {
    // Transformer(B -> D) Converter(C->D), payload A: FAIL
    Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).build();
    Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new A());
    try {
        transformationService.applyTransformers(message, null, transformer1, converter2);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerNotExecuted(transformer1);
    verifyTransformerNotExecuted(converter2);
}
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) MockTransformerBuilder(org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 40 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class TransformationServiceTestCase method failsOnTransformerWhenOriginalPayloadMatchesExpectedOutputType.

@Test
public void failsOnTransformerWhenOriginalPayloadMatchesExpectedOutputType() throws MuleException {
    // Transformer(B->C), payload C: FAIL
    Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeC).build();
    Message message = of(new C());
    try {
        transformationService.applyTransformers(message, null, transformer1);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerNotExecuted(transformer1);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) Message(org.mule.runtime.api.message.Message) MockTransformerBuilder(org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

Message (org.mule.runtime.api.message.Message)226 Test (org.junit.Test)189 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)104 SmallTest (org.mule.tck.size.SmallTest)68 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)46 Transformer (org.mule.runtime.core.api.transformer.Transformer)35 DataType (org.mule.runtime.api.metadata.DataType)33 ArrayList (java.util.ArrayList)26 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)26 Processor (org.mule.runtime.core.api.processor.Processor)25 List (java.util.List)20 Assert.assertThat (org.junit.Assert.assertThat)19 ExpectedException (org.junit.rules.ExpectedException)19 MuleContextUtils.eventBuilder (org.mule.tck.util.MuleContextUtils.eventBuilder)19 Map (java.util.Map)18 Rule (org.junit.Rule)18 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)18 ExpectedException.none (org.junit.rules.ExpectedException.none)17 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)17 TypedValue (org.mule.runtime.api.metadata.TypedValue)16