Search in sources :

Example 61 with Message

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));
}
Also used : Message(org.mule.runtime.api.message.Message) OptionalLong(java.util.OptionalLong) DataHandler(javax.activation.DataHandler) Test(org.junit.Test)

Example 62 with Message

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));
}
Also used : Message(org.mule.runtime.api.message.Message) Test(org.junit.Test)

Example 63 with Message

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));
}
Also used : Message(org.mule.runtime.api.message.Message) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 64 with Message

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));
}
Also used : Message(org.mule.runtime.api.message.Message) ArrayList(java.util.ArrayList) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) Test(org.junit.Test)

Example 65 with Message

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));
}
Also used : Message(org.mule.runtime.api.message.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

Message (org.mule.runtime.api.message.Message)226 Test (org.junit.Test)189 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)104 SmallTest (org.mule.tck.size.SmallTest)68 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)46 Transformer (org.mule.runtime.core.api.transformer.Transformer)35 DataType (org.mule.runtime.api.metadata.DataType)33 ArrayList (java.util.ArrayList)26 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)26 Processor (org.mule.runtime.core.api.processor.Processor)25 List (java.util.List)20 Assert.assertThat (org.junit.Assert.assertThat)19 ExpectedException (org.junit.rules.ExpectedException)19 MuleContextUtils.eventBuilder (org.mule.tck.util.MuleContextUtils.eventBuilder)19 Map (java.util.Map)18 Rule (org.junit.Rule)18 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)18 ExpectedException.none (org.junit.rules.ExpectedException.none)17 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)17 TypedValue (org.mule.runtime.api.metadata.TypedValue)16