Search in sources :

Example 61 with Converter

use of org.mule.runtime.core.api.transformer.Converter 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)

Example 62 with Converter

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

the class TypeMatchingVertexesFilterTestCase method matchingSourceTypeConvertersAreReturned.

@Test
public void matchingSourceTypeConvertersAreReturned() throws Exception {
    Converter stringToOrange = new MockConverterBuilder().named("stringToOrange").from(STRING).to(ORANGE_DATA_TYPE).build();
    Converter bananaToApple = new MockConverterBuilder().named("bananaToApple").from(BANANA_DATA_TYPE).to(APPLE_DATA_TYPE).build();
    Converter stringToSeed = new MockConverterBuilder().named("stringToSeed").from(STRING).to(SEED_DATA_TYPE).build();
    List<Converter> converters = asList(stringToOrange, bananaToApple, 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)

Example 63 with Converter

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

the class TypeMatchingVertexesFilterTestCase method bothVertexesMatchingIsBetterThanJustOne.

@Test
public void bothVertexesMatchingIsBetterThanJustOne() throws Exception {
    Converter stringToOrange = new MockConverterBuilder().named("stringToOrange").from(STRING).to(ORANGE_DATA_TYPE).build();
    Converter stringToBanana = new MockConverterBuilder().named("stringToBanana").from(STRING).to(BANANA_DATA_TYPE).build();
    Converter seedToOrange = new MockConverterBuilder().named("seedToOrange").from(SEED_DATA_TYPE).to(ORANGE_DATA_TYPE).build();
    List<Converter> converters = asList(stringToOrange, stringToBanana, seedToOrange);
    List<Converter> filtered = filter.filter(converters, STRING, ORANGE_DATA_TYPE);
    assertThat(filtered, hasSize(1));
    assertThat(filtered, contains(stringToOrange));
}
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)

Example 64 with Converter

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

the class CompositeConverterTestCase method isAcceptNull.

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

Example 65 with Converter

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

the class CompositeConverterTestCase method getSourceDataTypes.

@Test
public void getSourceDataTypes() {
    DataType[] dataTypes = new DataType[] { DataType.STRING };
    Converter converter = mock(Converter.class);
    when(converter.getSourceDataTypes()).thenReturn(Arrays.asList(dataTypes));
    CompositeConverter chain = new CompositeConverter(converter);
    assertEquals(DataType.STRING, chain.getSourceDataTypes().get(0));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) Converter(org.mule.runtime.core.api.transformer.Converter) 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