From 9b0f13e271f2b31d8cccce2ba6cff1a3933abf8e Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 17 Dec 2010 13:29:59 -0500 Subject: [PATCH] INT-1696 added tests for MessageProducerSupport --- .../endpoint/MessageProducerSupportTests.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/endpoint/MessageProducerSupportTests.java diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/MessageProducerSupportTests.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/MessageProducerSupportTests.java new file mode 100644 index 0000000000..cd8473f25c --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/MessageProducerSupportTests.java @@ -0,0 +1,85 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.endpoint; + +import org.junit.Ignore; +import org.junit.Test; + +import org.springframework.integration.Message; +import org.springframework.integration.MessageDeliveryException; +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.handler.ServiceActivatingHandler; +import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.test.util.TestUtils; + +/** + * @author Oleg Zhurakousky + * + */ +public class MessageProducerSupportTests { + + @Test(expected=MessageDeliveryException.class) + public void validateExceptionIfNoErrorChannel(){ + DirectChannel outChannel = new DirectChannel(); + outChannel.subscribe(new MessageHandler() { + public void handleMessage(Message message) throws MessagingException { + throw new RuntimeException("problems"); + } + }); + MessageProducerSupport mps = new MessageProducerSupport() {}; + + mps.setOutputChannel(outChannel); + mps.setBeanFactory(TestUtils.createTestApplicationContext()); + mps.afterPropertiesSet(); + mps.start(); + + mps.sendMessage(new GenericMessage("hello")); + } + + @Test(expected=MessageDeliveryException.class) + @Ignore + public void validateExceptionIfSendToErrorChannelFails(){ + DirectChannel outChannel = new DirectChannel(); + outChannel.subscribe(new MessageHandler() { + public void handleMessage(Message message) throws MessagingException { + throw new RuntimeException("problems"); + } + }); + PublishSubscribeChannel errorChannel = new PublishSubscribeChannel(); + ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyOneWayErrorService()); + handler.afterPropertiesSet(); + errorChannel.subscribe(handler); + MessageProducerSupport mps = new MessageProducerSupport() {}; + + mps.setOutputChannel(outChannel); + mps.setErrorChannel(errorChannel); + mps.setBeanFactory(TestUtils.createTestApplicationContext()); + mps.afterPropertiesSet(); + mps.start(); + + mps.sendMessage(new GenericMessage("hello")); + } + + public static class MyOneWayErrorService { + public void handleErrorMessage(Message errorMessage){ + throw new RuntimeException("ooops"); + } + } +}