Search in sources :

Example 26 with MockConverterBuilder

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

the class TypeMatchingVertexesFilterTestCase method matchingResultTypeConvertersAreReturned.

@Test
public void matchingResultTypeConvertersAreReturned() throws Exception {
    Converter stringToOrange = new MockConverterBuilder().named("stringToOrange").from(STRING).to(ORANGE_DATA_TYPE).build();
    Converter objectToApple = new MockConverterBuilder().named("objectToApple").from(OBJECT).to(APPLE_DATA_TYPE).build();
    Converter stringToSeed = new MockConverterBuilder().named("stringToSeed").from(STRING).to(SEED_DATA_TYPE).build();
    List<Converter> converters = asList(stringToOrange, objectToApple, stringToSeed);
    List<Converter> filtered = filter.filter(converters, SEED_DATA_TYPE, ORANGE_DATA_TYPE);
    assertThat(filtered, hasSize(1));
    assertThat(filtered, contains(stringToOrange));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 27 with MockConverterBuilder

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

the class TypeMatchingVertexesFilterTestCase method resultMimeTypeIsFiltered.

@Test
public void resultMimeTypeIsFiltered() throws Exception {
    Converter bananaToString = new MockConverterBuilder().named("BananaToString").from(BANANA_DATA_TYPE).to(STRING).build();
    Converter bananaToJsonString = new MockConverterBuilder().named("BananaToJsonString").from(BANANA_DATA_TYPE).to(JSON_STRING).build();
    List<Converter> converters = asList(bananaToString, bananaToJsonString);
    List<Converter> filtered = filter.filter(converters, BANANA_DATA_TYPE, JSON_STRING);
    assertThat(filtered, hasSize(1));
    assertThat(filtered, contains(bananaToJsonString));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 28 with MockConverterBuilder

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

the class TypeMatchingVertexesFilterTestCase method sameListIsReturnedIfNoMatch.

@Test
public void sameListIsReturnedIfNoMatch() throws Exception {
    Converter stringToOrange = new MockConverterBuilder().named("stringToOrange").from(STRING).to(ORANGE_DATA_TYPE).build();
    Converter bananaToApple = new MockConverterBuilder().named("bananaToApple").from(BANANA_DATA_TYPE).to(APPLE_DATA_TYPE).build();
    List<Converter> converters = asList(stringToOrange, bananaToApple);
    List<Converter> filtered = filter.filter(converters, PEACH_DATA_TYPE, SEED_DATA_TYPE);
    assertThat(filtered, is(equalTo(converters)));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 29 with MockConverterBuilder

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

the class TransformationServiceTestCase method skipsConverterThatDoesNotMatchWhenOriginalPayloadMatchesExpectedOutputType.

@Test
public void skipsConverterThatDoesNotMatchWhenOriginalPayloadMatchesExpectedOutputType() throws MuleException {
    // Converter(B->C), payload C: OK - skips transformer but C is the expected output type -> OK
    Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).build();
    Message message = of(new C());
    message = transformationService.applyTransformers(message, null, converter1);
    assertTrue(message.getPayload().getValue() instanceof C);
    verifyTransformerNotExecuted(converter1);
}
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 30 with MockConverterBuilder

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

the class TransformationServiceTestCase method failsOnConverterWhenSourceAndReturnTypeDoesNotMatchAndThereIsNoImplicitConversion.

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

Aggregations

MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)78 Test (org.junit.Test)77 SmallTest (org.mule.tck.size.SmallTest)74 Converter (org.mule.runtime.core.api.transformer.Converter)48 Transformer (org.mule.runtime.core.api.transformer.Transformer)37 CompositeConverter (org.mule.runtime.core.privileged.transformer.CompositeConverter)24 Message (org.mule.runtime.api.message.Message)18 ArrayList (java.util.ArrayList)13 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)11 TransformerWeighting (org.mule.runtime.core.internal.registry.TransformerWeighting)6 Serializable (java.io.Serializable)4 DataType (org.mule.runtime.api.metadata.DataType)4 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Before (org.junit.Before)1 MessageTransformerException (org.mule.runtime.core.api.transformer.MessageTransformerException)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1 FruitBowl (org.mule.tck.testmodels.fruit.FruitBowl)1