INT-1906
fix & refactor DefaultInboundChannelAdapterParser, plus some improvements
This commit is contained in:
@@ -1,46 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?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: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.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<channel id="queueChannel">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<channel id="queueChannelForHeadersTest">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<outbound-channel-adapter id="outboundWithImplicitChannel" ref="consumer"/>
|
||||
|
||||
<outbound-channel-adapter id="methodInvokingConsumer" ref="testBean" method="store"/>
|
||||
|
||||
<inbound-channel-adapter id="methodInvokingSource" ref="testBean" method="getMessage"
|
||||
channel="queueChannel" auto-startup="false">
|
||||
<poller max-messages-per-poll="1" fixed-delay="10000"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<channel id="withTimeoutChannel">
|
||||
<queue/>
|
||||
</channel>
|
||||
<inbound-channel-adapter id="methodInvokingSourceWithTimeout" ref="testBean" method="getMessage"
|
||||
channel="withTimeoutChannel" auto-startup="false"
|
||||
send-timeout="999">
|
||||
<poller max-messages-per-poll="1" fixed-rate="800"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<inbound-channel-adapter id="methodInvokingSourceWithHeaders" ref="testBean" method="getMessage" channel="queueChannelForHeadersTest" auto-startup="false">
|
||||
<poller max-messages-per-poll="1" fixed-delay="10000"/>
|
||||
<header name="foo" value="ABC"/>
|
||||
<header name="bar" expression="new Integer(123)"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<beans:bean id="consumer" class="org.springframework.integration.config.TestConsumer"/>
|
||||
|
||||
<beans:bean id="testBean" class="org.springframework.integration.config.TestBean"/>
|
||||
<channel id="queueChannel">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
</beans:beans>
|
||||
<channel id="queueChannelForHeadersTest">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<outbound-channel-adapter id="outboundWithImplicitChannel" ref="consumer"/>
|
||||
|
||||
<outbound-channel-adapter id="methodInvokingConsumer" ref="testBean" method="store"/>
|
||||
|
||||
<outbound-channel-adapter id="expressionConsumer" expression="@testBean.store(payload)"/>
|
||||
|
||||
<inbound-channel-adapter id="methodInvokingSource" ref="testBean" method="getMessage"
|
||||
channel="queueChannel" auto-startup="false">
|
||||
<poller max-messages-per-poll="1" fixed-delay="10000"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<channel id="withTimeoutChannel">
|
||||
<queue/>
|
||||
</channel>
|
||||
<inbound-channel-adapter id="methodInvokingSourceWithTimeout" ref="testBean" method="getMessage"
|
||||
channel="withTimeoutChannel" auto-startup="false"
|
||||
send-timeout="999">
|
||||
<poller max-messages-per-poll="1" fixed-rate="800"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<inbound-channel-adapter id="methodInvokingSourceWithHeaders" ref="testBean" method="getMessage" channel="queueChannelForHeadersTest" auto-startup="false">
|
||||
<poller max-messages-per-poll="1" fixed-delay="10000"/>
|
||||
<header name="foo" value="ABC"/>
|
||||
<header name="bar" expression="new Integer(123)"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
<beans:bean id="consumer" class="org.springframework.integration.config.TestConsumer"/>
|
||||
|
||||
<beans:bean id="testBean" class="org.springframework.integration.config.TestBean"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -23,13 +23,16 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
@@ -41,6 +44,7 @@ import org.springframework.integration.test.util.TestUtils;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class ChannelAdapterParserTests {
|
||||
|
||||
@@ -134,6 +138,27 @@ public class ChannelAdapterParserTests {
|
||||
assertEquals("consumer test", testBean.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* @since 2.1
|
||||
*/
|
||||
public void expressionConsumer() {
|
||||
String beanName = "expressionConsumer";
|
||||
Object channel = this.applicationContext.getBean(beanName);
|
||||
assertTrue(channel instanceof DirectChannel);
|
||||
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
|
||||
assertNotNull(channelResolver.resolveChannelName(beanName));
|
||||
Object adapter = this.applicationContext.getBean(beanName + ".adapter");
|
||||
assertNotNull(adapter);
|
||||
assertTrue(adapter instanceof EventDrivenConsumer);
|
||||
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
|
||||
assertNull(testBean.getMessage());
|
||||
Message<?> message = new GenericMessage<String>("consumer test expression");
|
||||
assertTrue(((MessageChannel) channel).send(message));
|
||||
assertNotNull(testBean.getMessage());
|
||||
assertEquals("consumer test expression", testBean.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodInvokingSource() {
|
||||
String beanName = "methodInvokingSource";
|
||||
@@ -221,19 +246,24 @@ public class ChannelAdapterParserTests {
|
||||
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
|
||||
channelResolver.resolveChannelName("methodInvokingSource");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void methodInvokingSourceWithSendTimeout() throws Exception{
|
||||
public void methodInvokingSourceWithSendTimeout() throws Exception {
|
||||
String beanName = "methodInvokingSourceWithTimeout";
|
||||
|
||||
SourcePollingChannelAdapter adapter =
|
||||
this.applicationContext.getBean(beanName, SourcePollingChannelAdapter.class);
|
||||
|
||||
SourcePollingChannelAdapter adapter =
|
||||
this.applicationContext.getBean(beanName, SourcePollingChannelAdapter.class);
|
||||
assertNotNull(adapter);
|
||||
long sendTimeout = TestUtils.getPropertyValue(adapter, "messagingTemplate.sendTimeout", Long.class);
|
||||
assertEquals(999, sendTimeout);
|
||||
}
|
||||
|
||||
public static class SampleBean{
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
public void innerBeanAndExpressionFail() throws Exception {
|
||||
new ClassPathXmlApplicationContext("InboundChannelAdapterInnerBeanWithExpression-fail-context.xml", this.getClass());
|
||||
}
|
||||
|
||||
public static class SampleBean {
|
||||
private String message = "hello";
|
||||
|
||||
String getMessage() {
|
||||
@@ -241,3 +271,4 @@ public class ChannelAdapterParserTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?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.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<channel id="channel"/>
|
||||
|
||||
<inbound-channel-adapter id="pojoWithExpression" expression="'test'" method="getMessage"
|
||||
channel="channel">
|
||||
<poller fixed-delay="1234"/>
|
||||
<beans:bean class="org.springframework.integration.config.ChannelAdapterParserTests$SampleBean"/>
|
||||
</inbound-channel-adapter>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user