Search in sources :

Example 1 with MediaType

use of org.mule.runtime.api.metadata.MediaType in project mule by mulesoft.

the class DataTypeTransformersTestCase method validMediaType.

@Test
public void validMediaType() throws TransformerException {
    final StringToMediaTypeTransformer transformer = new StringToMediaTypeTransformer();
    final MediaType transformed = (MediaType) transformer.transform("text/plain");
    assertThat(transformed.getPrimaryType(), is("text"));
    assertThat(transformed.getSubType(), is("plain"));
    assertThat(transformed.getCharset().isPresent(), is(false));
}
Also used : MediaType(org.mule.runtime.api.metadata.MediaType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with MediaType

use of org.mule.runtime.api.metadata.MediaType in project mule by mulesoft.

the class DataTypeTransformersTestCase method validMediaTypeWithCharset.

@Test
public void validMediaTypeWithCharset() throws TransformerException {
    final StringToMediaTypeTransformer transformer = new StringToMediaTypeTransformer();
    final MediaType transformed = (MediaType) transformer.transform("text/plain;charset=" + US_ASCII.name());
    assertThat(transformed.getPrimaryType(), is("text"));
    assertThat(transformed.getSubType(), is("plain"));
    assertThat(transformed.getCharset().get(), is(US_ASCII));
}
Also used : MediaType(org.mule.runtime.api.metadata.MediaType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with MediaType

use of org.mule.runtime.api.metadata.MediaType in project mule by mulesoft.

the class MuleMessageDataTypePropagationTestCase method setsCustomInboundPropertyDataType.

@Test
public void setsCustomInboundPropertyDataType() throws Exception {
    MediaType mediaType = APPLICATION_XML_CUSTOM;
    InternalMessage message = InternalMessage.builder().value(TEST_PAYLOAD).addInboundProperty(TEST_PROPERTY, TEST_PAYLOAD, mediaType).build();
    assertInboundPropertyDataType(message, DataType.builder().type(String.class).mediaType(mediaType).build());
}
Also used : MediaType(org.mule.runtime.api.metadata.MediaType) Matchers.anyString(org.mockito.Matchers.anyString) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with MediaType

use of org.mule.runtime.api.metadata.MediaType in project mule by mulesoft.

the class MuleMessageDataTypePropagationTestCase method setsCustomOutboundPropertyDataType.

@Test
public void setsCustomOutboundPropertyDataType() throws Exception {
    MediaType mediaType = APPLICATION_XML_CUSTOM;
    InternalMessage message = InternalMessage.builder().value(TEST_PAYLOAD).addOutboundProperty(TEST_PROPERTY, TEST_PAYLOAD, mediaType).build();
    assertOutboundPropertyDataType(message, DataType.builder().type(String.class).mediaType(mediaType).build());
}
Also used : MediaType(org.mule.runtime.api.metadata.MediaType) Matchers.anyString(org.mockito.Matchers.anyString) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with MediaType

use of org.mule.runtime.api.metadata.MediaType in project mule by mulesoft.

the class ExtendedTransformationService method mergeMediaType.

private MediaType mergeMediaType(Message message, DataType transformed) {
    DataType original = message.getPayload().getDataType();
    MediaType mimeType = ANY.matches(transformed.getMediaType()) ? original.getMediaType() : transformed.getMediaType();
    Charset encoding = transformed.getMediaType().getCharset().orElse(message.getPayload().getDataType().getMediaType().getCharset().orElse(getDefaultEncoding(muleContext)));
    return DataType.builder().mediaType(mimeType).charset(encoding).build().getMediaType();
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) MediaType(org.mule.runtime.api.metadata.MediaType) Charset(java.nio.charset.Charset)

Aggregations

MediaType (org.mule.runtime.api.metadata.MediaType)13 Test (org.junit.Test)10 SmallTest (org.mule.tck.size.SmallTest)10 Message (org.mule.runtime.api.message.Message)5 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 ExecutionContext (org.mule.runtime.extension.api.runtime.operation.ExecutionContext)3 Charset (java.nio.charset.Charset)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Result (org.mule.runtime.extension.api.runtime.operation.Result)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 DataType (org.mule.runtime.api.metadata.DataType)1 MediaTypeUtils.parseCharset (org.mule.runtime.api.metadata.MediaTypeUtils.parseCharset)1 MessageUtils.toMessageCollection (org.mule.runtime.core.internal.util.message.MessageUtils.toMessageCollection)1 MessageUtils.toMessageIterator (org.mule.runtime.core.internal.util.message.MessageUtils.toMessageIterator)1 ExtensionMetadataTypeUtils.isJavaCollection (org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isJavaCollection)1