Search in sources :

Example 86 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class OperationMessageProcessorTestCase method operationReturnsMapWithCorrectDataType.

@Test
public void operationReturnsMapWithCorrectDataType() throws Exception {
    Object payload = new HashMap<>();
    setUpOperationReturning(payload, new TypeToken<Map<String, String>>() {
    }.getType());
    Message message = messageProcessor.process(event).getMessage();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
    DataType dataType = message.getPayload().getDataType();
    assertThat(dataType, instanceOf(MapDataType.class));
    assertThat(((MapDataType) dataType).getKeyDataType(), like(String.class, ANY.withCharset(null)));
    assertThat(((MapDataType) dataType).getValueDataType(), like(String.class, ANY));
}
Also used : Message(org.mule.runtime.api.message.Message) HashMap(java.util.HashMap) TypeToken(com.google.common.reflect.TypeToken) MapDataType(org.mule.runtime.api.metadata.MapDataType) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) MapDataType(org.mule.runtime.api.metadata.MapDataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 87 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class OperationMessageProcessorTestCase method operationReturnsOperationResultWithPayloadAndAttributes.

@Test
public void operationReturnsOperationResultWithPayloadAndAttributes() throws Exception {
    Object payload = "hello world!";
    Object attributes = mock(Object.class);
    when(operationExecutor.execute(any(ExecutionContext.class))).thenReturn(just(builder().output(payload).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().getType().equals(String.class), is(true));
}
Also used : ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) Message(org.mule.runtime.api.message.Message) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 88 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class OperationMessageProcessorTestCase method operationReturnsResultCollectionWithCorrectDataType.

@Test
public void operationReturnsResultCollectionWithCorrectDataType() throws Exception {
    Object payload = new ArrayList<>();
    setUpOperationReturning(Result.builder().output(payload).build(), new TypeToken<List<Integer>>() {
    }.getType());
    Message message = messageProcessor.process(event).getMessage();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
    DataType dataType = message.getPayload().getDataType();
    assertThat(dataType, instanceOf(CollectionDataType.class));
    assertThat(((CollectionDataType) dataType).getItemDataType(), like(Integer.class, ANY.withCharset(null)));
}
Also used : Message(org.mule.runtime.api.message.Message) TypeToken(com.google.common.reflect.TypeToken) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) ArrayList(java.util.ArrayList) MapDataType(org.mule.runtime.api.metadata.MapDataType) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 89 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class OperationMessageProcessorTestCase method operationReturnsOperationResultOnTarget.

@Test
public void operationReturnsOperationResultOnTarget() throws Exception {
    target = TARGET_VAR;
    messageProcessor = setUpOperationMessageProcessor();
    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 = (Message) messageProcessor.process(event).getVariables().get(TARGET_VAR).getValue();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
    assertThat(message.getAttributes().getValue(), is(sameInstance(attributes)));
    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 90 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class ModulesUsingGraphTestCase method assertCalls.

private void assertCalls(String flow, String expected) throws Exception {
    final Message consumedMessage = flowRunner(flow).run().getMessage();
    assertThat(consumedMessage, hasPayload(equalTo(expected)));
}
Also used : Message(org.mule.runtime.api.message.Message)

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