use of org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder 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.MockTransformerBuilder in project mule by mulesoft.
the class TransformationServiceTestCase method appliesTransformer.
@Test
public void appliesTransformer() throws MuleException {
// Transformer(B->C), payload B: OK
Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeC).returning(new C()).build();
Message message = of(new B());
message = transformationService.applyTransformers(message, null, transformer1);
assertTrue(message.getPayload().getValue() instanceof C);
verifyTransformerExecuted(transformer1);
}
use of org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder in project mule by mulesoft.
the class TransformationServiceTestCase method failsOnFirstTransformerIgnoresSecondTransformerWhenOriginalPayloadMatchesExpectedOutputType.
@Test
public void failsOnFirstTransformerIgnoresSecondTransformerWhenOriginalPayloadMatchesExpectedOutputType() throws MuleException {
// Transformer(B ->D) Transformer(C->D), payload D: FAIL
Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).build();
Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
Message message = of(new D());
try {
transformationService.applyTransformers(message, null, transformer1, transformer2);
fail("Transformation is supposed to fail");
} catch (IllegalArgumentException expected) {
}
verifyTransformerNotExecuted(transformer1);
verifyTransformerNotExecuted(transformer2);
}
use of org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder in project mule by mulesoft.
the class TransformationServiceTestCase method failsWhenNoImplicitConversionAvailable.
@Test
public void failsWhenNoImplicitConversionAvailable() throws MuleException {
Transformer transformer = new MockTransformerBuilder().from(DataType.BYTE_ARRAY).to(DataType.STRING).build();
when(conversionResolver.resolve(any(DataType.class), anyList())).thenReturn(null);
Message message = of("TEST");
try {
transformationService.applyTransformers(message, null, transformer);
fail("Transformation is supposed to fail");
} catch (IllegalArgumentException expected) {
}
verifyTransformerNotExecuted(transformer);
}
use of org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder in project mule by mulesoft.
the class TransformationServiceTestCase method appliesImplicitConversionWhenAvailable.
@Test
public void appliesImplicitConversionWhenAvailable() throws MuleException {
Transformer transformer = new MockTransformerBuilder().from(DataType.BYTE_ARRAY).to(DataType.STRING).returning("bar").build();
Transformer converter = new MockConverterBuilder().from(DataType.STRING).to(DataType.BYTE_ARRAY).returning("bar".getBytes()).build();
when(conversionResolver.resolve(any(DataType.class), anyList())).thenReturn(converter);
Message message = of("TEST");
message = transformationService.applyTransformers(message, null, transformer);
assertEquals("bar", message.getPayload().getValue());
verifyTransformerExecuted(transformer);
verifyTransformerExecuted(converter);
}
Aggregations