This commit overhauls several of the tests that interact with an
MBeanServer with the goal of increasing the reliability of these tests.
- MBeanClientInterceptorTests now uses JUnit "assumptions" instead of
preemptively returning from test methods, thus allowing such methods
to be properly marked as "ignored" instead of "passed".
- MBeanClientInterceptorTests now uses JUnit's support for expected
exceptions where appropriate.
- MBeanClientInterceptorTests and RemoteMBeanClientInterceptorTests now
use Spring's SocketUtils to find an available TCP port when starting
an MBeanServer instead of aborting the tests when the default JMX
port is not available.
Issue: SPR-12601
@ -85,16 +91,14 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@@ -85,16 +91,14 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@ -104,8 +108,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@@ -104,8 +108,7 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@Test
publicvoidtestGetAttributeValue()throwsException{
if(!runTests)
return;
assumeTrue(runTests);
IJmxTestBeanproxy1=getProxy();
intage=proxy1.getAge();
assertEquals("The age should be 100",100,age);
@ -113,69 +116,43 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@@ -113,69 +116,43 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@Test
publicvoidtestSetAttributeValue()throwsException{
if(!runTests)
return;
assumeTrue(runTests);
IJmxTestBeanproxy=getProxy();
proxy.setName("Rob Harrop");
assertEquals("The name of the bean should have been updated","Rob Harrop",target.getName());
fail("Should not be able to write to a read only attribute");
}catch(InvalidInvocationExceptionex){
// success
}
proxy.setAge(900);
}
@Test
publicvoidtestInvokeNoArgs()throwsException{
if(!runTests)
return;
assumeTrue(runTests);
IJmxTestBeanproxy=getProxy();
longresult=proxy.myOperation();
assertEquals("The operation should return 1",1,result);
@ -183,34 +160,27 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@@ -183,34 +160,27 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@Test
publicvoidtestInvokeArgs()throwsException{
if(!runTests)
return;
assumeTrue(runTests);
IJmxTestBeanproxy=getProxy();
intresult=proxy.add(1,2);
assertEquals("The operation should return 3",3,result);
@ -227,9 +197,8 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
@@ -227,9 +197,8 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
try{
connector.start();
}catch(BindExceptionex){
// 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 remainder of JMX LazyConnectionToRemote test because binding to local port ["
@ -50,7 +62,8 @@ public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTes
@@ -50,7 +62,8 @@ public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTes
try{
this.connectorServer.start();
}catch(BindExceptionex){
// skipping tests, server already running at this port
System.out.println("Skipping remote JMX tests because binding to local port ["
@ -58,7 +57,6 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
@@ -58,7 +57,6 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
@ -84,15 +82,10 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
@@ -84,15 +82,10 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe