Search in sources :

Example 61 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TransformationGraphTestCase method multipleConvertersFromDifferentSourceToSameResultTypes.

@Test
public void multipleConvertersFromDifferentSourceToSameResultTypes() {
    Converter xmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
    Converter objectToJson = new MockConverterBuilder().from(INPUT_STREAM_DATA_TYPE).to(JSON_DATA_TYPE).build();
    TransformationGraph graph = new TransformationGraph();
    graph.addConverter(xmlToJson);
    graph.addConverter(objectToJson);
    assertEquals(3, graph.vertexSet().size());
    assertTrue(graph.containsVertex(XML_DATA_TYPE));
    assertTrue(graph.containsVertex(JSON_DATA_TYPE));
    assertTrue(graph.containsVertex(INPUT_STREAM_DATA_TYPE));
    assertEquals(2, graph.edgeSet().size());
    assertTrue(graph.containsEdge(XML_DATA_TYPE, JSON_DATA_TYPE));
    assertFalse(graph.containsEdge(JSON_DATA_TYPE, XML_DATA_TYPE));
    assertTrue(graph.containsEdge(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE));
    assertFalse(graph.containsEdge(JSON_DATA_TYPE, INPUT_STREAM_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 62 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TransformationGraphTestCase method processesConverterRemoved.

@Test
public void processesConverterRemoved() {
    Converter xmlToJson = new MockConverterBuilder().from(XML_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)

Example 63 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TransformationGraphTestCase method removesFirstDuplicateConverterAdded.

@Test
public void removesFirstDuplicateConverterAdded() {
    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(xmlToJson);
    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, betterXmlToJson);
}
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 64 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TransformationGraphTestCase method multipleConvertersFromSameSourceToResultTypes.

@Test
public void multipleConvertersFromSameSourceToResultTypes() {
    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);
    assertEquals(2, graph.vertexSet().size());
    assertTrue(graph.containsVertex(XML_DATA_TYPE));
    assertTrue(graph.containsVertex(JSON_DATA_TYPE));
    assertEquals(2, graph.edgeSet().size());
    assertTrue(graph.containsEdge(XML_DATA_TYPE, JSON_DATA_TYPE));
    assertFalse(graph.containsEdge(JSON_DATA_TYPE, XML_DATA_TYPE));
    assertContainsTransformer(graph.edgesOf(JSON_DATA_TYPE), xmlToJson);
    assertContainsTransformer(graph.edgesOf(JSON_DATA_TYPE), betterXmlToJson);
}
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 65 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder in project mule by mulesoft.

the class TypeMatchingVertexesFilterTestCase method matchingSourceTypeConvertersAreReturnedEvenWithSuperTypesPresent.

@Test
public void matchingSourceTypeConvertersAreReturnedEvenWithSuperTypesPresent() 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, STRING, PEACH_DATA_TYPE);
    assertThat(filtered, hasSize(2));
    assertThat(filtered, contains(stringToOrange, stringToSeed));
}
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)

Aggregations

MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)78 Test (org.junit.Test)77 SmallTest (org.mule.tck.size.SmallTest)74 Converter (org.mule.runtime.core.api.transformer.Converter)48 Transformer (org.mule.runtime.core.api.transformer.Transformer)37 CompositeConverter (org.mule.runtime.core.privileged.transformer.CompositeConverter)24 Message (org.mule.runtime.api.message.Message)18 ArrayList (java.util.ArrayList)13 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)11 TransformerWeighting (org.mule.runtime.core.internal.registry.TransformerWeighting)6 Serializable (java.io.Serializable)4 DataType (org.mule.runtime.api.metadata.DataType)4 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Before (org.junit.Before)1 MessageTransformerException (org.mule.runtime.core.api.transformer.MessageTransformerException)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1 FruitBowl (org.mule.tck.testmodels.fruit.FruitBowl)1