Search in sources :

Example 26 with Converter

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

the class TransformationGraphTestCase method processesConverterAdded.

@Test
public void processesConverterAdded() {
    Converter xmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
    TransformationGraph graph = new TransformationGraph();
    graph.addConverter(xmlToJson);
    assertEquals(2, graph.vertexSet().size());
    assertTrue(graph.containsVertex(XML_DATA_TYPE));
    assertTrue(graph.containsVertex(JSON_DATA_TYPE));
    assertEquals(1, graph.edgeSet().size());
    assertTrue(graph.containsEdge(XML_DATA_TYPE, JSON_DATA_TYPE));
    assertFalse(graph.containsEdge(JSON_DATA_TYPE, XML_DATA_TYPE));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 27 with Converter

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

the class TypeMatchingVertexesFilterTestCase method matchingResultTypeConvertersAreReturned.

@Test
public void matchingResultTypeConvertersAreReturned() throws Exception {
    Converter stringToOrange = new MockConverterBuilder().named("stringToOrange").from(STRING).to(ORANGE_DATA_TYPE).build();
    Converter objectToApple = new MockConverterBuilder().named("objectToApple").from(OBJECT).to(APPLE_DATA_TYPE).build();
    Converter stringToSeed = new MockConverterBuilder().named("stringToSeed").from(STRING).to(SEED_DATA_TYPE).build();
    List<Converter> converters = asList(stringToOrange, objectToApple, stringToSeed);
    List<Converter> filtered = filter.filter(converters, SEED_DATA_TYPE, ORANGE_DATA_TYPE);
    assertThat(filtered, hasSize(1));
    assertThat(filtered, contains(stringToOrange));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 28 with Converter

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

the class TypeMatchingVertexesFilterTestCase method resultMimeTypeIsFiltered.

@Test
public void resultMimeTypeIsFiltered() throws Exception {
    Converter bananaToString = new MockConverterBuilder().named("BananaToString").from(BANANA_DATA_TYPE).to(STRING).build();
    Converter bananaToJsonString = new MockConverterBuilder().named("BananaToJsonString").from(BANANA_DATA_TYPE).to(JSON_STRING).build();
    List<Converter> converters = asList(bananaToString, bananaToJsonString);
    List<Converter> filtered = filter.filter(converters, BANANA_DATA_TYPE, JSON_STRING);
    assertThat(filtered, hasSize(1));
    assertThat(filtered, contains(bananaToJsonString));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 29 with Converter

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

the class TypeMatchingVertexesFilterTestCase method sameListIsReturnedIfNoMatch.

@Test
public void sameListIsReturnedIfNoMatch() throws Exception {
    Converter stringToOrange = new MockConverterBuilder().named("stringToOrange").from(STRING).to(ORANGE_DATA_TYPE).build();
    Converter bananaToApple = new MockConverterBuilder().named("bananaToApple").from(BANANA_DATA_TYPE).to(APPLE_DATA_TYPE).build();
    List<Converter> converters = asList(stringToOrange, bananaToApple);
    List<Converter> filtered = filter.filter(converters, PEACH_DATA_TYPE, SEED_DATA_TYPE);
    assertThat(filtered, is(equalTo(converters)));
}
Also used : MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 30 with Converter

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

the class MuleRegistryHelper method notifyTransformerResolvers.

public void notifyTransformerResolvers(Transformer t, TransformerResolver.RegistryAction action) {
    if (t instanceof Converter) {
        Lock transformerResolversReadLock = transformerResolversLock.readLock();
        transformerResolversReadLock.lock();
        try {
            for (TransformerResolver resolver : transformerResolvers) {
                resolver.transformerChange(t, action);
            }
        } finally {
            transformerResolversReadLock.unlock();
        }
        transformerListCache.clear();
        exactTransformerCache.clear();
        Lock transformersWriteLock = transformersLock.writeLock();
        transformersWriteLock.lock();
        try {
            if (action == ADDED) {
                transformers.add(t);
            } else {
                transformers.remove(t);
            }
        } finally {
            transformersWriteLock.unlock();
        }
    }
}
Also used : Converter(org.mule.runtime.core.api.transformer.Converter) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

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