OPEN - issue INT-505: Add namespace support for MethodInvokingSelector

http://jira.springframework.org/browse/INT-505

Fixed 505, some prework for INT-547
This commit is contained in:
Iwein Fuld
2009-01-12 14:36:10 +00:00
parent 747050ab8c
commit aafdec0108
6 changed files with 397 additions and 225 deletions

View File

@@ -26,17 +26,23 @@
<selector ref="selector6"/>
</selector-chain>
</selector-chain>
<!-- TODO INT-547
<selector id="pojoSelector" ref="pojoSelectorBean" method="accept"/>
-->
<beans:bean id="pojoSelectorBean" class="org.springframework.integration.config.SelectorChainParserTests$StubPojoSelector"/>
<beans:bean id="selector1" class="org.springframework.integration.config.StubMessageSelector"/>
<beans:bean id="selector1" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector2" class="org.springframework.integration.config.StubMessageSelector"/>
<beans:bean id="selector2" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector3" class="org.springframework.integration.config.StubMessageSelector"/>
<beans:bean id="selector3" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector4" class="org.springframework.integration.config.StubMessageSelector"/>
<beans:bean id="selector4" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector5" class="org.springframework.integration.config.StubMessageSelector"/>
<beans:bean id="selector5" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
<beans:bean id="selector6" class="org.springframework.integration.config.StubMessageSelector"/>
<beans:bean id="selector6" class="org.springframework.integration.config.SelectorChainParserTests$StubMessageSelector"/>
</beans:beans>

View File

@@ -21,24 +21,41 @@ import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.StringMessage;
import org.springframework.integration.selector.MessageSelector;
import org.springframework.integration.selector.MessageSelectorChain;
import org.springframework.integration.selector.MessageSelectorChain.VotingStrategy;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Iwein Fuld
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class SelectorChainParserTests {
@Autowired
ApplicationContext context;
@Test @Ignore
public void topLevelSelector() throws Exception {
MessageSelector topLevelSelector = (MessageSelector) context.getBean("topLevelSelector");
}
@Test
public void selectorChain() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"selectorChainParserTests.xml", this.getClass());
MessageSelector selector1 = (MessageSelector) context.getBean("selector1");
MessageSelector selector2 = (MessageSelector) context.getBean("selector2");
MessageSelectorChain chain = (MessageSelectorChain) context.getBean("selectorChain");
@@ -51,8 +68,6 @@ public class SelectorChainParserTests {
@Test
public void nestedSelectorChain() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"selectorChainParserTests.xml", this.getClass());
MessageSelector selector1 = (MessageSelector) context.getBean("selector1");
MessageSelector selector2 = (MessageSelector) context.getBean("selector2");
MessageSelector selector3 = (MessageSelector) context.getBean("selector3");
@@ -96,5 +111,16 @@ public class SelectorChainParserTests {
private VotingStrategy getStrategy(MessageSelectorChain chain) {
return (VotingStrategy) new DirectFieldAccessor(chain).getPropertyValue("votingStrategy");
}
public static class StubMessageSelector implements MessageSelector {
public boolean accept(Message<?> message) {
return true;
}
}
public static class StubPojoSelector {
public boolean accept(Message<?> message) {
return true;
}
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<selector-chain id="selector">
<selector ref="someBean" method="accept" />
</selector-chain>
<beans:bean id="someBean"
class="org.springframework.integration.config.xml.MethodInvokingSelectorParserTests$SomeClass" />
</beans:beans>

View File

@@ -0,0 +1,38 @@
package org.springframework.integration.config.xml;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.filter.MethodInvokingSelector;
import org.springframework.integration.selector.MessageSelector;
import org.springframework.integration.selector.MessageSelectorChain;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class MethodInvokingSelectorParserTests {
@Autowired
MessageSelectorChain chain;
@Test
public void configOK() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(chain);
List<MessageSelector> selectors = (List<MessageSelector>) accessor.getPropertyValue("selectors");
assertThat(selectors.get(0), is(MethodInvokingSelector.class));
}
public static class SomeClass {
public boolean accept(Message m) {
return true;
}
}
}