INT-2275: any outbound-channel-adapter in <chain>

Add re-init logic for nested chains
Add logic about nested element for AbstractChannelAdapterParser
Refactor of DefaultOutboundChannelAdapterParser
Test for non-last nested chain with some outbound-channel-adapter
Improve XSD for chain-type
Manual outbound-channel-adapter ability for chain
Integration tests for all outbound-channel-adapter within <chain>
Remove redundant 'return-value-required' attribute from <stored-proc-outbound-channel-adapter>
Add support 'expectReply' for FileWritingMessageHandler

INT-2275 polishing & refactor FileOutbound*Parser

HttpRequestExecutingMessageHandlerTests polishing

INT-2275: polishing JavaDoc
This commit is contained in:
Artem Bilan
2012-01-03 23:26:16 +02:00
committed by Oleg Zhurakousky
parent 4d5b8d5be1
commit 45c429ee2b
58 changed files with 1302 additions and 318 deletions

View File

@@ -96,6 +96,17 @@
<service-activator ref="testHandler" />
</chain>
<chain input-channel="outboundChannelAdapterChannel">
<outbound-channel-adapter ref="testConsumer"/>
</chain>
<chain input-channel="loggingChannelAdapterChannel">
<transformer expression="payload.toUpperCase()"/>
<logging-channel-adapter level="WARN"/>
</chain>
<beans:bean id="testConsumer" class="org.springframework.integration.config.TestConsumer" />
<channel id="strings">
<queue/>
</channel>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 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.
@@ -16,22 +16,17 @@
package org.springframework.integration.config;
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 java.util.List;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
@@ -43,6 +38,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.matchers.JUnitMatchers.both;
import static org.junit.matchers.JUnitMatchers.containsString;
/**
* @author Mark Fisher
* @author Iwein Fuld
@@ -94,9 +98,19 @@ public class ChainParserTests {
@Autowired
private MessageChannel headerValueRouterWithMappingInput;
@Autowired
private MessageChannel loggingChannelAdapterChannel;
@Autowired
private MessageChannel outboundChannelAdapterChannel;
@Autowired
private TestConsumer testConsumer;
@Autowired
@Qualifier("claimCheckInput")
private MessageChannel claimCheckInput;
@Autowired
@Qualifier("claimCheckOutput")
private PollableChannel claimCheckOutput;
@@ -241,6 +255,40 @@ public class ChainParserTests {
assertEquals(message.getPayload(), reply.getPayload());
}
@Test //INT-2275
public void chainWithOutboundChannelAdapter() {
this.outboundChannelAdapterChannel.send(successMessage);
assertSame(successMessage, testConsumer.getLastMessage());
}
@Test //INT-2275
public void chainWithLoggingChannelAdapter() {
Message<?> message = MessageBuilder.withPayload("test").build();
PrintStream realOut = System.out;
try {
OutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
this.loggingChannelAdapterChannel.send(message);
assertEquals("LoggingHandler: TEST", out.toString().trim());
}
finally {
System.setOut(realOut);
}
}
@Test(expected = BeanCreationException.class) //INT-2275
public void invalidNestedChainWithLoggingChannelAdapter() {
try {
new ClassPathXmlApplicationContext("invalidNestedChainWithOutboundChannelAdapter-context.xml", this.getClass());
fail("BeanCreationException is expected!");
}
catch (BeansException e) {
assertEquals(IllegalArgumentException.class, e.getCause().getClass());
assertThat(e.getMessage(), both(containsString("output channel was provided")).and(containsString("does not implement the MessageProducer")));
throw e;
}
}
public static class StubHandler extends AbstractReplyProducingMessageHandler {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {

View File

@@ -0,0 +1,17 @@
<?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">
<chain input-channel="invalidNestedChain">
<chain>
<logging-channel-adapter/>
</chain>
<logging-channel-adapter/>
</chain>
</beans:beans>

View File

@@ -13,16 +13,22 @@
<queue capacity="2"/>
</channel>
<channel id="channelC"/>
<outbound-channel-adapter id="adapter" channel="channel" ref="bean" method="out" order="99" auto-startup="false"/>
<beans:bean id="bean"
class="org.springframework.integration.config.xml.MethodInvokingOutboundChannelAdapterParserTests$TestBean"/>
class="org.springframework.integration.config.xml.DefaultOutboundChannelAdapterParserTests$TestBean"/>
<outbound-channel-adapter id="adapterB" channel="channelB" method="out" order="99" auto-startup="false">
<beans:bean class="org.springframework.integration.config.xml.MethodInvokingOutboundChannelAdapterParserTests$TestBean"/>
<beans:bean class="org.springframework.integration.config.xml.DefaultOutboundChannelAdapterParserTests$TestBean"/>
<poller task-executor="executor" max-messages-per-poll="5" fixed-delay="20" />
</outbound-channel-adapter>
<task:executor id="executor" pool-size="5" />
<outbound-channel-adapter id="adapterC" channel="channelC" order="99">
<beans:bean class="org.springframework.integration.config.TestConsumer"/>
</outbound-channel-adapter>
</beans:beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2012 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.
@@ -25,6 +25,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.config.TestConsumer;
import org.springframework.integration.handler.MethodInvokingMessageHandler;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
@@ -32,10 +33,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class MethodInvokingOutboundChannelAdapterParserTests {
public class DefaultOutboundChannelAdapterParserTests {
@Autowired
private ApplicationContext context;
@@ -44,21 +46,29 @@ public class MethodInvokingOutboundChannelAdapterParserTests {
@Test
public void checkConfig() {
Object adapter = context.getBean("adapter");
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(adapter, "autoStartup"));
Object handler = TestUtils.getPropertyValue(adapter, "handler");
assertEquals(MethodInvokingMessageHandler.class, handler.getClass());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
assertEquals(99, handlerAccessor.getPropertyValue("order"));
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(adapter, "autoStartup"));
assertEquals(99, TestUtils.getPropertyValue(handler, "order"));
}
@Test
public void checkConfigWithInnerBeanAndPoller() {
Object adapter = context.getBean("adapterB");
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(adapter, "autoStartup"));
Object handler = TestUtils.getPropertyValue(adapter, "handler");
assertEquals(MethodInvokingMessageHandler.class, handler.getClass());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
assertEquals(99, handlerAccessor.getPropertyValue("order"));
assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(adapter, "autoStartup"));
assertEquals(99, TestUtils.getPropertyValue(handler, "order"));
}
@Test
public void checkConfigWithInnerMessageHandler() {
Object adapter = context.getBean("adapterC");
Object handler = TestUtils.getPropertyValue(adapter, "handler");
assertEquals(MethodInvokingMessageHandler.class, handler.getClass());
assertEquals(99, TestUtils.getPropertyValue(handler, "order"));
Object targetObject = TestUtils.getPropertyValue(handler, "processor.delegate.targetObject");
assertEquals(TestConsumer.class, targetObject.getClass());
}
@@ -68,4 +78,5 @@ public class MethodInvokingOutboundChannelAdapterParserTests {
}
}
}