@@ -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.
|
||||
@@ -22,6 +22,7 @@ import javax.management.ObjectName;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
@@ -51,12 +52,14 @@ public abstract class AbstractMBeanServerTests {
|
||||
|
||||
protected MBeanServer server;
|
||||
|
||||
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
this.server = MBeanServerFactory.createMBeanServer();
|
||||
try {
|
||||
onSetUp();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
releaseServer();
|
||||
throw ex;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -21,7 +21,6 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.management.Attribute;
|
||||
import javax.management.InstanceNotFoundException;
|
||||
import javax.management.JMException;
|
||||
@@ -34,6 +33,7 @@ import javax.management.ObjectName;
|
||||
import javax.management.modelmbean.ModelMBeanInfo;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
@@ -68,25 +68,10 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
|
||||
private static final String OBJECT_NAME = "spring:test=jmxMBeanAdaptor";
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testRegisterNonNotificationListenerType() throws Exception {
|
||||
Map listeners = new HashMap();
|
||||
// put a non-NotificationListener instance in as a value...
|
||||
listeners.put("*", this);
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
try {
|
||||
exporter.setNotificationListenerMappings(listeners);
|
||||
fail("Must have thrown a ClassCastException when registering a non-NotificationListener instance as a NotificationListener.");
|
||||
}
|
||||
catch (ClassCastException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testRegisterNullNotificationListenerType() throws Exception {
|
||||
Map listeners = new HashMap();
|
||||
Map<String, NotificationListener> listeners = new HashMap<String, NotificationListener>();
|
||||
// put null in as a value...
|
||||
listeners.put("*", null);
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
@@ -98,10 +83,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testRegisterNotificationListenerForNonExistentMBean() throws Exception {
|
||||
Map listeners = new HashMap();
|
||||
Map<String, NotificationListener> listeners = new HashMap<String, NotificationListener>();
|
||||
NotificationListener dummyListener = new NotificationListener() {
|
||||
@Override
|
||||
public void handleNotification(Notification notification, Object handback) {
|
||||
@@ -175,7 +159,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
assertNotNull(instance);
|
||||
instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true"));
|
||||
assertNotNull(instance);
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
bf.destroySingletons();
|
||||
}
|
||||
}
|
||||
@@ -193,9 +178,11 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
try {
|
||||
server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false"));
|
||||
fail("MBean with name spring:mbean=false should have been excluded");
|
||||
} catch (InstanceNotFoundException expected) {
|
||||
}
|
||||
} finally {
|
||||
catch (InstanceNotFoundException expected) {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
bf.destroySingletons();
|
||||
}
|
||||
}
|
||||
@@ -217,7 +204,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
assertNotNull(server.getObjectInstance(oname));
|
||||
name = (String) server.getAttribute(oname, "Name");
|
||||
assertEquals("Invalid name returned", "Juergen Hoeller", name);
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
bf.destroySingletons();
|
||||
}
|
||||
}
|
||||
@@ -228,7 +216,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectNoMBeans.xml", getClass()));
|
||||
try {
|
||||
bf.getBean("exporter");
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
bf.destroySingletons();
|
||||
}
|
||||
}
|
||||
@@ -241,7 +230,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
MBeanExporter exporter = new MBeanExporter();
|
||||
exporter.setBeans(getBeanMap());
|
||||
exporter.setServer(server);
|
||||
exporter.setListeners(new MBeanExporterListener[] { listener1, listener2 });
|
||||
exporter.setListeners(listener1, listener2);
|
||||
exporter.afterPropertiesSet();
|
||||
exporter.destroy();
|
||||
|
||||
@@ -257,7 +246,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
ProxyFactory factory = new ProxyFactory();
|
||||
factory.setTarget(bean);
|
||||
factory.addAdvice(new NopInterceptor());
|
||||
factory.setInterfaces(new Class<?>[] { IJmxTestBean.class });
|
||||
factory.setInterfaces(IJmxTestBean.class);
|
||||
|
||||
IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
|
||||
String name = "bean:mmm=whatever";
|
||||
@@ -377,8 +366,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
|
||||
assertIsRegistered("Bean instance not registered", objectName);
|
||||
|
||||
Object result = server.invoke(objectName, "add", new Object[] { new Integer(2), new Integer(3) }, new String[] {
|
||||
int.class.getName(), int.class.getName() });
|
||||
Object result = server.invoke(objectName, "add", new Object[] {new Integer(2), new Integer(3)}, new String[] {
|
||||
int.class.getName(), int.class.getName()});
|
||||
|
||||
assertEquals("Incorrect result return from add", result, new Integer(5));
|
||||
assertEquals("Incorrect attribute value", name, server.getAttribute(objectName, "Name"));
|
||||
@@ -593,7 +582,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
exporter.setBeans(getBeanMap());
|
||||
exporter.setServer(this.server);
|
||||
MockMBeanExporterListener listener = new MockMBeanExporterListener();
|
||||
exporter.setListeners(new MBeanExporterListener[] { listener });
|
||||
exporter.setListeners(listener);
|
||||
exporter.afterPropertiesSet();
|
||||
assertIsRegistered("The bean was not registered with the MBeanServer",
|
||||
ObjectNameManager.getInstance(OBJECT_NAME));
|
||||
@@ -702,6 +691,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
assertEquals("Incorrect ObjectName in unregister", desired, listener.getUnregistered().get(0));
|
||||
}
|
||||
|
||||
|
||||
private static class InvokeDetectAssembler implements MBeanInfoAssembler {
|
||||
|
||||
private boolean invoked = false;
|
||||
@@ -713,6 +703,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class MockMBeanExporterListener implements MBeanExporterListener {
|
||||
|
||||
private List<ObjectName> registered = new ArrayList<ObjectName>();
|
||||
@@ -738,6 +729,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class SelfNamingTestBean implements SelfNaming {
|
||||
|
||||
private ObjectName objectName;
|
||||
@@ -752,11 +744,13 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static interface PersonMBean {
|
||||
|
||||
String getName();
|
||||
}
|
||||
|
||||
|
||||
public static class Person implements PersonMBean {
|
||||
|
||||
private String name;
|
||||
@@ -771,6 +765,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class StubNotificationListener implements NotificationListener {
|
||||
|
||||
private List<Notification> notifications = new ArrayList<Notification>();
|
||||
@@ -785,6 +780,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class RuntimeExceptionThrowingConstructorBean {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -793,6 +789,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final class NamedBeanAutodetectCapableMBeanInfoAssemblerStub extends
|
||||
SimpleReflectiveMBeanInfoAssembler implements AutodetectCapableMBeanInfoAssembler {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user