Search in sources :

Example 96 with TypedValue

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

the class DefaultMuleMessageBuilderTestCase method mutateEntirePayload.

@Test
public void mutateEntirePayload() {
    Message message = createTestMessage();
    Message copy = new DefaultMessageBuilder(message).payload(new TypedValue<>(EMPTY_JSON, JSON_STRING)).build();
    assertThat(copy.getPayload().getValue(), equalTo(EMPTY_JSON));
    assertThat(copy.getPayload().getDataType().getType(), equalTo(String.class));
    assertThat(copy.getPayload().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 97 with TypedValue

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

the class DefaultMuleMessageTestCase method compatibilityToString.

@Test
public void compatibilityToString() {
    Message message = InternalMessage.builder().payload(TypedValue.of("test")).attributes(new TypedValue<>("{}", JSON_STRING)).mediaType(TEXT).addInboundProperty("bar", "in").addOutboundProperty(FOO_PROPERTY, "out").exceptionPayload(new DefaultExceptionPayload(new NullPointerException("error"))).build();
    assertThat(message.toString(), is("\n" + "org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation\n" + "{\n" + "  payload=test\n" + "  mediaType=text/plain\n" + "  attributes={}\n" + "  attributesMediaType=application/json\n" + "  exceptionPayload:\n" + "    message=error\n" + "    exception=java.lang.NullPointerException: error\n" + "  Message properties:\n" + "    INBOUND scoped properties:\n" + "    bar=in\n" + "    OUTBOUND scoped properties:\n" + "    foo=out\n" + "}"));
}
Also used : Message(org.mule.runtime.api.message.Message) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Aggregations

TypedValue (org.mule.runtime.api.metadata.TypedValue)97 Test (org.junit.Test)74 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)47 DataType (org.mule.runtime.api.metadata.DataType)17 Message (org.mule.runtime.api.message.Message)16 Description (io.qameta.allure.Description)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 List (java.util.List)11 SmallTest (org.mule.tck.size.SmallTest)10 BindingContext (org.mule.runtime.api.el.BindingContext)9 Map (java.util.Map)8 Optional (java.util.Optional)8 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)6 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)5 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 MuleException (org.mule.runtime.api.exception.MuleException)4 Error (org.mule.runtime.api.message.Error)4 ErrorType (org.mule.runtime.api.message.ErrorType)4