|
|
|
@ -39,8 +39,10 @@ import org.junit.Test; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.FactoryBean; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
|
|
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
|
|
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
|
|
import org.springframework.context.ConfigurableApplicationContext; |
|
|
|
import org.springframework.context.ConfigurableApplicationContext; |
|
|
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|
|
|
import org.springframework.context.support.ClassPathXmlApplicationContext; |
|
|
|
import org.springframework.jmx.AbstractMBeanServerTests; |
|
|
|
import org.springframework.jmx.AbstractMBeanServerTests; |
|
|
|
@ -68,7 +70,6 @@ import static org.junit.Assert.*; |
|
|
|
* @author Sam Brannen |
|
|
|
* @author Sam Brannen |
|
|
|
* @author Stephane Nicoll |
|
|
|
* @author Stephane Nicoll |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
|
|
|
|
public class MBeanExporterTests extends AbstractMBeanServerTests { |
|
|
|
public class MBeanExporterTests extends AbstractMBeanServerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Rule |
|
|
|
@Rule |
|
|
|
@ -235,7 +236,6 @@ public class MBeanExporterTests extends AbstractMBeanServerTests { |
|
|
|
assertListener(listener2); |
|
|
|
assertListener(listener2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testExportJdkProxy() throws Exception { |
|
|
|
public void testExportJdkProxy() throws Exception { |
|
|
|
JmxTestBean bean = new JmxTestBean(); |
|
|
|
JmxTestBean bean = new JmxTestBean(); |
|
|
|
@ -541,10 +541,7 @@ public class MBeanExporterTests extends AbstractMBeanServerTests { |
|
|
|
start(exporter); |
|
|
|
start(exporter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Test // SPR-2158
|
|
|
|
* SPR-2158 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testMBeanIsNotUnregisteredSpuriouslyIfSomeExternalProcessHasUnregisteredMBean() throws Exception { |
|
|
|
public void testMBeanIsNotUnregisteredSpuriouslyIfSomeExternalProcessHasUnregisteredMBean() throws Exception { |
|
|
|
MBeanExporter exporter = new MBeanExporter(); |
|
|
|
MBeanExporter exporter = new MBeanExporter(); |
|
|
|
exporter.setBeans(getBeanMap()); |
|
|
|
exporter.setBeans(getBeanMap()); |
|
|
|
@ -561,10 +558,7 @@ public class MBeanExporterTests extends AbstractMBeanServerTests { |
|
|
|
listener.getUnregistered().size()); |
|
|
|
listener.getUnregistered().size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@Test // SPR-3302
|
|
|
|
* SPR-3302 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testBeanNameCanBeUsedInNotificationListenersMap() throws Exception { |
|
|
|
public void testBeanNameCanBeUsedInNotificationListenersMap() throws Exception { |
|
|
|
String beanName = "charlesDexterWard"; |
|
|
|
String beanName = "charlesDexterWard"; |
|
|
|
BeanDefinitionBuilder testBean = BeanDefinitionBuilder.rootBeanDefinition(JmxTestBean.class); |
|
|
|
BeanDefinitionBuilder testBean = BeanDefinitionBuilder.rootBeanDefinition(JmxTestBean.class); |
|
|
|
@ -608,10 +602,7 @@ public class MBeanExporterTests extends AbstractMBeanServerTests { |
|
|
|
start(exporter); |
|
|
|
start(exporter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
@Test // SPR-3625
|
|
|
|
* SPR-3625 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testMBeanIsUnregisteredForRuntimeExceptionDuringInitialization() throws Exception { |
|
|
|
public void testMBeanIsUnregisteredForRuntimeExceptionDuringInitialization() throws Exception { |
|
|
|
BeanDefinitionBuilder builder1 = BeanDefinitionBuilder.rootBeanDefinition(Person.class); |
|
|
|
BeanDefinitionBuilder builder1 = BeanDefinitionBuilder.rootBeanDefinition(Person.class); |
|
|
|
BeanDefinitionBuilder builder2 = BeanDefinitionBuilder |
|
|
|
BeanDefinitionBuilder builder2 = BeanDefinitionBuilder |
|
|
|
@ -667,6 +658,37 @@ public class MBeanExporterTests extends AbstractMBeanServerTests { |
|
|
|
ObjectNameManager.getInstance(secondBeanName)); |
|
|
|
ObjectNameManager.getInstance(secondBeanName)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testRegisterFactoryBean() throws MalformedObjectNameException { |
|
|
|
|
|
|
|
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); |
|
|
|
|
|
|
|
factory.registerBeanDefinition("spring:type=FactoryBean", new RootBeanDefinition(ProperSomethingFactoryBean.class)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MBeanExporter exporter = new MBeanExporter(); |
|
|
|
|
|
|
|
exporter.setServer(getServer()); |
|
|
|
|
|
|
|
exporter.setBeanFactory(factory); |
|
|
|
|
|
|
|
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start(exporter); |
|
|
|
|
|
|
|
assertIsRegistered("Non-null FactoryBean object registered", |
|
|
|
|
|
|
|
ObjectNameManager.getInstance("spring:type=FactoryBean")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testIgnoreNullObjectFromFactoryBean() throws MalformedObjectNameException { |
|
|
|
|
|
|
|
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); |
|
|
|
|
|
|
|
factory.registerBeanDefinition("spring:type=FactoryBean", new RootBeanDefinition(NullSomethingFactoryBean.class)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MBeanExporter exporter = new MBeanExporter(); |
|
|
|
|
|
|
|
exporter.setServer(getServer()); |
|
|
|
|
|
|
|
exporter.setBeanFactory(factory); |
|
|
|
|
|
|
|
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start(exporter); |
|
|
|
|
|
|
|
assertIsNotRegistered("Null FactoryBean object not registered", |
|
|
|
|
|
|
|
ObjectNameManager.getInstance("spring:type=FactoryBean")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ConfigurableApplicationContext load(String context) { |
|
|
|
private ConfigurableApplicationContext load(String context) { |
|
|
|
return new ClassPathXmlApplicationContext(context, getClass()); |
|
|
|
return new ClassPathXmlApplicationContext(context, getClass()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -799,4 +821,41 @@ public class MBeanExporterTests extends AbstractMBeanServerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface SomethingMBean {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class Something implements SomethingMBean {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class ProperSomethingFactoryBean implements FactoryBean<Something> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public Something getObject() { |
|
|
|
|
|
|
|
return new Something(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public Class<?> getObjectType() { |
|
|
|
|
|
|
|
return Something.class; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public boolean isSingleton() { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class NullSomethingFactoryBean implements FactoryBean<Something> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public Something getObject() { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public Class<?> getObjectType() { |
|
|
|
|
|
|
|
return Something.class; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public boolean isSingleton() { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|