use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class ValueReturnDelegateContractTestCase method operationReturnsOperationResultThatOnlySpecifiesPayloadAndAttributes.
@Test
public void operationReturnsOperationResultThatOnlySpecifiesPayloadAndAttributes() throws Exception {
Object payload = "hello world!";
Object newAttributes = mock(Object.class);
CoreEvent result = delegate.asReturnValue(Result.builder().output(payload).attributes(newAttributes).build(), operationContext);
Message message = getOutputMessage(result);
assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
assertThat(message.getAttributes().getValue(), is(sameInstance(newAttributes)));
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 ValueReturnDelegateContractTestCase method operationReturnsOperationResultButKeepsAttributes.
@Test
public void operationReturnsOperationResultButKeepsAttributes() throws Exception {
Object payload = new Object();
MediaType mediaType = ANY.withCharset(getDefaultEncoding(muleContext));
CoreEvent result = delegate.asReturnValue(Result.builder().output(payload).mediaType(mediaType).build(), operationContext);
Message message = getOutputMessage(result);
assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
assertThat(message.getAttributes().getValue(), is(nullValue()));
assertThat(message.getPayload().getDataType().getMediaType(), equalTo(mediaType));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class TestEventBuilder method build.
/**
* Produces an event with the specified configuration.
*
* @param flow the recipient for the event to be built.
* @return an event with the specified configuration.
*/
public CoreEvent build(FlowConstruct flow) {
final Message.Builder messageBuilder;
messageBuilder = Message.builder().value(payload).mediaType(mediaType);
setInboundProperties(messageBuilder, inboundProperties);
setOutboundProperties(messageBuilder, outboundProperties);
if (attributes != null) {
messageBuilder.attributesValue(attributes);
}
final Message muleMessage = messageBuilder.build();
EventContext eventContext;
if (externalCompletionCallback != null) {
eventContext = create(flow, TEST_CONNECTOR_LOCATION, sourceCorrelationId, of(externalCompletionCallback));
} else {
eventContext = create(flow, TEST_CONNECTOR_LOCATION, sourceCorrelationId);
}
CoreEvent.Builder builder = InternalEvent.builder(eventContext).message(spyMessage.apply(muleMessage)).replyToHandler(replyToHandler).itemSequenceInfo(ofNullable(itemSequenceInfo));
for (Entry<String, TypedValue> variableEntry : variables.entrySet()) {
builder.addVariable(variableEntry.getKey(), variableEntry.getValue().getValue(), variableEntry.getValue().getDataType());
}
CoreEvent event = builder.build();
for (Entry<String, Attachment> outboundAttachmentEntry : outboundAttachments.entrySet()) {
event = outboundAttachmentEntry.getValue().addOutboundTo(event, outboundAttachmentEntry.getKey());
}
for (Entry<String, Object> sessionPropertyEntry : sessionProperties.entrySet()) {
((PrivilegedEvent) event).getSession().setProperty(sessionPropertyEntry.getKey(), sessionPropertyEntry.getValue());
}
return spyEvent.apply(event);
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class FlowExecutionLogger method assertRouteNthExecution.
public static void assertRouteNthExecution(String routeKey, int n, Object... values) {
waitUntilNthExecution(routeKey, n);
ExecutionLog executionLog = executionLogsMap.get(routeKey);
Message message = executionLog.getCollectedMessages().get(n - 1);
if (message.getPayload().getValue() instanceof List) {
List<TypedValue> aggregatedElements = (List<TypedValue>) message.getPayload().getValue();
assertThat(aggregatedElements.stream().map(element -> element.getValue()).collect(toList()), contains(values));
} else {
assertThat(values, arrayWithSize(1));
assertThat(message.getPayload().getValue(), is(equalTo(values[0])));
}
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class FlowExecutionLogger method process.
@Override
public CoreEvent process(CoreEvent coreEvent) throws MuleException {
String routeName = coreEvent.getVariables().get(EXECUTION_ROUTE_KEY).getValue().toString();
Message message = coreEvent.getMessage();
if (executionLogsMap.containsKey(routeName)) {
executionLogsMap.get(routeName).logExecution(message);
} else {
ExecutionLog newLog = new ExecutionLog(message);
executionLogsMap.put(routeName, newLog);
}
return coreEvent;
}
Aggregations