Search in sources :

Example 11 with Converter

use of org.mule.runtime.core.api.transformer.Converter 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));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) Converter(org.mule.runtime.core.api.transformer.Converter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 12 with Converter

use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.

the class ShortestTransformationLengthTransformerFilterTestCase method filtersEqualLength.

@Test
public void filtersEqualLength() throws ResolverException {
    Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).build();
    Converter xmlToJson = new MockConverterBuilder().named("xmlToJson").from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
    List<Converter> availableConverters = new ArrayList<Converter>();
    availableConverters.add(xmlToString);
    availableConverters.add(xmlToJson);
    List<Converter> transformers = filter.filter(availableConverters, UNUSED_DATA_TYPE, UNUSED_DATA_TYPE);
    assertEquals(2, transformers.size());
    assertTrue(transformers.contains(xmlToString));
    assertTrue(transformers.contains(xmlToJson));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) Converter(org.mule.runtime.core.api.transformer.Converter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 13 with Converter

use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.

the class TransformationGraphLookupStrategyTestCase method lookupTransformersNoTargetInGraph.

@Test
public void lookupTransformersNoTargetInGraph() throws Exception {
    Converter inputStreamToXml = new MockConverterBuilder().from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
    graph.addConverter(inputStreamToXml);
    List<Converter> converters = lookupStrategyTransformation.lookupConverters(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
    assertEquals(0, converters.size());
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 14 with Converter

use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.

the class TransformationGraphLookupStrategyTestCase method findsDirectTransformation.

@Test
public void findsDirectTransformation() throws Exception {
    Converter inputStreamToXml = new MockConverterBuilder().from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
    graph.addConverter(inputStreamToXml);
    List<Converter> converters = lookupStrategyTransformation.lookupConverters(INPUT_STREAM_DATA_TYPE, XML_DATA_TYPE);
    assertEquals(1, converters.size());
    assertEquals(inputStreamToXml, converters.get(0));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 15 with Converter

use of org.mule.runtime.core.api.transformer.Converter in project mule by mulesoft.

the class TransformationGraphLookupStrategyTestCase method findsMultipleCompositeConvertersWithMultipleEdgesFromSource.

@Test
public void findsMultipleCompositeConvertersWithMultipleEdgesFromSource() throws Exception {
    Converter inputStreamToString = new MockConverterBuilder().named("inputStreamToString").from(INPUT_STREAM_DATA_TYPE).to(STRING_DATA_TYPE).build();
    graph.addConverter(inputStreamToString);
    Converter inputStreamToJson = new MockConverterBuilder().named("inputStreamToJson").from(INPUT_STREAM_DATA_TYPE).to(JSON_DATA_TYPE).build();
    graph.addConverter(inputStreamToJson);
    Converter jsonToXml = new MockConverterBuilder().named("jsonToXml").from(JSON_DATA_TYPE).to(XML_DATA_TYPE).build();
    graph.addConverter(jsonToXml);
    Converter jsonToString = new MockConverterBuilder().named("jsonToString").from(JSON_DATA_TYPE).to(STRING_DATA_TYPE).build();
    graph.addConverter(jsonToString);
    Converter stringToXml = new MockConverterBuilder().named("stringToXml").from(STRING_DATA_TYPE).to(XML_DATA_TYPE).build();
    graph.addConverter(stringToXml);
    Converter stringToJson = new MockConverterBuilder().named("stringToJson").from(STRING_DATA_TYPE).to(JSON_DATA_TYPE).build();
    graph.addConverter(stringToJson);
    List<Converter> converters = lookupStrategyTransformation.lookupConverters(INPUT_STREAM_DATA_TYPE, XML_DATA_TYPE);
    assertEquals(4, converters.size());
    assertContainsCompositeTransformer(converters, inputStreamToString, stringToXml);
    assertContainsCompositeTransformer(converters, inputStreamToJson, jsonToXml);
    assertContainsCompositeTransformer(converters, inputStreamToString, stringToJson, jsonToXml);
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

Converter (org.mule.runtime.core.api.transformer.Converter)69 Test (org.junit.Test)56 SmallTest (org.mule.tck.size.SmallTest)55 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)48 CompositeConverter (org.mule.runtime.core.privileged.transformer.CompositeConverter)26 ArrayList (java.util.ArrayList)16 Transformer (org.mule.runtime.core.api.transformer.Transformer)12 List (java.util.List)5 DataType (org.mule.runtime.api.metadata.DataType)5 LinkedList (java.util.LinkedList)3 HashSet (java.util.HashSet)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 TransformerWeighting (org.mule.runtime.core.internal.registry.TransformerWeighting)2 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)2 ImmutableList (com.google.common.collect.ImmutableList)1 Charset (java.nio.charset.Charset)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 MessageTransformer (org.mule.runtime.core.api.transformer.MessageTransformer)1