Moved MessageSelector interface and implementations into a new 'org.springframework.integration.selector' package (instead of a sub-package under 'message'). Also added support for "Strategy" enum in MessageSelector with the following values available [ALL, ANY, AT_LEAST_HALF, MORE_THAN_HALF] (INT-308).
This commit is contained in:
@@ -26,7 +26,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.UnexpiredMessageSelector;
|
||||
import org.springframework.integration.selector.UnexpiredMessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.message.selector.MessageSelectorChain;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelectorChain;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
ref="testHandler" selector="typeSelector">
|
||||
</service-activator>
|
||||
|
||||
<beans:bean id="typeSelector" class="org.springframework.integration.message.selector.PayloadTypeSelector">
|
||||
<beans:bean id="typeSelector" class="org.springframework.integration.selector.PayloadTypeSelector">
|
||||
<beans:constructor-arg value="java.lang.String"/>
|
||||
</beans:bean>
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.TestHandlers;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -37,8 +37,8 @@ import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.TestHandlers;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.message.selector.MessageSelectorChain;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelectorChain;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.integration.endpoint.SubscribingConsumerEndpoint;
|
||||
import org.springframework.integration.filter.MessageFilter;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.selector.PayloadTypeSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.selector.UnexpiredMessageSelector;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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.selector;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessageSelectorChainTests {
|
||||
|
||||
private final Message<?> message = new StringMessage("test");
|
||||
|
||||
|
||||
@Test
|
||||
public void anyStrategyAccepts() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.ANY);
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
assertTrue(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anyStrategyRejects() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.ANY);
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(false));
|
||||
assertFalse(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allStrategyAccepts() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.ALL);
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(true));
|
||||
assertTrue(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allStrategyRejects() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.ALL);
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(true));
|
||||
assertFalse(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atLeastHalfStrategyWithOddNumberAccepts() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.AT_LEAST_HALF);
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
assertTrue(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atLeastHalfStrategyWithEvenNumberAccepts() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.AT_LEAST_HALF);
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(false));
|
||||
assertTrue(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atLeastHalfStrategyWithOddNumberRejects() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.AT_LEAST_HALF);
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
assertFalse(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atLeastHalfStrategyWithEvenNumberRejects() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.AT_LEAST_HALF);
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(false));
|
||||
assertFalse(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreThanHalfStrategyWithOddNumberAccepts() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.MORE_THAN_HALF);
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
assertTrue(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreThanHalfStrategyWithEvenNumberAccepts() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.MORE_THAN_HALF);
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(true));
|
||||
assertTrue(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreThanHalfStrategyWithOddNumberRejects() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.MORE_THAN_HALF);
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
assertFalse(chain.accept(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moreThanHalfStrategyWithEvenNumberRejects() {
|
||||
MessageSelectorChain chain = new MessageSelectorChain();
|
||||
chain.setStrategy(MessageSelectorChain.Strategy.MORE_THAN_HALF);
|
||||
chain.add(new TestSelector(false));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(true));
|
||||
chain.add(new TestSelector(false));
|
||||
assertFalse(chain.accept(message));
|
||||
}
|
||||
|
||||
|
||||
private static class TestSelector implements MessageSelector {
|
||||
|
||||
private final boolean accept;
|
||||
|
||||
private TestSelector(boolean accept) {
|
||||
this.accept = accept;
|
||||
}
|
||||
|
||||
public boolean accept(Message<?> message) {
|
||||
return this.accept;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user