IN PROGRESS - issue INT-662: ChannelResolver not initialized in Splitter

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

Added test to SplitterIntegrationTests instead of duplicating context, thanks Alex for the patch
This commit is contained in:
Iwein Fuld
2009-06-11 11:11:33 +00:00
parent d832b954ac
commit 370158155d
2 changed files with 31 additions and 4 deletions

View File

@@ -16,6 +16,9 @@
package org.springframework.integration.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
@@ -26,8 +29,9 @@ import org.springframework.util.Assert;
* Base class for FactoryBeans that create MessageHandler instances.
*
* @author Mark Fisher
* @author Alexander Peters
*/
public abstract class AbstractMessageHandlerFactoryBean implements FactoryBean {
public abstract class AbstractMessageHandlerFactoryBean implements FactoryBean, BeanFactoryAware {
private volatile MessageHandler handler;
@@ -41,6 +45,8 @@ public abstract class AbstractMessageHandlerFactoryBean implements FactoryBean {
private final Object initializationMonitor = new Object();
private BeanFactory beanFactory;
public void setTargetObject(Object targetObject) {
this.targetObject = targetObject;
@@ -53,14 +59,21 @@ public abstract class AbstractMessageHandlerFactoryBean implements FactoryBean {
public void setOutputChannel(MessageChannel outputChannel) {
this.outputChannel = outputChannel;
}
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
public Object getObject() throws Exception {
if (this.handler == null) {
this.initializeHandler();
Assert.notNull(this.handler, "failed to create MessageHandler");
if (this.outputChannel != null
&& this.handler instanceof AbstractReplyProducingMessageHandler) {
((AbstractReplyProducingMessageHandler) this.handler).setOutputChannel(this.outputChannel);
if (this.handler instanceof AbstractReplyProducingMessageHandler) {
AbstractReplyProducingMessageHandler abstractHandler = (AbstractReplyProducingMessageHandler) this.handler;
if(this.outputChannel != null){
abstractHandler.setOutputChannel(this.outputChannel);
}
abstractHandler.setBeanFactory(beanFactory);
}
}
return this.handler;

View File

@@ -30,13 +30,16 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.Splitter;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Iwein Fuld
* @author Alexander Peters
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -53,6 +56,9 @@ public class SplitterIntegrationTests {
@Autowired
@Qualifier("inDefault")
MessageChannel inDefault;
@Autowired
MethodInvokingSplitter splitter;
private String sentence = "The quick brown fox jumped over the lazy dog";
@@ -107,5 +113,13 @@ public class SplitterIntegrationTests {
assertTrue(receiver.receivedWords.containsAll(words));
assertTrue(words.containsAll(receiver.receivedWords));
}
@Test
public void channelResolver_isNotNull() throws Exception {
splitter.setOutputChannel(null);
Message<String> message = MessageBuilder.withPayload("fooBar")
.setReplyChannelName("out").build();
inMethodInvoking.send(message);
}
}