User: juhalindfors Date: 02/02/15 08:46:54 Modified: src/main/test/compliance/server MBeanServerTEST.java Log: Revision Changes Path 1.4 +353 -5 jmx/src/main/test/compliance/server/MBeanServerTEST.java Index: MBeanServerTEST.java =================================================================== RCS file: /cvsroot/jboss/jmx/src/main/test/compliance/server/MBeanServerTEST.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MBeanServerTEST.java 29 Jan 2002 03:33:22 -0000 1.3 +++ MBeanServerTEST.java 15 Feb 2002 16:46:54 -0000 1.4 @@ -8,6 +8,7 @@ package test.compliance.server; import junit.framework.TestCase; +import junit.framework.AssertionFailedError; import javax.management.MBeanServer; import javax.management.MBeanServerFactory; @@ -18,6 +19,7 @@ import javax.management.MBeanException; import javax.management.RuntimeMBeanException; import javax.management.RuntimeErrorException; +import javax.management.ReflectionException; import javax.management.InvalidAttributeValueException; import org.jboss.mx.server.ServerConstants; @@ -27,7 +29,13 @@ import test.compliance.server.support.ExceptionOnTheRun; import test.compliance.server.support.BabarError; - +/** + * Tests the MBean server impl. through the <tt>MBeanServer</tt> interface. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>. + * @version $Revision: 1.4 $ + * + */ public class MBeanServerTEST extends TestCase implements ServerConstants @@ -37,6 +45,12 @@ super(s); } + + // MBeanServer invoke -------------------------------------------- + + /** + * Attempts to invoke a method on an unregistered MBean; <tt>InstanceNotFoundException</tt> should occur. + */ public void testInvokeWithNonExistantMBean() { try @@ -51,6 +65,10 @@ { // should get here } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { t.printStackTrace(); @@ -58,6 +76,9 @@ } } + /** + * Attempts to invoke a MBean operation that throws a business exception; <tt>MBeanException</tt> should be thrown. + */ public void testInvokeWithBusinessException() { try @@ -76,6 +97,10 @@ // this is expected assertTrue(e.getTargetException() instanceof MyScreamingException); } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); @@ -83,6 +108,8 @@ } + // MBeanServer getAttribute -------------------------------------- + public void testGetAttributeWithNonExistingAttribute() { try @@ -97,6 +124,10 @@ { // Expecting this. } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); @@ -119,10 +150,12 @@ catch (MBeanException e) { // this is expected - // FIXME THS - commented the assertion below: is that really what's required? - // assertTrue(e.getMessage().startsWith("Exception thrown by attribute")); assertTrue(e.getTargetException() instanceof MyScreamingException); } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); @@ -145,6 +178,10 @@ { // this is expected } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); @@ -169,6 +206,10 @@ // this is expected assertTrue(e.getTargetException() instanceof ExceptionOnTheRun); } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected err0r: " + t.toString()); @@ -193,12 +234,19 @@ // this is expected assertTrue(e.getTargetError() instanceof BabarError); } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); } } + + // MBeanServer setAttribute -------------------------------------- + public void testSetAttributeWithNonExistingAttribute() { try @@ -213,6 +261,10 @@ { // Expecting this. } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); @@ -235,10 +287,12 @@ catch (MBeanException e) { // this is expected - // FIXME THS - is this a valid test? - //assertTrue(e.getMessage().startsWith("Exception thrown by attribute")); assertTrue(e.getTargetException() instanceof MyScreamingException); } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); @@ -261,6 +315,10 @@ { // this is expected } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); @@ -285,6 +343,10 @@ // this is expected assertTrue(e.getTargetException() instanceof ExceptionOnTheRun); } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected err0r: " + t.toString()); @@ -309,10 +371,296 @@ // this is expected assertTrue(e.getTargetError() instanceof BabarError); } + catch (AssertionFailedError e) + { + throw e; + } catch (Throwable t) { fail("Unexpected error: " + t.toString()); } } + + // MBeanServer instantiate --------------------------------------- + + /** + * Tests instantiate(String className). Class defined by system classloader. + */ + public void testInstantiateWithDefaultConstructor() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + Object o = server.instantiate("test.compliance.server.support.Test"); + + assertTrue(o instanceof test.compliance.server.support.Test); + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + /** + * Tests instantiate(String className) with constructor that throws a checked application exception. + * Class defined by system classloader. + */ + public void testInstantiateWithDefaultConstructorAndApplicationException() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + Object o = server.instantiate("test.compliance.server.support.ConstructorTest"); + + // shouldn't get here + fail("Instantiate should have thrown an MBeanException."); + } + catch (MBeanException e) + { + // this is expected + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + /** + * Tests instantiate(String className) with constructor that throws an unchecked application exception. + * Class defined by the system classloader. + */ + public void testInstantiateWithDefaultConstructorAndRuntimeException() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + Object o = server.instantiate("test.compliance.server.support.ConstructorTest2"); + + // shouldn't get here + fail("Instantiate should have thrown a RuntimeMBeanException."); + } + catch (RuntimeMBeanException e) + { + // this is expected + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + /** + * Tests instantiate(String className) with constructor that throws an error. + * Class defined by the system classloader. + */ + public void testInstantiateWithDefaultConstructorAndError() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + Object o = server.instantiate("test.compliance.server.support.ConstructorTest3"); + + // shouldn't get here + fail("Instantiate should have thrown a RuntimeErrorException."); + } + catch (RuntimeErrorException e) + { + // this is expected + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + /** + * Tests instantiate(String className) with constructor that fails with an unchecked exception in static init block. + * Class defined by the system classloader. + */ + public void testInstantiateWithDefaultConstructorAndExceptionInInit() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + + // FAILS IN RI + try + { + Object o = server.instantiate("test.compliance.server.support.ConstructorTest4"); + } + catch (ExceptionInInitializerError e) + { + // RI lets this error through unwrapped. In general, the MBean server is responsible + // of wrapping all errors and exceptions from MBeans and resource classes with either + // RuntimeErrorException, RuntimeMBeanException or MBeanException. The javadoc is unclear in + // this case should a ReflectionException or MBeanException be thrown (neither one can wrap an + // Error though). JBossMX throws an RuntimeMBeanException in case of an unchecked exception in + // static initializer and a RuntimeErrorException in case of an error in static initializer. + fail("FAILS IN RI: MBeanServer fails to wrap an error or exception from a static initializer block correctly."); + } + + // shouldn't get here + fail("Instantiate should have thrown a RuntimeMBeanException."); + } + catch (RuntimeMBeanException e) + { + // this is expected + + assertTrue(e.getTargetException() instanceof NullPointerException); + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + /** + * Tests instatiante(String className) with constructor that fails with an error in static init block. + * Class defined by the system classloader. + */ + public void testInstantiateWithDefaultConstructorAndErrorInInit() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + + // FAILS IN RI + try + { + Object o = server.instantiate("test.compliance.server.support.ConstructorTest5"); + } + catch (BabarError e) + { + // RI lets this error through unwrapped. In general, the MBean server is responsible + // of wrapping all errors and exceptions from MBeans and resource classes with either + // RuntimeErrorException, RuntimeMBeanException or MBeanException. The javadoc is unclear in + // this case should a ReflectionException or MBeanException be thrown (neither one can wrap an + // Error though). JBossMX throws an RuntimeMBeanException in case of an unchecked exception in + // static initializer and a RuntimeErrorException in case of an error in static initializer. + fail("FAILS IN RI: MBeanServer fails to wrap an error or exception from a static initializer block correctly."); + } + + // shouldn't get here + fail("Instantiate should have thrown a RuntimeErrorException."); + } + catch (RuntimeErrorException e) + { + // this is expected + + assertTrue(e.getTargetError() instanceof test.compliance.server.support.BabarError); + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + /** + * Tests instantiate(String className) with unfound class. + */ + public void testInstantiateWithDefaultConstructorAndUnknownClass() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + Object o = server.instantiate("foo.Bar"); + + // should not get here + fail("Instantiate should have thrown a ReflectionException."); + } + catch (ReflectionException e) + { + // this is expected + assertTrue(e.getTargetException() instanceof ClassNotFoundException); + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + /** + * Tests instantiate(String className) with class that doesn't have a default constructor. + */ + public void testInstantiateWithMissingDefaultConstructor() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + Object o = server.instantiate("test.compliance.server.support.ConstructorTest6"); + + // should not get here + fail("Instantiate should have thrown a ReflectionException."); + } + catch (ReflectionException e) + { + // this is expected + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + /** + * Tests instantiate(String className) with protected (no access) no args constructor. + */ + public void testInstantiateWithInaccessibleNoArgsConstructor() + { + try + { + MBeanServer server = MBeanServerFactory.createMBeanServer(); + Object o = server.instantiate("test.compliance.server.support.ConstructorTest7"); + + // should not get here + fail("Instantiate should have thrown a ReflectionException."); + } + catch (ReflectionException e) + { + // this is expected + } + catch (AssertionFailedError e) + { + throw e; + } + catch (Throwable t) + { + fail("Unexpected error: " + t.toString()); + } + } + + }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
