use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder 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.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.
the class TypeBasedTransformerResolverTestCase method resolvesTypeWithOneMatchingTransformer.
@Test
public void resolvesTypeWithOneMatchingTransformer() throws ResolverException, TransformerException {
MuleRegistry muleRegistry = mock(MuleRegistry.class);
when(muleContext.getRegistry()).thenReturn(muleRegistry);
Transformer aToBConverter = new MockConverterBuilder().from(dataTypeA).to(dataTypeB).build();
ArrayList<Transformer> transformers = new ArrayList<>();
transformers.add(aToBConverter);
when(muleRegistry.lookupTransformers(dataTypeA, dataTypeB)).thenReturn(transformers);
TypeBasedTransformerResolver resolver = new TypeBasedTransformerResolver();
resolver.setMuleContext(muleContext);
Transformer resolvedTransformer = resolver.resolve(dataTypeA, dataTypeB);
assertEquals(aToBConverter, resolvedTransformer);
}
use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.
the class TypeBasedTransformerResolverTestCase method resolvesTypeWithTwoMatchingTransformer.
@Test
public void resolvesTypeWithTwoMatchingTransformer() throws ResolverException, TransformerException {
MuleRegistry muleRegistry = mock(MuleRegistry.class);
when(muleContext.getRegistry()).thenReturn(muleRegistry);
Transformer aToBConverter = new MockConverterBuilder().from(dataTypeA).to(dataTypeB).weighting(1).build();
Transformer betterAToBConverter = new MockConverterBuilder().from(dataTypeA).to(dataTypeB).weighting(2).build();
ArrayList<Transformer> transformers = new ArrayList<>();
transformers.add(aToBConverter);
transformers.add(betterAToBConverter);
when(muleRegistry.lookupTransformers(dataTypeA, dataTypeB)).thenReturn(transformers);
TypeBasedTransformerResolver resolver = new TypeBasedTransformerResolver();
resolver.setMuleContext(muleContext);
Transformer resolvedTransformer = resolver.resolve(dataTypeA, dataTypeB);
assertEquals(betterAToBConverter, resolvedTransformer);
}
Aggregations