INT-578 added tests for dynamic recipient list router namespace support

This commit is contained in:
Mark Fisher
2010-07-03 22:15:40 +00:00
parent 1553df8a54
commit efd8857871
4 changed files with 39 additions and 2 deletions

View File

@@ -51,7 +51,7 @@ public class RecipientListRouterParser extends AbstractConsumerEndpointParser {
BeanDefinitionBuilder recipientBuilder = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.router.RecipientListRouter.Recipient");
recipientBuilder.addConstructorArgReference(childElement.getAttribute("channel"));
String expression = childElement.getAttribute("expression");
String expression = childElement.getAttribute("selector-expression");
if (StringUtils.hasText(expression)) {
BeanDefinition selectorDef = new RootBeanDefinition(
"org.springframework.integration.filter.ExpressionEvaluatingSelector");

View File

@@ -1642,7 +1642,7 @@
<xsd:sequence>
<xsd:element name="recipient" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="expression" type="xsd:string">
<xsd:attribute name="selector-expression" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
An expression to be evaluated to determine if this recipient should be included in the recipient

View File

@@ -15,10 +15,16 @@
<queue capacity="1" />
</channel>
<channel id="channel3">
<queue capacity="1" />
</channel>
<channel id="routingChannelA" />
<channel id="routingChannelB" />
<channel id="routingChannelC" />
<recipient-list-router id="simpleRouter" input-channel="routingChannelA">
<recipient channel="channel1"/>
<recipient channel="channel2"/>
@@ -32,4 +38,12 @@
<recipient channel="channel2"/>
</recipient-list-router>
<recipient-list-router id="simpleDynamicRouter" input-channel="simpleDynamicInput">
<recipient selector-expression="true" channel="channel1"/>
<recipient selector-expression="false" channel="channel2"/>
<recipient selector-expression="@testBean.accept(payload)" channel="channel3"/>
</recipient-list-router>
<beans:bean id="testBean" class="org.springframework.integration.router.config.RecipientListRouterParserTests.TestBean"/>
</beans:beans>

View File

@@ -17,6 +17,7 @@
package org.springframework.integration.router.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -51,6 +52,9 @@ public class RecipientListRouterParserTests {
@Qualifier("routingChannelA")
private MessageChannel channel;
@Autowired
private MessageChannel simpleDynamicInput;
@Test
public void checkMessageRouting() {
context.start();
@@ -88,4 +92,23 @@ public class RecipientListRouterParserTests {
assertEquals(Boolean.TRUE, accessor.getPropertyValue("ignoreSendFailures"));
}
@Test
public void simpleDynamicRouter() {
context.start();
Message<?> message = new GenericMessage<Integer>(1);
simpleDynamicInput.send(message);
PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
PollableChannel chanel2 = (PollableChannel) context.getBean("channel2");
assertTrue(chanel1.receive(0).getPayload().equals(1));
assertNull(chanel2.receive(0));
}
public static class TestBean {
public boolean accept(int number) {
return number == 1;
}
}
}