use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithAmbiguousGenericMessageMethod.
@Test
public /*
* No handler fallback methods; ambiguous message handler fallbacks; force RRE
*/
void testRequestReplyExchangerWithAmbiguousGenericMessageMethod() {
RequestReplyExchanger testBean = new RequestReplyExchanger() {
@Override
public Message<?> exchange(Message<?> request) {
return request;
}
@SuppressWarnings("unused")
public String foo(Message<String> request) {
return request.getPayload().toUpperCase();
}
@SuppressWarnings("unused")
public String bar(Message<String> request) {
return request.getPayload().toUpperCase();
}
};
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
PollableChannel outputChannel = new QueueChannel();
serviceActivator.setOutputChannel(outputChannel);
Message<?> test = new GenericMessage<Object>(new Date());
serviceActivator.handleMessage(test);
assertEquals(test, outputChannel.receive(10));
test = new GenericMessage<Object>("foo");
serviceActivator.handleMessage(test);
assertNotEquals("FOO", outputChannel.receive(10).getPayload());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithAmbiguousMethod.
@Test
public /*
* One message handler fallback method (RRE); ambiguous handler fallbacks; force RRE
*/
void testRequestReplyExchangerWithAmbiguousMethod() {
RequestReplyExchanger testBean = new RequestReplyExchanger() {
@Override
public Message<?> exchange(Message<?> request) {
return request;
}
@SuppressWarnings("unused")
public String foo(String request) {
return request.toUpperCase();
}
@SuppressWarnings("unused")
public String bar(String request) {
return request.toUpperCase();
}
};
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
PollableChannel outputChannel = new QueueChannel();
serviceActivator.setOutputChannel(outputChannel);
Message<?> test = new GenericMessage<Object>(new Date());
serviceActivator.handleMessage(test);
assertEquals(test, outputChannel.receive(10));
test = new GenericMessage<Object>("foo");
serviceActivator.handleMessage(test);
assertNotEquals("FOO", outputChannel.receive(10).getPayload());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ServiceActivatorMethodResolutionTests method testRequestReplyExchanger.
@Test
public void testRequestReplyExchanger() {
RequestReplyExchanger testBean = new RequestReplyExchanger() {
@Override
public Message<?> exchange(Message<?> request) {
return request;
}
};
final Message<?> test = new GenericMessage<Object>("foo");
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean) {
@Override
protected Object handleRequestMessage(Message<?> message) {
Object o = super.handleRequestMessage(message);
assertSame(test, o);
return null;
}
};
serviceActivator.handleMessage(test);
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class AsyncMessagingTemplateTests method asyncSendAndReceiveWithDefaultChannel.
@Test
public void asyncSendAndReceiveWithDefaultChannel() throws Exception {
DirectChannel channel = new DirectChannel();
channel.subscribe(new EchoHandler(200));
AsyncMessagingTemplate template = new AsyncMessagingTemplate();
template.setDefaultDestination(channel);
long start = System.currentTimeMillis();
Future<Message<?>> result = template.asyncSendAndReceive(MessageBuilder.withPayload("test").build());
assertNotNull(result.get());
long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= 200 - safety);
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class GatewayParserTests method testAsyncCompletableNoAsyncMessage.
@Test
public void testAsyncCompletableNoAsyncMessage() throws Exception {
QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel");
final AtomicReference<Thread> thread = new AtomicReference<>();
requestChannel.addInterceptor(new ChannelInterceptorAdapter() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
thread.set(Thread.currentThread());
return super.preSend(message, channel);
}
});
MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
this.startResponder(requestChannel, replyChannel);
TestService service = context.getBean("completableNoAsync", TestService.class);
CompletableFuture<Message<?>> result = service.completableReturnsMessage("flowCompletableM");
Message<?> reply = result.get(10, TimeUnit.SECONDS);
assertEquals("flowCompletableM", reply.getPayload());
assertEquals(Thread.currentThread(), thread.get());
assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
Aggregations