use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder 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.transformer.builder.MockConverterBuilder 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.transformer.builder.MockConverterBuilder in project mule by mulesoft.
the class GraphTransformerResolverTestCase method cachesResolvedTransformer.
@Test
public void cachesResolvedTransformer() throws ResolverException {
Converter xmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
Converter inputStreamToXml = new MockConverterBuilder().from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
graphResolver.transformerChange(inputStreamToXml, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(xmlToJson, TransformerResolver.RegistryAction.ADDED);
Transformer transformer1 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
Transformer transformer2 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
assertSame(transformer1, transformer2);
}
use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.
the class GraphTransformerResolverTestCase method ignoresAddedTransformer.
@Test
public void ignoresAddedTransformer() throws ResolverException {
Converter xmlToJson = new MockConverterBuilder().named("xmlToJson").from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
Converter inputStreamToXml = new MockConverterBuilder().named("inputStreamToXml").from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
graphResolver.transformerChange(inputStreamToXml, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(xmlToJson, TransformerResolver.RegistryAction.ADDED);
Transformer transformer1 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
assertNotNull(transformer1);
Transformer xmlToString = new MockTransformerBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).build();
graphResolver.transformerChange(xmlToString, TransformerResolver.RegistryAction.ADDED);
Transformer transformer2 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
assertSame(transformer1, transformer2);
}
use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.
the class GraphTransformerResolverTestCase method resolvesTransformersWithDifferentLength.
@Test
public void resolvesTransformersWithDifferentLength() throws ResolverException {
Converter xmlToInputStream = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(1).build();
Converter xmlToJson = new MockConverterBuilder().named("xmlToJson").from(XML_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
Converter inputStreamToJson = new MockConverterBuilder().named("inputStreamToJson").from(INPUT_STREAM_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
graphResolver.transformerChange(xmlToInputStream, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(xmlToJson, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(inputStreamToJson, TransformerResolver.RegistryAction.ADDED);
Transformer transformer = graphResolver.resolve(XML_DATA_TYPE, JSON_DATA_TYPE);
assertEquals(xmlToJson, transformer);
}
Aggregations