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-2010 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,6 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -32,13 +33,14 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.jmx.export.MBeanExporter;
|
||||
import org.springframework.jmx.export.notification.NotificationPublisher;
|
||||
import org.springframework.jmx.export.notification.NotificationPublisherAware;
|
||||
import org.springframework.jmx.support.MBeanServerFactoryBean;
|
||||
import org.springframework.jmx.support.ObjectNameManager;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -78,6 +80,7 @@ public class NotificationListeningMessageProducerTests {
|
||||
adapter.setServer(this.server);
|
||||
adapter.setObjectName(this.objectName);
|
||||
adapter.setOutputChannel(outputChannel);
|
||||
adapter.setBeanFactory(mock(BeanFactory.class));
|
||||
adapter.afterPropertiesSet();
|
||||
adapter.start();
|
||||
this.numberHolder.publish("foo");
|
||||
@@ -99,6 +102,7 @@ public class NotificationListeningMessageProducerTests {
|
||||
adapter.setOutputChannel(outputChannel);
|
||||
Integer handback = new Integer(123);
|
||||
adapter.setHandback(handback);
|
||||
adapter.setBeanFactory(mock(BeanFactory.class));
|
||||
adapter.afterPropertiesSet();
|
||||
adapter.start();
|
||||
this.numberHolder.publish("foo");
|
||||
@@ -120,10 +124,12 @@ public class NotificationListeningMessageProducerTests {
|
||||
adapter.setObjectName(this.objectName);
|
||||
adapter.setOutputChannel(outputChannel);
|
||||
adapter.setFilter(new NotificationFilter() {
|
||||
@Override
|
||||
public boolean isNotificationEnabled(Notification notification) {
|
||||
return !notification.getMessage().equals("bad");
|
||||
}
|
||||
});
|
||||
adapter.setBeanFactory(mock(BeanFactory.class));
|
||||
adapter.afterPropertiesSet();
|
||||
adapter.start();
|
||||
this.numberHolder.publish("bad");
|
||||
@@ -154,6 +160,7 @@ public class NotificationListeningMessageProducerTests {
|
||||
this.number.set(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
|
||||
this.notificationPublisher = notificationPublisher;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.jmx;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -30,19 +31,21 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.jmx.config.DynamicRouterTests;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.jmx.support.MBeanServerFactoryBean;
|
||||
import org.springframework.jmx.support.ObjectNameManager;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
|
||||
/**
|
||||
* See DynamicRouterTests for additional tests where the MBean is registered by the Spring exporter.
|
||||
* @see DynamicRouterTests
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*/
|
||||
public class OperationInvokingMessageHandlerTests {
|
||||
@@ -75,6 +78,7 @@ public class OperationInvokingMessageHandlerTests {
|
||||
handler.setObjectName(this.objectName);
|
||||
handler.setOutputChannel(outputChannel);
|
||||
handler.setOperationName("x");
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("p1", "foo");
|
||||
@@ -94,6 +98,7 @@ public class OperationInvokingMessageHandlerTests {
|
||||
handler.setObjectName(this.objectName);
|
||||
handler.setOutputChannel(outputChannel);
|
||||
handler.setOperationName("y");
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Message<?> message = MessageBuilder.withPayload("foo").build();
|
||||
handler.handleMessage(message);
|
||||
@@ -107,6 +112,7 @@ public class OperationInvokingMessageHandlerTests {
|
||||
handler.setObjectName(this.objectName);
|
||||
handler.setOutputChannel(outputChannel);
|
||||
handler.setOperationName("x");
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("p1", "foo");
|
||||
@@ -125,6 +131,7 @@ public class OperationInvokingMessageHandlerTests {
|
||||
handler.setObjectName(this.objectName);
|
||||
handler.setOutputChannel(outputChannel);
|
||||
handler.setOperationName("x");
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
List<Object> params = Arrays.asList(new Object[] { "foo", new Integer(123) });
|
||||
Message<?> message = MessageBuilder.withPayload(params).build();
|
||||
@@ -146,14 +153,17 @@ public class OperationInvokingMessageHandlerTests {
|
||||
|
||||
public static class TestOps implements TestOpsMBean {
|
||||
|
||||
@Override
|
||||
public String x(String s1, String s2) {
|
||||
return s1 + s2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String x(String s, Integer i) {
|
||||
return s + i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void y(String s){}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user