User: peter
Date: 01/02/14 18:29:55
Modified: src/main/org/jboss/test/cts/test AllJUnitTests.java
bmpTest.java
Log:
More tests for BMP in JCTS.
Revision Changes Path
1.7 +14 -11 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AllJUnitTests.java 2001/01/25 02:45:41 1.6
+++ AllJUnitTests.java 2001/02/15 02:29:53 1.7
@@ -55,18 +55,21 @@
System.exit(0);
}
- suite.addTest(new StatefulSessionTest("testBasicSession"));
- suite.addTest(new StatefulSessionTest("testEJBHomeInterface"));
+ //suite.addTest(new StatefulSessionTest("testBasicSession"));
+ //suite.addTest(new StatefulSessionTest("testEJBHomeInterface"));
// Broken 12/05/00
- suite.addTest(new StatefulSessionTest("testRemoveSessionObject"));
- suite.addTest(new StatefulSessionTest("testSerialization"));
- suite.addTest(new StatefulSessionTest("testUnSerialization"));
- 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 bmpTest("testBasicBmp"));
+ //suite.addTest(new StatefulSessionTest("testRemoveSessionObject"));
+ //suite.addTest(new StatefulSessionTest("testSerialization"));
+ //suite.addTest(new StatefulSessionTest("testUnSerialization"));
+ //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 bmpTest("testEjbCreate"));
+ suite.addTest(new bmpTest("testEjbFinder"));
+ suite.addTest(new bmpTest("testEjbRemove"));
+ suite.addTest(new bmpTest("testEjbLifeCycle"));
return suite;
}
1.2 +227 -12 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- bmpTest.java 2001/01/25 02:45:42 1.1
+++ bmpTest.java 2001/02/15 02:29:54 1.2
@@ -6,8 +6,7 @@
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.rmi.*;
-import java.sql.*;
-import javax.sql.DataSource;
+import java.util.*;
import org.jboss.test.cts.interfaces.*;
import org.jboss.test.cts.keys.*;
import org.jboss.test.util.ejb.*;
@@ -26,7 +25,9 @@
{
static boolean deployed = false;
private SessionContext ctx = null;
- private DataSource ds = null;
+ public static final String BEAN_NAME = "GuysName";
+ public static final String BEAN_OTHER_NAME = "OtherGuysName";
+ public static final String BEAN_PK_007 = "007";
/**
* Constructor bmpTest
@@ -42,19 +43,68 @@
}
/**
- * Method testBasicBmp
+ * Method testEjbCreate
+ * EJB 1.1 [8.3.1] p. 89
+ * An entity bean's home interface can define zero or more create(...)
+ * methods.
*
+ * @throws Exception
+ *
+ */
+
+ public void testEjbCreate ()
+ throws Exception
+ {
+ System.out.println(
+ "**************************************************************");
+ System.out.println(" testEjbCreate()");
+
+ CtsBmp bean = null;
+
+ try
+ {
+ Context ctx = new InitialContext();
+ CtsBmpHome home =
+ ( CtsBmpHome ) new InitialContext().lookup("ejbcts/BMPBean");
+
+ System.out.println("create bean, name=" + bmpTest.BEAN_NAME);
+
+ AccountPK pk = new AccountPK(BEAN_PK_007);
+
+ bean = home.create(pk, bmpTest.BEAN_NAME);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("testEjbCreate has failed!");
+ }
+
+ System.out.println(
+ "**************************************************************");
+ }
+
+ /**
+ * Method testEjbFinder
+ * EJB 1.1 [8.3.2] p. 90
+ * An entity bean's home interface defines one or more finder methods,
+ * one for each way to find and entity object or collection of entity objects
+ * within the home.
*
+ * Test stategy: use the bean that has been previously created, and call
+ * the finder method. Make sure that a result set is returned
+ * and that the bean returned has the same name associated with
+ * it as the bean that was previously created.
+ *
* @throws Exception
*
*/
- public void testBasicBmp ()
+ public void testEjbFinder ()
throws Exception
{
System.out.println(
"**************************************************************");
- System.out.println(" testBasicBmp()");
+ System.out.println(" testEjbFinder()");
CtsBmp bean = null;
@@ -63,28 +113,188 @@
Context ctx = new InitialContext();
CtsBmpHome home =
( CtsBmpHome ) new InitialContext().lookup("ejbcts/BMPBean");
+
+ System.out.println("Find bean, name=" + 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(); )
+ {
+ bean = ( CtsBmp ) itr.next();
+ System.out.println( "Name from Bean=" + bean.getPersonsName() );
+ System.out.println( "Verify bean name equals: " + bmpTest.BEAN_NAME );
+ assert (bean.getPersonsName().trim().equals(bmpTest.BEAN_NAME) );
+ System.out.println( "OK" );
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("testEjbFinder has failed!");
+ }
- System.out.println("create foo bean");
+ System.out.println(
+ "**************************************************************");
+ }
- AccountPK pk = new AccountPK("1");
+ /**
+ * Method testEjbRemove
+ * EJB 1.1 [8.3.3] p. 90
+ *
+ * Test Strategy: 1) Attempt a simple remove using the home interface and
+ * primary key.
+ * 2) Reconstitute the bean instance and try to remove the
+ * instance using the handle.
+ * 3) Reconstitue the instance, delete and try to access the
+ * instance. This should result in a
java.rmi.NoSuchObjectException
+ *
+ * @throws Exception
+ *
+ */
- bean = home.create(pk, "foo");
+ public void testEjbRemove ()
+ throws Exception
+ {
+ System.out.println(
+ "**************************************************************");
+ System.out.println(" testEjbRemove()");
+
+ CtsBmp bean = null;
+
+ try
+ {
+ Context ctx = new InitialContext();
+ CtsBmpHome home =
+ ( CtsBmpHome ) new InitialContext().lookup("ejbcts/BMPBean");
+
+ System.out.println("Build primary key for removal specification: " +
BEAN_PK_007);
+ AccountPK pk = new AccountPK(BEAN_PK_007);
+ System.out.println("Remove the bean using primary key");
+ home.remove(pk);
+ System.out.println("OK");
+ System.out.println("Reconstitute the bean");
+ bean = home.create(pk, bmpTest.BEAN_NAME);
+ System.out.println("OK, get Handle object");
+ Handle hn = bean.getHandle( );
+ System.out.println( "Remove the bean using the handle" );
+ home.remove(hn);
+ System.out.println("OK");
+ System.out.println("Recreate the bean");
+ bean = home.create(pk, bmpTest.BEAN_NAME);
+ System.out.println("Ok, bean created.. now delete");
+ home.remove(pk);
+ System.out.println("Bean remove, try to use.. should get
'java.rmi.NoSuchObjectException'" );
+ try
+ {
+ bean.getPersonsName();
+ }
+ catch(java.rmi.NoSuchObjectException nsoex)
+ {
+ System.out.println("OK");
+ }
+ catch(Exception ex)
+ {
+ System.err.println( ex.toString( ) );
+ fail("Got Exception: expecting java.rmi.NoSuchObjectException" );
+ }
+
}
catch (Exception ex)
{
ex.printStackTrace();
- fail("testBasicBMP has failed!");
+ fail("testEjbRemove has failed!");
}
- finally
+
+ System.out.println(
+ "**************************************************************");
+ }
+
+ /**
+ * Method testEjbLifeCycle
+ * EJB 1.1 [8.4] p. 92
+ *
+ * A client can get a refernce to an existing entity objects remote interface in
+ * any of the following ways:
+ * - Receive the reference as a parameter in a method call.
+ * - Find the entity object using a finder method defined in the EB home i/f.
+ * - Obtain the reference from the entity objects' handle.
+ *
+ * @throws Exception
+ *
+ */
+
+ public void testEjbLifeCycle ()
+ {
+ System.out.println(
+ "**************************************************************");
+ System.out.println(" testEjbLifeCycle()");
+
+ CtsBmp bean = null;
+
+ try
{
- System.out.println("Removing BMP bean");
+ 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("Use a finder method to retrieve the bean");
+ bean = home.findByPrimaryKey( pk );
+ System.out.println("Assert it is the same bean as passed to a method.." );
+ // Send to a method as a reference, make sure it is usable by the method
+ assert( this.gotRefOkay(bean,bmpTest.BEAN_NAME) );
+ // Execute a business method
+ System.out.println("Calling setter as a business method");
+ bean.setPersonsName(bmpTest.BEAN_OTHER_NAME);
+ System.out.println("OK");
+ // Get the home interface
+ System.out.println( "Get the HOME interface" );
+ home = ( CtsBmpHome ) bean.getEJBHome();
+ System.out.println("OK");
+ // Get the primary key
+ System.out.println( "Get the bean's Primary Key" );
+ pk = ( AccountPK ) bean.getPrimaryKey();
+ System.out.println("OK");
+ System.out.println( "Get the bean's handle" );
+ Handle hn = bean.getHandle( );
+ System.out.println("OK");
+ // Remove
+ System.out.println( "Remove the bean" );
bean.remove();
+ System.out.println("OK");
+
}
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("testEjbCreate has failed!");
+ }
System.out.println(
"**************************************************************");
}
+ // Used to test passing a Entity bean as a parameter.
+ private boolean gotRefOkay ( CtsBmp bean, String expectedName )
+ {
+ boolean retVal = false;
+
+ try
+ {
+ System.out.println(expectedName + "==" + bean.getPersonsName()+"?" );
+ retVal = ( bean.getPersonsName().equals(expectedName) );
+ }
+ catch(Exception ex)
+ { System.err.println("Unknown Exception : " + ex.toString() ); }
+
+ return retVal;
+ }
+
protected void setUp ()
throws Exception
{
@@ -100,3 +310,8 @@
/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
+
+
+
+
+