Search in sources :

Example 76 with MockConverterBuilder

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);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Message(org.mule.runtime.api.message.Message) MockTransformerBuilder(org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 77 with MockConverterBuilder

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);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 78 with MockConverterBuilder

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);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)78 Test (org.junit.Test)77 SmallTest (org.mule.tck.size.SmallTest)74 Converter (org.mule.runtime.core.api.transformer.Converter)48 Transformer (org.mule.runtime.core.api.transformer.Transformer)37 CompositeConverter (org.mule.runtime.core.privileged.transformer.CompositeConverter)24 Message (org.mule.runtime.api.message.Message)18 ArrayList (java.util.ArrayList)13 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)11 TransformerWeighting (org.mule.runtime.core.internal.registry.TransformerWeighting)6 Serializable (java.io.Serializable)4 DataType (org.mule.runtime.api.metadata.DataType)4 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Before (org.junit.Before)1 MessageTransformerException (org.mule.runtime.core.api.transformer.MessageTransformerException)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1 FruitBowl (org.mule.tck.testmodels.fruit.FruitBowl)1