From 332f078e8172aacd119cf57ad3354575d460e982 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 28 Dec 2007 17:40:14 +0000 Subject: [PATCH] Added test for UnicastMessageDispatcher. --- .../bus/UnicastMessageDispatcherTests.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 spring-integration-core/src/test/java/org/springframework/integration/bus/UnicastMessageDispatcherTests.java diff --git a/spring-integration-core/src/test/java/org/springframework/integration/bus/UnicastMessageDispatcherTests.java b/spring-integration-core/src/test/java/org/springframework/integration/bus/UnicastMessageDispatcherTests.java new file mode 100644 index 0000000000..fd0889acef --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/bus/UnicastMessageDispatcherTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2002-2007 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.bus; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import org.springframework.integration.channel.PointToPointChannel; +import org.springframework.integration.endpoint.GenericMessageEndpoint; +import org.springframework.integration.message.Message; +import org.springframework.integration.message.StringMessage; + +/** + * @author Mark Fisher + */ +public class UnicastMessageDispatcherTests { + + @Test + public void testExactlyOneEndpointReceivesMessage() { + PointToPointChannel inputChannel = new PointToPointChannel(); + PointToPointChannel outputChannel1 = new PointToPointChannel(); + PointToPointChannel outputChannel2 = new PointToPointChannel(); + GenericMessageEndpoint endpoint1 = new GenericMessageEndpoint(); + endpoint1.setDefaultOutputChannelName("output1"); + endpoint1.setInputChannelName("input"); + GenericMessageEndpoint endpoint2 = new GenericMessageEndpoint(); + endpoint2.setDefaultOutputChannelName("output2"); + endpoint2.setInputChannelName("input"); + MessageBus bus = new MessageBus(); + bus.registerChannel("input", inputChannel); + bus.registerChannel("output1", outputChannel1); + bus.registerChannel("output2", outputChannel2); + bus.registerEndpoint("endpoint1", endpoint1); + bus.registerEndpoint("endpoint2", endpoint2); + bus.start(); + inputChannel.send(new StringMessage(1, "testing")); + Message message1 = outputChannel1.receive(100); + Message message2 = outputChannel2.receive(0); + bus.stop(); + assertTrue("exactly one message should be null", message1 == null ^ message2 == null); + } + +}