User: ejort   
  Date: 02/02/22 08:44:34

  Added:       src/main/test/implementation/server
                        ObjectInstanceTestCase.java ServerSUITE.java
  Log:
  Default Domain, Querying, Various Other Fixes
  
  Revision  Changes    Path
  1.1                  
jmx/src/main/test/implementation/server/ObjectInstanceTestCase.java
  
  Index: ObjectInstanceTestCase.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package test.implementation.server;
  
  import junit.framework.TestCase;
  
  import test.implementation.server.support.Trivial;
  
  import java.io.ByteArrayInputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.ObjectName;
  import javax.management.ObjectInstance;
  
  import org.jboss.mx.server.ServerObjectInstance;
  
  /**
   * Tests the ObjectInstance handling which is a bit brain-dead in the RI.<p>
   *
   * Maybe one-day these will be part of the compliance testsuite.
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>.
   */
  public class ObjectInstanceTestCase
    extends TestCase
  {
     // Attributes ----------------------------------------------------------------
  
     // Constructor ---------------------------------------------------------------
  
     /**
      * Construct the test
      */
     public ObjectInstanceTestCase(String s)
     {
        super(s);
     }
  
     // Tests that should work in the RI ------------------------------------------
  
     /**
      * Test default domain
      */
     public void testDefaultDomain()
     {
        MBeanServer server =null;
        ObjectName unqualifiedName = null;
        ObjectName qualifiedName = null;
        ObjectInstance instance1 = null;
        ObjectInstance instance2 = null;
        try
        {
           server = MBeanServerFactory.createMBeanServer();
           unqualifiedName = new ObjectName(":property=1");
           qualifiedName = new ObjectName("DefaultDomain:property=1");
           instance1 = server.registerMBean(new Trivial(), qualifiedName);
           instance2 = server.getObjectInstance(unqualifiedName);
        }
        catch (Exception e)
        {
           fail(e.toString());
        }
  
        assertEquals(instance1.getObjectName(),qualifiedName);
        assertEquals(instance1, instance2);
  
        if (server != null)
           MBeanServerFactory.releaseMBeanServer(server);
     }
  
     /**
      * Test different servers
      */
     public void testDifferentServers()
     {
        MBeanServer server =null;
        ObjectName name = null;
        ObjectInstance instance1 = null;
        ObjectInstance instance2 = null;
        try
        {
           server = MBeanServerFactory.createMBeanServer();
           name = new ObjectName(":property=1");
           instance1 = server.registerMBean(new Trivial(), name);
           MBeanServerFactory.releaseMBeanServer(server);
           server = MBeanServerFactory.createMBeanServer();
           instance2 = server.registerMBean(new Trivial(), name);
        }
        catch (Exception e)
        {
           fail(e.toString());
        }
  
        if (instance1.equals(instance2) == true)
           fail("Instances in different servers are the same");
  
        if (server != null)
           MBeanServerFactory.releaseMBeanServer(server);
     }
  
     // Tests that need to work in JBossMX  because of the extra agent id --------
  
     /**
      * Test ObjectInstance/ServerObjectInstance Equals
      */
     public void testEquals()
     {
        // Create the object instances
        ObjectInstance oi = null;
        ServerObjectInstance soi = null;
        ObjectName name = null;
        String className = "org.jboss.AClass";
        try
        {
           name = new ObjectName(":a=a");
           oi = new ObjectInstance(name, className);
           soi = new ServerObjectInstance(name, className, "agentid");
        }
        catch (Exception e)
        {
          fail(e.toString());
        }
        assertEquals(oi, soi);
     }
     /**
      * Test serialization. For moving between implementations, this HAS
      * to produce an ObjectInstance.
      */
     public void testSerialization()
     {
        // Create the new object Instance
        ServerObjectInstance original = null;
        ObjectInstance result = null;
        ObjectName name = null;
        String className = "org.jboss.AClassName";
        try
        {
           name = new ObjectName(":a=a");
           original = new ServerObjectInstance(name, className, "agentid");
        }
        catch (Exception e)
        {
           fail(e.toString());
        }
  
        try
        {
           // Serialize it
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           ObjectOutputStream oos = new ObjectOutputStream(baos);
           oos.writeObject(original);
      
           // Deserialize it
           ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
           ObjectInputStream ois = new ObjectInputStream(bais);
           result = (ObjectInstance) ois.readObject();
        }
        catch (IOException ioe)
        {
           fail(ioe.toString());
        }
        catch (ClassNotFoundException cnfe)
        {
           fail(cnfe.toString());
        }
  
        // Did it work?
        assertEquals("javax.management.ObjectInstance", result.getClass().getName());
        assertEquals(name, result.getObjectName());
        assertEquals(className, result.getClassName());
     }
  }
  
  
  
  1.1                  jmx/src/main/test/implementation/server/ServerSUITE.java
  
  Index: ServerSUITE.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package test.implementation.server;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  /**
   * JBossMX Specific Server tests.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>.
   */
  public class ServerSUITE
    extends TestSuite
  {
    /**
     * Run the tests
     * 
     * @param args the arguments for the test
     */
    public static void main(String[] args)
    {
      junit.textui.TestRunner.run(suite());
    }
  
    /**
     * Get a list of tests.
     *
     * @return the tests
     */
    public static Test suite()
    {
      TestSuite suite = new TestSuite("JBossMX Specific Server tests");
  
      suite.addTest(new TestSuite(ObjectInstanceTestCase.class));
  
      return suite;
    }
  }
  
  
  

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

Reply via email to