[SPR-8089] cleaning up ignored and broken JMX tests; suppressing warnings; using generics where feasible; documented the jmxremote_optional.jar requirement in AbstractMBeanServerTests.

This commit is contained in:
Sam Brannen 2011-03-28 17:57:01 +00:00
parent 726564c84d
commit 71d70a6e06
9 changed files with 203 additions and 220 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2011 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.
@ -27,8 +27,18 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
/**
* <strong>Note:</strong> the JMX test suite requires the presence of the
* <code>jmxremote_optional.jar</code> in your classpath. Thus, if you
* run into the <em>"Unsupported protocol: jmxmp"</em> error, you will
* need to download the
* <a href="http://www.oracle.com/technetwork/java/javase/tech/download-jsp-141676.html">JMX Remote API 1.0.1_04 Reference Implementation</a>
* from Oracle and extract <code>jmxremote_optional.jar</code> into your
* classpath, for example in the <code>lib/ext</code> folder of your JVM.
* See also <a href="https://issuetracker.springsource.com/browse/EBR-349">EBR-349</a>.
*
* @author Rob Harrop
* @author Juergen Hoeller
* @author Sam Brannen
*/
public abstract class AbstractMBeanServerTests extends TestCase {
@ -38,8 +48,7 @@ public abstract class AbstractMBeanServerTests extends TestCase {
this.server = MBeanServerFactory.createMBeanServer();
try {
onSetUp();
}
catch (Exception ex) {
} catch (Exception ex) {
releaseServer();
throw ex;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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. You may obtain a copy of
@ -19,9 +19,6 @@ package org.springframework.jmx.access;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.management.MemoryMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.net.BindException;
import java.util.HashMap;
import java.util.Map;
@ -32,28 +29,24 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.Ignore;
import org.springframework.jmx.AbstractMBeanServerTests;
import org.springframework.jmx.IJmxTestBean;
import org.springframework.jmx.JmxException;
import org.springframework.jmx.JmxTestBean;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.jmx.export.assembler.AbstractReflectiveMBeanInfoAssembler;
import org.springframework.aop.framework.ProxyFactory;
import com.sun.management.HotSpotDiagnosticMXBean;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Sam Brannen
*/
//@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
protected static final String OBJECT_NAME = "spring:test=proxy";
protected JmxTestBean target;
protected boolean runTests = true;
public void onSetUp() throws Exception {
@ -62,7 +55,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
target.setName("Rob Harrop");
MBeanExporter adapter = new MBeanExporter();
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(OBJECT_NAME, target);
adapter.setServer(getServer());
adapter.setBeans(beans);
@ -84,14 +77,15 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
}
public void testProxyClassIsDifferent() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy = getProxy();
assertTrue("The proxy class should be different than the base class",
(proxy.getClass() != IJmxTestBean.class));
assertTrue("The proxy class should be different than the base class", (proxy.getClass() != IJmxTestBean.class));
}
public void testDifferentProxiesSameClass() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy1 = getProxy();
IJmxTestBean proxy2 = getProxy();
@ -100,96 +94,100 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
}
public void testGetAttributeValue() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy1 = getProxy();
int age = proxy1.getAge();
assertEquals("The age should be 100", 100, age);
}
public void testSetAttributeValue() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy = getProxy();
proxy.setName("Rob Harrop");
assertEquals("The name of the bean should have been updated", "Rob Harrop", target.getName());
}
public void testSetAttributeValueWithRuntimeException() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy = getProxy();
try {
proxy.setName("Juergen");
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException ex) {
} catch (IllegalArgumentException ex) {
// expected
}
}
public void testSetAttributeValueWithCheckedException() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy = getProxy();
try {
proxy.setName("Juergen Class");
fail("Should have thrown ClassNotFoundException");
}
catch (ClassNotFoundException ex) {
} catch (ClassNotFoundException ex) {
// expected
}
}
public void testSetAttributeValueWithIOException() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy = getProxy();
try {
proxy.setName("Juergen IO");
fail("Should have thrown IOException");
}
catch (IOException ex) {
} catch (IOException ex) {
// expected
}
}
public void testSetReadOnlyAttribute() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy = getProxy();
try {
proxy.setAge(900);
fail("Should not be able to write to a read only attribute");
}
catch (InvalidInvocationException ex) {
} catch (InvalidInvocationException ex) {
// success
}
}
public void testInvokeNoArgs() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy = getProxy();
long result = proxy.myOperation();
assertEquals("The operation should return 1", 1, result);
}
public void testInvokeArgs() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean proxy = getProxy();
int result = proxy.add(1, 2);
assertEquals("The operation should return 3", 3, result);
}
public void testInvokeUnexposedMethodWithException() throws Exception {
if (!runTests) return;
if (!runTests)
return;
IJmxTestBean bean = getProxy();
try {
bean.dontExposeMe();
fail("Method dontExposeMe should throw an exception");
}
catch (InvalidInvocationException desired) {
} catch (InvalidInvocationException desired) {
// success
}
}
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public void ignoreTestLazyConnectionToRemote() throws Exception {
if (!runTests) return;
public void testLazyConnectionToRemote() throws Exception {
if (!runTests)
return;
JMXServiceURL url = new JMXServiceURL("service:jmx:jmxmp://localhost:9876");
JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer());
@ -207,12 +205,10 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
// now start the connector
try {
connector.start();
}
catch (BindException ex) {
} catch (BindException ex) {
// couldn't bind to local port 9876 - let's skip the remainder of this test
System.out.println(
"Skipping JMX LazyConnectionToRemote test because binding to local port 9876 failed: " +
ex.getMessage());
System.out.println("Skipping JMX LazyConnectionToRemote test because binding to local port 9876 failed: "
+ ex.getMessage());
return;
}
@ -220,15 +216,13 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
try {
assertEquals("Rob Harrop", bean.getName());
assertEquals(100, bean.getAge());
}
finally {
} finally {
connector.stop();
}
try {
bean.getName();
}
catch (JmxException ex) {
} catch (JmxException ex) {
// expected
}
@ -239,8 +233,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
try {
assertEquals("Rob Harrop", bean.getName());
assertEquals(100, bean.getAge());
}
finally {
} finally {
connector.stop();
}
}
@ -272,7 +265,6 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
}
*/
private static class ProxyTestAssembler extends AbstractReflectiveMBeanInfoAssembler {
protected boolean includeReadAttribute(Method method, String beanKey) {
@ -293,26 +285,32 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
return true;
}
@SuppressWarnings("unused")
protected String getOperationDescription(Method method) {
return method.getName();
}
@SuppressWarnings("unused")
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) {
return propertyDescriptor.getDisplayName();
}
@SuppressWarnings("unused")
protected void populateAttributeDescriptor(Descriptor descriptor, Method getter, Method setter) {
}
@SuppressWarnings("unused")
protected void populateOperationDescriptor(Descriptor descriptor, Method method) {
}
@SuppressWarnings({ "unused", "rawtypes" })
protected String getDescription(String beanKey, Class beanClass) {
return "";
}
@SuppressWarnings({ "unused", "rawtypes" })
protected void populateMBeanDescriptor(Descriptor mbeanDescriptor, String beanKey, Class beanClass) {
}

View File

@ -26,12 +26,9 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.Ignore;
/**
* @author Rob Harrop
*/
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTests {
private static final String SERVICE_URL = "service:jmx:jmxmp://localhost:9876";

View File

@ -22,13 +22,11 @@ import java.util.Date;
import javax.management.ObjectName;
import org.junit.Ignore;
import org.springframework.jmx.AbstractJmxTests;
/**
* @author Rob Harrop
*/
@Ignore // changes in CustomEditorConfigurer broke these tests (see diff between r304:305)
public class CustomEditorConfigurerTests extends AbstractJmxTests {
private final SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
@ -38,7 +36,7 @@ public class CustomEditorConfigurerTests extends AbstractJmxTests {
}
public void testDatesInJmx() throws Exception {
System.out.println(getServer().getClass().getName());
// System.out.println(getServer().getClass().getName());
ObjectName oname = new ObjectName("bean:name=dateRange");
Date startJmx = (Date) getServer().getAttribute(oname, "StartDate");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2011 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.
@ -59,27 +59,32 @@ import test.interceptor.NopInterceptor;
* @author Rick Evans
* @author Mark Fisher
* @author Chris Beams
* @author Sam Brannen
*/
@SuppressWarnings("deprecation")
public final class MBeanExporterTests extends AbstractMBeanServerTests {
private static final String OBJECT_NAME = "spring:test=jmxMBeanAdaptor";
@Ignore // throwing CCE
public void ignoreTestRegisterNonNotificationListenerType() throws Exception {
@SuppressWarnings({ "rawtypes", "unchecked" })
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 an IllegalArgumentException when registering a non-NotificationListener instance as a NotificationListener.");
}
catch (IllegalArgumentException expected) {
fail("Must have thrown a ClassCastException when registering a non-NotificationListener instance as a NotificationListener.");
} catch (ClassCastException expected) {
}
}
@Ignore // not throwing expected IAE
// Note that @Ignore has no effect for JUnit 3.8 TestCase-based tests,
// we leave it here to allow developers to easily search for ignored
// tests. As a work-around, the method is prefixed with "ignore"
// instead of "test" as required by JUnit 3.x.
@Ignore("NotificationListenerBean constructor does not throw the expected IllegalArgumentException")
@SuppressWarnings({ "rawtypes", "unchecked" })
public void ignoreTestRegisterNullNotificationListenerType() throws Exception {
Map listeners = new HashMap();
// put null in as a value...
@ -88,11 +93,11 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
try {
exporter.setNotificationListenerMappings(listeners);
fail("Must have thrown an IllegalArgumentException when registering a null instance as a NotificationListener.");
}
catch (IllegalArgumentException expected) {
} catch (IllegalArgumentException expected) {
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerForNonExistentMBean() throws Exception {
Map listeners = new HashMap();
NotificationListener dummyListener = new NotificationListener() {
@ -109,8 +114,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
try {
exporter.afterPropertiesSet();
fail("Must have thrown an MBeanExportException when registering a NotificationListener on a non-existent MBean.");
}
catch (MBeanExportException expected) {
} catch (MBeanExportException expected) {
assertTrue(expected.contains(InstanceNotFoundException.class));
}
}
@ -120,7 +124,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setBeans(getBeanMap());
exporter.setServer(server);
exporter.afterPropertiesSet();
assertIsRegistered("The bean was not registered with the MBeanServer", ObjectNameManager.getInstance(OBJECT_NAME));
assertIsRegistered("The bean was not registered with the MBeanServer",
ObjectNameManager.getInstance(OBJECT_NAME));
}
/** Fails if JVM platform MBean server has been started already
@ -134,7 +139,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
*/
public void testUserCreatedMBeanRegWithDynamicMBean() throws Exception {
Map map = new HashMap();
Map<String, Object> map = new HashMap<String, Object>();
map.put("spring:name=dynBean", new TestDynamicMBean());
InvokeDetectAssembler asm = new InvokeDetectAssembler();
@ -161,8 +166,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertNotNull(instance);
instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true"));
assertNotNull(instance);
}
finally {
} finally {
bf.destroySingletons();
}
}
@ -178,11 +182,9 @@ 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) {
}
catch (InstanceNotFoundException expected) {
}
}
finally {
} finally {
bf.destroySingletons();
}
}
@ -202,8 +204,7 @@ 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();
}
}
@ -212,8 +213,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("autodetectNoMBeans.xml", getClass()));
try {
bf.getBean("exporter");
}
finally {
} finally {
bf.destroySingletons();
}
}
@ -225,10 +225,10 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setBeans(getBeanMap());
exporter.setServer(server);
exporter.setListeners(new MBeanExporterListener[] {listener1, listener2});
exporter.setListeners(new MBeanExporterListener[] { listener1, listener2 });
exporter.afterPropertiesSet();
exporter.destroy();
assertListener(listener1);
assertListener(listener2);
}
@ -240,12 +240,12 @@ 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(new Class[] { IJmxTestBean.class });
IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
String name = "bean:mmm=whatever";
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(name, proxy);
MBeanExporter exporter = new MBeanExporter();
@ -263,7 +263,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
SelfNamingTestBean testBean = new SelfNamingTestBean();
testBean.setObjectName(objectName);
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put("foo", testBean);
MBeanExporter exporter = new MBeanExporter();
@ -289,7 +289,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
String objectName2 = "spring:test=equalBean";
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.toString(), springRegistered);
beans.put(objectName2, springRegistered);
@ -320,7 +320,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
Person springRegistered = new Person();
springRegistered.setName("Sally Greenwood");
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.toString(), springRegistered);
MBeanExporter exporter = new MBeanExporter();
@ -345,7 +345,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
bean.setName(name);
ObjectName objectName = ObjectNameManager.getInstance("spring:type=Test");
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.toString(), bean);
MBeanExporter exporter = new MBeanExporter();
@ -356,9 +356,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"));
@ -375,7 +374,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
factory.registerSingleton(exportedBeanName, new TestBean());
MBeanExporter exporter = new MBeanExporter();
Map beansToExport = new HashMap();
Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put(OBJECT_NAME, exportedBeanName);
exporter.setBeans(beansToExport);
exporter.setServer(getServer());
@ -456,7 +455,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
Map beansToExport = new HashMap();
Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put(OBJECT_NAME, OBJECT_NAME);
exporter.setBeans(beansToExport);
exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(OBJECT_NAME));
@ -472,8 +471,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectMode(-1);
fail("Must have failed when supplying an invalid negative out-of-range autodetect mode");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {}
}
public void testSetAutodetectModeToOutOfRangePositiveValue() throws Exception {
@ -481,8 +480,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectMode(5);
fail("Must have failed when supplying an invalid positive out-of-range autodetect mode");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {}
}
public void testSetAutodetectModeNameToNull() throws Exception {
@ -490,8 +489,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectModeName(null);
fail("Must have failed when supplying a null autodetect mode name");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {}
}
public void testSetAutodetectModeNameToAnEmptyString() throws Exception {
@ -499,8 +498,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectModeName("");
fail("Must have failed when supplying an empty autodetect mode name");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {}
}
public void testSetAutodetectModeNameToAWhitespacedString() throws Exception {
@ -508,8 +507,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectModeName(" \t");
fail("Must have failed when supplying a whitespace-only autodetect mode name");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {}
}
public void testSetAutodetectModeNameToARubbishValue() throws Exception {
@ -517,20 +516,20 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectModeName("That Hansel is... *sssooo* hot right now!");
fail("Must have failed when supplying a whitespace-only autodetect mode name");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {}
}
public void testNotRunningInBeanFactoryAndPassedBeanNameToExport() throws Exception {
try {
MBeanExporter exporter = new MBeanExporter();
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(OBJECT_NAME, "beanName");
exporter.setBeans(beans);
exporter.afterPropertiesSet();
fail("Expecting exception because MBeanExporter is not running in a BeanFactory and was passed bean name to (lookup and then) export");
} catch (MBeanExportException expected) {
}
catch (MBeanExportException expected) {}
}
public void testNotRunningInBeanFactoryAndAutodetectionIsOn() throws Exception {
@ -539,8 +538,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL);
exporter.afterPropertiesSet();
fail("Expecting exception because MBeanExporter is not running in a BeanFactory and was configured to autodetect beans");
} catch (MBeanExportException expected) {
}
catch (MBeanExportException expected) {}
}
/**
@ -551,13 +550,15 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setBeans(getBeanMap());
exporter.setServer(this.server);
MockMBeanExporterListener listener = new MockMBeanExporterListener();
exporter.setListeners(new MBeanExporterListener[]{listener});
exporter.setListeners(new MBeanExporterListener[] { listener });
exporter.afterPropertiesSet();
assertIsRegistered("The bean was not registered with the MBeanServer", ObjectNameManager.getInstance(OBJECT_NAME));
assertIsRegistered("The bean was not registered with the MBeanServer",
ObjectNameManager.getInstance(OBJECT_NAME));
this.server.unregisterMBean(new ObjectName(OBJECT_NAME));
exporter.destroy();
assertEquals("Listener should not have been invoked (MBean previously unregistered by external agent)", 0, listener.getUnregistered().size());
assertEquals("Listener should not have been invoked (MBean previously unregistered by external agent)", 0,
listener.getUnregistered().size());
}
/**
@ -574,7 +575,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
Map beansToExport = new HashMap();
Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put("test:what=ever", testBeanInstance);
exporter.setBeans(beansToExport);
exporter.setBeanFactory(factory);
@ -595,7 +596,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
Map beansToExport = new HashMap();
Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put("test:what=ever", testBeanInstance);
exporter.setBeans(beansToExport);
exporter.setBeanFactory(factory);
@ -610,18 +611,19 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
*/
public void testMBeanIsUnregisteredForRuntimeExceptionDuringInitialization() throws Exception {
BeanDefinitionBuilder builder1 = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
BeanDefinitionBuilder builder2 = BeanDefinitionBuilder.rootBeanDefinition(RuntimeExceptionThrowingConstructorBean.class);
BeanDefinitionBuilder builder2 = BeanDefinitionBuilder
.rootBeanDefinition(RuntimeExceptionThrowingConstructorBean.class);
String objectName1 = "spring:test=bean1";
String objectName2 = "spring:test=bean2";
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition(objectName1, builder1.getBeanDefinition());
factory.registerBeanDefinition(objectName2, builder2.getBeanDefinition());
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer());
Map beansToExport = new HashMap();
Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put(objectName1, objectName1);
beansToExport.put(objectName2, objectName2);
exporter.setBeans(beansToExport);
@ -630,8 +632,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
try {
exporter.afterPropertiesSet();
fail("Must have failed during creation of RuntimeExceptionThrowingConstructorBean");
}
catch (RuntimeException expected) {
} catch (RuntimeException expected) {
}
assertIsNotRegistered("Must have unregistered all previously registered MBeans due to RuntimeException",
@ -639,10 +640,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsNotRegistered("Must have never registered this MBean due to RuntimeException",
ObjectNameManager.getInstance(objectName2));
}
private Map getBeanMap() {
Map map = new HashMap();
private Map<String, Object> getBeanMap() {
Map<String, Object> map = new HashMap<String, Object>();
map.put(OBJECT_NAME, new JmxTestBean());
return map;
}
@ -655,7 +655,6 @@ 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;
@ -666,12 +665,11 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
private static class MockMBeanExporterListener implements MBeanExporterListener {
private List registered = new ArrayList();
private List<ObjectName> registered = new ArrayList<ObjectName>();
private List unregistered = new ArrayList();
private List<ObjectName> unregistered = new ArrayList<ObjectName>();
public void mbeanRegistered(ObjectName objectName) {
registered.add(objectName);
@ -681,16 +679,15 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
unregistered.add(objectName);
}
public List getRegistered() {
public List<ObjectName> getRegistered() {
return registered;
}
public List getUnregistered() {
public List<ObjectName> getUnregistered() {
return unregistered;
}
}
private static class SelfNamingTestBean implements SelfNaming {
private ObjectName objectName;
@ -704,13 +701,11 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
public static interface PersonMBean {
String getName();
}
public static class Person implements PersonMBean {
private String name;
@ -724,40 +719,37 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
}
}
public static final class StubNotificationListener implements NotificationListener {
private List notifications = new ArrayList();
private List<Notification> notifications = new ArrayList<Notification>();
public void handleNotification(Notification notification, Object handback) {
this.notifications.add(notification);
}
public List getNotifications() {
public List<Notification> getNotifications() {
return this.notifications;
}
}
private static class RuntimeExceptionThrowingConstructorBean {
@SuppressWarnings("unused")
public RuntimeExceptionThrowingConstructorBean() {
throw new RuntimeException();
}
}
private static final class NamedBeanAutodetectCapableMBeanInfoAssemblerStub extends
SimpleReflectiveMBeanInfoAssembler implements AutodetectCapableMBeanInfoAssembler {
private static final class NamedBeanAutodetectCapableMBeanInfoAssemblerStub
extends SimpleReflectiveMBeanInfoAssembler
implements AutodetectCapableMBeanInfoAssembler {
private String namedBean;
public NamedBeanAutodetectCapableMBeanInfoAssemblerStub(String namedBean) {
this.namedBean = namedBean;
}
public boolean includeBean(Class beanClass, String beanName) {
public boolean includeBean(Class<?> beanClass, String beanName) {
return this.namedBean.equals(beanName);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2011 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.
@ -27,7 +27,6 @@ import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import org.junit.Ignore;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.jmx.AbstractMBeanServerTests;
import org.springframework.jmx.JmxTestBean;
@ -38,16 +37,17 @@ import org.springframework.jmx.support.ObjectNameManager;
/**
* @author Rob Harrop
* @author Mark Fisher
* @author Sam Brannen
*/
@Ignore // Getting CCEs regarding ObjectName being cast to String
public class NotificationListenerTests extends AbstractMBeanServerTests {
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerForMBean() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap();
beans.put(objectName, bean);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -66,12 +66,13 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount(attributeName));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithWildcard() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap();
beans.put(objectName, bean);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -94,7 +95,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
String objectName = "spring:name=Test";
JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName, bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -108,12 +109,13 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.setNotificationListeners(new NotificationListenerBean[]{listenerBean});
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
exporter.afterPropertiesSet();
// update the attribute
String attributeName = "Name";
server.setAttribute(ObjectNameManager.getInstance("spring:name=Test"), new Attribute(attributeName, "Rob Harrop"));
server.setAttribute(ObjectNameManager.getInstance("spring:name=Test"), new Attribute(attributeName,
"Rob Harrop"));
assertEquals("Listener not notified", 1, listener.getCount(attributeName));
assertEquals("Handback object not transmitted correctly", handback, listener.getLastHandback(attributeName));
@ -123,8 +125,8 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap();
beans.put(objectName, bean);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -134,7 +136,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.setNotificationListeners(new NotificationListenerBean[]{listenerBean});
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
exporter.afterPropertiesSet();
// update the attribute
@ -144,12 +146,13 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount(attributeName));
}
@SuppressWarnings("serial")
public void testRegisterNotificationListenerWithFilter() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap();
beans.put(objectName, bean);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -160,8 +163,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
if (notification instanceof AttributeChangeNotification) {
AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
return "Name".equals(changeNotification.getAttributeName());
}
else {
} else {
return false;
}
}
@ -170,7 +172,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.setNotificationListeners(new NotificationListenerBean[]{listenerBean});
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
exporter.afterPropertiesSet();
// update the attributes
@ -188,11 +190,11 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
try {
new NotificationListenerBean().afterPropertiesSet();
fail("Must have thrown an IllegalArgumentException (no NotificationListener supplied)");
}
catch (IllegalArgumentException expected) {
} catch (IllegalArgumentException expected) {
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithBeanNameAndBeanNameInBeansMap() throws Exception {
String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
@ -203,7 +205,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerSingleton(beanName, testBean);
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName, beanName);
Map listenerMappings = new HashMap();
@ -222,6 +224,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount("Age"));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithBeanNameAndBeanInstanceInBeansMap() throws Exception {
String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
@ -232,7 +235,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerSingleton(beanName, testBean);
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName, testBean);
Map listenerMappings = new HashMap();
@ -251,6 +254,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount("Age"));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithBeanNameBeforeObjectNameMappedToSameBeanInstance() throws Exception {
String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
@ -261,7 +265,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerSingleton(beanName, testBean);
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName, testBean);
Map listenerMappings = new HashMap();
@ -281,6 +285,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithObjectNameBeforeBeanNameMappedToSameBeanInstance() throws Exception {
String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
@ -291,7 +296,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerSingleton(beanName, testBean);
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName, testBean);
Map listenerMappings = new HashMap();
@ -311,6 +316,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithTwoBeanNamesMappedToDifferentBeanInstances() throws Exception {
String beanName1 = "testBean1";
String beanName2 = "testBean2";
@ -328,7 +334,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
factory.registerSingleton(beanName1, testBean1);
factory.registerSingleton(beanName2, testBean2);
Map beans = new HashMap();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName1, testBean1);
beans.put(beanName2, testBean2);
@ -357,8 +363,8 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap();
beans.put(objectName, bean);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.getCanonicalName(), bean);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
@ -391,9 +397,9 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
JmxTestBean bean = new JmxTestBean();
JmxTestBean bean2 = new JmxTestBean();
Map beans = new HashMap();
beans.put(objectName, bean);
beans.put(objectName2, bean2);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.getCanonicalName(), bean);
beans.put(objectName2.getCanonicalName(), bean2);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
@ -406,7 +412,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
registrar.setServer(server);
registrar.setNotificationListener(listener);
//registrar.setMappedObjectNames(new Object[] {objectName, objectName2});
registrar.setMappedObjectNames(new String[] {"spring:name=Test", "spring:name=Test2"});
registrar.setMappedObjectNames(new String[] { "spring:name=Test", "spring:name=Test2" });
registrar.afterPropertiesSet();
// update the attribute
@ -421,7 +427,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private static class CountingAttributeChangeNotificationListener implements NotificationListener {
private Map attributeCounts = new HashMap();
@ -438,8 +444,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
if (currentCount != null) {
int count = currentCount.intValue() + 1;
this.attributeCounts.put(attributeName, new Integer(count));
}
else {
} else {
this.attributeCounts.put(attributeName, new Integer(1));
}
@ -457,7 +462,6 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
}
}
public static class SelfNamingTestBean implements SelfNaming {
private ObjectName objectName;

View File

@ -48,11 +48,11 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
private CountingNotificationListener listener = new CountingNotificationListener();
public void testSimpleBean() throws Exception {
// start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherTests.xml");
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=Publisher"), listener, null, null);
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=Publisher"), listener, null,
null);
MyNotificationPublisher publisher = (MyNotificationPublisher) ctx.getBean("publisher");
assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher());
@ -66,7 +66,8 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
MBeanExporter exporter = (MBeanExporter) ctx.getBean("exporter");
MyNotificationPublisher publisher = new MyNotificationPublisher();
exporter.registerManagedResource(publisher, ObjectNameManager.getInstance("spring:type=Publisher2"));
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=Publisher2"), listener, null, null);
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=Publisher2"), listener, null,
null);
assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher());
publisher.sendNotification();
@ -76,7 +77,8 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
public void testMBean() throws Exception {
// start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherTests.xml");
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=PublisherMBean"), listener, null, null);
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=PublisherMBean"), listener,
null, null);
MyNotificationPublisherMBean publisher = (MyNotificationPublisherMBean) ctx.getBean("publisherMBean");
publisher.sendNotification();
@ -102,7 +104,8 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
// need to touch the MBean proxy
server.getAttribute(ObjectNameManager.getInstance("spring:type=Publisher"), "Name");
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=Publisher"), listener, null, null);
this.server.addNotificationListener(ObjectNameManager.getInstance("spring:type=Publisher"), listener, null,
null);
MyNotificationPublisher publisher = (MyNotificationPublisher) ctx.getBean("publisher");
assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher());
@ -110,7 +113,6 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
assertEquals("Notification not sent", 1, listener.count);
}
private static class CountingNotificationListener implements NotificationListener {
private int count;
@ -122,16 +124,17 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
this.count++;
}
@SuppressWarnings("unused")
public int getCount() {
return count;
}
@SuppressWarnings("unused")
public Notification getLastNotification() {
return lastNotification;
}
}
public static class MyNotificationPublisher implements NotificationPublisherAware {
private NotificationPublisher notificationPublisher;
@ -153,14 +156,15 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
}
}
public static class MyNotificationPublisherMBean extends NotificationBroadcasterSupport implements DynamicMBean {
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException,
ReflectionException {
return null;
}
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
public void setAttribute(Attribute attribute) throws AttributeNotFoundException,
InvalidAttributeValueException, MBeanException, ReflectionException {
}
public AttributeList getAttributes(String[] attributes) {
@ -171,17 +175,14 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
return null;
}
public Object invoke(String actionName, Object params[], String signature[]) throws MBeanException, ReflectionException {
public Object invoke(String actionName, Object params[], String signature[]) throws MBeanException,
ReflectionException {
return null;
}
public MBeanInfo getMBeanInfo() {
return new MBeanInfo(
MyNotificationPublisherMBean.class.getName(), "",
new MBeanAttributeInfo[0],
new MBeanConstructorInfo[0],
new MBeanOperationInfo[0],
new MBeanNotificationInfo[0]);
return new MBeanInfo(MyNotificationPublisherMBean.class.getName(), "", new MBeanAttributeInfo[0],
new MBeanConstructorInfo[0], new MBeanOperationInfo[0], new MBeanNotificationInfo[0]);
}
public void sendNotification() {
@ -189,7 +190,6 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
}
}
public static class MyNotificationPublisherStandardMBean extends NotificationBroadcasterSupport implements MyMBean {
public void sendNotification() {
@ -197,7 +197,6 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
}
}
public interface MyMBean {
void sendNotification();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2011 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. You may obtain a copy of
@ -28,13 +28,11 @@ import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.Ignore;
import org.springframework.jmx.AbstractMBeanServerTests;
/**
* @author Rob Harrop
*/
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
private static final String OBJECT_NAME = "spring:type=connector,name=test";
@ -45,8 +43,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
try {
checkServerConnection(getServer());
}
finally {
} finally {
bean.destroy();
}
}
@ -62,8 +59,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
try {
checkServerConnection(getServer());
}
finally {
} finally {
bean.destroy();
}
}
@ -80,8 +76,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
// Try to get the connector bean.
ObjectInstance instance = getServer().getObjectInstance(ObjectName.getInstance(OBJECT_NAME));
assertNotNull("ObjectInstance should not be null", instance);
}
finally {
} finally {
bean.destroy();
}
}
@ -94,11 +89,9 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
// Try to get the connector bean.
getServer().getObjectInstance(ObjectName.getInstance(OBJECT_NAME));
fail("Instance should not be found");
}
catch (InstanceNotFoundException ex) {
} catch (InstanceNotFoundException ex) {
// expected
}
finally {
} finally {
bean.destroy();
}
}
@ -115,8 +108,8 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
assertNotNull("MBeanServerConnection should not be null", connection);
// Test for MBean server equality.
assertEquals("Registered MBean count should be the same",
hostedServer.getMBeanCount(), connection.getMBeanCount());
assertEquals("Registered MBean count should be the same", hostedServer.getMBeanCount(),
connection.getMBeanCount());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2011 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.
@ -23,7 +23,6 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.Ignore;
import org.springframework.aop.support.AopUtils;
import org.springframework.jmx.AbstractMBeanServerTests;
@ -43,8 +42,7 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
return JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, getServer());
}
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public void ignoreTestValidConnection() throws Exception {
public void testValidConnection() throws Exception {
JMXConnectorServer connectorServer = getConnectorServer();
connectorServer.start();
@ -59,12 +57,10 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
// perform simple MBean count test
assertEquals("MBean count should be the same", getServer().getMBeanCount(), connection.getMBeanCount());
}
finally {
} finally {
bean.destroy();
}
}
finally {
} finally {
connectorServer.stop();
}
}
@ -74,14 +70,12 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
try {
bean.afterPropertiesSet();
fail("IllegalArgumentException should be raised when no service url is provided");
}
catch (IllegalArgumentException ex) {
} catch (IllegalArgumentException ex) {
// expected
}
}
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public void ignoreTestWithLazyConnection() throws Exception {
public void testWithLazyConnection() throws Exception {
MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
bean.setServiceUrl(SERVICE_URL);
bean.setConnectOnStartup(false);
@ -95,8 +89,7 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
connector = getConnectorServer();
connector.start();
assertEquals("Incorrect MBean count", getServer().getMBeanCount(), connection.getMBeanCount());
}
finally {
} finally {
bean.destroy();
if (connector != null) {
connector.stop();