User: peter   
  Date: 01/02/18 08:04:47

  Modified:    src/main/org/jboss/test/cts/test AllJUnitTests.java
                        bmpTest.java
  Log:
  Added some callback tests for BMP.  Added support for CMP
  testing.
  
  Revision  Changes    Path
  1.8       +8 -3      jbosstest/src/main/org/jboss/test/cts/test/AllJUnitTests.java
  
  Index: AllJUnitTests.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jbosstest/src/main/org/jboss/test/cts/test/AllJUnitTests.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AllJUnitTests.java        2001/02/15 02:29:53     1.7
  +++ AllJUnitTests.java        2001/02/18 16:04:47     1.8
  @@ -46,8 +46,8 @@
   
         try
         {
  -         System.out.println("Deploying");
  -         new org.jboss.jmx.client.Deployer().deploy("../deploy/cts.jar");
  +       System.out.println("Deploying");
  +       new org.jboss.jmx.client.Deployer().deploy("../deploy/cts.jar");
         }
         catch (Exception ex)
         {
  @@ -64,12 +64,17 @@
         //suite.addTest(new StatefulSessionTest("testCompareSerializeGetPK"));
         //suite.addTest(new StatefulSessionTest("testProbeBeanContext"));
         //suite.addTest(new StatefulSessionTest("testLoopback"));
  -      //suite.addTest(new StatelessSessionTest("testBasicStatelessSession"));
         //suite.addTest(new StatefulSessionTest("testUserTrx"));
  +
  +      //suite.addTest(new StatelessSessionTest("testBasicStatelessSession"));
  +
         suite.addTest(new bmpTest("testEjbCreate"));
         suite.addTest(new bmpTest("testEjbFinder"));
         suite.addTest(new bmpTest("testEjbRemove"));
         suite.addTest(new bmpTest("testEjbLifeCycle"));
  +      suite.addTest(new bmpTest("testPrimaryKeyObjectIdentity"));
  +      suite.addTest(new bmpTest("testEjbRemoteIF"));
  +      suite.addTest(new bmpTest("testEntityHandle"));
   
         return suite;
      }
  
  
  
  1.3       +216 -1    jbosstest/src/main/org/jboss/test/cts/test/bmpTest.java
  
  Index: bmpTest.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jbosstest/src/main/org/jboss/test/cts/test/bmpTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- bmpTest.java      2001/02/15 02:29:54     1.2
  +++ bmpTest.java      2001/02/18 16:04:47     1.3
  @@ -1,7 +1,7 @@
   package org.jboss.test.cts.test;
   
   
  -
  +import java.io.*;
   import javax.ejb.*;
   import javax.naming.*;
   import javax.rmi.PortableRemoteObject;
  @@ -277,6 +277,221 @@
   
         System.out.println(
            "**************************************************************");
  +   }
  +
  +   /**
  +    * Method testPrimaryKeyObjectIdentity
  +    * EJB 1.1 [8.5] p. 92-93
  +    * 
  +    * Every entity object has a unique identity within its home.   If
  +    * two entity objects have the same home and the same primary key
  +    * they are considered identitcal.
  +    *
  +    * getPrimaryKey() always returns the same value when called one the
  +    * same entity object.
  +    * 
  +    * A client can test whether two entity object references refer to the 
  +    * same entity object by using the isIdentical(EBJObject) method. 
  +    * Alternatively, if a client obtains two entity object references from
  +    * the same home, it can determin if they refer to the same entity by comparing 
  +    * their primary keys using the 'equals' method.
  +    * 
  +    * @throws Exception
  +    *
  +    */
  +
  +   public void testPrimaryKeyObjectIdentity ()
  +   {
  +     System.out.println(
  +         "**************************************************************");
  +     System.out.println("     testPrimaryKeyObjectIdentity()");
  +
  +     CtsBmp bean = null;
  +     CtsBmp anotherBean = null;
  +     CtsBmp differentBean = null;
  +
  +     try
  +     {
  +       Context    ctx  = new InitialContext();
  +       CtsBmpHome home =
  +            ( CtsBmpHome ) new InitialContext().lookup("ejbcts/BMPBean");
  +
  +       System.out.println("new bean");
  +       AccountPK pk = new AccountPK(BEAN_PK_007);
  +       bean = home.create(pk, bmpTest.BEAN_NAME);
  +       System.out.println("OK");
  +       System.out.println("Now query based on the 'PersonsName': " + 
bmpTest.BEAN_NAME);
  +       Collection clct = home.findByPersonsName(bmpTest.BEAN_NAME);
  +       System.out.println( "Verify result set not empty" );
  +       assert( !clct.isEmpty() );
  +       System.out.println( "OK" );
  +       System.out.println( "Bean result set:" );
  +       for( Iterator itr=clct.iterator(); itr.hasNext(); )
  +       {
  +             anotherBean = ( CtsBmp ) itr.next();
  +             System.out.println("Use 'isIdentical()' to compare beans");
  +             anotherBean.isIdentical(bean);
  +             System.out.println( "beans match..OK" );
  +       }
  +       System.out.println("Make a bean that doesn't match");
  +       AccountPK anotherPK = new AccountPK("123");
  +       differentBean = home.create(anotherPK, "SomeOtherGuy");
  +       System.out.println("OK");
  +       System.out.println("Use 'isIdentical()' to verify different beans");
  +       assert( !differentBean.isIdentical(bean) );
  +       System.out.println("OK...beans are different!");
  +       System.out.println("Test the Primary Keys" );
  +       AccountPK beansPK = ( AccountPK ) bean.getPrimaryKey( );
  +       AccountPK anotherBeansPK = ( AccountPK ) anotherBean.getPrimaryKey( );
  +       assert( beansPK.equals(anotherBeansPK) );
  +       System.out.println("OK...they're the same");
  +       System.out.println("Compare different keys");
  +       assert( !beansPK.equals(anotherPK) );
  +       System.out.println("OK...they're different");
  +
  +      System.out.println(
  +         "**************************************************************");
  +
  +     }
  +     catch(Exception ex)
  +     {
  +      fail("Caught an unknown exception: " + ex.toString() );
  +     }
  +   }
  +
  +   /**
  +    * Method testEjbRemoteIF
  +    * EJB 1.1 [8.6] p. 93-94
  +    *
  +    * The javax.ejb.EJBObject I/F defines the methods that allow the client
  +    * to perform the following:
  +    * - Obtain the home interface for the entity object
  +    * - Remove the entity object
  +    * - Obtain the entity object's handle
  +    * - Obtain the entity object's primary key 
  +    * 
  +    * @throws Exception
  +    *
  +    */
  +
  +   public void testEjbRemoteIF ()
  +   {
  +     System.out.println(
  +         "**************************************************************");
  +     System.out.println("     testEjbRemoteIF ()");
  +
  +      CtsBmp bean = null;
  +
  +      try
  +      {
  +         Context    ctx  = new InitialContext();
  +         CtsBmpHome home =
  +            ( CtsBmpHome ) new InitialContext().lookup("ejbcts/BMPBean");
  +
  +         System.out.println("new bean");
  +         AccountPK pk = new AccountPK(BEAN_PK_007);
  +         bean = home.create(pk, bmpTest.BEAN_NAME);
  +         System.out.println( "Obtain the HOME interface" );
  +         home = ( CtsBmpHome ) bean.getEJBHome( );
  +         assert( home != null );
  +         System.out.println("OK");
  +         System.out.println( "Obtain the HANDLE" );
  +         Handle han = bean.getHandle( );
  +         assert ( han != null );
  +         System.out.println("OK");
  +         pk = ( AccountPK ) bean.getPrimaryKey();
  +         assert( pk != null );
  +         System.out.println("OK");
  +         System.out.println("Remove the entity bean");
  +         System.out.println("OK");
  +      }
  +      catch( Exception ex )
  +      {
  +       fail("Caught an unknown exception" + ex.toString() );
  +      }
  +
  +      System.out.println(
  +         "**************************************************************");
  +   }
  +
  +   /**
  +    * Method testEntityHandle
  +    * EJB 1.1 [8.7] p. 93-94
  +    *
  +    * - Client can get handle to remote interface
  +    * - Use javax.rmi.PortableRemoteObject.narrow(...) to convert the 
  +    *   result of the getEJBObject().
  +    * - An entity handle is typically implemented to be usable over a 
  +    *   long period of time it must be usable at least across a server
  +    *   restart.
  +    * 
  +    * @throws Exception
  +    *
  +    */
  +
  +   public void testEntityHandle ()
  +   {
  +     System.out.println(
  +         "**************************************************************");
  +     System.out.println("     testEntityHandle()"); 
  +
  +      CtsBmp bean = null;
  +
  +      try
  +      {
  +         Context    ctx  = new InitialContext();
  +         CtsBmpHome home =
  +            ( CtsBmpHome ) new InitialContext().lookup("ejbcts/BMPBean");
  +
  +         System.out.println("make a new bean");
  +         AccountPK pk = new AccountPK(BEAN_PK_007);
  +         bean = home.create(pk, bmpTest.BEAN_NAME); 
  +         System.out.println("OK");
  +         System.out.println("Get a Handle reference and serialize it");
  +         Handle beanHandle = bean.getHandle();
  +         FileOutputStream out = new FileOutputStream("bmp.ser");
  +         ObjectOutputStream s = new ObjectOutputStream(out);
  +
  +         s.writeObject(beanHandle);
  +         s.flush();
  +         System.out.println("OK");
  +  
  +         unserializeBean( );
  +
  +      }
  +      catch(Exception ex)
  +      {
  +       fail("Caught an unknown exeption: " + ex.toString() );
  +      }
  +
  +     System.out.println(
  +         "**************************************************************");
  +
  +   }
  +
  +   // Use this to unserialize a bean reference and reconstitue
  +   private void unserializeBean( ) 
  +   {
  +     try
  +     {
  +      System.out.println("unserialize bean");
  +         FileInputStream in = new FileInputStream("bmp.ser");
  +         ObjectInputStream s = new ObjectInputStream(in);
  +         System.out.println("Constitute handle from file");
  +         Handle beanHandle = ( Handle ) s.readObject();
  +         System.out.println("OK");
  +
  +         System.out.println("Use PortableRemoteObject to narrow result");
  +         CtsBmp bean = 
  +          ( CtsBmp ) 
PortableRemoteObject.narrow(beanHandle.getEJBObject(),CtsBmp.class);
  +         System.out.println("OK");
  +         System.out.println("Clean up and remove bean");
  +         bean.remove();
  +         System.out.println("OK");
  +     }
  +     catch(Exception ex)
  +     {
  +     }
      }
   
      // Used to test passing a Entity bean as a parameter.
  
  
  

Reply via email to