Search in sources :

Example 66 with MockConverterBuilder

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

the class TypeMatchingVertexesFilterTestCase method matchingSourceTypeConvertersAreReturned.

@Test
public void matchingSourceTypeConvertersAreReturned() 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();
    Converter stringToSeed = new MockConverterBuilder().named("stringToSeed").from(STRING).to(SEED_DATA_TYPE).build();
    List<Converter> converters = asList(stringToOrange, bananaToApple, stringToSeed);
    List<Converter> filtered = filter.filter(converters, STRING, PEACH_DATA_TYPE);
    assertThat(filtered, hasSize(2));
    assertThat(filtered, contains(stringToOrange, stringToSeed));
}
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 67 with MockConverterBuilder

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

the class TypeMatchingVertexesFilterTestCase method bothVertexesMatchingIsBetterThanJustOne.

@Test
public void bothVertexesMatchingIsBetterThanJustOne() throws Exception {
    Converter stringToOrange = new MockConverterBuilder().named("stringToOrange").from(STRING).to(ORANGE_DATA_TYPE).build();
    Converter stringToBanana = new MockConverterBuilder().named("stringToBanana").from(STRING).to(BANANA_DATA_TYPE).build();
    Converter seedToOrange = new MockConverterBuilder().named("seedToOrange").from(SEED_DATA_TYPE).to(ORANGE_DATA_TYPE).build();
    List<Converter> converters = asList(stringToOrange, stringToBanana, seedToOrange);
    List<Converter> filtered = filter.filter(converters, STRING, 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 68 with MockConverterBuilder

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

the class TransformationServiceTestCase method failsTransformerIgnoringMatchingConverterWhenOriginalPayloadMatchesExpectedOutputType.

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

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

the class TransformationServiceTestCase method appliesImplicitConversionOnConverterWhenSourceAndReturnTypeDoesNotMatch.

@Test
public void appliesImplicitConversionOnConverterWhenSourceAndReturnTypeDoesNotMatch() throws MuleException {
    // Converter(C->D), payload B: uses implicit conversion B->C
    Transformer converter1 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).returning(new D()).build();
    Transformer converter2 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).returning(new C()).build();
    when(conversionResolver.resolve(any(DataType.class), anyList())).thenReturn(converter2);
    Message message = of(new B());
    message = transformationService.applyTransformers(message, null, converter1);
    assertTrue(message.getPayload().getValue() instanceof D);
    verifyTransformerExecuted(converter1);
    verifyTransformerExecuted(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) DataType(org.mule.runtime.api.metadata.DataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 70 with MockConverterBuilder

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

the class TransformationServiceTestCase method appliesConverter.

@Test
public void appliesConverter() throws MuleException {
    // Converter(B->C), payload B: OK
    Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).returning(new C()).build();
    Message message = of(new B());
    message = transformationService.applyTransformers(message, null, converter1);
    assertTrue(message.getPayload().getValue() instanceof C);
    verifyTransformerExecuted(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