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));
}
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));
}
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);
}
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);
}
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);
}
Aggregations