use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultMuleMessageBuilderTestCase method mutatePayloadDifferentTypeWithMediaTypeUpdateTypeAndConserveMimeType.
@Test
public void mutatePayloadDifferentTypeWithMediaTypeUpdateTypeAndConserveMimeType() {
Long payload = new Long(1);
DataHandler dataHandler = new DataHandler(payload, XML.toString());
Message copy = new DefaultMessageBuilder(createTestMessage()).value(dataHandler).build();
assertThat(copy.getPayload().getValue(), is(dataHandler));
assertThat(copy.getPayload().getDataType().getType(), equalTo(DataHandler.class));
assertThat(copy.getPayload().getDataType().getMediaType(), is(XML));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultMuleMessageBuilderTestCase method testOnlyPayload.
@Test
public void testOnlyPayload() {
Message message = of(TEST_PAYLOAD);
assertThat(message.getPayload().getValue(), is(TEST_PAYLOAD));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultMuleMessageBuilderTestCase method wholeAttributes.
@Test
public void wholeAttributes() {
Message message = Message.builder().nullValue().attributes(new TypedValue<>(EMPTY_JSON, JSON_STRING)).build();
assertThat(message.getAttributes().getValue(), equalTo(EMPTY_JSON));
assertThat(message.getAttributes().getDataType().getType(), equalTo(String.class));
assertThat(message.getAttributes().getDataType().getMediaType(), is(APPLICATION_JSON));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultMuleMessageBuilderTestCase method createNewMessageCollectionViaMessageInterfaceCopy.
@Test
public void createNewMessageCollectionViaMessageInterfaceCopy() {
List<String> htmlStringList = new ArrayList<>();
htmlStringList.add("HTML1");
htmlStringList.add("HTML2");
htmlStringList.add("HTML3");
Message message = InternalMessage.builder().collectionValue(htmlStringList, String.class).itemMediaType(HTML).build();
Message copy = InternalMessage.builder(message).build();
assertThat(copy.getPayload().getValue(), is(htmlStringList));
assertThat(copy.getPayload().getDataType().getType(), equalTo(ArrayList.class));
assertThat(copy.getPayload().getDataType().getMediaType(), is(ANY));
assertThat(copy.getPayload().getDataType(), instanceOf(DefaultCollectionDataType.class));
assertThat(((DefaultCollectionDataType) copy.getPayload().getDataType()).getItemDataType().getMediaType(), equalTo(HTML));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultMuleMessageSerializationTestCase method testStreamPayloadSerialization.
@Test
public void testStreamPayloadSerialization() throws Exception {
InputStream stream = new ByteArrayInputStream(TEST_MESSAGE.getBytes());
final Message message = InternalMessage.builder().value(stream).addOutboundProperty("foo", "bar").build();
currentMuleContext.set(muleContext);
InternalMessage deserializedMessage = serializationRoundtrip(message);
assertEquals(byte[].class, deserializedMessage.getPayload().getDataType().getType());
byte[] payload = (byte[]) deserializedMessage.getPayload().getValue();
assertTrue(Arrays.equals(TEST_MESSAGE.getBytes(), payload));
}
Aggregations