use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultMuleMessageSerializationTestCase method testNonSerializablePayload.
@Test
public void testNonSerializablePayload() throws Exception {
// add a transformer to the registry that can convert a NonSerializable to byte[]. This
// will be used during Serialization
((MuleContextWithRegistries) muleContext).getRegistry().registerTransformer(new NonSerializableToByteArray());
final Message message = InternalMessage.builder().value(new NonSerializable()).addOutboundProperty("foo", "bar").build();
currentMuleContext.set(muleContext);
InternalMessage deserializedMessage = serializationRoundtrip(message);
assertTrue(deserializedMessage.getPayload().getValue() instanceof byte[]);
assertEquals(INNER_TEST_MESSAGE, getPayloadAsString(deserializedMessage));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultMuleMessageTestCase method usesNullPayloadAsNull.
@Test
public void usesNullPayloadAsNull() throws Exception {
Message message = InternalMessage.builder(createMuleMessage()).addOutboundProperty(FOO_PROPERTY, null).build();
assertThat(((InternalMessage) message).getOutboundProperty(FOO_PROPERTY), is(nullValue()));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class MuleMessageDataTypePropagationTestCase method updatesTypeOnTransformation.
@Test
public void updatesTypeOnTransformation() throws Exception {
Message message = Message.builder().value(1).mediaType(APPLICATION_XML_DEFAULT).build();
Transformer transformer = mock(Transformer.class);
when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
DataType outputDataType = DataType.builder().type(Integer.class).mediaType(ANY).charset(DEFAULT_ENCODING).build();
when(transformer.getReturnDataType()).thenReturn(outputDataType);
when(transformer.transform(anyObject())).thenReturn(1);
CoreEvent muleEvent = mock(CoreEvent.class);
Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
assertDataType(result, Integer.class, APPLICATION_XML, DEFAULT_ENCODING);
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class MuleMessageDataTypePropagationTestCase method updatesEncodingOnTransformation.
@Test
public void updatesEncodingOnTransformation() throws Exception {
Message message = Message.builder().value(TEST_PAYLOAD).mediaType(APPLICATION_XML_DEFAULT).build();
Transformer transformer = mock(Transformer.class);
when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
DataType outputDataType = DataType.builder().type(Integer.class).charset(CUSTOM_ENCODING).build();
when(transformer.getReturnDataType()).thenReturn(outputDataType);
when(transformer.transform(anyObject())).thenReturn(Integer.valueOf(1));
CoreEvent muleEvent = mock(CoreEvent.class);
Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
assertDataType(result, Integer.class, APPLICATION_XML, CUSTOM_ENCODING);
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class MuleMessageDataTypePropagationTestCase method setsNullPayloadWithDataType.
@Test
public void setsNullPayloadWithDataType() throws Exception {
Message muleMessage = of(TEST_PAYLOAD);
assertDataType(InternalMessage.builder(muleMessage).nullValue().mediaType(APPLICATION_XML_CUSTOM).build(), Object.class, APPLICATION_XML, CUSTOM_ENCODING);
}
Aggregations