Search in sources :

Example 41 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class DynamicDataTypeConverterResolverTestCase method findsExpectedConverter.

@Test
public void findsExpectedConverter() throws TransformerException {
    Transformer expectedConverter = new MockConverterBuilder().from(DataType.BYTE_ARRAY).to(DataType.STRING).build();
    when(muleContext.getRegistry()).thenReturn(muleRegistry);
    when(muleRegistry.lookupTransformer(DataType.BYTE_ARRAY, DataType.STRING)).thenReturn(expectedConverter);
    DynamicDataTypeConversionResolver resolver = new DynamicDataTypeConversionResolver(muleContext);
    List<DataType> targetValues = new ArrayList<>();
    targetValues.add(DataType.INPUT_STREAM);
    targetValues.add(DataType.STRING);
    Transformer resolvedConverter = resolver.resolve(DataType.BYTE_ARRAY, targetValues);
    assertEquals(expectedConverter, resolvedConverter);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) DataType(org.mule.runtime.api.metadata.DataType) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 42 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TransformerWeightingTestCase method testCompareWeightingWithNearMatches.

@Test
public void testCompareWeightingWithNearMatches() throws Exception {
    Transformer trans1 = new MockConverterBuilder().from(DataType.fromType(Serializable.class)).to(DataType.BYTE_ARRAY).build();
    Transformer trans2 = new MockConverterBuilder().from(DataType.fromType(Exception.class)).to(DataType.BYTE_ARRAY).build();
    TransformerWeighting weighting1 = new TransformerWeighting(IOException.class, byte[].class, trans1);
    TransformerWeighting weighting2 = new TransformerWeighting(IOException.class, byte[].class, trans2);
    assertFalse(weighting1.isNotMatch());
    assertFalse(weighting2.isNotMatch());
    assertFalse(weighting1.isExactMatch());
    assertFalse(weighting2.isExactMatch());
    // Weighting2 two is a better match
    assertEquals(1, weighting2.compareTo(weighting1));
    assertEquals(3, weighting1.getInputWeighting());
    assertEquals(1, weighting2.getInputWeighting());
    assertEquals(0, weighting1.getOutputWeighting());
    assertEquals(0, weighting2.getOutputWeighting());
}
Also used : TransformerWeighting(org.mule.runtime.core.internal.registry.TransformerWeighting) Serializable(java.io.Serializable) Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) IOException(java.io.IOException) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 43 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TransformerWeightingTestCase method testExactMatch.

@Test
public void testExactMatch() throws Exception {
    Transformer trans = new MockConverterBuilder().from(DataType.fromType(IOException.class)).to(DataType.BYTE_ARRAY).build();
    TransformerWeighting weighting = new TransformerWeighting(IOException.class, byte[].class, trans);
    assertFalse(weighting.isNotMatch());
    assertTrue(weighting.isExactMatch());
}
Also used : TransformerWeighting(org.mule.runtime.core.internal.registry.TransformerWeighting) Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) IOException(java.io.IOException) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 44 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TransformerWeightingTestCase method testNearMatch.

@Test
public void testNearMatch() throws Exception {
    Transformer trans = new MockConverterBuilder().from(DataType.INPUT_STREAM).to(DataType.BYTE_ARRAY).build();
    TransformerWeighting weighting = new TransformerWeighting(FilterInputStream.class, byte[].class, trans);
    assertFalse(weighting.isNotMatch());
    assertFalse(weighting.isExactMatch());
    assertEquals(1, weighting.getInputWeighting());
    assertEquals(0, weighting.getOutputWeighting());
}
Also used : TransformerWeighting(org.mule.runtime.core.internal.registry.TransformerWeighting) Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 45 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TransformerWeightingTestCase method testNoMatchWeighting.

@Test
public void testNoMatchWeighting() throws Exception {
    Transformer trans = new MockConverterBuilder().from(DataType.fromType(Serializable.class)).to(DataType.BYTE_ARRAY).build();
    TransformerWeighting weighting = new TransformerWeighting(FruitBowl.class, byte[].class, trans);
    assertTrue(weighting.isNotMatch());
    assertEquals(-1, weighting.getInputWeighting());
    assertEquals(0, weighting.getOutputWeighting());
}
Also used : TransformerWeighting(org.mule.runtime.core.internal.registry.TransformerWeighting) Serializable(java.io.Serializable) Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) 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