use of org.mule.runtime.core.internal.registry.TransformerWeighting in project mule by mulesoft.
the class TransformerWeightingTestCase method testCompareWeightingWithExactMatch.
@Test
public void testCompareWeightingWithExactMatch() throws Exception {
Transformer trans1 = new MockConverterBuilder().from(DataType.fromType(Serializable.class)).to(DataType.BYTE_ARRAY).build();
Transformer trans2 = new MockConverterBuilder().from(DataType.fromType(IOException.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());
assertTrue(weighting2.isExactMatch());
// Weighting2 two is an exact match
assertEquals(1, weighting2.compareTo(weighting1));
assertEquals(3, weighting1.getInputWeighting());
assertEquals(0, weighting2.getInputWeighting());
assertEquals(0, weighting1.getOutputWeighting());
assertEquals(0, weighting2.getOutputWeighting());
}
use of org.mule.runtime.core.internal.registry.TransformerWeighting in project mule by mulesoft.
the class TransformerWeightingTestCase method testCompareWeightingWithNoMatch.
@Test
public void testCompareWeightingWithNoMatch() throws Exception {
Transformer trans1 = new MockConverterBuilder().from(DataType.fromType(Serializable.class)).to(DataType.BYTE_ARRAY).build();
Transformer trans2 = new MockConverterBuilder().from(DataType.fromType(FruitBowl.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());
assertTrue(weighting2.isNotMatch());
assertFalse(weighting1.isExactMatch());
assertFalse(weighting2.isExactMatch());
// Weighting2 two is not a match
assertEquals(-1, weighting2.compareTo(weighting1));
assertEquals(3, weighting1.getInputWeighting());
assertEquals(-1, weighting2.getInputWeighting());
assertEquals(0, weighting1.getOutputWeighting());
assertEquals(0, weighting2.getOutputWeighting());
}
use of org.mule.runtime.core.internal.registry.TransformerWeighting in project mule by mulesoft.
the class PriorityWeightingConverterFilter method filter.
@Override
public List<Converter> filter(List<Converter> converters, DataType source, DataType result) {
if (converters.size() == 0) {
return Collections.emptyList();
}
List<TransformerWeighting> weightings = getTransformerWeightings(converters, source.getType(), result.getType());
TransformerWeighting transformerWeighting = weightings.get(weightings.size() - 1);
int index = weightings.size() - 2;
List<Converter> heaviestConverter = new LinkedList<>();
heaviestConverter.add((Converter) transformerWeighting.getTransformer());
for (; index > -1; --index) {
if (weightings.get(index).compareTo(transformerWeighting) < 0) {
break;
} else {
heaviestConverter.add((Converter) weightings.get(index).getTransformer());
}
}
return heaviestConverter;
}
use of org.mule.runtime.core.internal.registry.TransformerWeighting 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());
}
use of org.mule.runtime.core.internal.registry.TransformerWeighting 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());
}
Aggregations