diff --git a/spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java b/spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java index 8010dca2e7d784092d1e4241961b5bfbb143c738..ab05a3ea6ed094c46ec8cd9be0d34b2caccd2e38 100644 --- a/spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java @@ -25,18 +25,21 @@ import org.junit.Before; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericApplicationContext; +import org.springframework.tests.TestGroup; import org.springframework.util.MBeanTestUtils; import static org.junit.Assert.*; /** - * Note: the JMX test suite requires the presence of the - * {@code jmxremote_optional.jar} in your classpath. Thus, if you - * run into the "Unsupported protocol: jmxmp" error, you will - * need to download the - * JMX Remote API 1.0.1_04 Reference Implementation - * from Oracle and extract {@code jmxremote_optional.jar} into your - * classpath, for example in the {@code lib/ext} folder of your JVM. + * Note: certain tests throughout this hierarchy require the presence of + * the {@code jmxremote_optional.jar} in your classpath. For this reason, these tests are + * run only if {@link TestGroup#JMXMP} is enabled. If you wish to run these tests, follow + * the instructions in the TestGroup class to enable JMXMP tests. If you run into the + * "Unsupported protocol: jmxmp" error, you will need to download the + * + * JMX Remote API 1.0.1_04 Reference Implementation from Oracle and extract + * {@code jmxremote_optional.jar} into your classpath, for example in the {@code lib/ext} + * folder of your JVM. * See also EBR-349. * * @author Rob Harrop diff --git a/spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java b/spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java index c8d7b1c6b038f3d9ceedb630854f85852c7ab6c8..e1bd521a1df6dcd21149e1f9cc4b0d78e2a307d6 100644 --- a/spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java @@ -36,6 +36,10 @@ 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.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; /** * @author Rob Harrop @@ -204,6 +208,8 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests { if (!runTests) return; + Assume.group(TestGroup.JMXMP); + JMXServiceURL url = new JMXServiceURL("service:jmx:jmxmp://localhost:9876"); JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer()); diff --git a/spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java b/spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java index c36e788f1e7e50d589e77b84ea6d8cf03cb7df3b..74a29b0be018efe06a1d88219dcc46ea2fa884c9 100644 --- a/spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java @@ -26,6 +26,9 @@ import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + /** * @author Rob Harrop * @author Chris Beams @@ -40,6 +43,9 @@ public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTes @Override public void onSetUp() throws Exception { + runTests = false; + Assume.group(TestGroup.JMXMP); + runTests = true; super.onSetUp(); this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, getServer()); try { @@ -65,8 +71,12 @@ public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTes if (this.connector != null) { this.connector.close(); } - this.connectorServer.stop(); - super.tearDown(); + if (this.connectorServer != null) { + this.connectorServer.stop(); + } + if (runTests) { + super.tearDown(); + } } } diff --git a/spring-context/src/test/java/org/springframework/jmx/support/ConnectorServerFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/jmx/support/ConnectorServerFactoryBeanTests.java index 6bf72b5dbfb3ad6f2a3ac2daee8f9f5849be3e87..6d66caa79cf95b5bbf2d192b556f5ac5e8365825 100644 --- a/spring-context/src/test/java/org/springframework/jmx/support/ConnectorServerFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/support/ConnectorServerFactoryBeanTests.java @@ -30,6 +30,10 @@ import javax.management.remote.JMXServiceURL; import org.junit.Test; import org.springframework.jmx.AbstractMBeanServerTests; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; /** * @author Rob Harrop @@ -38,6 +42,20 @@ import org.springframework.jmx.AbstractMBeanServerTests; public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests { private static final String OBJECT_NAME = "spring:type=connector,name=test"; + private boolean runTests = false; + + @Override + protected void onSetUp() throws Exception { + Assume.group(TestGroup.JMXMP); + runTests = true; + } + + @Override + public void tearDown() throws Exception { + if (runTests) { + super.tearDown(); + } + } @Test public void testStartupWithLocatedServer() throws Exception { diff --git a/spring-context/src/test/java/org/springframework/jmx/support/MBeanServerConnectionFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/jmx/support/MBeanServerConnectionFactoryBeanTests.java index 0a346b6fc14a91cc41b1bebc51628d624f212da5..c9c83cffaeedfbd354a773eaec5c8f8760d60771 100644 --- a/spring-context/src/test/java/org/springframework/jmx/support/MBeanServerConnectionFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/support/MBeanServerConnectionFactoryBeanTests.java @@ -26,6 +26,10 @@ import javax.management.remote.JMXServiceURL; import org.junit.Test; import org.springframework.aop.support.AopUtils; import org.springframework.jmx.AbstractMBeanServerTests; +import org.springframework.tests.Assume; +import org.springframework.tests.TestGroup; + +import static org.junit.Assert.*; /** * @author Rob Harrop @@ -45,6 +49,7 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe @Test public void testTestValidConnection() throws Exception { + Assume.group(TestGroup.JMXMP); JMXConnectorServer connectorServer = getConnectorServer(); connectorServer.start(); @@ -78,7 +83,9 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe } } + @Test public void testTestWithLazyConnection() throws Exception { + Assume.group(TestGroup.JMXMP); MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); bean.setServiceUrl(SERVICE_URL); bean.setConnectOnStartup(false); diff --git a/spring-core/src/test/java/org/springframework/tests/TestGroup.java b/spring-core/src/test/java/org/springframework/tests/TestGroup.java index 7bd0ccdfd5e2ee928ddad871e90149f1e667f96b..662f0dab532f3df2bec33ef9efeaa6f035dbe883 100644 --- a/spring-core/src/test/java/org/springframework/tests/TestGroup.java +++ b/spring-core/src/test/java/org/springframework/tests/TestGroup.java @@ -48,7 +48,13 @@ public enum TestGroup { * {@code StopWatch}, etc. should be considered a candidate as their successful * execution is likely to be based on events occurring within a given time window. */ - PERFORMANCE; + PERFORMANCE, + + /** + * Tests requiring the presence of jmxremote_optional.jar in jre/lib/ext in order to + * avoid "Unsupported protocol: jmxmp" errors. + */ + JMXMP; /**