INT-1377, deleted AbstractSingleChannelRouter and the corresponding tests

This commit is contained in:
Oleg Zhurakousky
2010-10-13 10:53:43 -04:00
parent 1f367bc5ee
commit 9f8b4d93a5
2 changed files with 0 additions and 137 deletions

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2002-2008 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.router;
import java.util.Collection;
import java.util.Collections;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
/**
* Extends {@link AbstractMessageRouter} to support router implementations that
* always return a single {@link MessageChannel} instance (or null).
*
* @author Mark Fisher
*/
public abstract class AbstractSingleChannelRouter extends AbstractMessageRouter {
@Override
protected final Collection<MessageChannel> determineTargetChannels(Message<?> message) {
MessageChannel channel = this.determineTargetChannel(message);
return (channel != null) ? Collections.singletonList(channel) : null;
}
/**
* Subclasses must implement this method to return the target channel.
*/
protected abstract MessageChannel determineTargetChannel(Message<?> message);
}

View File

@@ -1,93 +0,0 @@
/*
* 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.router;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessagingException;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.channel.TestChannelResolver;
import org.springframework.integration.message.GenericMessage;
/**
* @author Mark Fisher
*/
public class SingleChannelRouterTests {
@Test
public void routeWithChannelResolver() {
final QueueChannel channel = new QueueChannel();
AbstractSingleChannelRouter router = new AbstractSingleChannelRouter() {
public MessageChannel determineTargetChannel(Message<?> message) {
return channel;
}
};
Message<String> message = new GenericMessage<String>("test");
router.handleMessage(message);
Message<?> result = channel.receive(25);
assertNotNull(result);
assertEquals("test", result.getPayload());
}
@Test
public void routeWithChannelNameResolver() {
AbstractSingleChannelNameRouter router = new AbstractSingleChannelNameRouter() {
public String determineTargetChannelName(Message<?> message) {
return "testChannel";
}
};
QueueChannel channel = new QueueChannel();
TestChannelResolver channelResolver = new TestChannelResolver();
channelResolver.addChannel("testChannel", channel);
router.setChannelResolver(channelResolver);
Message<String> message = new GenericMessage<String>("test");
router.handleMessage(message);
Message<?> result = channel.receive(25);
assertNotNull(result);
assertEquals("test", result.getPayload());
}
@Test
public void nullChannelResultIgnored() {
AbstractSingleChannelRouter router = new AbstractSingleChannelRouter() {
public MessageChannel determineTargetChannel(Message<?> message) {
return null;
}
};
Message<String> message = new GenericMessage<String>("test");
router.handleMessage(message);
}
@Test(expected = MessagingException.class)
public void channelNameResolutionFailure() {
AbstractSingleChannelNameRouter router = new AbstractSingleChannelNameRouter() {
public String determineTargetChannelName(Message<?> message) {
return "noSuchChannel";
}
};
TestChannelResolver channelResolver = new TestChannelResolver();
router.setChannelResolver(channelResolver);
Message<String> message = new GenericMessage<String>("test");
router.handleMessage(message);
}
}