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));
}
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));
}
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());
}
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());
}
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();
}
Aggregations