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));
}
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));
}
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)));
}
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));
}
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)));
}
Aggregations