Search in sources :

Example 11 with MediaType

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

the class OperationMessageProcessorTestCase method operationReturnsOperationResultWhichKeepsNoValues.

@Test
public void operationReturnsOperationResultWhichKeepsNoValues() throws Exception {
    Object payload = new Object();
    MediaType mediaType = ANY.withCharset(getDefaultEncoding(context));
    Object attributes = mock(Object.class);
    when(operationExecutor.execute(any(ExecutionContext.class))).thenReturn(just(builder().output(payload).mediaType(mediaType).attributes(attributes).build()));
    Message message = messageProcessor.process(event).getMessage();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
    assertThat(message.getAttributes().getValue(), is(sameInstance(attributes)));
    assertThat(message.getPayload().getDataType().getMediaType(), is(mediaType));
}
Also used : ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) Message(org.mule.runtime.api.message.Message) MediaType(org.mule.runtime.api.metadata.MediaType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 12 with MediaType

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

the class OperationMessageProcessorTestCase method operationReturnsOperationResultButKeepsAttributes.

@Test
public void operationReturnsOperationResultButKeepsAttributes() throws Exception {
    Object payload = new Object();
    MediaType mediaType = ANY.withCharset(getDefaultEncoding(context));
    when(operationExecutor.execute(any(ExecutionContext.class))).thenReturn(just(builder().output(payload).mediaType(mediaType).build()));
    event = CoreEvent.builder(event).message(Message.builder().value("").attributesValue(mock(Object.class)).build()).build();
    Message message = messageProcessor.process(event).getMessage();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
    assertThat(message.getAttributes().getValue(), is(nullValue()));
    assertThat(message.getPayload().getDataType().getMediaType(), equalTo(mediaType));
}
Also used : ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) Message(org.mule.runtime.api.message.Message) MediaType(org.mule.runtime.api.metadata.MediaType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 13 with MediaType

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

the class MuleMessageDataTypePropagationTestCase method setsCustomPropertyDataType.

@Test
public void setsCustomPropertyDataType() 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(STRING).mediaType(mediaType).build());
}
Also used : MediaType(org.mule.runtime.api.metadata.MediaType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

MediaType (org.mule.runtime.api.metadata.MediaType)13 Test (org.junit.Test)10 SmallTest (org.mule.tck.size.SmallTest)10 Message (org.mule.runtime.api.message.Message)5 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 ExecutionContext (org.mule.runtime.extension.api.runtime.operation.ExecutionContext)3 Charset (java.nio.charset.Charset)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Result (org.mule.runtime.extension.api.runtime.operation.Result)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 DataType (org.mule.runtime.api.metadata.DataType)1 MediaTypeUtils.parseCharset (org.mule.runtime.api.metadata.MediaTypeUtils.parseCharset)1 MessageUtils.toMessageCollection (org.mule.runtime.core.internal.util.message.MessageUtils.toMessageCollection)1 MessageUtils.toMessageIterator (org.mule.runtime.core.internal.util.message.MessageUtils.toMessageIterator)1 ExtensionMetadataTypeUtils.isJavaCollection (org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isJavaCollection)1