INT-3349 BeanFactory Propagation

JIRA: https://jira.spring.io/browse/INT-3349

Several FactoryBeans did not propagate the BeanFactory
to their created object(s). Beans that create messages
must have access to a bean factory to get the
message builder factory.

Fix the FactoryBeans and add a mock FB to all tests that
need one.

Add a runtime environment variable to make any infractions
fatal. This should be set to `true` on CI builds and on
framework developer environments.
This commit is contained in:
Gary Russell
2014-04-01 13:42:29 -04:00
parent 35af66c364
commit 9dee131e3c
62 changed files with 524 additions and 143 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -20,13 +20,13 @@ import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.SmartLifecycle;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter;
import org.springframework.integration.syslog.MessageConverter;
import org.springframework.integration.syslog.inbound.SyslogReceivingChannelAdapterSupport;
import org.springframework.integration.syslog.inbound.TcpSyslogReceivingChannelAdapter;
import org.springframework.integration.syslog.inbound.UdpSyslogReceivingChannelAdapter;
import org.springframework.messaging.MessageChannel;
import org.springframework.util.Assert;
/**
@@ -213,6 +213,9 @@ public class SyslogReceivingChannelAdapterFactoryBean extends AbstractFactoryBea
if (this.beanName != null) {
adapter.setBeanName(this.beanName);
}
if (this.getBeanFactory() != null) {
adapter.setBeanFactory(this.getBeanFactory());
}
adapter.afterPropertiesSet();
this.adapter = adapter;
return adapter;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -40,6 +40,7 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.integration.channel.QueueChannel;
@@ -64,6 +65,7 @@ public class SyslogReceivingChannelAdapterTests {
factory.setPort(port);
PollableChannel outputChannel = new QueueChannel();
factory.setOutputChannel(outputChannel);
factory.setBeanFactory(mock(BeanFactory.class));
factory.afterPropertiesSet();
factory.start();
UdpSyslogReceivingChannelAdapter adapter = (UdpSyslogReceivingChannelAdapter) factory.getObject();
@@ -98,6 +100,7 @@ public class SyslogReceivingChannelAdapterTests {
}
}).when(publisher).publishEvent(any(ApplicationEvent.class));
factory.setApplicationEventPublisher(publisher);
factory.setBeanFactory(mock(BeanFactory.class));
factory.afterPropertiesSet();
factory.start();
TcpSyslogReceivingChannelAdapter adapter = (TcpSyslogReceivingChannelAdapter) factory.getObject();