Search in sources :

Example 6 with TransformerWeighting

use of org.mule.runtime.core.internal.registry.TransformerWeighting 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 7 with TransformerWeighting

use of org.mule.runtime.core.internal.registry.TransformerWeighting 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)

Example 8 with TransformerWeighting

use of org.mule.runtime.core.internal.registry.TransformerWeighting in project mule by mulesoft.

the class PriorityWeightingConverterFilter method getTransformerWeightings.

private List<TransformerWeighting> getTransformerWeightings(List<Converter> converters, Class input, Class output) {
    List<TransformerWeighting> weightings = new LinkedList<>();
    for (Converter converter : converters) {
        TransformerWeighting current = new TransformerWeighting(input, output, converter);
        weightings.add(current);
    }
    Collections.sort(weightings);
    return weightings;
}
Also used : TransformerWeighting(org.mule.runtime.core.internal.registry.TransformerWeighting) Converter(org.mule.runtime.core.api.transformer.Converter) LinkedList(java.util.LinkedList)

Aggregations

TransformerWeighting (org.mule.runtime.core.internal.registry.TransformerWeighting)8 Test (org.junit.Test)6 Transformer (org.mule.runtime.core.api.transformer.Transformer)6 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)6 SmallTest (org.mule.tck.size.SmallTest)6 Serializable (java.io.Serializable)4 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)2 Converter (org.mule.runtime.core.api.transformer.Converter)2 FruitBowl (org.mule.tck.testmodels.fruit.FruitBowl)1