From cd4bc0480184fc2c1424e4e0b47fe0c426907fce Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 3 Sep 2010 00:40:56 +0000 Subject: [PATCH] INT-1411 added tests for asyncReceiveAndConvert operations --- .../core/AsyncMessagingTemplateTests.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/core/AsyncMessagingTemplateTests.java b/spring-integration-core/src/test/java/org/springframework/integration/core/AsyncMessagingTemplateTests.java index 40a9948a8a..9aadcf86fc 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/core/AsyncMessagingTemplateTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/core/AsyncMessagingTemplateTests.java @@ -98,6 +98,57 @@ public class AsyncMessagingTemplateTests { result.get(100, TimeUnit.MILLISECONDS); } + @Test + public void asyncReceiveAndConvertWithDefaultChannel() throws Exception { + QueueChannel channel = new QueueChannel(); + AsyncMessagingTemplate template = new AsyncMessagingTemplate(); + template.setDefaultChannel(channel); + Future result = template.asyncReceiveAndConvert(); + sendMessageAfterDelay(channel, new GenericMessage("test"), 200); + long start = System.currentTimeMillis(); + assertNotNull(result.get(1000, TimeUnit.MILLISECONDS)); + long elapsed = System.currentTimeMillis() - start; + assertEquals("test", result.get()); + assertTrue(elapsed >= 200); + } + + @Test + public void asyncReceiveAndConvertWithExplicitChannel() throws Exception { + QueueChannel channel = new QueueChannel(); + AsyncMessagingTemplate template = new AsyncMessagingTemplate(); + Future result = template.asyncReceiveAndConvert(channel); + sendMessageAfterDelay(channel, new GenericMessage("test"), 200); + long start = System.currentTimeMillis(); + assertNotNull(result.get(1000, TimeUnit.MILLISECONDS)); + long elapsed = System.currentTimeMillis() - start; + assertEquals("test", result.get()); + assertTrue(elapsed >= 200); + } + + @Test + public void asyncReceiveAndConvertWithResolvedChannel() throws Exception { + StaticApplicationContext context = new StaticApplicationContext(); + context.registerSingleton("testChannel", QueueChannel.class); + context.refresh(); + QueueChannel channel = context.getBean("testChannel", QueueChannel.class); + AsyncMessagingTemplate template = new AsyncMessagingTemplate(); + template.setBeanFactory(context); + Future result = template.asyncReceiveAndConvert("testChannel"); + sendMessageAfterDelay(channel, new GenericMessage("test"), 200); + long start = System.currentTimeMillis(); + assertNotNull(result.get(1000, TimeUnit.MILLISECONDS)); + long elapsed = System.currentTimeMillis() - start; + assertTrue(elapsed >= 200); + assertEquals("test", result.get()); + } + + @Test(expected = TimeoutException.class) + public void asyncReceiveAndConvertWithTimeoutException() throws Exception { + AsyncMessagingTemplate template = new AsyncMessagingTemplate(); + Future result = template.asyncReceiveAndConvert(new QueueChannel()); + result.get(100, TimeUnit.MILLISECONDS); + } + @Test public void asyncSendAndReceiveWithDefaultChannel() throws Exception { DirectChannel channel = new DirectChannel();