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:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user