use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class TransformationServiceTestCase method appliesBothConverters.
@Test
public void appliesBothConverters() throws MuleException {
// Converter(B -> C) Converter(C->D), payload B: converts B->C, C->D
Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).returning(new C()).build();
Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).returning(new D()).build();
Message message = of(new B());
message = transformationService.applyTransformers(message, null, converter1, converter2);
assertTrue(message.getPayload().getValue() instanceof D);
verifyTransformerExecuted(converter1);
verifyTransformerExecuted(converter2);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class TransformationServiceTestCase method skipBothConvertersButPayloadMatchesExpectedOutputType.
@Test
public void skipBothConvertersButPayloadMatchesExpectedOutputType() throws MuleException {
// Converter(B -> C) Converter(C->D), payload D: skips converter(B-C), skips converter(C->D), but D is the expected output
// type -> OK
Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).build();
Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).build();
Message message = of(new D());
message = transformationService.applyTransformers(message, null, converter1, converter2);
assertTrue(message.getPayload().getValue() instanceof D);
verifyTransformerNotExecuted(converter1);
verifyTransformerNotExecuted(converter2);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class TransformationServiceTestCase method appliesConverterFailsOnTransformer.
@Test
public void appliesConverterFailsOnTransformer() throws MuleException {
// Converter(B -> D) Transformer(C->D), payload B: converts B-> D, cannot apply transformer -> FAIL
Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeD).returning(new D()).build();
Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
Message message = of(new B());
try {
transformationService.applyTransformers(message, null, converter1, transformer2);
fail("Transformation is supposed to fail");
} catch (IllegalArgumentException expected) {
}
verifyTransformerExecuted(converter1);
verifyTransformerNotExecuted(transformer2);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class TransformationServiceTestCase method failsOnTransformerWhenSourceAndReturnTypeDoesNotMatch.
@Test
public void failsOnTransformerWhenSourceAndReturnTypeDoesNotMatch() throws MuleException {
// Transformer(B->C), payload A: FAIL
Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeC).build();
Message message = of(new A());
try {
transformationService.applyTransformers(message, null, transformer1);
fail("Transformation is supposed to fail");
} catch (IllegalArgumentException expected) {
}
verifyTransformerNotExecuted(transformer1);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class TransformerCachingTestCase method testCacheUpdate.
@Test
public void testCacheUpdate() throws Exception {
DataType sourceType = DataType.fromType(FilterInputStream.class);
MuleRegistry registry = ((MuleContextWithRegistries) muleContext).getRegistry();
Transformer trans = registry.lookupTransformer(sourceType, BYTE_ARRAY);
assertNotNull(trans);
assertTrue(trans instanceof InputStreamToByteArray);
Transformer trans2 = new FilterInputStreamToByteArray();
registry.registerTransformer(trans2);
trans = registry.lookupTransformer(sourceType, BYTE_ARRAY);
assertNotNull(trans);
assertTrue(trans instanceof FilterInputStreamToByteArray);
trans = registry.lookupTransformer(INPUT_STREAM, BYTE_ARRAY);
assertNotNull(trans);
assertTrue(trans instanceof InputStreamToByteArray);
registry.unregisterTransformer(trans2.getName());
trans = registry.lookupTransformer(sourceType, BYTE_ARRAY);
assertNotNull(trans);
assertTrue(trans instanceof InputStreamToByteArray);
}
Aggregations