use of org.mule.runtime.core.privileged.transformer.CompositeConverter 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.privileged.transformer.CompositeConverter in project mule by mulesoft.
the class ShortestTransformationLengthTransformerFilterTestCase method filtersDifferentLengthWithBetterTransformerLast.
@Test
public void filtersDifferentLengthWithBetterTransformerLast() throws ResolverException {
Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).build();
Converter stringToJson = new MockConverterBuilder().named("stringToJson").from(STRING_DATA_TYPE).to(JSON_DATA_TYPE).build();
List<Converter> availableConverters = new ArrayList<Converter>();
CompositeConverter compositeConverter = new CompositeConverter(xmlToString, stringToJson);
availableConverters.add(compositeConverter);
availableConverters.add(xmlToString);
List<Converter> transformers = filter.filter(availableConverters, UNUSED_DATA_TYPE, UNUSED_DATA_TYPE);
assertEquals(1, transformers.size());
assertEquals(xmlToString, transformers.get(0));
}
use of org.mule.runtime.core.privileged.transformer.CompositeConverter in project mule by mulesoft.
the class TransformationGraphLookupStrategyTestCase method assertContainsCompositeTransformer.
private void assertContainsCompositeTransformer(List<Converter> converters, Converter... composedConverters) {
for (Converter converter : converters) {
if (converter instanceof CompositeConverter) {
CompositeConverter compositeConverter = (CompositeConverter) converter;
if (compositeConverter.getConverters().size() != composedConverters.length) {
continue;
}
boolean matches = true;
for (int i = 0; i < composedConverters.length - 1; i++) {
if (composedConverters[i] != compositeConverter.getConverters().get(i)) {
matches = false;
break;
}
}
if (matches) {
return;
}
}
}
fail("Converter list does not contain a composite converter with: " + composedConverters);
}
use of org.mule.runtime.core.privileged.transformer.CompositeConverter in project mule by mulesoft.
the class TransformationGraphLookupStrategy method createConverters.
private List<Converter> createConverters(List<List<TransformationEdge>> transformationPaths) {
// Using a set instead of a list for when a path of just one converter is found multiple times.
Set<Converter> converters = new HashSet<>();
for (List<TransformationEdge> transformationPath : transformationPaths) {
Converter[] pathConverters = new Converter[transformationPath.size()];
int index = 0;
for (TransformationEdge edge : transformationPath) {
pathConverters[index++] = edge.getConverter();
}
Converter converter;
if (transformationPath.size() == 1) {
converter = transformationPath.get(0).getConverter();
} else {
converter = new CompositeConverter(pathConverters);
}
converters.add(converter);
}
return new ArrayList<>(converters);
}
use of org.mule.runtime.core.privileged.transformer.CompositeConverter in project mule by mulesoft.
the class GraphTransformerResolverTestCase method resolvesTransformerWithSameLengthAndSameWeight.
@Test
public void resolvesTransformerWithSameLengthAndSameWeight() 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(1).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));
}
Aggregations