Removed MessageHandlerChain.

This commit is contained in:
Mark Fisher
2008-09-05 02:43:40 +00:00
parent 4ea9f755e0
commit 0e5fafe6df
3 changed files with 5 additions and 158 deletions

View File

@@ -16,16 +16,11 @@
package org.springframework.integration.handler;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.springframework.integration.handler.MessageFilter;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.handler.MessageHandlerChain;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.StringMessage;
import org.springframework.integration.message.selector.MessageSelector;
@@ -37,42 +32,23 @@ public class MessageFilterTests {
@Test
public void testFilterAcceptsMessage() {
final AtomicBoolean secondHandlerReceived = new AtomicBoolean();
MessageHandlerChain chain = new MessageHandlerChain();
MessageFilter filter = new MessageFilter(new MessageSelector() {
public boolean accept(Message<?> message) {
return true;
}
});
chain.add(filter);
chain.add(new MessageHandler() {
public Message<?> handle(Message<?> message) {
secondHandlerReceived.set(true);
return null;
}
});
chain.handle(new StringMessage("test"));
assertTrue(secondHandlerReceived.get());
Message<?> message = new StringMessage("test");
assertEquals(message, filter.handle(message));
}
@Test
public void testFilterRejectsMessage() {
final AtomicBoolean secondHandlerReceived = new AtomicBoolean();
MessageHandlerChain chain = new MessageHandlerChain();
MessageFilter filter = new MessageFilter(new MessageSelector() {
public boolean accept(Message<?> message) {
return false;
}
});
chain.add(filter);
chain.add(new MessageHandler() {
public Message<?> handle(Message<?> message) {
secondHandlerReceived.set(true);
return null;
}
});
chain.handle(new StringMessage("test"));
assertFalse(secondHandlerReceived.get());
assertNull(filter.handle(new StringMessage("test")));
}
}

View File

@@ -1,56 +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.handler;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
*/
public class MessageHandlerChainTests {
@Test
public void testChain() {
MessageHandlerChain chain = new MessageHandlerChain();
chain.add(new TestHandler("a"));
chain.add(new TestHandler("b"));
chain.add(new TestHandler("c"));
chain.add(new TestHandler("d"));
Message<?> result = chain.handle(new StringMessage("!"));
assertEquals("!abcd", result.getPayload());
}
private static class TestHandler implements MessageHandler {
private String text;
TestHandler(String text) {
this.text = text;
}
public Message<?> handle(Message<?> message) {
return new StringMessage(message.getPayload() + text);
}
}
}