From 4dd2265e4c33a92cbd403baab01545dd09c9c930 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 17 Dec 2010 12:40:41 -0500 Subject: [PATCH] adding MessagingGatewaySupport tests for error-channel --- .../gateway/MessagingGatewayTests.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/MessagingGatewayTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/MessagingGatewayTests.java index 459a3e0906..75df22606c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/MessagingGatewayTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/MessagingGatewayTests.java @@ -16,6 +16,7 @@ package org.springframework.integration.gateway; +import static junit.framework.Assert.assertFalse; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.expect; @@ -37,7 +38,13 @@ import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.MessageDeliveryException; import org.springframework.integration.MessageHeaders; +import org.springframework.integration.MessagingException; +import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.channel.PublishSubscribeChannel; +import org.springframework.integration.core.MessageHandler; import org.springframework.integration.core.PollableChannel; +import org.springframework.integration.handler.ServiceActivatingHandler; +import org.springframework.integration.message.ErrorMessage; import org.springframework.integration.test.util.TestUtils; /** @@ -228,5 +235,69 @@ public class MessagingGatewayTests { verify(allmocks); } } + + // should fail but it doesn't now + @Test(expected=MessagingException.class) + @Ignore + public void validateErroMessageCanNotBeReplyMessage() { + DirectChannel reqChannel = new DirectChannel(); + reqChannel.subscribe(new MessageHandler() { + public void handleMessage(Message message) throws MessagingException { + throw new RuntimeException("ooops"); + } + }); + PublishSubscribeChannel errorChannel = new PublishSubscribeChannel(); + ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyErrorService()); + handler.afterPropertiesSet(); + errorChannel.subscribe(handler); + this.messagingGateway = new MessagingGatewaySupport() {}; + + this.messagingGateway.setRequestChannel(reqChannel); + this.messagingGateway.setErrorChannel(errorChannel); + this.messagingGateway.setBeanFactory(TestUtils.createTestApplicationContext()); + this.messagingGateway.afterPropertiesSet(); + this.messagingGateway.start(); + + this.messagingGateway.sendAndReceiveMessage("hello"); + + } + + + // should not fail but it does now + @Test + @Ignore + public void validateErrorChannelWithSuccessfullReply() { + DirectChannel reqChannel = new DirectChannel(); + reqChannel.subscribe(new MessageHandler() { + public void handleMessage(Message message) throws MessagingException { + throw new RuntimeException("ooops"); + } + }); + PublishSubscribeChannel errorChannel = new PublishSubscribeChannel(); + ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyOneWayErrorService()); + handler.afterPropertiesSet(); + errorChannel.subscribe(handler); + this.messagingGateway = new MessagingGatewaySupport() {}; + + this.messagingGateway.setRequestChannel(reqChannel); + this.messagingGateway.setErrorChannel(errorChannel); + this.messagingGateway.setBeanFactory(TestUtils.createTestApplicationContext()); + this.messagingGateway.afterPropertiesSet(); + this.messagingGateway.start(); + + this.messagingGateway.send("hello"); + } + + public static class MyErrorService { + public Message handleErrorMessage(Message errorMessage){ + return errorMessage; + } + } + + public static class MyOneWayErrorService { + public void handleErrorMessage(Message errorMessage){ + return; + } + } }