OPEN - issue INT-555: chain allows bean as a subelement, but parser cannot handle this.

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

added condition to parser to parse bean elements too (with test).
This commit is contained in:
Iwein Fuld
2009-01-29 11:58:13 +00:00
parent 62e744457d
commit 0a652749c3
3 changed files with 74 additions and 29 deletions

View File

@@ -1,58 +1,62 @@
<?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"
<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">
<channel id="filterInput"/>
<channel id="pollableInput">
<queue/>
<queue />
</channel>
<channel id="output">
<queue/>
<queue />
</channel>
<channel id="replyOutput">
<queue/>
<queue />
</channel>
<chain input-channel="filterInput" output-channel="output">
<filter ref="typeSelector"/>
<service-activator ref="testHandler"/>
<filter ref="typeSelector" />
<service-activator ref="testHandler" />
</chain>
<chain input-channel="headerEnricherInput">
<header-enricher reply-channel="replyOutput" correlation-id="ABC">
<header name="testValue" value="XYZ"/>
<header name="testRef" ref="testHeaderValue"/>
<header-enricher reply-channel="replyOutput"
correlation-id="ABC">
<header name="testValue" value="XYZ" />
<header name="testRef" ref="testHeaderValue" />
</header-enricher>
<service-activator ref="testHandler"/>
<service-activator ref="testHandler" />
</chain>
<chain input-channel="pollableInput" output-channel="output">
<poller>
<interval-trigger interval="10000"/>
<interval-trigger interval="10000" />
</poller>
<filter ref="typeSelector"/>
<service-activator ref="testHandler"/>
<filter ref="typeSelector" />
<service-activator ref="testHandler" />
</chain>
<chain input-channel="beanInput" output-channel="output">
<beans:bean
class="org.springframework.integration.config.ChainParserTests$StubHandler" />
</chain>
<beans:bean id="testHeaderValue" class="java.lang.Integer">
<beans:constructor-arg value="123"/>
<beans:constructor-arg value="123" />
</beans:bean>
<beans:bean id="typeSelector" class="org.springframework.integration.selector.PayloadTypeSelector">
<beans:constructor-arg value="java.lang.String"/>
<beans:bean id="typeSelector"
class="org.springframework.integration.selector.PayloadTypeSelector">
<beans:constructor-arg value="java.lang.String" />
</beans:bean>
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler">
<beans:constructor-arg value="1"/>
<beans:property name="replyMessageText" value="foo"/>
</beans:bean>
<beans:bean id="testHandler"
class="org.springframework.integration.config.TestHandler">
<beans:constructor-arg value="1" />
<beans:property name="replyMessageText" value="foo" />
</beans:bean>
</beans:beans>

View File

@@ -16,26 +16,35 @@
package org.springframework.integration.config;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.handler.ReplyMessageHolder;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Iwein Fuld
*/
@ContextConfiguration
public class ChainParserTests extends AbstractJUnit4SpringContextTests {
@RunWith(SpringJUnit4ClassRunner.class)
public class ChainParserTests {
@Autowired
@Qualifier("filterInput")
@@ -57,6 +66,13 @@ public class ChainParserTests extends AbstractJUnit4SpringContextTests {
@Qualifier("replyOutput")
private PollableChannel replyOutput;
@Autowired
@Qualifier("beanInput")
private MessageChannel beanInput;
public static Message successMessage = MessageBuilder.withPayload("success").build();
@Test
public void chainWithAcceptingFilter() {
@@ -95,5 +111,22 @@ public class ChainParserTests extends AbstractJUnit4SpringContextTests {
assertNotNull(reply);
assertEquals("foo", reply.getPayload());
}
@Test
public void chainHandlerBean() throws Exception {
Message<?> message = MessageBuilder.withPayload("test").build();
this.beanInput.send(message);
Message<?> reply = this.output.receive(3000);
assertNotNull(reply);
assertThat(reply, is(successMessage));
}
public static class StubHandler extends AbstractReplyProducingMessageHandler {
@Override
protected void handleRequestMessage(Message<?> requestMessage, ReplyMessageHolder replyMessageHolder) {
replyMessageHolder.add(successMessage);
}
}
}