[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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; 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 Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen
*/ */
public abstract class AbstractMBeanServerTests extends TestCase { public abstract class AbstractMBeanServerTests extends TestCase {
@ -38,8 +48,7 @@ public abstract class AbstractMBeanServerTests extends TestCase {
this.server = MBeanServerFactory.createMBeanServer(); this.server = MBeanServerFactory.createMBeanServer();
try { try {
onSetUp(); onSetUp();
} } catch (Exception ex) {
catch (Exception ex) {
releaseServer(); releaseServer();
throw ex; 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 * 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 * 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.beans.PropertyDescriptor;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; 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.net.BindException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -32,22 +29,18 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXServiceURL;
import org.junit.Ignore;
import org.springframework.jmx.AbstractMBeanServerTests; import org.springframework.jmx.AbstractMBeanServerTests;
import org.springframework.jmx.IJmxTestBean; import org.springframework.jmx.IJmxTestBean;
import org.springframework.jmx.JmxException; import org.springframework.jmx.JmxException;
import org.springframework.jmx.JmxTestBean; import org.springframework.jmx.JmxTestBean;
import org.springframework.jmx.export.MBeanExporter; import org.springframework.jmx.export.MBeanExporter;
import org.springframework.jmx.export.assembler.AbstractReflectiveMBeanInfoAssembler; import org.springframework.jmx.export.assembler.AbstractReflectiveMBeanInfoAssembler;
import org.springframework.aop.framework.ProxyFactory;
import com.sun.management.HotSpotDiagnosticMXBean;
/** /**
* @author Rob Harrop * @author Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen
*/ */
//@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public class MBeanClientInterceptorTests extends AbstractMBeanServerTests { public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
protected static final String OBJECT_NAME = "spring:test=proxy"; protected static final String OBJECT_NAME = "spring:test=proxy";
@ -62,7 +55,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
target.setName("Rob Harrop"); target.setName("Rob Harrop");
MBeanExporter adapter = new MBeanExporter(); MBeanExporter adapter = new MBeanExporter();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(OBJECT_NAME, target); beans.put(OBJECT_NAME, target);
adapter.setServer(getServer()); adapter.setServer(getServer());
adapter.setBeans(beans); adapter.setBeans(beans);
@ -84,14 +77,15 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
} }
public void testProxyClassIsDifferent() throws Exception { public void testProxyClassIsDifferent() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy = getProxy(); IJmxTestBean proxy = getProxy();
assertTrue("The proxy class should be different than the base class", assertTrue("The proxy class should be different than the base class", (proxy.getClass() != IJmxTestBean.class));
(proxy.getClass() != IJmxTestBean.class));
} }
public void testDifferentProxiesSameClass() throws Exception { public void testDifferentProxiesSameClass() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy1 = getProxy(); IJmxTestBean proxy1 = getProxy();
IJmxTestBean proxy2 = getProxy(); IJmxTestBean proxy2 = getProxy();
@ -100,96 +94,100 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
} }
public void testGetAttributeValue() throws Exception { public void testGetAttributeValue() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy1 = getProxy(); IJmxTestBean proxy1 = getProxy();
int age = proxy1.getAge(); int age = proxy1.getAge();
assertEquals("The age should be 100", 100, age); assertEquals("The age should be 100", 100, age);
} }
public void testSetAttributeValue() throws Exception { public void testSetAttributeValue() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy = getProxy(); IJmxTestBean proxy = getProxy();
proxy.setName("Rob Harrop"); proxy.setName("Rob Harrop");
assertEquals("The name of the bean should have been updated", "Rob Harrop", target.getName()); assertEquals("The name of the bean should have been updated", "Rob Harrop", target.getName());
} }
public void testSetAttributeValueWithRuntimeException() throws Exception { public void testSetAttributeValueWithRuntimeException() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy = getProxy(); IJmxTestBean proxy = getProxy();
try { try {
proxy.setName("Juergen"); proxy.setName("Juergen");
fail("Should have thrown IllegalArgumentException"); fail("Should have thrown IllegalArgumentException");
} } catch (IllegalArgumentException ex) {
catch (IllegalArgumentException ex) {
// expected // expected
} }
} }
public void testSetAttributeValueWithCheckedException() throws Exception { public void testSetAttributeValueWithCheckedException() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy = getProxy(); IJmxTestBean proxy = getProxy();
try { try {
proxy.setName("Juergen Class"); proxy.setName("Juergen Class");
fail("Should have thrown ClassNotFoundException"); fail("Should have thrown ClassNotFoundException");
} } catch (ClassNotFoundException ex) {
catch (ClassNotFoundException ex) {
// expected // expected
} }
} }
public void testSetAttributeValueWithIOException() throws Exception { public void testSetAttributeValueWithIOException() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy = getProxy(); IJmxTestBean proxy = getProxy();
try { try {
proxy.setName("Juergen IO"); proxy.setName("Juergen IO");
fail("Should have thrown IOException"); fail("Should have thrown IOException");
} } catch (IOException ex) {
catch (IOException ex) {
// expected // expected
} }
} }
public void testSetReadOnlyAttribute() throws Exception { public void testSetReadOnlyAttribute() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy = getProxy(); IJmxTestBean proxy = getProxy();
try { try {
proxy.setAge(900); proxy.setAge(900);
fail("Should not be able to write to a read only attribute"); fail("Should not be able to write to a read only attribute");
} } catch (InvalidInvocationException ex) {
catch (InvalidInvocationException ex) {
// success // success
} }
} }
public void testInvokeNoArgs() throws Exception { public void testInvokeNoArgs() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy = getProxy(); IJmxTestBean proxy = getProxy();
long result = proxy.myOperation(); long result = proxy.myOperation();
assertEquals("The operation should return 1", 1, result); assertEquals("The operation should return 1", 1, result);
} }
public void testInvokeArgs() throws Exception { public void testInvokeArgs() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean proxy = getProxy(); IJmxTestBean proxy = getProxy();
int result = proxy.add(1, 2); int result = proxy.add(1, 2);
assertEquals("The operation should return 3", 3, result); assertEquals("The operation should return 3", 3, result);
} }
public void testInvokeUnexposedMethodWithException() throws Exception { public void testInvokeUnexposedMethodWithException() throws Exception {
if (!runTests) return; if (!runTests)
return;
IJmxTestBean bean = getProxy(); IJmxTestBean bean = getProxy();
try { try {
bean.dontExposeMe(); bean.dontExposeMe();
fail("Method dontExposeMe should throw an exception"); fail("Method dontExposeMe should throw an exception");
} } catch (InvalidInvocationException desired) {
catch (InvalidInvocationException desired) {
// success // success
} }
} }
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235 public void testLazyConnectionToRemote() throws Exception {
public void ignoreTestLazyConnectionToRemote() throws Exception { if (!runTests)
if (!runTests) return; return;
JMXServiceURL url = new JMXServiceURL("service:jmx:jmxmp://localhost:9876"); JMXServiceURL url = new JMXServiceURL("service:jmx:jmxmp://localhost:9876");
JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer()); JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer());
@ -207,12 +205,10 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
// now start the connector // now start the connector
try { try {
connector.start(); connector.start();
} } catch (BindException ex) {
catch (BindException ex) {
// couldn't bind to local port 9876 - let's skip the remainder of this test // couldn't bind to local port 9876 - let's skip the remainder of this test
System.out.println( System.out.println("Skipping JMX LazyConnectionToRemote test because binding to local port 9876 failed: "
"Skipping JMX LazyConnectionToRemote test because binding to local port 9876 failed: " + + ex.getMessage());
ex.getMessage());
return; return;
} }
@ -220,15 +216,13 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
try { try {
assertEquals("Rob Harrop", bean.getName()); assertEquals("Rob Harrop", bean.getName());
assertEquals(100, bean.getAge()); assertEquals(100, bean.getAge());
} } finally {
finally {
connector.stop(); connector.stop();
} }
try { try {
bean.getName(); bean.getName();
} } catch (JmxException ex) {
catch (JmxException ex) {
// expected // expected
} }
@ -239,8 +233,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
try { try {
assertEquals("Rob Harrop", bean.getName()); assertEquals("Rob Harrop", bean.getName());
assertEquals(100, bean.getAge()); assertEquals(100, bean.getAge());
} } finally {
finally {
connector.stop(); connector.stop();
} }
} }
@ -272,7 +265,6 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
} }
*/ */
private static class ProxyTestAssembler extends AbstractReflectiveMBeanInfoAssembler { private static class ProxyTestAssembler extends AbstractReflectiveMBeanInfoAssembler {
protected boolean includeReadAttribute(Method method, String beanKey) { protected boolean includeReadAttribute(Method method, String beanKey) {
@ -293,26 +285,32 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
return true; return true;
} }
@SuppressWarnings("unused")
protected String getOperationDescription(Method method) { protected String getOperationDescription(Method method) {
return method.getName(); return method.getName();
} }
@SuppressWarnings("unused")
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) { protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) {
return propertyDescriptor.getDisplayName(); return propertyDescriptor.getDisplayName();
} }
@SuppressWarnings("unused")
protected void populateAttributeDescriptor(Descriptor descriptor, Method getter, Method setter) { protected void populateAttributeDescriptor(Descriptor descriptor, Method getter, Method setter) {
} }
@SuppressWarnings("unused")
protected void populateOperationDescriptor(Descriptor descriptor, Method method) { protected void populateOperationDescriptor(Descriptor descriptor, Method method) {
} }
@SuppressWarnings({ "unused", "rawtypes" })
protected String getDescription(String beanKey, Class beanClass) { protected String getDescription(String beanKey, Class beanClass) {
return ""; return "";
} }
@SuppressWarnings({ "unused", "rawtypes" })
protected void populateMBeanDescriptor(Descriptor mbeanDescriptor, String beanKey, Class beanClass) { 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.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXServiceURL;
import org.junit.Ignore;
/** /**
* @author Rob Harrop * @author Rob Harrop
*/ */
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTests { public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTests {
private static final String SERVICE_URL = "service:jmx:jmxmp://localhost:9876"; 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 javax.management.ObjectName;
import org.junit.Ignore;
import org.springframework.jmx.AbstractJmxTests; import org.springframework.jmx.AbstractJmxTests;
/** /**
* @author Rob Harrop * @author Rob Harrop
*/ */
@Ignore // changes in CustomEditorConfigurer broke these tests (see diff between r304:305)
public class CustomEditorConfigurerTests extends AbstractJmxTests { public class CustomEditorConfigurerTests extends AbstractJmxTests {
private final SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd"); private final SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
@ -38,7 +36,7 @@ public class CustomEditorConfigurerTests extends AbstractJmxTests {
} }
public void testDatesInJmx() throws Exception { public void testDatesInJmx() throws Exception {
System.out.println(getServer().getClass().getName()); // System.out.println(getServer().getClass().getName());
ObjectName oname = new ObjectName("bean:name=dateRange"); ObjectName oname = new ObjectName("bean:name=dateRange");
Date startJmx = (Date) getServer().getAttribute(oname, "StartDate"); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Rick Evans
* @author Mark Fisher * @author Mark Fisher
* @author Chris Beams * @author Chris Beams
* @author Sam Brannen
*/ */
@SuppressWarnings("deprecation")
public final class MBeanExporterTests extends AbstractMBeanServerTests { public final class MBeanExporterTests extends AbstractMBeanServerTests {
private static final String OBJECT_NAME = "spring:test=jmxMBeanAdaptor"; private static final String OBJECT_NAME = "spring:test=jmxMBeanAdaptor";
@SuppressWarnings({ "rawtypes", "unchecked" })
@Ignore // throwing CCE public void testRegisterNonNotificationListenerType() throws Exception {
public void ignoreTestRegisterNonNotificationListenerType() throws Exception {
Map listeners = new HashMap(); Map listeners = new HashMap();
// put a non-NotificationListener instance in as a value... // put a non-NotificationListener instance in as a value...
listeners.put("*", this); listeners.put("*", this);
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
try { try {
exporter.setNotificationListenerMappings(listeners); exporter.setNotificationListenerMappings(listeners);
fail("Must have thrown an IllegalArgumentException when registering a non-NotificationListener instance as a NotificationListener."); fail("Must have thrown a ClassCastException when registering a non-NotificationListener instance as a NotificationListener.");
} } catch (ClassCastException expected) {
catch (IllegalArgumentException 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 { public void ignoreTestRegisterNullNotificationListenerType() throws Exception {
Map listeners = new HashMap(); Map listeners = new HashMap();
// put null in as a value... // put null in as a value...
@ -88,11 +93,11 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
try { try {
exporter.setNotificationListenerMappings(listeners); exporter.setNotificationListenerMappings(listeners);
fail("Must have thrown an IllegalArgumentException when registering a null instance as a NotificationListener."); 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 { public void testRegisterNotificationListenerForNonExistentMBean() throws Exception {
Map listeners = new HashMap(); Map listeners = new HashMap();
NotificationListener dummyListener = new NotificationListener() { NotificationListener dummyListener = new NotificationListener() {
@ -109,8 +114,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
try { try {
exporter.afterPropertiesSet(); exporter.afterPropertiesSet();
fail("Must have thrown an MBeanExportException when registering a NotificationListener on a non-existent MBean."); 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)); assertTrue(expected.contains(InstanceNotFoundException.class));
} }
} }
@ -120,7 +124,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setBeans(getBeanMap()); exporter.setBeans(getBeanMap());
exporter.setServer(server); exporter.setServer(server);
exporter.afterPropertiesSet(); 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 /** 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 { public void testUserCreatedMBeanRegWithDynamicMBean() throws Exception {
Map map = new HashMap(); Map<String, Object> map = new HashMap<String, Object>();
map.put("spring:name=dynBean", new TestDynamicMBean()); map.put("spring:name=dynBean", new TestDynamicMBean());
InvokeDetectAssembler asm = new InvokeDetectAssembler(); InvokeDetectAssembler asm = new InvokeDetectAssembler();
@ -161,8 +166,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertNotNull(instance); assertNotNull(instance);
instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true")); instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true"));
assertNotNull(instance); assertNotNull(instance);
} } finally {
finally {
bf.destroySingletons(); bf.destroySingletons();
} }
} }
@ -178,11 +182,9 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
try { try {
server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false")); server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false"));
fail("MBean with name spring:mbean=false should have been excluded"); fail("MBean with name spring:mbean=false should have been excluded");
} catch (InstanceNotFoundException expected) {
} }
catch (InstanceNotFoundException expected) { } finally {
}
}
finally {
bf.destroySingletons(); bf.destroySingletons();
} }
} }
@ -202,8 +204,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertNotNull(server.getObjectInstance(oname)); assertNotNull(server.getObjectInstance(oname));
name = (String) server.getAttribute(oname, "Name"); name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "Juergen Hoeller", name); assertEquals("Invalid name returned", "Juergen Hoeller", name);
} } finally {
finally {
bf.destroySingletons(); bf.destroySingletons();
} }
} }
@ -212,8 +213,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("autodetectNoMBeans.xml", getClass())); XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("autodetectNoMBeans.xml", getClass()));
try { try {
bf.getBean("exporter"); bf.getBean("exporter");
} } finally {
finally {
bf.destroySingletons(); bf.destroySingletons();
} }
} }
@ -225,7 +225,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setBeans(getBeanMap()); exporter.setBeans(getBeanMap());
exporter.setServer(server); exporter.setServer(server);
exporter.setListeners(new MBeanExporterListener[] {listener1, listener2}); exporter.setListeners(new MBeanExporterListener[] { listener1, listener2 });
exporter.afterPropertiesSet(); exporter.afterPropertiesSet();
exporter.destroy(); exporter.destroy();
@ -240,12 +240,12 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
ProxyFactory factory = new ProxyFactory(); ProxyFactory factory = new ProxyFactory();
factory.setTarget(bean); factory.setTarget(bean);
factory.addAdvice(new NopInterceptor()); factory.addAdvice(new NopInterceptor());
factory.setInterfaces(new Class[]{IJmxTestBean.class}); factory.setInterfaces(new Class[] { IJmxTestBean.class });
IJmxTestBean proxy = (IJmxTestBean) factory.getProxy(); IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
String name = "bean:mmm=whatever"; String name = "bean:mmm=whatever";
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(name, proxy); beans.put(name, proxy);
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
@ -263,7 +263,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
SelfNamingTestBean testBean = new SelfNamingTestBean(); SelfNamingTestBean testBean = new SelfNamingTestBean();
testBean.setObjectName(objectName); testBean.setObjectName(objectName);
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put("foo", testBean); beans.put("foo", testBean);
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
@ -289,7 +289,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
String objectName2 = "spring:test=equalBean"; String objectName2 = "spring:test=equalBean";
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.toString(), springRegistered); beans.put(objectName.toString(), springRegistered);
beans.put(objectName2, springRegistered); beans.put(objectName2, springRegistered);
@ -320,7 +320,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
Person springRegistered = new Person(); Person springRegistered = new Person();
springRegistered.setName("Sally Greenwood"); springRegistered.setName("Sally Greenwood");
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.toString(), springRegistered); beans.put(objectName.toString(), springRegistered);
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
@ -345,7 +345,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
bean.setName(name); bean.setName(name);
ObjectName objectName = ObjectNameManager.getInstance("spring:type=Test"); ObjectName objectName = ObjectNameManager.getInstance("spring:type=Test");
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName.toString(), bean); beans.put(objectName.toString(), bean);
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
@ -356,9 +356,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("Bean instance not registered", objectName); assertIsRegistered("Bean instance not registered", objectName);
Object result = server.invoke(objectName, "add", Object result = server.invoke(objectName, "add", new Object[] { new Integer(2), new Integer(3) }, new String[] {
new Object[]{new Integer(2), new Integer(3)}, int.class.getName(), int.class.getName() });
new String[]{int.class.getName(), int.class.getName()});
assertEquals("Incorrect result return from add", result, new Integer(5)); assertEquals("Incorrect result return from add", result, new Integer(5));
assertEquals("Incorrect attribute value", name, server.getAttribute(objectName, "Name")); assertEquals("Incorrect attribute value", name, server.getAttribute(objectName, "Name"));
@ -375,7 +374,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
factory.registerSingleton(exportedBeanName, new TestBean()); factory.registerSingleton(exportedBeanName, new TestBean());
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
Map beansToExport = new HashMap(); Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put(OBJECT_NAME, exportedBeanName); beansToExport.put(OBJECT_NAME, exportedBeanName);
exporter.setBeans(beansToExport); exporter.setBeans(beansToExport);
exporter.setServer(getServer()); exporter.setServer(getServer());
@ -456,7 +455,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer()); exporter.setServer(getServer());
Map beansToExport = new HashMap(); Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put(OBJECT_NAME, OBJECT_NAME); beansToExport.put(OBJECT_NAME, OBJECT_NAME);
exporter.setBeans(beansToExport); exporter.setBeans(beansToExport);
exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(OBJECT_NAME)); exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(OBJECT_NAME));
@ -472,8 +471,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectMode(-1); exporter.setAutodetectMode(-1);
fail("Must have failed when supplying an invalid negative out-of-range autodetect mode"); 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 { public void testSetAutodetectModeToOutOfRangePositiveValue() throws Exception {
@ -481,8 +480,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectMode(5); exporter.setAutodetectMode(5);
fail("Must have failed when supplying an invalid positive out-of-range autodetect mode"); 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 { public void testSetAutodetectModeNameToNull() throws Exception {
@ -490,8 +489,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectModeName(null); exporter.setAutodetectModeName(null);
fail("Must have failed when supplying a null autodetect mode name"); fail("Must have failed when supplying a null autodetect mode name");
} catch (IllegalArgumentException expected) {
} }
catch (IllegalArgumentException expected) {}
} }
public void testSetAutodetectModeNameToAnEmptyString() throws Exception { public void testSetAutodetectModeNameToAnEmptyString() throws Exception {
@ -499,8 +498,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectModeName(""); exporter.setAutodetectModeName("");
fail("Must have failed when supplying an empty autodetect mode name"); fail("Must have failed when supplying an empty autodetect mode name");
} catch (IllegalArgumentException expected) {
} }
catch (IllegalArgumentException expected) {}
} }
public void testSetAutodetectModeNameToAWhitespacedString() throws Exception { public void testSetAutodetectModeNameToAWhitespacedString() throws Exception {
@ -508,8 +507,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectModeName(" \t"); exporter.setAutodetectModeName(" \t");
fail("Must have failed when supplying a whitespace-only autodetect mode name"); fail("Must have failed when supplying a whitespace-only autodetect mode name");
} catch (IllegalArgumentException expected) {
} }
catch (IllegalArgumentException expected) {}
} }
public void testSetAutodetectModeNameToARubbishValue() throws Exception { public void testSetAutodetectModeNameToARubbishValue() throws Exception {
@ -517,20 +516,20 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setAutodetectModeName("That Hansel is... *sssooo* hot right now!"); exporter.setAutodetectModeName("That Hansel is... *sssooo* hot right now!");
fail("Must have failed when supplying a whitespace-only autodetect mode name"); fail("Must have failed when supplying a whitespace-only autodetect mode name");
} catch (IllegalArgumentException expected) {
} }
catch (IllegalArgumentException expected) {}
} }
public void testNotRunningInBeanFactoryAndPassedBeanNameToExport() throws Exception { public void testNotRunningInBeanFactoryAndPassedBeanNameToExport() throws Exception {
try { try {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(OBJECT_NAME, "beanName"); beans.put(OBJECT_NAME, "beanName");
exporter.setBeans(beans); exporter.setBeans(beans);
exporter.afterPropertiesSet(); exporter.afterPropertiesSet();
fail("Expecting exception because MBeanExporter is not running in a BeanFactory and was passed bean name to (lookup and then) export"); 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 { public void testNotRunningInBeanFactoryAndAutodetectionIsOn() throws Exception {
@ -539,8 +538,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL); exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL);
exporter.afterPropertiesSet(); exporter.afterPropertiesSet();
fail("Expecting exception because MBeanExporter is not running in a BeanFactory and was configured to autodetect beans"); 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.setBeans(getBeanMap());
exporter.setServer(this.server); exporter.setServer(this.server);
MockMBeanExporterListener listener = new MockMBeanExporterListener(); MockMBeanExporterListener listener = new MockMBeanExporterListener();
exporter.setListeners(new MBeanExporterListener[]{listener}); exporter.setListeners(new MBeanExporterListener[] { listener });
exporter.afterPropertiesSet(); 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)); this.server.unregisterMBean(new ObjectName(OBJECT_NAME));
exporter.destroy(); 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(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer()); exporter.setServer(getServer());
Map beansToExport = new HashMap(); Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put("test:what=ever", testBeanInstance); beansToExport.put("test:what=ever", testBeanInstance);
exporter.setBeans(beansToExport); exporter.setBeans(beansToExport);
exporter.setBeanFactory(factory); exporter.setBeanFactory(factory);
@ -595,7 +596,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer()); exporter.setServer(getServer());
Map beansToExport = new HashMap(); Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put("test:what=ever", testBeanInstance); beansToExport.put("test:what=ever", testBeanInstance);
exporter.setBeans(beansToExport); exporter.setBeans(beansToExport);
exporter.setBeanFactory(factory); exporter.setBeanFactory(factory);
@ -610,7 +611,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
*/ */
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.rootBeanDefinition(RuntimeExceptionThrowingConstructorBean.class); BeanDefinitionBuilder builder2 = BeanDefinitionBuilder
.rootBeanDefinition(RuntimeExceptionThrowingConstructorBean.class);
String objectName1 = "spring:test=bean1"; String objectName1 = "spring:test=bean1";
String objectName2 = "spring:test=bean2"; String objectName2 = "spring:test=bean2";
@ -621,7 +623,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(getServer()); exporter.setServer(getServer());
Map beansToExport = new HashMap(); Map<String, Object> beansToExport = new HashMap<String, Object>();
beansToExport.put(objectName1, objectName1); beansToExport.put(objectName1, objectName1);
beansToExport.put(objectName2, objectName2); beansToExport.put(objectName2, objectName2);
exporter.setBeans(beansToExport); exporter.setBeans(beansToExport);
@ -630,8 +632,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
try { try {
exporter.afterPropertiesSet(); exporter.afterPropertiesSet();
fail("Must have failed during creation of RuntimeExceptionThrowingConstructorBean"); 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", assertIsNotRegistered("Must have unregistered all previously registered MBeans due to RuntimeException",
@ -640,9 +641,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
ObjectNameManager.getInstance(objectName2)); ObjectNameManager.getInstance(objectName2));
} }
private Map<String, Object> getBeanMap() {
private Map getBeanMap() { Map<String, Object> map = new HashMap<String, Object>();
Map map = new HashMap();
map.put(OBJECT_NAME, new JmxTestBean()); map.put(OBJECT_NAME, new JmxTestBean());
return map; return map;
} }
@ -655,7 +655,6 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
assertEquals("Incorrect ObjectName in unregister", desired, listener.getUnregistered().get(0)); assertEquals("Incorrect ObjectName in unregister", desired, listener.getUnregistered().get(0));
} }
private static class InvokeDetectAssembler implements MBeanInfoAssembler { private static class InvokeDetectAssembler implements MBeanInfoAssembler {
private boolean invoked = false; private boolean invoked = false;
@ -666,12 +665,11 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
} }
} }
private static class MockMBeanExporterListener implements MBeanExporterListener { 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) { public void mbeanRegistered(ObjectName objectName) {
registered.add(objectName); registered.add(objectName);
@ -681,16 +679,15 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
unregistered.add(objectName); unregistered.add(objectName);
} }
public List getRegistered() { public List<ObjectName> getRegistered() {
return registered; return registered;
} }
public List getUnregistered() { public List<ObjectName> getUnregistered() {
return unregistered; return unregistered;
} }
} }
private static class SelfNamingTestBean implements SelfNaming { private static class SelfNamingTestBean implements SelfNaming {
private ObjectName objectName; private ObjectName objectName;
@ -704,13 +701,11 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
} }
} }
public static interface PersonMBean { public static interface PersonMBean {
String getName(); String getName();
} }
public static class Person implements PersonMBean { public static class Person implements PersonMBean {
private String name; private String name;
@ -724,32 +719,29 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
} }
} }
public static final class StubNotificationListener implements NotificationListener { 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) { public void handleNotification(Notification notification, Object handback) {
this.notifications.add(notification); this.notifications.add(notification);
} }
public List getNotifications() { public List<Notification> getNotifications() {
return this.notifications; return this.notifications;
} }
} }
private static class RuntimeExceptionThrowingConstructorBean { private static class RuntimeExceptionThrowingConstructorBean {
@SuppressWarnings("unused")
public RuntimeExceptionThrowingConstructorBean() { public RuntimeExceptionThrowingConstructorBean() {
throw new RuntimeException(); throw new RuntimeException();
} }
} }
private static final class NamedBeanAutodetectCapableMBeanInfoAssemblerStub extends
private static final class NamedBeanAutodetectCapableMBeanInfoAssemblerStub SimpleReflectiveMBeanInfoAssembler implements AutodetectCapableMBeanInfoAssembler {
extends SimpleReflectiveMBeanInfoAssembler
implements AutodetectCapableMBeanInfoAssembler {
private String namedBean; private String namedBean;
@ -757,7 +749,7 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
this.namedBean = namedBean; this.namedBean = namedBean;
} }
public boolean includeBean(Class beanClass, String beanName) { public boolean includeBean(Class<?> beanClass, String beanName) {
return this.namedBean.equals(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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.NotificationListener;
import javax.management.ObjectName; import javax.management.ObjectName;
import org.junit.Ignore;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.jmx.AbstractMBeanServerTests; import org.springframework.jmx.AbstractMBeanServerTests;
import org.springframework.jmx.JmxTestBean; import org.springframework.jmx.JmxTestBean;
@ -38,16 +37,17 @@ import org.springframework.jmx.support.ObjectNameManager;
/** /**
* @author Rob Harrop * @author Rob Harrop
* @author Mark Fisher * @author Mark Fisher
* @author Sam Brannen
*/ */
@Ignore // Getting CCEs regarding ObjectName being cast to String
public class NotificationListenerTests extends AbstractMBeanServerTests { public class NotificationListenerTests extends AbstractMBeanServerTests {
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerForMBean() throws Exception { public void testRegisterNotificationListenerForMBean() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean(); JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName, bean); beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -66,12 +66,13 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount(attributeName)); assertEquals("Listener not notified", 1, listener.getCount(attributeName));
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithWildcard() throws Exception { public void testRegisterNotificationListenerWithWildcard() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean(); JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName, bean); beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -94,7 +95,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
String objectName = "spring:name=Test"; String objectName = "spring:name=Test";
JmxTestBean bean = new JmxTestBean(); JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName, bean); beans.put(objectName, bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -108,12 +109,13 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server); exporter.setServer(server);
exporter.setBeans(beans); exporter.setBeans(beans);
exporter.setNotificationListeners(new NotificationListenerBean[]{listenerBean}); exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
exporter.afterPropertiesSet(); exporter.afterPropertiesSet();
// update the attribute // update the attribute
String attributeName = "Name"; 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("Listener not notified", 1, listener.getCount(attributeName));
assertEquals("Handback object not transmitted correctly", handback, listener.getLastHandback(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"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean(); JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName, bean); beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -134,7 +136,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server); exporter.setServer(server);
exporter.setBeans(beans); exporter.setBeans(beans);
exporter.setNotificationListeners(new NotificationListenerBean[]{listenerBean}); exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
exporter.afterPropertiesSet(); exporter.afterPropertiesSet();
// update the attribute // update the attribute
@ -144,12 +146,13 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount(attributeName)); assertEquals("Listener not notified", 1, listener.getCount(attributeName));
} }
@SuppressWarnings("serial")
public void testRegisterNotificationListenerWithFilter() throws Exception { public void testRegisterNotificationListenerWithFilter() throws Exception {
ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean(); JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName, bean); beans.put(objectName.getCanonicalName(), bean);
CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener(); CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
@ -160,8 +163,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
if (notification instanceof AttributeChangeNotification) { if (notification instanceof AttributeChangeNotification) {
AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification; AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
return "Name".equals(changeNotification.getAttributeName()); return "Name".equals(changeNotification.getAttributeName());
} } else {
else {
return false; return false;
} }
} }
@ -170,7 +172,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server); exporter.setServer(server);
exporter.setBeans(beans); exporter.setBeans(beans);
exporter.setNotificationListeners(new NotificationListenerBean[]{listenerBean}); exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
exporter.afterPropertiesSet(); exporter.afterPropertiesSet();
// update the attributes // update the attributes
@ -188,11 +190,11 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
try { try {
new NotificationListenerBean().afterPropertiesSet(); new NotificationListenerBean().afterPropertiesSet();
fail("Must have thrown an IllegalArgumentException (no NotificationListener supplied)"); fail("Must have thrown an IllegalArgumentException (no NotificationListener supplied)");
} } catch (IllegalArgumentException expected) {
catch (IllegalArgumentException expected) {
} }
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithBeanNameAndBeanNameInBeansMap() throws Exception { public void testRegisterNotificationListenerWithBeanNameAndBeanNameInBeansMap() throws Exception {
String beanName = "testBean"; String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
@ -203,7 +205,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerSingleton(beanName, testBean); factory.registerSingleton(beanName, testBean);
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName, beanName); beans.put(beanName, beanName);
Map listenerMappings = new HashMap(); Map listenerMappings = new HashMap();
@ -222,6 +224,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount("Age")); assertEquals("Listener not notified", 1, listener.getCount("Age"));
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithBeanNameAndBeanInstanceInBeansMap() throws Exception { public void testRegisterNotificationListenerWithBeanNameAndBeanInstanceInBeansMap() throws Exception {
String beanName = "testBean"; String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
@ -232,7 +235,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerSingleton(beanName, testBean); factory.registerSingleton(beanName, testBean);
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName, testBean); beans.put(beanName, testBean);
Map listenerMappings = new HashMap(); Map listenerMappings = new HashMap();
@ -251,6 +254,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener not notified", 1, listener.getCount("Age")); assertEquals("Listener not notified", 1, listener.getCount("Age"));
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithBeanNameBeforeObjectNameMappedToSameBeanInstance() throws Exception { public void testRegisterNotificationListenerWithBeanNameBeforeObjectNameMappedToSameBeanInstance() throws Exception {
String beanName = "testBean"; String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
@ -261,7 +265,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerSingleton(beanName, testBean); factory.registerSingleton(beanName, testBean);
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName, testBean); beans.put(beanName, testBean);
Map listenerMappings = new HashMap(); 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")); assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithObjectNameBeforeBeanNameMappedToSameBeanInstance() throws Exception { public void testRegisterNotificationListenerWithObjectNameBeforeBeanNameMappedToSameBeanInstance() throws Exception {
String beanName = "testBean"; String beanName = "testBean";
ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
@ -291,7 +296,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerSingleton(beanName, testBean); factory.registerSingleton(beanName, testBean);
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName, testBean); beans.put(beanName, testBean);
Map listenerMappings = new HashMap(); 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")); assertEquals("Listener should have been notified exactly once", 1, listener.getCount("Age"));
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRegisterNotificationListenerWithTwoBeanNamesMappedToDifferentBeanInstances() throws Exception { public void testRegisterNotificationListenerWithTwoBeanNamesMappedToDifferentBeanInstances() throws Exception {
String beanName1 = "testBean1"; String beanName1 = "testBean1";
String beanName2 = "testBean2"; String beanName2 = "testBean2";
@ -328,7 +334,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
factory.registerSingleton(beanName1, testBean1); factory.registerSingleton(beanName1, testBean1);
factory.registerSingleton(beanName2, testBean2); factory.registerSingleton(beanName2, testBean2);
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(beanName1, testBean1); beans.put(beanName1, testBean1);
beans.put(beanName2, testBean2); beans.put(beanName2, testBean2);
@ -357,8 +363,8 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
ObjectName objectName = ObjectName.getInstance("spring:name=Test"); ObjectName objectName = ObjectName.getInstance("spring:name=Test");
JmxTestBean bean = new JmxTestBean(); JmxTestBean bean = new JmxTestBean();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName, bean); beans.put(objectName.getCanonicalName(), bean);
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server); exporter.setServer(server);
@ -391,9 +397,9 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
JmxTestBean bean = new JmxTestBean(); JmxTestBean bean = new JmxTestBean();
JmxTestBean bean2 = new JmxTestBean(); JmxTestBean bean2 = new JmxTestBean();
Map beans = new HashMap(); Map<String, Object> beans = new HashMap<String, Object>();
beans.put(objectName, bean); beans.put(objectName.getCanonicalName(), bean);
beans.put(objectName2, bean2); beans.put(objectName2.getCanonicalName(), bean2);
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server); exporter.setServer(server);
@ -406,7 +412,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
registrar.setServer(server); registrar.setServer(server);
registrar.setNotificationListener(listener); registrar.setNotificationListener(listener);
//registrar.setMappedObjectNames(new Object[] {objectName, objectName2}); //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(); registrar.afterPropertiesSet();
// update the attribute // update the attribute
@ -421,7 +427,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName)); assertEquals("Listener notified after destruction", 1, listener.getCount(attributeName));
} }
@SuppressWarnings({ "rawtypes", "unchecked" })
private static class CountingAttributeChangeNotificationListener implements NotificationListener { private static class CountingAttributeChangeNotificationListener implements NotificationListener {
private Map attributeCounts = new HashMap(); private Map attributeCounts = new HashMap();
@ -438,8 +444,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
if (currentCount != null) { if (currentCount != null) {
int count = currentCount.intValue() + 1; int count = currentCount.intValue() + 1;
this.attributeCounts.put(attributeName, new Integer(count)); this.attributeCounts.put(attributeName, new Integer(count));
} } else {
else {
this.attributeCounts.put(attributeName, new Integer(1)); this.attributeCounts.put(attributeName, new Integer(1));
} }
@ -457,7 +462,6 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
} }
} }
public static class SelfNamingTestBean implements SelfNaming { public static class SelfNamingTestBean implements SelfNaming {
private ObjectName objectName; private ObjectName objectName;

View File

@ -48,11 +48,11 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
private CountingNotificationListener listener = new CountingNotificationListener(); private CountingNotificationListener listener = new CountingNotificationListener();
public void testSimpleBean() throws Exception { public void testSimpleBean() throws Exception {
// start the MBeanExporter // start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherTests.xml"); 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"); MyNotificationPublisher publisher = (MyNotificationPublisher) ctx.getBean("publisher");
assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher()); assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher());
@ -66,7 +66,8 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
MBeanExporter exporter = (MBeanExporter) ctx.getBean("exporter"); MBeanExporter exporter = (MBeanExporter) ctx.getBean("exporter");
MyNotificationPublisher publisher = new MyNotificationPublisher(); MyNotificationPublisher publisher = new MyNotificationPublisher();
exporter.registerManagedResource(publisher, ObjectNameManager.getInstance("spring:type=Publisher2")); 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()); assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher());
publisher.sendNotification(); publisher.sendNotification();
@ -76,7 +77,8 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
public void testMBean() throws Exception { public void testMBean() throws Exception {
// start the MBeanExporter // start the MBeanExporter
ConfigurableApplicationContext ctx = loadContext("org/springframework/jmx/export/notificationPublisherTests.xml"); 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"); MyNotificationPublisherMBean publisher = (MyNotificationPublisherMBean) ctx.getBean("publisherMBean");
publisher.sendNotification(); publisher.sendNotification();
@ -102,7 +104,8 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
// need to touch the MBean proxy // need to touch the MBean proxy
server.getAttribute(ObjectNameManager.getInstance("spring:type=Publisher"), "Name"); 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"); MyNotificationPublisher publisher = (MyNotificationPublisher) ctx.getBean("publisher");
assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher()); assertNotNull("NotificationPublisher should not be null", publisher.getNotificationPublisher());
@ -110,7 +113,6 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
assertEquals("Notification not sent", 1, listener.count); assertEquals("Notification not sent", 1, listener.count);
} }
private static class CountingNotificationListener implements NotificationListener { private static class CountingNotificationListener implements NotificationListener {
private int count; private int count;
@ -122,16 +124,17 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
this.count++; this.count++;
} }
@SuppressWarnings("unused")
public int getCount() { public int getCount() {
return count; return count;
} }
@SuppressWarnings("unused")
public Notification getLastNotification() { public Notification getLastNotification() {
return lastNotification; return lastNotification;
} }
} }
public static class MyNotificationPublisher implements NotificationPublisherAware { public static class MyNotificationPublisher implements NotificationPublisherAware {
private NotificationPublisher notificationPublisher; private NotificationPublisher notificationPublisher;
@ -153,14 +156,15 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
} }
} }
public static class MyNotificationPublisherMBean extends NotificationBroadcasterSupport implements DynamicMBean { 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; 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) { public AttributeList getAttributes(String[] attributes) {
@ -171,17 +175,14 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
return null; 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; return null;
} }
public MBeanInfo getMBeanInfo() { public MBeanInfo getMBeanInfo() {
return new MBeanInfo( return new MBeanInfo(MyNotificationPublisherMBean.class.getName(), "", new MBeanAttributeInfo[0],
MyNotificationPublisherMBean.class.getName(), "", new MBeanConstructorInfo[0], new MBeanOperationInfo[0], new MBeanNotificationInfo[0]);
new MBeanAttributeInfo[0],
new MBeanConstructorInfo[0],
new MBeanOperationInfo[0],
new MBeanNotificationInfo[0]);
} }
public void sendNotification() { public void sendNotification() {
@ -189,7 +190,6 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
} }
} }
public static class MyNotificationPublisherStandardMBean extends NotificationBroadcasterSupport implements MyMBean { public static class MyNotificationPublisherStandardMBean extends NotificationBroadcasterSupport implements MyMBean {
public void sendNotification() { public void sendNotification() {
@ -197,7 +197,6 @@ public class NotificationPublisherTests extends AbstractMBeanServerTests {
} }
} }
public interface MyMBean { public interface MyMBean {
void sendNotification(); 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 * 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 * 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.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXServiceURL;
import org.junit.Ignore;
import org.springframework.jmx.AbstractMBeanServerTests; import org.springframework.jmx.AbstractMBeanServerTests;
/** /**
* @author Rob Harrop * @author Rob Harrop
*/ */
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235
public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests { public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
private static final String OBJECT_NAME = "spring:type=connector,name=test"; private static final String OBJECT_NAME = "spring:type=connector,name=test";
@ -45,8 +43,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
try { try {
checkServerConnection(getServer()); checkServerConnection(getServer());
} } finally {
finally {
bean.destroy(); bean.destroy();
} }
} }
@ -62,8 +59,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
try { try {
checkServerConnection(getServer()); checkServerConnection(getServer());
} } finally {
finally {
bean.destroy(); bean.destroy();
} }
} }
@ -80,8 +76,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
// Try to get the connector bean. // Try to get the connector bean.
ObjectInstance instance = getServer().getObjectInstance(ObjectName.getInstance(OBJECT_NAME)); ObjectInstance instance = getServer().getObjectInstance(ObjectName.getInstance(OBJECT_NAME));
assertNotNull("ObjectInstance should not be null", instance); assertNotNull("ObjectInstance should not be null", instance);
} } finally {
finally {
bean.destroy(); bean.destroy();
} }
} }
@ -94,11 +89,9 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
// Try to get the connector bean. // Try to get the connector bean.
getServer().getObjectInstance(ObjectName.getInstance(OBJECT_NAME)); getServer().getObjectInstance(ObjectName.getInstance(OBJECT_NAME));
fail("Instance should not be found"); fail("Instance should not be found");
} } catch (InstanceNotFoundException ex) {
catch (InstanceNotFoundException ex) {
// expected // expected
} } finally {
finally {
bean.destroy(); bean.destroy();
} }
} }
@ -115,8 +108,8 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
assertNotNull("MBeanServerConnection should not be null", connection); assertNotNull("MBeanServerConnection should not be null", connection);
// Test for MBean server equality. // Test for MBean server equality.
assertEquals("Registered MBean count should be the same", assertEquals("Registered MBean count should be the same", hostedServer.getMBeanCount(),
hostedServer.getMBeanCount(), connection.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXServiceURL;
import org.junit.Ignore;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.jmx.AbstractMBeanServerTests; import org.springframework.jmx.AbstractMBeanServerTests;
@ -43,8 +42,7 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
return JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, getServer()); return JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, getServer());
} }
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235 public void testValidConnection() throws Exception {
public void ignoreTestValidConnection() throws Exception {
JMXConnectorServer connectorServer = getConnectorServer(); JMXConnectorServer connectorServer = getConnectorServer();
connectorServer.start(); connectorServer.start();
@ -59,12 +57,10 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
// perform simple MBean count test // perform simple MBean count test
assertEquals("MBean count should be the same", getServer().getMBeanCount(), connection.getMBeanCount()); assertEquals("MBean count should be the same", getServer().getMBeanCount(), connection.getMBeanCount());
} } finally {
finally {
bean.destroy(); bean.destroy();
} }
} } finally {
finally {
connectorServer.stop(); connectorServer.stop();
} }
} }
@ -74,14 +70,12 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
try { try {
bean.afterPropertiesSet(); bean.afterPropertiesSet();
fail("IllegalArgumentException should be raised when no service url is provided"); fail("IllegalArgumentException should be raised when no service url is provided");
} } catch (IllegalArgumentException ex) {
catch (IllegalArgumentException ex) {
// expected // expected
} }
} }
@Ignore // see https://issuetracker.springsource.com/browse/BRITS-235 public void testWithLazyConnection() throws Exception {
public void ignoreTestWithLazyConnection() throws Exception {
MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean();
bean.setServiceUrl(SERVICE_URL); bean.setServiceUrl(SERVICE_URL);
bean.setConnectOnStartup(false); bean.setConnectOnStartup(false);
@ -95,8 +89,7 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
connector = getConnectorServer(); connector = getConnectorServer();
connector.start(); connector.start();
assertEquals("Incorrect MBean count", getServer().getMBeanCount(), connection.getMBeanCount()); assertEquals("Incorrect MBean count", getServer().getMBeanCount(), connection.getMBeanCount());
} } finally {
finally {
bean.destroy(); bean.destroy();
if (connector != null) { if (connector != null) {
connector.stop(); connector.stop();