User: peter
Date: 00/08/09 21:10:20
Modified: src/main/org/jboss/test/cts/test Main.java
Log:
Update stateful session tests
Revision Changes Path
1.2 +187 -32 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Main.java 2000/06/21 15:52:39 1.1
+++ Main.java 2000/08/10 04:10:20 1.2
@@ -1,5 +1,6 @@
package org.jboss.test.cts.test;
+import java.io.*;
import java.util.*;
import java.lang.reflect.*;
import javax.ejb.*;
@@ -11,62 +12,74 @@
/**
*
* @see <related>
- * @author $Author: oberg $
- * @version $Revision: 1.1 $
+ * @author $Author: peter $
+ * @version $Revision: 1.2 $
*/
public class Main
extends junit.framework.TestCase
{
+ // Inner class --------------------------------------------------
+ class DummyPK implements Serializable
+ {
+ public String key;
+
+ public DummyPK( String key )
+ {
+ this.key = key;
+ }
+
+ }
+
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
- static boolean deployed = false;
+ static boolean deployed = false;
// Constructors --------------------------------------------------
- public Main(String name)
- {
- super(name);
- }
+ public Main(String name)
+ {
+ super(name);
+ }
- // Public --------------------------------------------------------
+ // 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.
- */
+ /**
+ * 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("cts/StatefulSessionBean");
- StatefulSession sessionBean = home.create();
- String result = sessionBean.method1( "CTS-Test" );
+ 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") );
+ // Test response
+ assert( result.equals("CTS-Test") );
- sessionBean.remove();
+ sessionBean.remove();
}
- /**
- * EJB 1.1 (Page 42)
- * "The home interface allows a client to do the following:"
- * - Create a new session object
- * - Remove session object
- * - Get the javax.ejb.EJBMetaData interface for the
- * session bean.
- * - Obtain a handle for the home interface
- */
+ //
+ // EJB 1.1 (Page 42)
+ // "The home interface allows a client to do the following:"
+ // - Create a new session object
+ // - Remove session object
+ // - Get the javax.ejb.EJBMetaData interface for the
+ // session bean.
+ // - Obtain a handle for the home interface
+ //
public void testEJBHomeInterface()
throws Exception
{
// Create a new session object
Context ctx = new InitialContext();
- StatefulSessionHome home = (StatefulSessionHome)
ctx.lookup("cts/StatefulSessionBean");
+ StatefulSessionHome home = (StatefulSessionHome)
ctx.lookup("ejbcts/StatefulSessionBean");
StatefulSession sessionBean = home.create();
// Get the EJBMetaData
@@ -89,15 +102,157 @@
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 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();
+
+ 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" );
- protected void setUp()
+ 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;
- }
+ }
}