User: juhalindfors
  Date: 02/04/08 14:22:47

  Modified:    src/main/test/compliance/server MBeanServerTEST.java
  Log:
  
  
  Revision  Changes    Path
  1.10      +78 -91    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MBeanServerTEST.java      15 Mar 2002 20:26:42 -0000      1.9
  +++ MBeanServerTEST.java      8 Apr 2002 21:22:47 -0000       1.10
  @@ -30,6 +30,8 @@
   import javax.management.Notification;
   import javax.management.ObjectInstance;
   
  +import javax.management.loading.MLet;
  +
   import test.compliance.server.support.Test;
   import test.compliance.server.support.TestMBean;
   import test.compliance.server.support.Test2;
  @@ -52,7 +54,7 @@
    * Tests the MBean server impl. through the <tt>MBeanServer</tt> interface.
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Juha Lindfors</a>.
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    *   
    */
   public class MBeanServerTEST
  @@ -598,30 +600,19 @@
      /**
       * Tests instantiate(String className). Class defined by system classloader.
       */
  -   public void testInstantiateWithDefaultConstructor()
  +   public void testInstantiateWithDefaultConstructor() throws Exception
      {
  -      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());
  -      }
  +      MBeanServer server = MBeanServerFactory.createMBeanServer();
  +      Object o = server.instantiate("test.compliance.server.support.Test");
  +      
  +      assertTrue(o instanceof test.compliance.server.support.Test);
      }
      
      /**
       * Tests instantiate(String className) with constructor that throws a checked 
application exception.
       * Class defined by system classloader.
       */
  -    public void testInstantiateWithDefaultConstructorAndApplicationException()
  +    public void testInstantiateWithDefaultConstructorAndApplicationException() 
throws Exception
       {
          try
          {
  @@ -635,21 +626,13 @@
          {
             // 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()
  +    public void testInstantiateWithDefaultConstructorAndRuntimeException() throws 
Exception
       {
          try
          {
  @@ -663,21 +646,13 @@
          {
             // 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()
  +    public void testInstantiateWithDefaultConstructorAndError() throws Exception
       {
          try
          {
  @@ -691,21 +666,13 @@
          {
             // 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()
  +    public void testInstantiateWithDefaultConstructorAndExceptionInInit() throws 
Exception
       {
          try
          {
  @@ -736,21 +703,13 @@
             
             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()
  +    public void testInstantiateWithDefaultConstructorAndErrorInInit() throws 
Exception
       {
          try
          {
  @@ -781,20 +740,12 @@
             
             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()
  +    public void testInstantiateWithDefaultConstructorAndUnknownClass() throws 
Exception
       {
          try
          {
  @@ -809,20 +760,12 @@
             // 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()
  +    public void testInstantiateWithMissingDefaultConstructor() throws Exception
       {
          try
          {
  @@ -836,20 +779,12 @@
          {
             // 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()
  +    public void testInstantiateWithInaccessibleNoArgsConstructor() throws Exception
       {
          try
          {
  @@ -863,17 +798,69 @@
          {
             // this is expected
          }
  -       catch (AssertionFailedError e)
  -       {
  -          throw e;
  -       }
  -       catch (Throwable t)
  -       {
  -          fail("Unexpected error: " + t.toString());
  -       }
       }
  -    
  -    
  +
  +   /**
  +    * Tests instantiate(String className) classloading behaviour. According to
  +    * javadoc, DLR should be used to instantiate the class
  +    */
  +   public void testInstantiateWithDefaultLoaderRepository() throws Exception
  +   {
  +      // NOTE: 
  +      // the urls used here are relative to the location of the build.xml
  +
  +      MBeanServer server = MBeanServerFactory.createMBeanServer();
  +      MLet mlet = new MLet();
  +      
  +      // mlet cl to DLR
  +      mlet.addURL("file:./output/etc/test/compliance/server/Test.jar");
  +      server.registerMBean(mlet, new ObjectName(":test=test"));
  +      
  +      Object o = server.instantiate("test.compliance.server.support.AClass");
  +      
  +      assertTrue(o.getClass().getClassLoader().equals(mlet));
  +   }  
  +   
  +   /**
  +    * Tests instantiate(String className) classloading behaviour. According to
  +    * javadoc, DLR should be used to instantiate the class. This should fail as
  +    * the MLet MBean is never added to the agent and therefore not in the DLR.
  +    */
  +   public void testInstantiateWithDefaultLoaderRepository2() throws Exception
  +   {
  +      try
  +      {
  +         // NOTE: 
  +         // the urls used here are relative to the location of the build.xml
  +
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         MLet mlet = new MLet();
  +      
  +         // mlet cl to DLR
  +         mlet.addURL("file:./output/etc/test/compliance/server/Test.jar");
  +         //server.registerMBean(mlet, new ObjectName(":test=test"));
  +      
  +         Object o = server.instantiate("test.compliance.server.support.AClass");
  +      
  +//
  +// FIXME: this test won't work until we have means to reset the JVM wide
  +//        loader repository
  +//
  +
  +         // should not reach here
  +         //fail("incorrect classloading behavior");
  +         //assertTrue(o.getClass().getClassLoader().equals(mlet));
  +      }
  +      catch (ReflectionException e)
  +      {
  +         // expected
  +         
  +         // check that it wraps CNFE
  +         assertTrue(e.getTargetException() instanceof ClassNotFoundException);
  +      }
  +   }  
  +   
  +   
       // MBeanServer registerMBean ------------------------------------
       
       /**
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Sponsored by http://www.ThinkGeek.com/

Reply via email to