Search in sources :

Example 6 with MockTransformerBuilder

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

Example 7 with MockTransformerBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder in project mule by mulesoft.

the class TransformationServiceTestCase method failsOnFirstTransformerIgnoresSecondTransformer.

@Test
public void failsOnFirstTransformerIgnoresSecondTransformer() throws MuleException {
    // Transformer(B ->D) Transformer(C->D), payload C: FAIL
    Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).build();
    Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new C());
    try {
        transformationService.applyTransformers(message, null, transformer1, transformer2);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerNotExecuted(transformer1);
    verifyTransformerNotExecuted(transformer2);
}
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)

Example 8 with MockTransformerBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder in project mule by mulesoft.

the class TransformationServiceTestCase method appliesTransformerSkipsConverter.

@Test
public void appliesTransformerSkipsConverter() throws MuleException {
    // Transformer(B -> D) Converter(C->D), payload B: converts B->D, skips converter C->D, resulting output is of the expected
    // type -> OK
    Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).returning(new D()).build();
    Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new B());
    message = transformationService.applyTransformers(message, null, transformer1, converter2);
    assertTrue(message.getPayload().getValue() instanceof D);
    verifyTransformerExecuted(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 9 with MockTransformerBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder in project mule by mulesoft.

the class TransformationServiceTestCase method skipsConverterFailsOnTransformer.

@Test
public void skipsConverterFailsOnTransformer() throws MuleException {
    // Converter(B -> D) Transformer(C->D), payload A: FAIL
    Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeD).build();
    Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new A());
    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 10 with MockTransformerBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder in project mule by mulesoft.

the class TransformationServiceTestCase method appliesFirstTransformerFailsOnSecondTransformer.

@Test
public void appliesFirstTransformerFailsOnSecondTransformer() throws MuleException {
    // Transformer(B ->D) Transformer(C->D), payload B: applies first transformer, cannot apply second transformer -> FAIL
    Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).returning(new D()).build();
    Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
    Message message = of(new B());
    try {
        transformationService.applyTransformers(message, null, transformer1, transformer2);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerExecuted(transformer1);
    verifyTransformerNotExecuted(transformer2);
}
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

Test (org.junit.Test)19 Transformer (org.mule.runtime.core.api.transformer.Transformer)19 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)19 SmallTest (org.mule.tck.size.SmallTest)19 Message (org.mule.runtime.api.message.Message)17 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)11 DataType (org.mule.runtime.api.metadata.DataType)2 Converter (org.mule.runtime.core.api.transformer.Converter)2 CompositeConverter (org.mule.runtime.core.privileged.transformer.CompositeConverter)2