User: peter   
  Date: 01/01/04 17:24:12

  Modified:    src/main/org/jboss/test/cts/test Main.java
  Log:
  Added loopback test.
  
  Revision  Changes    Path
  1.3       +254 -206  jbosstest/src/main/org/jboss/test/cts/test/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /products/cvs/ejboss/jbosstest/src/main/org/jboss/test/cts/test/Main.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Main.java 2000/08/10 04:10:20     1.2
  +++ Main.java 2001/01/05 01:24:11     1.3
  @@ -1,70 +1,90 @@
   package org.jboss.test.cts.test;
   
  +
  +
   import java.io.*;
   import java.util.*;
   import java.lang.reflect.*;
   import javax.ejb.*;
   import javax.naming.*;
   import javax.management.*;
  -
   import org.jboss.test.cts.interfaces.*;
   
  +
   /**
  - *      
  + *
    *   @see <related>
    *   @author $Author: peter $
  - *   @version $Revision: 1.2 $
  + *   @version $Revision: 1.3 $
    */
  +
   public class Main
      extends junit.framework.TestCase
   {
  +
      // Inner class --------------------------------------------------
  -   class DummyPK implements Serializable
  +   class DummyPK
  +      implements Serializable
      {
  -     public String key;
  -      
  -      public DummyPK( String key )
  -      {
  -        this.key = key;
  -      }
  -     
  -   } 
  +      public String key;
  +
  +      /**
  +       * Constructor DummyPK
  +       *
  +       *
  +       * @param key
  +       *
  +       */
  +
  +      public DummyPK (String key)
  +      {
  +         this.key = key;
  +      }
  +   }
   
      // Constants -----------------------------------------------------
  -    
      // Attributes ----------------------------------------------------
  -   
      // Static --------------------------------------------------------
      static boolean deployed = false;
  -     
  +
      // Constructors --------------------------------------------------
  -   public Main(String name)
  +
  +   /**
  +    * Constructor Main
  +    *
  +    *
  +    * @param name
  +    *
  +    */
  +
  +   public Main (String name)
      {
  -       super(name);
  +      super(name);
      }
  -   
  -  // Public --------------------------------------------------------
   
  -  /**
  -   * EJB 1.1 (Page 40) 
  -   *  "The container is responsible for making the home interfaces 
  -   *   of its deployed enterprise of its deployed enterprise beans
  -   *   available to the client through JNDI API extension.
  -   */
  -   public void testBasicSession() 
  -             throws Exception
  -   {
  -     Context ctx = new InitialContext();
  -      StatefulSessionHome home = (StatefulSessionHome) 
ctx.lookup("ejbcts/StatefulSessionBean");
  -      StatefulSession sessionBean = home.create();
  -      String result = sessionBean.method1( "CTS-Test" );             
  -        
  -     // Test response
  -     assert( result.equals("CTS-Test") );
  +   // Public --------------------------------------------------------
  +
  +   /**
  +    * EJB 1.1 (Page 40)
  +    *  "The container is responsible for making the home interfaces
  +    *   of its deployed enterprise of its deployed enterprise beans
  +    *   available to the client through JNDI API extension.
  +    */
   
  -     sessionBean.remove();
  +   public void testBasicSession ()
  +      throws Exception
  +   {
  +      Context             ctx         = new InitialContext();
  +      StatefulSessionHome home        =
  +         ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
  +      StatefulSession     sessionBean = home.create();
  +      String              result      = sessionBean.method1("CTS-Test");
  +
  +      // Test response
  +      assert(result.equals("CTS-Test"));
  +      sessionBean.remove();
      }
  -   
  +
      //
      // EJB 1.1 (Page 42) 
      // "The home interface allows a client to do the following:"
  @@ -73,186 +93,214 @@
      //    - Get the javax.ejb.EJBMetaData interface for the 
      //       session bean.
      //     - Obtain a handle for the home interface
  +   //
  +
  +   /**
  +    * Method testEJBHomeInterface
  +    *
  +    *
  +    * @throws Exception
  +    *
  +    */
  +
  +   public void testEJBHomeInterface ()
  +      throws Exception
  +   {
  +
  +      // Create a new session object   
  +      Context             ctx         = new InitialContext();
  +      StatefulSessionHome home        =
  +         ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
  +      StatefulSession     sessionBean = home.create();
  +
  +      // Get the EJBMetaData
  +      javax.ejb.EJBMetaData md = home.getEJBMetaData();
  +
  +      System.out.println("Verify EJBMetaData from home interface");
  +      assert(md != null);
  +
  +      // Get the EJBMetaData constructs
  +      System.out.println("Get Home interface class");
  +
  +      java.lang.Class homeInterface = md.getHomeInterfaceClass();
  +
  +      System.out.println("Get Primary key class");
  +
  +      java.lang.Class primaryKey = md.getPrimaryKeyClass();
  +
  +      System.out.println("Get Remote Interface class");
  +
  +      java.lang.Class remoteInterface = md.getRemoteInterfaceClass();
  +
  +      System.out.println("Verify isSession..");
  +      assert(md.isSession());
  +
  +      // EJB 1.1 only
  +      System.out.println("Verify is not Stateless session...");
  +      assert(!md.isStatelessSession());
  +   }
  +
  +   /*
  +   //-------------------------------------------------------------------------
  +   // EJB 1.1 (Page 42)
  +   // Removing a Session Object.
  +   // Because session objects do not have primary keys that are
  +   // accessible to clients, invoking the javax.ejb.Home.remove( Object primaryKey )
  +   // method on a session results in the javax.ejb.RemoveException.
      //
  -   public void testEJBHomeInterface() 
  -        throws Exception
  +   public void testRemoveSessionObject()
      {
  -             // Create a new session object   
  -             Context ctx = new InitialContext();
  -             StatefulSessionHome home = (StatefulSessionHome) 
ctx.lookup("ejbcts/StatefulSessionBean");
  -             StatefulSession sessionBean = home.create();
  -
  -             // Get the EJBMetaData
  -             javax.ejb.EJBMetaData md = home.getEJBMetaData();
  -             System.out.println( "Verify EJBMetaData from home interface" );
  -             assert(md != null );
  -
  -             // Get the EJBMetaData constructs
  -             System.out.println( "Get Home interface class" );
  -             java.lang.Class homeInterface  = md.getHomeInterfaceClass();
  -             System.out.println( "Get Primary key class" );
  -             java.lang.Class primaryKey     = md.getPrimaryKeyClass();
  -             System.out.println( "Get Remote Interface class" );
  -             java.lang.Class remoteInterface= md.getRemoteInterfaceClass();
  -
  -             System.out.println( "Verify isSession.." );
  -             assert( md.isSession() );
  -
  -             // EJB 1.1 only
  -             System.out.println( "Verify is not Stateless session..." );
  -             assert( !md.isStatelessSession() );
  +     try
  +         {
  +       Properties props = System.getProperties();
  +
  +       System.out.println( "Obtain home interface" );
  +       // Create a new session object
  +       Context ctx = new InitialContext(props);
  +           StatefulSessionHome home =
  +                   (StatefulSessionHome) ctx.lookup("ejbcts/StatefulSessionBean");
  +       StatefulSession sessionBean = home.create();
  +
  +           home.remove( new DummyPK( "pk" ) );
  +
  +     }
  +     catch(javax.ejb.RemoveException rmEx)
  +         {
  +           // Expected behavior
  +       return;
  +     }
  +         catch(Exception ex)
  +         {
  +           ex.printStackTrace();
  +           fail("Expected javax.ejb.RemoveException, got Unknown Exception");
  +         }
  +
  +         fail("Expected javax.ejb.RemoveException, got NO exception");
  +
      }
  +   //-------------------------------------------------------------------------
   
  -  /* 
  -  //-------------------------------------------------------------------------
  -  // EJB 1.1 (Page 42) 
  -  // Removing a Session Object.
  -  // Because session objects do not have primary keys that are
  -  // accessible to clients, invoking the javax.ejb.Home.remove( Object primaryKey )
  -  // method on a session results in the javax.ejb.RemoveException.
  -  // 
  -  public void testRemoveSessionObject() 
  -  {
  -    try 
  -     {
  -      Properties props = System.getProperties();
   
  -      System.out.println( "Obtain home interface" );
  -      // Create a new session object   
  -      Context ctx = new InitialContext(props);
  -       StatefulSessionHome home = 
  -               (StatefulSessionHome) ctx.lookup("ejbcts/StatefulSessionBean");
  -      StatefulSession sessionBean = home.create();
  -             
  -       home.remove( new DummyPK( "pk" ) ); 
  -       
  -    }
  -    catch(javax.ejb.RemoveException rmEx) 
  -     {
  -       // Expected behavior
  -      return;
  -    }
  -     catch(Exception ex)
  -     {
  -       ex.printStackTrace();
  -       fail("Expected javax.ejb.RemoveException, got Unknown Exception");
  -     }       
  -     
  -     fail("Expected javax.ejb.RemoveException, got NO exception");
  -     
  -  }
  -  //-------------------------------------------------------------------------
  -     
  -     
  -  //-------------------------------------------------------------------------
  -  // EJB 1.1 [5.5] Page 43
  -  // EJBOjbect.getPrimaryKey results in a RemoteException
  -  // Get a serializable handle
  -  // Compare on bean to another for equality
  -  // 
  -  public void testCompareSerializeGetPK() 
  -  {
  -     StatefulSession sessionBean = null;
  -     
  -    try 
  -     {
  -      Properties props = System.getProperties();
  +   //-------------------------------------------------------------------------
  +   // EJB 1.1 [5.5] Page 43
  +   // EJBOjbect.getPrimaryKey results in a RemoteException
  +   // Get a serializable handle
  +   // Compare on bean to another for equality
  +   //
  +   public void testCompareSerializeGetPK()
  +   {
  +         StatefulSession sessionBean = null;
   
  -      System.out.println( "Obtain home interface" );
  -      // Create a new session object   
  -      Context ctx = new InitialContext(props);
  -       StatefulSessionHome home = 
  -               (StatefulSessionHome) ctx.lookup("ejbcts/StatefulSessionBean");
  -      sessionBean = home.create();
  -     }
  -     catch( Exception Ex )
  -     {
  -       fail("Caught an Unknown Exception in lookup" );
  -     }
  -     
  -     try
  -     {
  -       // Get the bean handle
  -       Handle hn = sessionBean.getHandle();
  -       assert( hn != null );
  -       
  -       // "Copy" the bean
  -       StatefulSession theOtherBean = 
  -         (StatefulSession)javax.rmi.PortableRemoteObject.narrow(hn.getEJBObject( ),
  -                                                                    
StatefulSession.class);
  -       assert( theOtherBean != null );
  -       assert( sessionBean.isIdentical(theOtherBean) );         
  -       
  -     }
  -     catch( java.lang.ClassCastException CCEx )
  -     {
  -             fail( "Caught ClassCast exception!" );
  -     }
  -     catch( Exception Ex )
  -     {
  -      fail( "Caught an Unknown exception copying the beans" );
  -     }
  -     
  -  }
  -  //-------------------------------------------------------------------------       
 
  -  */
  - 
  -  //-------------------------------------------------------------------------
  -  // EJB 1.1 
  -  // 
  -  public void testCallbacks( )
  -  {
  -    System.out.println( "Callback test" );
  -     
  -     StatefulSession sessionBean[] = 
  -       new StatefulSession[125];
  -     StatefulSessionHome home = null;  
  -     int i=0;  
  -       
  -    try 
  -     {
  -      Properties props = System.getProperties();
  +     try
  +         {
  +       Properties props = System.getProperties();
  +
  +       System.out.println( "Obtain home interface" );
  +       // Create a new session object
  +       Context ctx = new InitialContext(props);
  +           StatefulSessionHome home =
  +                   (StatefulSessionHome) ctx.lookup("ejbcts/StatefulSessionBean");
  +       sessionBean = home.create();
  +         }
  +         catch( Exception Ex )
  +         {
  +           fail("Caught an Unknown Exception in lookup" );
  +         }
  +
  +         try
  +         {
  +           // Get the bean handle
  +           Handle hn = sessionBean.getHandle();
  +           assert( hn != null );
  +
  +           // "Copy" the bean
  +           StatefulSession theOtherBean =
  +             
(StatefulSession)javax.rmi.PortableRemoteObject.narrow(hn.getEJBObject( ),
  +                                                                        
StatefulSession.class);
  +           assert( theOtherBean != null );
  +           assert( sessionBean.isIdentical(theOtherBean) );
  +
  +         }
  +         catch( java.lang.ClassCastException CCEx )
  +         {
  +                 fail( "Caught ClassCast exception!" );
  +         }
  +         catch( Exception Ex )
  +         {
  +       fail( "Caught an Unknown exception copying the beans" );
  +         }
   
  -      System.out.println( "Obtain home interface" );
  -      // Create a new session object   
  -      Context ctx = new InitialContext(props);
  -       home = 
  -        (StatefulSessionHome) ctx.lookup("ejbcts/StatefulSessionBean");
  -      
  -     }
  -     catch( Exception Ex )
  -     {
  -       fail("Caught an Unknown Exception in lookup" );
  -     }
  -     
  -     try
  -     {
  -       for( i=0; i<125; i++ )
  -       {
  -         sessionBean[i] = home.create();
  -             sessionBean[i].method1("test");
  -             Thread.sleep(500);
  -       }
  -       // Kill all the beans
  -       for( i=0; i<125; i++ )
  -             sessionBean[i].remove();
  -     }
  -     catch( Exception ex )
  -     {
  -       ex.printStackTrace();
  -       fail( "Caught an unknown excpeption" );
  -     }
  -  
  -  } // testCallbacks()
  - 
  -  protected void setUp()
  +   }
  +   //-------------------------------------------------------------------------
  +   */
  +
  +   //-------------------------------------------------------------------------
  +   // EJB 1.1 
  +   // 
  +
  +   /**
  +    * Method testCallbacks
  +    *
  +    *
  +    */
  +
  +   public void testCallbacks ()
  +   {
  +      System.out.println("Callback test");
  +
  +      StatefulSession     sessionBean [] = new StatefulSession [125];
  +      StatefulSessionHome home           = null;
  +      int                 i              = 0;
  +
  +      try
  +      {
  +         Properties props = System.getProperties();
  +
  +         System.out.println("Obtain home interface");
  +
  +         // Create a new session object   
  +         Context ctx = new InitialContext(props);
  +
  +         home =
  +            ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
  +      }
  +      catch (Exception Ex)
  +      {
  +         fail("Caught an Unknown Exception in lookup");
  +      }
  +
  +      try
  +      {
  +         for (i = 0; i < 125; i++)
  +         {
  +            sessionBean [i] = home.create();
  +
  +            sessionBean [i].method1("test");
  +            Thread.sleep(500);
  +         }
  +
  +         // Kill all the beans
  +         for (i = 0; i < 125; i++)
  +            sessionBean [i].remove();
  +      }
  +      catch (Exception ex)
  +      {
  +         ex.printStackTrace();
  +         fail("Caught an unknown excpeption");
  +      }
  +   }   // testCallbacks()
  +
  +   protected void setUp ()
         throws Exception
  -  {
  +   {
         if (deployed) return;
  +
         System.out.println("Deploying");
         new org.jboss.jmx.client.Deployer().deploy("../deploy/cts.jar");
  +
         deployed = true;
  -  }
  +   }
   }
   
   
  +/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
  
  
  

Reply via email to