use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder 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);
}
use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder 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);
}
use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.
the class MuleRegistryHelperTestCase method setUp.
@Before
public void setUp() throws Exception {
t1 = new MockConverterBuilder().named("t1").from(ORANGE_DATA_TYPE).to(FRUIT_DATA_TYPE).build();
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(t1);
t2 = new MockConverterBuilder().named("t2").from(DataType.OBJECT).to(FRUIT_DATA_TYPE).build();
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(t2);
}
use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.
the class MuleRegistryHelperTestCase method findsCompositeTransformerEvenIfDirectNotFound.
@Test
public void findsCompositeTransformerEvenIfDirectNotFound() throws Exception {
Transformer fruitToSeed = new MockConverterBuilder().named("fruitToSeed").from(FRUIT_DATA_TYPE).to(SEED_DATA_TYPE).build();
Transformer seedToApple = new MockConverterBuilder().named("seedToApple").from(SEED_DATA_TYPE).to(APPLE_DATA_TYPE).build();
Transformer appleToBanana = new MockConverterBuilder().named("appleToBanana").from(APPLE_DATA_TYPE).to(BANANA_DATA_TYPE).build();
Transformer bananaToBloodOrange = new MockConverterBuilder().named("bananaToBloodOrange").from(BANANA_DATA_TYPE).to(BLOOD_ORANGE_DATA_TYPE).build();
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(fruitToSeed);
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(seedToApple);
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(appleToBanana);
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(bananaToBloodOrange);
Transformer trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(FRUIT_DATA_TYPE, BLOOD_ORANGE_DATA_TYPE);
assertThat(trans, is(notNullValue()));
assertThat(trans, instanceOf(CompositeConverter.class));
assertThat(trans.getName(), is("fruitToSeedseedToAppleappleToBananabananaToBloodOrange"));
// The same should be returned if we ask for it with compatible data types
trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(FRUIT_DATA_TYPE, ORANGE_DATA_TYPE);
assertThat(trans, instanceOf(CompositeConverter.class));
assertThat(trans.getName(), is("fruitToSeedseedToAppleappleToBananabananaToBloodOrange"));
trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(PEACH_DATA_TYPE, BLOOD_ORANGE_DATA_TYPE);
assertThat(trans, instanceOf(CompositeConverter.class));
assertThat(trans.getName(), is("fruitToSeedseedToAppleappleToBananabananaToBloodOrange"));
trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(PEACH_DATA_TYPE, ORANGE_DATA_TYPE);
assertThat(trans, instanceOf(CompositeConverter.class));
assertThat(trans.getName(), is("fruitToSeedseedToAppleappleToBananabananaToBloodOrange"));
}
use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.
the class MuleRegistryHelperTestCase method closestToTypesTransformerIsFoundEvenIfWeightIsLess.
@Test
public void closestToTypesTransformerIsFoundEvenIfWeightIsLess() throws Exception {
Transformer bananaToBloodOrange = new MockConverterBuilder().named("bananaToBloodOrange").from(BANANA_DATA_TYPE).to(BLOOD_ORANGE_DATA_TYPE).weighting(10).build();
Transformer bananaToOrange = new MockConverterBuilder().named("bananaToOrange").from(BANANA_DATA_TYPE).to(ORANGE_DATA_TYPE).weighting(1).build();
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(bananaToBloodOrange);
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(bananaToOrange);
Transformer trans = ((MuleContextWithRegistries) muleContext).getRegistry().lookupTransformer(BANANA_DATA_TYPE, ORANGE_DATA_TYPE);
assertThat(trans, is(notNullValue()));
assertThat(trans.getName(), is("bananaToOrange"));
}
Aggregations