Search in sources :

Example 36 with Converter

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

the class CompositeConverterTestCase method setReturnDataType.

@Test
public void setReturnDataType() {
    Converter converter = mock(Converter.class);
    CompositeConverter chain = new CompositeConverter(converter);
    chain.setReturnDataType(DataType.STRING);
    verify(converter, atLeastOnce()).setReturnDataType(DataType.STRING);
}
Also used : Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 37 with Converter

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

the class CompositeConverterTestCase method isIgnoreBadInput.

@Test
public void isIgnoreBadInput() {
    Converter converter = mock(Converter.class);
    when(converter.isIgnoreBadInput()).thenReturn(true);
    CompositeConverter chain = new CompositeConverter(converter);
    assertTrue(chain.isIgnoreBadInput());
}
Also used : Converter(org.mule.runtime.core.api.transformer.Converter) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 38 with Converter

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

the class CompositeConverter method transform.

@Override
public Object transform(Object src, Charset encoding) throws TransformerException {
    Object current = src;
    Charset currentEncoding = encoding;
    for (Converter converter : chain) {
        if (currentEncoding != null) {
            current = converter.transform(current, currentEncoding);
        } else {
            current = converter.transform(current);
        }
        currentEncoding = converter.getReturnDataType().getMediaType().getCharset().orElse(encoding);
    }
    return current;
}
Also used : Charset(java.nio.charset.Charset) Converter(org.mule.runtime.core.api.transformer.Converter)

Example 39 with Converter

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

the class CompositeConverter method compositeConverterName.

private String compositeConverterName(Converter[] converters) {
    StringBuilder builder = new StringBuilder();
    for (Converter converter : converters) {
        chain.addLast(converter);
        builder.append(converter.getName());
    }
    return builder.toString();
}
Also used : Converter(org.mule.runtime.core.api.transformer.Converter)

Example 40 with Converter

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

the class AbstractMockConverterBuilder method build.

@Override
public Converter build() {
    Transformer converter = super.build();
    doReturn(weight).when((Converter) converter).getPriorityWeighting();
    return (Converter) converter;
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) Converter(org.mule.runtime.core.api.transformer.Converter)

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