Search in sources :

Example 1 with Converter

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

the class CompositeConverterFilterTestCase method failsWhenFiltersDoNotReduceListToASingleElement.

@Test
public void failsWhenFiltersDoNotReduceListToASingleElement() throws Exception {
    Converter transformer1 = mock(Converter.class);
    Converter transformer2 = mock(Converter.class);
    List<Converter> transformers = new ArrayList<Converter>();
    transformers.add(transformer1);
    transformers.add(transformer2);
    ConverterFilter filter1 = Mockito.mock(ConverterFilter.class);
    when(filter1.filter(transformers, XML_DATA_TYPE, JSON_DATA_TYPE)).thenReturn(transformers);
    ConverterFilter filter2 = Mockito.mock(ConverterFilter.class);
    when(filter2.filter(transformers, XML_DATA_TYPE, JSON_DATA_TYPE)).thenReturn(transformers);
    CompositeConverterFilter compositeConverterFilter = new CompositeConverterFilter(filter1, filter2);
    List<Converter> filteredTransformers = compositeConverterFilter.filter(transformers, XML_DATA_TYPE, JSON_DATA_TYPE);
    assertEquals(transformers, filteredTransformers);
    verify(filter1, times(1)).filter(any(List.class), any(DataType.class), any(DataType.class));
    verify(filter2, times(1)).filter(any(List.class), any(DataType.class), any(DataType.class));
}
Also used : ArrayList(java.util.ArrayList) Converter(org.mule.runtime.core.api.transformer.Converter) DataType(org.mule.runtime.api.metadata.DataType) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 2 with Converter

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

the class CompositeConverterFilterTestCase method filtersSingletonList.

@Test
public void filtersSingletonList() throws Exception {
    Converter transformer1 = mock(Converter.class);
    List<Converter> transformers = Collections.singletonList(transformer1);
    ConverterFilter filter1 = Mockito.mock(ConverterFilter.class);
    ConverterFilter filter2 = Mockito.mock(ConverterFilter.class);
    CompositeConverterFilter compositeConverterFilter = new CompositeConverterFilter(filter1, filter2);
    List<Converter> filteredTransformers = compositeConverterFilter.filter(transformers, XML_DATA_TYPE, JSON_DATA_TYPE);
    assertEquals(transformers, filteredTransformers);
    verify(filter1, times(0)).filter(any(List.class), any(DataType.class), any(DataType.class));
    verify(filter2, times(0)).filter(any(List.class), any(DataType.class), any(DataType.class));
}
Also used : Converter(org.mule.runtime.core.api.transformer.Converter) DataType(org.mule.runtime.api.metadata.DataType) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 3 with Converter

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

the class GraphTransformerResolverTestCase method cachesResolvedTransformer.

@Test
public void cachesResolvedTransformer() 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 transformer1 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
    Transformer transformer2 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
    assertSame(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 4 with Converter

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

the class GraphTransformerResolverTestCase method ignoresAddedTransformer.

@Test
public void ignoresAddedTransformer() 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);
    Transformer xmlToString = new MockTransformerBuilder().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);
    assertSame(transformer1, transformer2);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) MockTransformerBuilder(org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder) 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 5 with Converter

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

the class GraphTransformerResolverTestCase method resolvesTransformersWithDifferentLength.

@Test
public void resolvesTransformersWithDifferentLength() throws ResolverException {
    Converter xmlToInputStream = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(1).build();
    Converter xmlToJson = new MockConverterBuilder().named("xmlToJson").from(XML_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
    Converter inputStreamToJson = new MockConverterBuilder().named("inputStreamToJson").from(INPUT_STREAM_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
    graphResolver.transformerChange(xmlToInputStream, TransformerResolver.RegistryAction.ADDED);
    graphResolver.transformerChange(xmlToJson, TransformerResolver.RegistryAction.ADDED);
    graphResolver.transformerChange(inputStreamToJson, TransformerResolver.RegistryAction.ADDED);
    Transformer transformer = graphResolver.resolve(XML_DATA_TYPE, JSON_DATA_TYPE);
    assertEquals(xmlToJson, 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)

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