use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class GraphTransformerResolverTestCase method ignoresRemovedTransformer.
@Test
public void ignoresRemovedTransformer() 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.REMOVED);
Transformer transformer2 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
assertSame(transformer1, transformer2);
}
use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class GraphTransformerResolverTestCase method resolvesTransformersWithSameLengthAndDifferentWeight.
@Test
public void resolvesTransformersWithSameLengthAndDifferentWeight() throws ResolverException {
Converter xmlToInputStream = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(1).build();
Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).weighting(1).build();
Converter inputStreamToJson = new MockConverterBuilder().named("inputStreamToJson").from(INPUT_STREAM_DATA_TYPE).to(JSON_DATA_TYPE).weighting(2).build();
Converter stringToJson = new MockConverterBuilder().named("stringToJson").from(STRING_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
graphResolver.transformerChange(xmlToInputStream, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(xmlToString, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(inputStreamToJson, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(stringToJson, TransformerResolver.RegistryAction.ADDED);
Transformer transformer = graphResolver.resolve(XML_DATA_TYPE, JSON_DATA_TYPE);
assertTrue(transformer instanceof CompositeConverter);
CompositeConverter compositeConverter = (CompositeConverter) transformer;
assertEquals(2, compositeConverter.getConverters().size());
assertEquals(xmlToInputStream, compositeConverter.getConverters().get(0));
assertEquals(inputStreamToJson, compositeConverter.getConverters().get(1));
}
use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class PriorityWeightingConverterFilterTestCase method filtersSameLengthDifferentWeightsAddingBetterTransformerLast.
@Test
public void filtersSameLengthDifferentWeightsAddingBetterTransformerLast() throws ResolverException {
Converter xmlToInputStream = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(2).build();
Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).weighting(1).build();
List<Converter> availableConverters = new ArrayList<Converter>();
availableConverters.add(xmlToString);
availableConverters.add(xmlToInputStream);
List<Converter> converters = filter.filter(availableConverters, XML_DATA_TYPE, JSON_DATA_TYPE);
assertEquals(1, converters.size());
assertEquals(xmlToInputStream, converters.get(0));
}
use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class PriorityWeightingConverterFilterTestCase method filtersSameWeight.
@Test
public void filtersSameWeight() throws ResolverException {
Converter xmlToInputStream = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(1).build();
Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).weighting(1).build();
List<Converter> availableConverters = new ArrayList<Converter>();
availableConverters.add(xmlToInputStream);
availableConverters.add(xmlToString);
List<Converter> converters = filter.filter(availableConverters, XML_DATA_TYPE, JSON_DATA_TYPE);
assertEquals(2, converters.size());
assertTrue(converters.contains(xmlToInputStream));
assertTrue(converters.contains(xmlToString));
}
use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.
the class PriorityWeightingConverterFilterTestCase method filtersSameLengthDifferentWeightsAddingBetterTransformerFirst.
@Test
public void filtersSameLengthDifferentWeightsAddingBetterTransformerFirst() throws ResolverException {
Converter xmlToInputStream = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(2).build();
Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).weighting(1).build();
List<Converter> availableConverters = new ArrayList<Converter>();
availableConverters.add(xmlToInputStream);
availableConverters.add(xmlToString);
List<Converter> converters = filter.filter(availableConverters, XML_DATA_TYPE, JSON_DATA_TYPE);
assertEquals(1, converters.size());
assertEquals(xmlToInputStream, converters.get(0));
}
Aggregations