User: starksm
Date: 02/04/05 09:59:39
Modified: src/main/org/jboss/test/cts/test Tag: Branch_2_4
StatefulSessionTest.java
Log:
Add tests of execeptions thrown from the SessionSynchronization methods
Revision Changes Path
No revision
No revision
1.9.2.1 +206 -224
jbosstest/src/main/org/jboss/test/cts/test/Attic/StatefulSessionTest.java
Index: StatefulSessionTest.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/cts/test/Attic/StatefulSessionTest.java,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -r1.9 -r1.9.2.1
--- StatefulSessionTest.java 17 Jun 2001 16:47:51 -0000 1.9
+++ StatefulSessionTest.java 5 Apr 2002 17:59:39 -0000 1.9.2.1
@@ -4,7 +4,6 @@
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.util.Properties;
import java.rmi.RemoteException;
import java.rmi.ServerException;
@@ -12,18 +11,19 @@
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.rmi.PortableRemoteObject;
+import javax.transaction.UserTransaction;
import org.jboss.test.cts.interfaces.StatefulSession;
import org.jboss.test.cts.interfaces.StatefulSessionHome;
import org.jboss.test.cts.interfaces.BeanContextInfo;
import org.jboss.test.cts.keys.AccountPK;
-
+import org.jboss.test.util.Deploy;
/**
*
* @see <related>
- * @author $Author: sparre $
- * @version $Revision: 1.9 $
+ * @author $Author: starksm $
+ * @version $Revision: 1.9.2.1 $
*/
public class StatefulSessionTest
@@ -38,47 +38,39 @@
* @param name
*
*/
-
- public StatefulSessionTest (String name)
+
+ public StatefulSessionTest(String name)
{
super(name);
}
-
+
/**
* 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 ()
+ */
+ public void testBasicSession()
throws Exception
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testBasicSession()");
-
+ System.out.println("+++ testBasicSession()");
Context ctx = new InitialContext();
StatefulSessionHome home =
- ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
+ ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
StatefulSession sessionBean = home.create();
String result = sessionBean.method1("CTS-Test");
-
+
// Test response
- assert(result.equals("CTS-Test"));
-
+ assertTrue(result.equals("CTS-Test"));
+
try
{
sessionBean.remove();
}
- catch (Exception ex){}
-
- System.out.println(
- "**************************************************************");
+ catch (Exception ex)
+ {}
}
-
- //
-
+
/**
* Method testEJBHomeInterface
* EJB 1.1 (Page 42)
@@ -91,61 +83,54 @@
*
* @throws Exception
*
- */
-
- public void testEJBHomeInterface ()
+ */
+ public void testEJBHomeInterface()
throws Exception
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testEJBHomeInterface()");
-
+ System.out.println("+++ testEJBHomeInterface()");
+
// Create a new session object
Context ctx = new InitialContext();
StatefulSessionHome home =
- ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
+ ( 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);
-
+ assertTrue(md != null);
+
// Get the EJBMetaData constructs
System.out.println("Get Home interface class");
-
+
java.lang.Class homeInterface = md.getHomeInterfaceClass();
-
+
System.out.println("home Interface : " + homeInterface.getName());
- assert(
- homeInterface.getName().equals(
- "org.jboss.test.cts.interfaces.StatefulSessionHome"));
+ assertTrue(homeInterface.getName().equals(
+ "org.jboss.test.cts.interfaces.StatefulSessionHome"));
System.out.println("Get Remote Interface class");
-
+
java.lang.Class remoteInterface = md.getRemoteInterfaceClass();
-
+
System.out.println("remote Interface: " + remoteInterface.getName());
- assert(
- remoteInterface.getName().equals(
- "org.jboss.test.cts.interfaces.StatefulSession"));
+ assertTrue(remoteInterface.getName().equals(
+ "org.jboss.test.cts.interfaces.StatefulSession"));
System.out.println("Verify isSession..");
- assert(md.isSession());
-
+ assertTrue(md.isSession());
+
// EJB 1.1 only
System.out.println("Verify is not Stateless session...");
- assert(!md.isStatelessSession());
-
+ assertTrue(!md.isStatelessSession());
+
try
{
sessionBean.remove();
}
- catch (Exception ex){}
-
- System.out.println(
- "**************************************************************");
+ catch (Exception ex)
+ {}
}
-
+
/**
* Method testRemoveSessionObject
* EJB 1.1 (Page 42)
@@ -154,32 +139,25 @@
* accessible to clients, invoking the javax.ejb.Home.remove( Object primaryKey )
* method on a session results in the javax.ejb.RemoveException.
*
- */
-
- public void testRemoveSessionObject ()
+ */
+ public void testRemoveSessionObject()
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testRemoveSessionObject()");
-
+ System.out.println("+++ testRemoveSessionObject()");
+
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");
-
+ Context ctx = new InitialContext();
+ StatefulSessionHome home = ( StatefulSessionHome )
ctx.lookup("ejbcts/StatefulSessionBean");
+
sessionBean = home.create();
System.out.println("OK");
System.out.println("Call remove using a primary key");
home.remove(new AccountPK("pk"));
-
+
}
catch (javax.ejb.RemoveException rmEx)
{
@@ -192,15 +170,13 @@
ex.printStackTrace();
fail("[EJB 1.1, p42, section 5.3.2] Expected 'RemoveException' when
remove-ing a session object, detail:" + ex.toString());
}
-
+
fail("[EJB 1.1, p42, section 5.3.2] Expected 'RemoveException' when
remove-ing a session object, got NO exception");
- System.out.println(
- "**************************************************************");
}
-
+
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
-
+
/**
* Method testCompareSerializeGetPK
* EJB 1.1 [5.5] Page 43
@@ -210,48 +186,40 @@
*
*
*/
-
- public void testCompareSerializeGetPK ()
+
+ public void testCompareSerializeGetPK()
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testCompareSerializeGetPK()");
-
+ System.out.println("+++ testCompareSerializeGetPK()");
StatefulSession sessionBean = null;
-
+
try
{
- Properties props = System.getProperties();
-
- System.out.println("Obtain home interface");
-
+ System.out.println("Obtain home interface");
// Create a new session object
- Context ctx = new InitialContext(props);
- StatefulSessionHome home =
- ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
-
+ Context ctx = new InitialContext();
+ 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);
-
+
+ assertTrue(hn != null);
+
// "Copy" the bean
StatefulSession theOtherBean =
- ( StatefulSession ) javax.rmi.PortableRemoteObject.narrow(
- hn.getEJBObject(), StatefulSession.class);
-
- assert(theOtherBean != null);
- assert(sessionBean.isIdentical(theOtherBean));
+ ( StatefulSession ) javax.rmi.PortableRemoteObject.narrow(
+ hn.getEJBObject(), StatefulSession.class);
+
+ assertTrue(theOtherBean != null);
+ assertTrue(sessionBean.isIdentical(theOtherBean));
}
catch (java.lang.ClassCastException CCEx)
{
@@ -267,57 +235,48 @@
{
sessionBean.remove();
}
- catch (Exception ex){}
+ catch (Exception ex)
+ {}
}
-
- System.out.println(
- "**************************************************************");
}
-
+
/**
* Method testSerialization
* EJB 1.1 [5.7] Page 45
* Session bean must be serializable.
- */
-
- public void testSerialization ()
+ */
+ public void testSerialization()
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testSerialize");
-
+ System.out.println("+++ testSerialize");
+
StatefulSession bean = null;
-
try
{
- Properties props = System.getProperties();
-
System.out.println("Obtain home interface");
-
// Create a new session object
- Context ctx = new InitialContext(props);
+ Context ctx = new InitialContext();
StatefulSessionHome home =
- ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
-
+ ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
+
bean = ( StatefulSession ) home.create();
-
+
System.out.println("Increment bean, count = 3");
-
+
// put on some state...
bean.setCounter(1);
bean.incCounter();
bean.incCounter();
-
+
// bean should be=3;
System.out.println("Bean == 3?");
- assert(bean.getCounter() == 3);
+ assertTrue(bean.getCounter() == 3);
System.out.println("passes..");
-
+
// Get handle and serialize
Handle beanHandle = bean.getHandle();
FileOutputStream out = new FileOutputStream("abean.ser");
ObjectOutputStream s = new ObjectOutputStream(out);
-
+
s.writeObject(beanHandle);
s.flush();
}
@@ -329,39 +288,31 @@
{
fail("caught an unknown exception, testSerialization");
}
-
- System.out.println(
- "**************************************************************");
}
-
+
/**
* Method testUnSerialization
* EJB 1.1 [5.7] Page 45
* Part II of the test, makes sure the bean can be resurected and used.
*/
-
- public void testUnSerialization ()
+
+ public void testUnSerialization()
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testUnSerialize");
-
+ System.out.println("+++ testUnSerialize");
StatefulSession bean = null;
-
try
{
System.out.println("Resurrect bean from .ser file");
-
FileInputStream in = new FileInputStream("abean.ser");
ObjectInputStream s = new ObjectInputStream(in);
Handle beanHandle = ( Handle ) s.readObject();
-
+
bean = ( StatefulSession ) beanHandle.getEJBObject();
-
+
// Should still equal '3'?
System.out.println("Bean reanimated, still equal '3'? bean = "
- + bean.getCounter());
- assert(bean.getCounter() == 3);
+ + bean.getCounter());
+ assertTrue(bean.getCounter() == 3);
System.out.println("Yup, equal to '3'");
bean.decCounter();
bean.remove();
@@ -389,56 +340,42 @@
{
bean.remove();
}
- catch (Exception ex){}
+ catch (Exception ex)
+ {}
}
}
-
+
/**
* Method testProbeBeanContext
*
* EJB 1.1 [6.4.1] Page 51
*
*/
-
- public void testProbeBeanContext ()
+ public void testProbeBeanContext()
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testProbeBeanContext");
-
- StatefulSession bean = null;
-
+ System.out.println("+++ testProbeBeanContext");
+ StatefulSession bean = null;
try
{
- Properties props = System.getProperties();
-
try
{
System.out.println("Obtain home interface");
-
// Create a new session object
- Context ctx = new InitialContext(props);
- Object ref =
- ctx.lookup("ejbcts/StatefulSessionBean");
+ Context ctx = new InitialContext();
+ Object ref = ctx.lookup("ejbcts/StatefulSessionBean");
StatefulSessionHome home =
- ( StatefulSessionHome ) PortableRemoteObject.narrow(ref,
- StatefulSessionHome.class);
-
+ ( StatefulSessionHome ) PortableRemoteObject.narrow(ref,
+ StatefulSessionHome.class);
+
bean = home.create();
-
System.out.println("Invoking bean...");
-
BeanContextInfo beanCtxInfo = bean.getBeanContextInfo();
-
- assert(beanCtxInfo != null);
-
- System.out.println("remote interface: "
- + beanCtxInfo.remoteInterface);
- System.out.println("home interface: "
- + beanCtxInfo.homeInterface);
-
+ assertTrue(beanCtxInfo != null);
+
+ System.out.println("remote interface: " + beanCtxInfo.remoteInterface);
+ System.out.println("home interface: " + beanCtxInfo.homeInterface);
System.out.println("Testing rollback only setting...");
- assert(beanCtxInfo.isRollbackOnly.booleanValue());
+ assertTrue(beanCtxInfo.isRollbackOnly.booleanValue());
}
catch (javax.naming.NamingException ne)
{
@@ -458,47 +395,36 @@
{
bean.remove();
}
- catch (Exception ex){}
+ catch (Exception ex)
+ {}
}
}
catch (Exception ex)
{
fail("Caught an unknown exception in testProbeBeanContex");
}
-
- System.out.println(
- "**************************************************************");
}
-
+
/**
* Method testLoopback
* EJB 1.1 [6.5.6]
* A client call to bean 'A' which calls bean 'B' and bean 'B'
* in turn calls a method on bean 'A', there should be a
* RemoteException should be thrown.
- */
-
- public void testLoopback ()
+ */
+ public void testLoopback()
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testLoopback");
-
+ System.out.println("+++ testLoopback");
StatefulSession bean = null;
-
try
{
- Properties props = System.getProperties();
-
- System.out.println("Obtain home interface");
-
+ System.out.println("Obtain home interface");
// Create a new session object
- Context ctx = new InitialContext(props);
+ Context ctx = new InitialContext();
StatefulSessionHome home =
- ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
-
+ ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
+
bean = ( StatefulSession ) home.create();
-
System.out.println("Calling loopbackTest( )....");
bean.loopbackTest();
}
@@ -517,7 +443,9 @@
{
bean.remove();
}
- catch (Exception ex){}
+ catch (Exception ex)
+ {
+ }
}
}
@@ -526,38 +454,25 @@
*
*
*/
-
- public void testUserTrx ()
+ public void testUserTrx()
{
- System.out.println(
- "**************************************************************");
- System.out.println(" testUsrTrx");
-
+ System.out.println("+++ testUsrTrx");
StatefulSession bean = null;
-
try
{
- Properties props = System.getProperties();
-
try
{
System.out.println("Obtain home interface");
-
// Create a new session object
- Context ctx = new InitialContext(props);
- Object ref =
- ctx.lookup("ejbcts/StatefulSessionBean");
+ Context ctx = new InitialContext();
+ Object ref = ctx.lookup("ejbcts/StatefulSessionBean");
StatefulSessionHome home =
- ( StatefulSessionHome ) PortableRemoteObject.narrow(ref,
- StatefulSessionHome.class);
-
+ ( StatefulSessionHome ) PortableRemoteObject.narrow(ref,
+ StatefulSessionHome.class);
+
bean = home.create();
-
System.out.println("Try to instantiate a UserTransaction");
-
- javax.transaction.UserTransaction uTrx =
- (javax.transaction.UserTransaction)ctx.lookup("UserTransaction");
-
+ UserTransaction uTrx = (UserTransaction)ctx.lookup("UserTransaction");
bean.remove();
}
catch (javax.naming.NamingException ne)
@@ -581,19 +496,86 @@
ex.printStackTrace();
fail("Caught an unknown exception in testProbeBeanContex");
}
+ }
+
+ public void testSessionSynchronizationErrs() throws Exception
+ {
+ System.out.println("+++ testSessionSynchronizationErrs");
+ Context ctx = new InitialContext();
+ Object ref = ctx.lookup("ejbcts/StatefulSessionBean");
+ StatefulSessionHome home = ( StatefulSessionHome ) ref;
+
+ StatefulSession afterBeginBean =
home.create(StatefulSessionHome.THROW_EX_IN_AFTER_BEGIN);
+ System.out.println("Test THROW_EX_IN_AFTER_BEGIN");
+ try
+ {
+ afterBeginBean.method1("afterBegin test");
+ fail("Call should have failed in afterBegin");
+ }
+ catch(Exception e)
+ {
+ System.out.println("Called failed as expected with e="+e.getClass());
+ }
+ try
+ {
+ afterBeginBean.getCounter();
+ fail("Was able to call getCounter() after bean should have been
discarded");
+ }
+ catch(Exception e)
+ {
+ System.out.println("afterBeginBean is not usable as expected");
+ }
+
+ StatefulSession beforeCompletionBean =
home.create(StatefulSessionHome.THROW_EX_IN_BEFORE_COMPLETION);
+ System.out.println("Test THROW_EX_IN_BEFORE_COMPLETION");
+ try
+ {
+ beforeCompletionBean.method1("beforeCompletion test");
+ fail("Call should have failed in beforeCompletion");
+ }
+ catch(Exception e)
+ {
+ System.out.println("Called failed as expected with e="+e.getClass());
+ }
+ try
+ {
+ beforeCompletionBean.getCounter();
+ fail("Was able to call getCounter() after bean should have been
discarded");
+ }
+ catch(Exception e)
+ {
+ System.out.println("beforeCompletionBean is not usable as expected");
+ }
+
+ StatefulSession afterCompletionBean =
home.create(StatefulSessionHome.THROW_EX_IN_AFTER_COMPLETION);
+ System.out.println("Test THROW_EX_IN_AFTER_COMPLETION");
+ try
+ {
+ afterCompletionBean.method1("afterCompletion test");
+ fail("Call should have failed in afterCompletion");
+ }
+ catch(Exception e)
+ {
+ System.out.println("Called failed as expected with e="+e.getClass());
+ }
+ try
+ {
+ afterCompletionBean.getCounter();
+ fail("Was able to call getCounter() after bean should have been
discarded");
+ }
+ catch(Exception e)
+ {
+ System.out.println("afterCompletionBean is not usable as expected");
+ }
- System.out.println(
- "**************************************************************");
}
- protected void setUp ()
+ protected void setUp()
throws Exception
{
- if (deployed) return;
-
+ if (deployed)
+ return;
+ Deploy.deploy("cts.jar");
deployed = true;
}
}
-
-
-/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development