Search in sources :

Example 86 with Transformer

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

the class MuleMessageDataTypePropagationTestCase method maintainsDataTypeOnGetPayloadTransformation.

@Test
public void maintainsDataTypeOnGetPayloadTransformation() throws Exception {
    InputStream payload = mock(InputStream.class);
    Message message = Message.builder().value(payload).mediaType(APPLICATION_XML_CUSTOM).build();
    MuleRegistry muleRegistry = mock(MuleRegistry.class);
    when(muleContext.getRegistry()).thenReturn(muleRegistry);
    Transformer transformer = mock(Transformer.class);
    when(transformer.transform(anyObject(), anyObject())).thenReturn(TEST_PAYLOAD);
    when(muleRegistry.lookupTransformer(any(), any())).thenReturn(transformer);
    assertThat(message.getPayload().getDataType().getMediaType().getPrimaryType(), equalTo(APPLICATION_XML.getPrimaryType()));
    assertThat(message.getPayload().getDataType().getMediaType().getSubType(), equalTo(APPLICATION_XML.getSubType()));
    assertThat(message.getPayload().getDataType().getMediaType().getCharset().get(), equalTo(CUSTOM_ENCODING));
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) Message(org.mule.runtime.api.message.Message) InputStream(java.io.InputStream) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 87 with Transformer

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

the class MuleRegistryHelperTransformersAsObjectsTestCase method testRegisterTransformersAsNamedObjects.

@Test
public void testRegisterTransformersAsNamedObjects() throws Exception {
    Transformer transformer1 = muleRegistryHelper.lookupTransformer(DataType.STRING, APPLE_DATA_TYPE);
    Transformer transformer2 = muleRegistryHelper.lookupTransformer(APPLE_DATA_TYPE, DataType.STRING);
    assertEquals(stringToApple, transformer1);
    assertEquals(appleToString, transformer2);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

Transformer (org.mule.runtime.core.api.transformer.Transformer)87 Test (org.junit.Test)65 SmallTest (org.mule.tck.size.SmallTest)54 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)37 Message (org.mule.runtime.api.message.Message)35 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)19 DataType (org.mule.runtime.api.metadata.DataType)14 Converter (org.mule.runtime.core.api.transformer.Converter)12 ArrayList (java.util.ArrayList)10 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)10 AbstractTransformer (org.mule.runtime.core.api.transformer.AbstractTransformer)9 CompositeConverter (org.mule.runtime.core.privileged.transformer.CompositeConverter)9 Serializable (java.io.Serializable)6 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)6 TransformerWeighting (org.mule.runtime.core.internal.registry.TransformerWeighting)6 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)4 MessageTransformerException (org.mule.runtime.core.api.transformer.MessageTransformerException)4 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3