Search in sources :

Example 51 with Converter

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

the class TransformationGraphLookupStrategyTestCase method transformerWithNoCharsetDataTypeAsTargetNotFoundSinceIsMoreSpecific.

@Test
public void transformerWithNoCharsetDataTypeAsTargetNotFoundSinceIsMoreSpecific() throws Exception {
    Converter jsonToUtf16 = new MockConverterBuilder().from(JSON_DATA_TYPE).to(builder(UTF_16_DATA_TYPE).charset((String) null).build()).build();
    graph.addConverter(jsonToUtf16);
    List<Converter> converters = lookupStrategyTransformation.lookupConverters(JSON_DATA_TYPE, UTF_16_DATA_TYPE);
    assertThat(converters, hasSize(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 52 with Converter

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

the class TransformationGraphLookupStrategyTestCase method findsCompositeConverter.

@Test
public void findsCompositeConverter() throws Exception {
    Converter inputStreamToString = new MockConverterBuilder().named("inputStreamToString").from(INPUT_STREAM_DATA_TYPE).to(STRING_DATA_TYPE).build();
    graph.addConverter(inputStreamToString);
    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, JSON_DATA_TYPE);
    assertEquals(1, converters.size());
    assertContainsCompositeTransformer(converters, inputStreamToString, stringToJson);
}
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 53 with Converter

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

the class TransformationGraphLookupStrategyTestCase method transformerWithNoCharsetDataTypeAsSourceFoundEvenWhenSpecified.

@Test
public void transformerWithNoCharsetDataTypeAsSourceFoundEvenWhenSpecified() throws Exception {
    Converter utf16ToJson = new MockConverterBuilder().from(builder(UTF_16_DATA_TYPE).charset((String) null).build()).to(JSON_DATA_TYPE).build();
    graph.addConverter(utf16ToJson);
    List<Converter> converters = lookupStrategyTransformation.lookupConverters(UTF_16_DATA_TYPE, JSON_DATA_TYPE);
    assertThat(converters, hasSize(1));
    assertThat(converters, contains(utf16ToJson));
}
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 54 with Converter

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

the class TransformationGraphTestCase method removesSecondDuplicateConverterAdded.

@Test
public void removesSecondDuplicateConverterAdded() {
    Converter xmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
    Converter betterXmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
    TransformationGraph graph = new TransformationGraph();
    graph.addConverter(xmlToJson);
    graph.addConverter(betterXmlToJson);
    graph.removeConverter(betterXmlToJson);
    assertEquals(2, graph.vertexSet().size());
    assertTrue(graph.containsVertex(JSON_DATA_TYPE));
    assertTrue(graph.containsVertex(XML_DATA_TYPE));
    Set<TransformationEdge> transformationEdges = graph.edgesOf(JSON_DATA_TYPE);
    assertEquals(1, transformationEdges.size());
    assertContainsTransformer(transformationEdges, xmlToJson);
}
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 55 with Converter

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

the class TransformationGraphTestCase method processesConverterRemovedWithMultipleSourceTypes.

@Test
public void processesConverterRemovedWithMultipleSourceTypes() {
    Converter xmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE, INPUT_STREAM_DATA_TYPE).to(JSON_DATA_TYPE).build();
    TransformationGraph graph = new TransformationGraph();
    graph.addConverter(xmlToJson);
    graph.removeConverter(xmlToJson);
    assertEquals(0, graph.vertexSet().size());
    assertEquals(0, graph.edgeSet().size());
}
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)

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