}
@Override
public Message receive(String selector, TestContext context, long timeout) {
String destinationChannelName;
MessageChannel destinationChannel = getDestinationChannel();
if (StringUtils.hasText(selector)) {
destinationChannelName = getDestinationChannelName() + "(" + selector + ")";
} else {
destinationChannelName = getDestinationChannelName();
}
log.info("Receiving message from: " + destinationChannelName);
Message message;
if (StringUtils.hasText(selector)) {
if (!(destinationChannel instanceof MessageSelectingQueueChannel)) {
throw new CitrusRuntimeException("Message channel type '" + endpointConfiguration.getChannel().getClass() +
"' does not support selective receive operations.");
}
MessageSelector messageSelector = new DispatchingMessageSelector(selector, endpointConfiguration.getBeanFactory());
MessageSelectingQueueChannel queueChannel = ((MessageSelectingQueueChannel) destinationChannel);
if (timeout <= 0) {
message = endpointConfiguration.getMessageConverter().convertInbound(queueChannel.receive(messageSelector), endpointConfiguration);
} else {
message = endpointConfiguration.getMessageConverter().convertInbound(queueChannel.receive(messageSelector, timeout), endpointConfiguration);
}
} else {
if (!(destinationChannel instanceof PollableChannel)) {
throw new CitrusRuntimeException("Invalid destination channel type " + destinationChannel.getClass().getName() +
" - must be of type PollableChannel");
}
endpointConfiguration.getMessagingTemplate().setReceiveTimeout(timeout);
message = endpointConfiguration.getMessageConverter().convertInbound(