use of org.mule.runtime.core.api.transformer.Transformer 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.api.transformer.Transformer 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());
}
use of org.mule.runtime.core.api.transformer.Transformer 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());
}
use of org.mule.runtime.core.api.transformer.Transformer 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());
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class AbstractMockConverterBuilder method build.
@Override
public Converter build() {
Transformer converter = super.build();
doReturn(weight).when((Converter) converter).getPriorityWeighting();
return (Converter) converter;
}
Aggregations