Search in sources :

Example 46 with Converter

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

the class NameTransformerFilterTestCase method filtersEqualName.

@Test
public void filtersEqualName() throws ResolverException {
    Converter xmlToString = new MockConverterBuilder().named("xmlToString").build();
    List<Converter> availableConverters = new ArrayList<>();
    availableConverters.add(xmlToString);
    availableConverters.add(xmlToString);
    List<Converter> transformers = filter.filter(availableConverters, UNUSED_DATA_TYPE, UNUSED_DATA_TYPE);
    assertEquals(2, transformers.size());
    assertEquals(xmlToString, transformers.get(0));
    assertEquals(xmlToString, transformers.get(1));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) Converter(org.mule.runtime.core.api.transformer.Converter) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 47 with Converter

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

the class NameTransformerFilterTestCase method filtersDifferentNameWithBetterTransformerLast.

@Test
public void filtersDifferentNameWithBetterTransformerLast() throws ResolverException {
    Converter xmlToString = new MockConverterBuilder().named("xmlToString").build();
    Converter stringToJson = new MockConverterBuilder().named("stringToJson").build();
    List<Converter> availableConverters = new ArrayList<>();
    availableConverters.add(xmlToString);
    availableConverters.add(stringToJson);
    List<Converter> transformers = filter.filter(availableConverters, UNUSED_DATA_TYPE, UNUSED_DATA_TYPE);
    assertEquals(1, transformers.size());
    assertTrue(transformers.contains(stringToJson));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) Converter(org.mule.runtime.core.api.transformer.Converter) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 48 with Converter

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

the class NameTransformerFilterTestCase method filtersDifferentNameWithBetterTransformerFist.

@Test
public void filtersDifferentNameWithBetterTransformerFist() throws ResolverException {
    Converter xmlToString = new MockConverterBuilder().named("xmlToString").build();
    Converter stringToJson = new MockConverterBuilder().named("stringToJson").build();
    List<Converter> availableConverters = new ArrayList<>();
    availableConverters.add(stringToJson);
    availableConverters.add(xmlToString);
    List<Converter> transformers = filter.filter(availableConverters, UNUSED_DATA_TYPE, UNUSED_DATA_TYPE);
    assertEquals(1, transformers.size());
    assertTrue(transformers.contains(stringToJson));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) Converter(org.mule.runtime.core.api.transformer.Converter) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 49 with Converter

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

the class ShortestTransformationLengthTransformerFilterTestCase method filtersDifferentLengthWithBetterTrasnformerFist.

@Test
public void filtersDifferentLengthWithBetterTrasnformerFist() 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>();
    availableConverters.add(xmlToString);
    CompositeConverter compositeConverter = new CompositeConverter(xmlToString, stringToJson);
    availableConverters.add(compositeConverter);
    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 50 with Converter

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

the class SynchronizedTransformationGraphTestCase method modifyGraphWhileResolvingTransformer.

@Test
public void modifyGraphWhileResolvingTransformer() throws ResolverException, InterruptedException {
    final Converter xmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
    final Converter inputStreamToXml = new MockConverterBuilder().from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
    final SynchronizedTransformationGraph graph = new SynchronizedTransformationGraph();
    final TransformationGraphLookupStrategy lookupStrategyTransformation = new TransformationGraphLookupStrategy(graph);
    Runnable addTransformer = new Runnable() {

        @Override
        public void run() {
            graph.addConverter(xmlToJson);
            graph.addConverter(inputStreamToXml);
        }
    };
    Runnable resolveTransformer = new Runnable() {

        @Override
        public void run() {
            lookupStrategyTransformation.lookupConverters(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
        }
    };
    List<Runnable> runnables = new ArrayList<>();
    for (int i = 0; i < CONCURRENCY_TEST_SIZE; i++) {
        runnables.add(addTransformer);
        runnables.add(resolveTransformer);
    }
    assertConcurrent("Modify transformers while resolving it", runnables, MAX_TIMEOUT_SECONDS);
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) ArrayList(java.util.ArrayList) Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test)

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