Search in sources :

Example 16 with Converter

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

the class TransformationGraphLookupStrategyTestCase method compatibleConverterShouldBeReturnedEvenIfTargetDataTypeDoesNotExist.

@Test
public void compatibleConverterShouldBeReturnedEvenIfTargetDataTypeDoesNotExist() throws Exception {
    Converter jsonToTextString = new MockConverterBuilder().named("jsonToTextString").from(JSON_STRING).to(TEXT_STRING).build();
    graph.addConverter(jsonToTextString);
    List<Converter> converters = lookupStrategyTransformation.lookupConverters(JSON_STRING, STRING);
    assertThat(converters, hasSize(1));
    assertThat(converters.get(0).getName(), is("jsonToTextString"));
}
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 17 with Converter

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

the class TransformationGraphLookupStrategyTestCase method findsDirectTransformationWhileChangingGraph.

@Test
public void findsDirectTransformationWhileChangingGraph() 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);
    assertThat(converters, hasSize(1));
    assertThat(converters.get(0), is(inputStreamToXml));
}
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 18 with Converter

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

the class TransformationGraphLookupStrategyTestCase method lookupTransformersNoSourceInGraph.

@Test
public void lookupTransformersNoSourceInGraph() throws Exception {
    Converter inputStreamToXml = new MockConverterBuilder().from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
    graph.addConverter(inputStreamToXml);
    List<Converter> converters = lookupStrategyTransformation.lookupConverters(JSON_DATA_TYPE, INPUT_STREAM_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 19 with Converter

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

the class TransformationGraphLookupStrategyTestCase method compatibleConverterShouldBeReturnedEvenIfTSourceDataTypeDoesNotExist.

@Test
public void compatibleConverterShouldBeReturnedEvenIfTSourceDataTypeDoesNotExist() throws Exception {
    Converter xmlToTextString = new MockConverterBuilder().named("textStringToXML").from(XML_DATA_TYPE).to(TEXT_STRING).build();
    graph.addConverter(xmlToTextString);
    List<Converter> converters = lookupStrategyTransformation.lookupConverters(XML_DATA_TYPE, STRING);
    assertThat(converters, hasSize(1));
    assertThat(converters.get(0).getName(), is("textStringToXML"));
}
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 20 with Converter

use of org.mule.runtime.core.api.transformer.Converter 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);
}
Also used : Converter(org.mule.runtime.core.api.transformer.Converter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter)

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