Search in sources :

Example 46 with MockConverterBuilder

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

the class GraphTransformerResolverTestCase method clearsCacheWhenRemovesTransformer.

@Test
public void clearsCacheWhenRemovesTransformer() throws ResolverException {
    Converter xmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
    Converter inputStreamToXml = new MockConverterBuilder().from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
    graphResolver.transformerChange(inputStreamToXml, TransformerResolver.RegistryAction.ADDED);
    graphResolver.transformerChange(xmlToJson, TransformerResolver.RegistryAction.ADDED);
    Transformer transformer = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
    assertNotNull(transformer);
    graphResolver.transformerChange(inputStreamToXml, TransformerResolver.RegistryAction.REMOVED);
    transformer = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
    assertNull(transformer);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) 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 47 with MockConverterBuilder

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

the class GraphTransformerResolverTestCase method resolvesTransformerWithSameLengthAndSameWeight.

@Test
public void resolvesTransformerWithSameLengthAndSameWeight() throws ResolverException {
    Converter xmlToInputStream = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(1).build();
    Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).weighting(1).build();
    Converter inputStreamToJson = new MockConverterBuilder().named("inputStreamToJson").from(INPUT_STREAM_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
    Converter stringToJson = new MockConverterBuilder().named("stringToJson").from(STRING_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
    graphResolver.transformerChange(xmlToInputStream, TransformerResolver.RegistryAction.ADDED);
    graphResolver.transformerChange(xmlToString, TransformerResolver.RegistryAction.ADDED);
    graphResolver.transformerChange(inputStreamToJson, TransformerResolver.RegistryAction.ADDED);
    graphResolver.transformerChange(stringToJson, TransformerResolver.RegistryAction.ADDED);
    Transformer transformer = graphResolver.resolve(XML_DATA_TYPE, JSON_DATA_TYPE);
    assertTrue(transformer instanceof CompositeConverter);
    CompositeConverter compositeConverter = (CompositeConverter) transformer;
    assertEquals(2, compositeConverter.getConverters().size());
    assertEquals(xmlToInputStream, compositeConverter.getConverters().get(0));
    assertEquals(inputStreamToJson, compositeConverter.getConverters().get(1));
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) 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) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 48 with MockConverterBuilder

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

the class GraphTransformerResolverTestCase method clearsCacheWhenAddsConverter.

@Test
public void clearsCacheWhenAddsConverter() throws ResolverException {
    Converter xmlToJson = new MockConverterBuilder().named("xmlToJson").from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
    Converter inputStreamToXml = new MockConverterBuilder().named("inputStreamToXml").from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
    graphResolver.transformerChange(inputStreamToXml, TransformerResolver.RegistryAction.ADDED);
    graphResolver.transformerChange(xmlToJson, TransformerResolver.RegistryAction.ADDED);
    Transformer transformer1 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
    assertNotNull(transformer1);
    Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).build();
    graphResolver.transformerChange(xmlToString, TransformerResolver.RegistryAction.ADDED);
    Transformer transformer2 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
    assertNotSame(transformer1, transformer2);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) 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 49 with MockConverterBuilder

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

the class GraphTransformerResolverTestCase method cannotResolveTransformerWithSameLengthAndSameWeightAndSameName.

@Test(expected = ResolverException.class)
public void cannotResolveTransformerWithSameLengthAndSameWeightAndSameName() throws ResolverException {
    Converter xmlToInputStream1 = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(1).build();
    Converter xmlToInputStream2 = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(1).build();
    graphResolver.transformerChange(xmlToInputStream1, TransformerResolver.RegistryAction.ADDED);
    graphResolver.transformerChange(xmlToInputStream2, TransformerResolver.RegistryAction.ADDED);
    graphResolver.resolve(XML_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) CompositeConverter(org.mule.runtime.core.privileged.transformer.CompositeConverter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 50 with MockConverterBuilder

use of org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder 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)

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