User: juhalindfors
  Date: 02/01/24 14:16:04

  Modified:    src/main/test/compliance/server MBeanServerTEST.java
  Log:
  exception tests
  
  Revision  Changes    Path
  1.2       +280 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MBeanServerTEST.java      2002/01/23 21:39:35     1.1
  +++ MBeanServerTEST.java      2002/01/24 22:16:04     1.2
  @@ -9,18 +9,38 @@
   
   import junit.framework.TestCase;
   
  -import javax.management.*;
  +import javax.management.MBeanServer;
  +import javax.management.MBeanServerFactory;
  +import javax.management.ObjectName;
  +import javax.management.Attribute;
  +import javax.management.InstanceNotFoundException;
  +import javax.management.AttributeNotFoundException;
  +import javax.management.MBeanException;
  +import javax.management.RuntimeMBeanException;
  +import javax.management.RuntimeErrorException;
  +import javax.management.InvalidAttributeValueException;
   
  -public class MBeanServerTEST extends TestCase
  +import org.jboss.mx.server.ServerConstants;
  +import test.compliance.server.support.Test;
  +import test.compliance.server.support.TestMBean;
  +import test.compliance.server.support.MyScreamingException;
  +import test.compliance.server.support.ExceptionOnTheRun;
  +import test.compliance.server.support.BabarError;
  +
  +
  +public class MBeanServerTEST 
  +   extends TestCase 
  +   implements ServerConstants
   {
      public MBeanServerTEST(String s)
      {
         super(s);
      }
   
  -   public void testInvokeNonExistantMBean()
  +   public void testInvokeWithNonExistantMBean()
      {
  -      try {
  +      try
  +      {
            MBeanServer server = MBeanServerFactory.createMBeanServer();
            server.invoke(new ObjectName(":mbean=doesnotexist"), "noMethod", null, 
null);
            
  @@ -37,5 +57,260 @@
            fail("Unexpected error on server.invoke(NonExistantMBean): " + 
t.toString());
         }
      }
  -
  +   
  +   public void testInvokeWithBusinessException()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:test=test");
  +         server.registerMBean(new Test(), name);
  +         
  +         server.invoke(name, "operationWithException", null, null);
  +         
  +         // should not get here
  +         fail("MBeanException was not thrown.");
  +      }
  +      catch (MBeanException e)
  +      {
  +         // this is expected
  +         assertTrue(e.getTargetException() instanceof MyScreamingException);
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }
  +   }
  +   
  +   
  +   public void testGetAttributeWithNonExistingAttribute()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         Object foo = server.getAttribute(new ObjectName(MBEAN_SERVER_DELEGATE), 
"Foo");
  +         
  +         // should not reach here
  +         fail("AttributeNotFoundexception was not thrown when invoking 
getAttribute() call on a non-existant attribute.");
  +      }
  +      catch (AttributeNotFoundException e)
  +      {
  +         // Expecting this.
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }
  +   }
  +   
  +   public void testGetAttributeWithBusinessException()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:test=test");
  +         server.registerMBean(new Test(), name);
  +         
  +         Object foo = server.getAttribute(name, "ThisWillScream");
  +         
  +         // should not reach here
  +         fail("Did not throw the screaming exception");
  +      }
  +      catch (MBeanException e)
  +      {
  +         // this is expected
  +         assertTrue(e.getMessage().startsWith("Exception thrown by attribute"));
  +         assertTrue(e.getTargetException() instanceof MyScreamingException);
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }
  +   }
  +   
  +   public void testGetAttributeWithNonExistingMBean()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:name=DoesNotExist");
  +         
  +         server.getAttribute(name, "Whatever");
  +         
  +         // should not reach here
  +         fail("InstanceNotFoundException was not thrown on a nonexistant MBean.");
  +      }
  +      catch (InstanceNotFoundException e)
  +      {
  +         // this is expected
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }
  +   }
  +   
  +   public void testGetAttributeWithUncheckedException()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:test=test");
  +         server.registerMBean(new Test(), name);
  +         
  +         server.getAttribute(name, "ThrowUncheckedException");
  +         
  +         // should not reach here
  +         fail("RuntimeMBeanException was not thrown");
  +      }
  +      catch (RuntimeMBeanException e)
  +      {
  +         // this is expected
  +         assertTrue(e.getTargetException() instanceof ExceptionOnTheRun);
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected err0r: " + t.toString());
  +      }
  +   }
  +   
  +   public void testGetAttributeWithError()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:test=test");
  +         server.registerMBean(new Test(), name);
  +         
  +         server.getAttribute(name, "Error");
  +         
  +         // should not reach here
  +         fail("Error was not thrown");
  +      }
  +      catch (RuntimeErrorException e)
  +      {
  +         // this is expected
  +         assertTrue(e.getTargetError() instanceof BabarError);
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }
  +   }
  +   
  +   public void testSetAttributeWithNonExistingAttribute()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         server.setAttribute(new ObjectName(MBEAN_SERVER_DELEGATE), new 
Attribute("Foo", "value"));
  +         
  +         // should not reach here
  +         fail("AttributeNotFoundexception was not thrown when invoking 
getAttribute() call on a non-existant attribute.");
  +      }
  +      catch (AttributeNotFoundException e)
  +      {
  +         // Expecting this.
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }
  +   }
  +   
  +   public void testSetAttributeWithBusinessException()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:test=test");
  +         server.registerMBean(new Test(), name);
  +         
  +         server.setAttribute(name, new Attribute("ThisWillScream", "value"));
  +         
  +         // should not reach here
  +         fail("Did not throw the screaming exception");
  +      }
  +      catch (MBeanException e)
  +      {
  +         // this is expected
  +         assertTrue(e.getMessage().startsWith("Exception thrown by attribute"));
  +         assertTrue(e.getTargetException() instanceof MyScreamingException);
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }
  +   }
  +   
  +   public void testSetAttributeWithNonExistingMBean()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:name=DoesNotExist");
  +         
  +         server.setAttribute(name, new Attribute("Whatever", "nothing"));
  +         
  +         // should not reach here
  +         fail("InstanceNotFoundException was not thrown on a nonexistant MBean.");
  +      }
  +      catch (InstanceNotFoundException e)
  +      {
  +         // this is expected
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }      
  +   }
  +   
  +   public void testSetAttributeWithUncheckedException()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:test=test");
  +         server.registerMBean(new Test(), name);
  +         
  +         server.setAttribute(name, new Attribute("ThrowUncheckedException", 
"value"));
  +         
  +         // should not reach here
  +         fail("RuntimeMBeanException was not thrown");
  +      }
  +      catch (RuntimeMBeanException e)
  +      {
  +         // this is expected
  +         assertTrue(e.getTargetException() instanceof ExceptionOnTheRun);
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected err0r: " + t.toString());
  +      }      
  +   }
  +   
  +   public void testSetAttributeWithError()
  +   {
  +      try
  +      {
  +         MBeanServer server = MBeanServerFactory.createMBeanServer();
  +         ObjectName name = new ObjectName("test:test=test");
  +         server.registerMBean(new Test(), name);
  +         
  +         server.setAttribute(name, new Attribute("Error", "value"));
  +         
  +         // should not reach here
  +         fail("Error was not thrown");
  +      }
  +      catch (RuntimeErrorException e)
  +      {
  +         // this is expected
  +         assertTrue(e.getTargetError() instanceof BabarError);
  +      }
  +      catch (Throwable t)
  +      {
  +         fail("Unexpected error: " + t.toString());
  +      }      
  +   }
  +   
   }
  
  
  

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

Reply via email to