User: peter
Date: 01/01/10 19:55:49
Modified: src/main/org/jboss/test/cts/test AllJUnitTests.java
StatefulSessionTest.java
Added: src/main/org/jboss/test/cts/test StatelessSessionTest.java
Log:
Fixed the getCallerPrincipal( ) problems.
Addes some rudimentary tests for stateless session beans.
Began some work on UserTransaction tests.
Revision Changes Path
1.3 +3 -2 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AllJUnitTests.java 2001/01/07 23:14:38 1.2
+++ AllJUnitTests.java 2001/01/11 03:55:48 1.3
@@ -62,9 +62,10 @@
//suite.addTest(new StatefulSessionTest("testSerialization"));
//suite.addTest(new StatefulSessionTest("testUnSerialization"));
//suite.addTest(new StatefulSessionTest("testCompareSerializeGetPK"));
- suite.addTest(new StatefulSessionTest("testProbeBeanContext"));
+ //suite.addTest(new StatefulSessionTest("testProbeBeanContext"));
//suite.addTest(new StatefulSessionTest("testLoopback"));
-
+ //suite.addTest(new StatelessSessionTest("testBasicStatelessSession"));
+ suite.addTest(new StatefulSessionTest("testUserTrx"));
return suite;
}
}
1.3 +167 -59
jbosstest/src/main/org/jboss/test/cts/test/StatefulSessionTest.java
Index: StatefulSessionTest.java
===================================================================
RCS file:
/products/cvs/ejboss/jbosstest/src/main/org/jboss/test/cts/test/StatefulSessionTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StatefulSessionTest.java 2001/01/07 23:14:38 1.2
+++ StatefulSessionTest.java 2001/01/11 03:55:48 1.3
@@ -9,6 +9,7 @@
import javax.naming.*;
import javax.management.*;
import javax.rmi.PortableRemoteObject;
+import java.rmi.*;
import javax.security.auth.login.*;
import org.jboss.test.cts.interfaces.*;
import org.jboss.test.util.ejb.*;
@@ -18,7 +19,7 @@
*
* @see <related>
* @author $Author: peter $
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class StatefulSessionTest
@@ -80,7 +81,9 @@
// Test response
assert(result.equals("CTS-Test"));
- sessionBean.remove();
+ try{sessionBean.remove();}
+ catch( Exception ex ) {}
+
System.out.println(
"**************************************************************");
}
@@ -143,6 +146,10 @@
// EJB 1.1 only
System.out.println("Verify is not Stateless session...");
assert(!md.isStatelessSession());
+
+ try {sessionBean.remove( );}
+ catch(Exception ex ) {}
+
System.out.println(
"**************************************************************");
}
@@ -163,6 +170,8 @@
"**************************************************************");
System.out.println(" testRemoveSessionObject()");
+ StatefulSession sessionBean = null;
+
try
{
Properties props = System.getProperties();
@@ -173,7 +182,7 @@
Context ctx = new InitialContext(props);
StatefulSessionHome home =
( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
- StatefulSession sessionBean = home.create();
+ sessionBean = home.create();
home.remove(new DummyPK("pk"));
}
@@ -257,6 +266,11 @@
{
fail("Caught an Unknown exception copying the beans");
}
+ finally
+ {
+ try{sessionBean.remove( );}
+ catch(Exception ex){}
+ }
System.out.println(
"**************************************************************");
@@ -274,6 +288,8 @@
"**************************************************************");
System.out.println(" testSerialize");
+ StatefulSession bean = null;
+
try
{
Properties props = System.getProperties();
@@ -284,7 +300,7 @@
Context ctx = new InitialContext(props);
StatefulSessionHome home =
( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
- StatefulSession bean = ( StatefulSession ) home.create();
+ bean = ( StatefulSession ) home.create();
System.out.println("Increment bean, count = 3");
@@ -320,6 +336,62 @@
}
/**
+ * 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 ()
+ {
+ System.out.println(
+ "**************************************************************");
+ 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);
+ System.out.println("Yup, equal to '3'");
+ bean.decCounter();
+ bean.remove();
+ }
+ catch (java.io.StreamCorruptedException scex)
+ {
+ fail("caught a StramCorrupted exception testUnSerialization");
+ }
+ catch (java.io.IOException ioex)
+ {
+ ioex.printStackTrace( );
+ fail("caught a IOException, testUnSerialization");
+ }
+ catch (java.lang.ClassNotFoundException cnfex)
+ {
+ fail("caught a ClassNotFoundException, testUnSerialization");
+ }
+ catch (javax.ejb.RemoveException rmex)
+ {
+ fail("caught a RemoveException, testUnSerialization");
+ }
+
+ finally
+ {
+ try{bean.remove( );}
+ catch(Exception ex){}
+ }
+ }
+
+ /**
* Method testProbeBeanContext
*
* EJB 1.1 [6.4.1] Page 51
@@ -332,10 +404,19 @@
"**************************************************************");
System.out.println(" testProbeBeanContext");
+ StatefulSession bean = null;
+
try
{
Properties props = System.getProperties();
+ System.out.println( "Checking for an RMI security manager..." );
+ if (System.getSecurityManager() == null)
+ {
+ System.out.println( "Installing an RMI security manager..." );
+ System.setSecurityManager(new RMISecurityManager());
+ }
+
System.out.println( "Setting LoginContext callback..." );
LoginContext lc = new LoginContext("JCTS", new LoginCallback());
lc.login();
@@ -348,19 +429,19 @@
Object ref = ctx.lookup("ejbcts/StatefulSessionBean");
StatefulSessionHome home = ( StatefulSessionHome )
PortableRemoteObject.narrow(ref, StatefulSessionHome.class);
- StatefulSession bean = home.create();
+ 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);
-
- //System.out.println("principleName: " + beanCtxInfo.principleName);
- //System.out.println("Testing rollback only setting...");
- //assert(beanCtxInfo.isRollbackOnly.booleanValue());
+ System.out.println("remote interface: "
+ + beanCtxInfo.remoteInterface);
+ System.out.println("home interface: " + beanCtxInfo.homeInterface);
+
+ System.out.println("principleName: " + beanCtxInfo.principleName);
+ System.out.println("Testing rollback only setting...");
+ assert(beanCtxInfo.isRollbackOnly.booleanValue());
}
catch (javax.naming.NamingException ne)
{
@@ -377,7 +458,11 @@
fail( "Remote exception" );
re.printStackTrace();
}
-
+ finally
+ {
+ try{bean.remove( );}
+ catch(Exception ex){}
+ }
}
catch (Exception ex)
@@ -390,53 +475,8 @@
"**************************************************************");
}
- /**
- * 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 ()
- {
- System.out.println(
- "**************************************************************");
- System.out.println(" testUnSerialize");
- 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();
- StatefulSession bean =
- ( StatefulSession ) beanHandle.getEJBObject();
-
- // Should still equal '3'?
- System.out.println("Bean reanimated, still equal '3'?");
- assert(bean.getCounter() == 3);
- System.out.println("Yup, equal to '3'");
- bean.decCounter();
- bean.remove();
- }
- catch (java.io.StreamCorruptedException scex)
- {
- fail("caught a StramCorrupted exception testUnSerialization");
- }
- catch (java.io.IOException ioex)
- {
- fail("caught a IOException, testUnSerialization");
- }
- catch (java.lang.ClassNotFoundException cnfex)
- {
- fail("caught a ClassNotFoundException, testUnSerialization");
- }
- catch (javax.ejb.RemoveException rmex)
- {
- fail("caught a RemoveException, testUnSerialization");
- }
- }
-
/**
* Method testLoopback
* EJB 1.1 [6.5.6]
@@ -451,6 +491,8 @@
"**************************************************************");
System.out.println(" testLoopback");
+ StatefulSession bean = null;
+
try
{
Properties props = System.getProperties();
@@ -461,7 +503,7 @@
Context ctx = new InitialContext(props);
StatefulSessionHome home =
( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
- StatefulSession bean = ( StatefulSession ) home.create();
+ bean = ( StatefulSession ) home.create();
System.out.println( "Calling loopbackTest( )...." );
bean.loopbackTest();
}
@@ -474,8 +516,70 @@
ex.printStackTrace( );
fail("Test failed in testLoopback, expected RemoteException, got
Exception");
}
+
+ finally
+ {
+ try{bean.remove( );}
+ catch(Exception ex){}
+ }
}
+ public void testUserTrx ()
+ {
+ System.out.println(
+ "**************************************************************");
+ 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");
+ StatefulSessionHome home = ( 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("java:comp/UserTransaction");
+ bean.remove( );
+
+ }
+ catch (javax.naming.NamingException ne)
+ {
+ fail( "Naming excepiton failure" );
+ ne.printStackTrace();
+ }
+ catch (java.rmi.ServerException se)
+ {
+ fail( "Server exception" );
+ se.printStackTrace();
+ }
+ catch (java.rmi.RemoteException re)
+ {
+ fail( "Remote exception" );
+ re.printStackTrace();
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Caught an unknown exception in testProbeBeanContex");
+
+ }
+
+ System.out.println(
+ "**************************************************************");
+ }
+
+
protected void setUp ()
throws Exception
{
@@ -487,3 +591,7 @@
/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
+
+
+
+
1.1
jbosstest/src/main/org/jboss/test/cts/test/StatelessSessionTest.java
Index: StatelessSessionTest.java
===================================================================
package org.jboss.test.cts.test;
import java.io.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import org.jboss.test.cts.interfaces.*;
import org.jboss.test.util.ejb.*;
public class StatelessSessionTest
extends junit.framework.TestCase
{
static boolean deployed = false;
/**
* Constructor Main
*
*
* @param name
*
*/
public StatelessSessionTest (String name)
{
super(name);
}
public void testBasicStatelessSession ()
throws Exception
{
System.out.println(
"**************************************************************");
System.out.println(" testBasicStatelessSession()");
Context ctx = new InitialContext();
StatelessSessionHome home =
( StatelessSessionHome ) ctx.lookup("ejbcts/StatelessSessionHome");
StatelessSession sessionBean = home.create();
String result = sessionBean.method1("CTS-Test");
// Test response
assert(result.equals("CTS-Test"));
sessionBean.remove();
System.out.println(
"**************************************************************");
}
protected void setUp ()
throws Exception
{
if (deployed) return;
deployed = true;
}
}
/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/