User: peter
Date: 01/01/24 18:45:43
Modified: src/main/org/jboss/test/cts/test AllJUnitTests.java
LoginCallback.java StatefulSessionTest.java
StatelessSessionTest.java
Added: src/main/org/jboss/test/cts/test bmpTest.java
Log:
Added rudimentary BMP tests.
Revision Changes Path
1.6 +2 -1 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AllJUnitTests.java 2001/01/16 03:23:10 1.5
+++ AllJUnitTests.java 2001/01/25 02:45:41 1.6
@@ -66,7 +66,8 @@
suite.addTest(new StatefulSessionTest("testLoopback"));
suite.addTest(new StatelessSessionTest("testBasicStatelessSession"));
suite.addTest(new StatefulSessionTest("testUserTrx"));
- //suite.addTest(new bmpTest("testBasicBmp") );
+ suite.addTest(new bmpTest("testBasicBmp"));
+
return suite;
}
}
1.2 +53 -33 jbosstest/src/main/org/jboss/test/cts/test/LoginCallback.java
Index: LoginCallback.java
===================================================================
RCS file:
/products/cvs/ejboss/jbosstest/src/main/org/jboss/test/cts/test/LoginCallback.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LoginCallback.java 2001/01/07 23:14:38 1.1
+++ LoginCallback.java 2001/01/25 02:45:41 1.2
@@ -1,47 +1,67 @@
package org.jboss.test.cts.test;
+
+
import javax.security.auth.callback.*;
+
+/**
+ * Class LoginCallback
+ *
+ *
+ * @author
+ * @version %I%, %G%
+ */
+
public class LoginCallback
- implements CallbackHandler
+ implements CallbackHandler
{
- private static final String PASSWORD = "jcts";
- private static final String USER_ID = "jcts";
+ private static final String PASSWORD = "jcts";
+ private static final String USER_ID = "jcts";
- public void handle(Callback[] callbacks)
- throws java.io.IOException,
- UnsupportedCallbackException
- {
-
- for( int i = 0 ; i < callbacks.length; i++ )
+ /**
+ * Method handle
+ *
+ *
+ * @param callbacks
+ *
+ * @throws UnsupportedCallbackException
+ * @throws java.io.IOException
+ *
+ */
+
+ public void handle (Callback[] callbacks)
+ throws java.io.IOException, UnsupportedCallbackException
+ {
+ for (int i = 0; i < callbacks.length; i++)
{
- if (callbacks[i] instanceof NameCallback)
- {
-
- // prompt the user for a username
- NameCallback nc = (NameCallback)callbacks[i];
- System.out.println( "Setting userid to " + USER_ID );
- nc.setName(USER_ID);
-
- }
- else if (callbacks[i] instanceof PasswordCallback)
+ if (callbacks [i] instanceof NameCallback)
{
-
- // prompt the user for sensitive information
- PasswordCallback pc = (PasswordCallback)callbacks[i];
- System.out.println( "Setting password to " + PASSWORD );
- pc.setPassword(PASSWORD.toCharArray());
-
- }
- else
- {
- throw new UnsupportedCallbackException
- (callbacks[i], "Unrecognized Callback");
- }
- }
- }
+ // prompt the user for a username
+ NameCallback nc = ( NameCallback ) callbacks [i];
+ System.out.println("Setting userid to " + USER_ID);
+ nc.setName(USER_ID);
+ }
+ else
+ if (callbacks [i] instanceof PasswordCallback)
+ {
+
+ // prompt the user for sensitive information
+ PasswordCallback pc = ( PasswordCallback ) callbacks [i];
+
+ System.out.println("Setting password to " + PASSWORD);
+ pc.setPassword(PASSWORD.toCharArray());
+ }
+ else
+ {
+ throw new UnsupportedCallbackException(
+ callbacks [i], "Unrecognized Callback");
+ }
+ }
+ }
}
+/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
1.4 +118 -92
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StatefulSessionTest.java 2001/01/11 03:55:48 1.3
+++ StatefulSessionTest.java 2001/01/25 02:45:41 1.4
@@ -10,7 +10,7 @@
import javax.management.*;
import javax.rmi.PortableRemoteObject;
import java.rmi.*;
-import javax.security.auth.login.*;
+import javax.security.auth.login.*;
import org.jboss.test.cts.interfaces.*;
import org.jboss.test.util.ejb.*;
@@ -19,7 +19,7 @@
*
* @see <related>
* @author $Author: peter $
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class StatefulSessionTest
@@ -81,9 +81,13 @@
// Test response
assert(result.equals("CTS-Test"));
- try{sessionBean.remove();}
- catch( Exception ex ) {}
+ try
+ {
+ sessionBean.remove();
+ }
+ catch (Exception ex){}
+
System.out.println(
"**************************************************************");
}
@@ -146,10 +150,13 @@
// EJB 1.1 only
System.out.println("Verify is not Stateless session...");
assert(!md.isStatelessSession());
+
+ try
+ {
+ sessionBean.remove();
+ }
+ catch (Exception ex){}
- try {sessionBean.remove( );}
- catch(Exception ex ) {}
-
System.out.println(
"**************************************************************");
}
@@ -179,9 +186,10 @@
System.out.println("Obtain home interface");
// Create a new session object
- Context ctx = new InitialContext(props);
- StatefulSessionHome home =
+ Context ctx = new InitialContext(props);
+ StatefulSessionHome home =
( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
+
sessionBean = home.create();
home.remove(new DummyPK("pk"));
@@ -268,8 +276,11 @@
}
finally
{
- try{sessionBean.remove( );}
- catch(Exception ex){}
+ try
+ {
+ sessionBean.remove();
+ }
+ catch (Exception ex){}
}
System.out.println(
@@ -300,6 +311,7 @@
Context ctx = new InitialContext(props);
StatefulSessionHome home =
( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
+
bean = ( StatefulSession ) home.create();
System.out.println("Increment bean, count = 3");
@@ -356,11 +368,12 @@
FileInputStream in = new FileInputStream("abean.ser");
ObjectInputStream s = new ObjectInputStream(in);
Handle beanHandle = ( Handle ) s.readObject();
- bean =
- ( StatefulSession ) beanHandle.getEJBObject();
+
+ bean = ( StatefulSession ) beanHandle.getEJBObject();
// Should still equal '3'?
- System.out.println("Bean reanimated, still equal '3'? bean = " +
bean.getCounter());
+ System.out.println("Bean reanimated, still equal '3'? bean = "
+ + bean.getCounter());
assert(bean.getCounter() == 3);
System.out.println("Yup, equal to '3'");
bean.decCounter();
@@ -372,7 +385,7 @@
}
catch (java.io.IOException ioex)
{
- ioex.printStackTrace( );
+ ioex.printStackTrace();
fail("caught a IOException, testUnSerialization");
}
catch (java.lang.ClassNotFoundException cnfex)
@@ -383,11 +396,13 @@
{
fail("caught a RemoveException, testUnSerialization");
}
-
finally
{
- try{bean.remove( );}
- catch(Exception ex){}
+ try
+ {
+ bean.remove();
+ }
+ catch (Exception ex){}
}
}
@@ -410,60 +425,63 @@
{
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..." );
+ System.out.println("Setting LoginContext callback...");
+
LoginContext lc = new LoginContext("JCTS", new LoginCallback());
+
lc.login();
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( "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("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("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());
+ }
catch (javax.naming.NamingException ne)
{
- fail( "Naming excepiton failure" );
- ne.printStackTrace();
+ fail("Naming excepiton failure");
+ ne.printStackTrace();
}
catch (java.rmi.ServerException se)
{
- fail( "Server exception" );
- se.printStackTrace();
+ fail("Server exception");
+ se.printStackTrace();
}
catch (java.rmi.RemoteException re)
{
- fail( "Remote exception" );
- re.printStackTrace();
+ fail("Remote exception");
+ re.printStackTrace();
}
finally
{
- try{bean.remove( );}
- catch(Exception ex){}
+ try
+ {
+ bean.remove();
+ }
+ catch (Exception ex){}
}
-
}
catch (Exception ex)
{
@@ -475,13 +493,11 @@
"**************************************************************");
}
-
-
/**
* 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
+ * 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.
*/
@@ -503,8 +519,10 @@
Context ctx = new InitialContext(props);
StatefulSessionHome home =
( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
+
bean = ( StatefulSession ) home.create();
- System.out.println( "Calling loopbackTest( )...." );
+
+ System.out.println("Calling loopbackTest( )....");
bean.loopbackTest();
}
catch (java.rmi.RemoteException rex)
@@ -513,17 +531,25 @@
}
catch (Exception ex)
{
- ex.printStackTrace( );
+ ex.printStackTrace();
fail("Test failed in testLoopback, expected RemoteException, got
Exception");
}
-
finally
{
- try{bean.remove( );}
- catch(Exception ex){}
+ try
+ {
+ bean.remove();
+ }
+ catch (Exception ex){}
}
}
+ /**
+ * Method testUserTrx
+ *
+ *
+ */
+
public void testUserTrx ()
{
System.out.println(
@@ -537,48 +563,52 @@
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( );
+ {
+ 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();
+ fail("Naming excepiton failure");
+ ne.printStackTrace();
}
catch (java.rmi.ServerException se)
{
- fail( "Server exception" );
- se.printStackTrace();
+ fail("Server exception");
+ se.printStackTrace();
}
catch (java.rmi.RemoteException re)
{
- fail( "Remote exception" );
- re.printStackTrace();
+ 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
@@ -591,7 +621,3 @@
/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
-
-
-
-
1.2 +21 -3
jbosstest/src/main/org/jboss/test/cts/test/StatelessSessionTest.java
Index: StatelessSessionTest.java
===================================================================
RCS file:
/products/cvs/ejboss/jbosstest/src/main/org/jboss/test/cts/test/StatelessSessionTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StatelessSessionTest.java 2001/01/11 03:55:48 1.1
+++ StatelessSessionTest.java 2001/01/25 02:45:41 1.2
@@ -1,5 +1,7 @@
package org.jboss.test.cts.test;
+
+
import java.io.*;
import java.util.*;
import javax.ejb.*;
@@ -9,6 +11,14 @@
import org.jboss.test.util.ejb.*;
+/**
+ * Class StatelessSessionTest
+ *
+ *
+ * @author
+ * @version %I%, %G%
+ */
+
public class StatelessSessionTest
extends junit.framework.TestCase
{
@@ -27,6 +37,14 @@
super(name);
}
+ /**
+ * Method testBasicStatelessSession
+ *
+ *
+ * @throws Exception
+ *
+ */
+
public void testBasicStatelessSession ()
throws Exception
{
@@ -34,11 +52,11 @@
"**************************************************************");
System.out.println(" testBasicStatelessSession()");
- Context ctx = new InitialContext();
+ Context ctx = new InitialContext();
StatelessSessionHome home =
( StatelessSessionHome ) ctx.lookup("ejbcts/StatelessSessionHome");
- StatelessSession sessionBean = home.create();
- String result = sessionBean.method1("CTS-Test");
+ StatelessSession sessionBean = home.create();
+ String result = sessionBean.method1("CTS-Test");
// Test response
assert(result.equals("CTS-Test"));
1.1 jbosstest/src/main/org/jboss/test/cts/test/bmpTest.java
Index: bmpTest.java
===================================================================
package org.jboss.test.cts.test;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.rmi.*;
import java.sql.*;
import javax.sql.DataSource;
import org.jboss.test.cts.interfaces.*;
import org.jboss.test.cts.keys.*;
import org.jboss.test.util.ejb.*;
/**
* Class bmpTest
*
*
* @author
* @version %I%, %G%
*/
public class bmpTest
extends junit.framework.TestCase
{
static boolean deployed = false;
private SessionContext ctx = null;
private DataSource ds = null;
/**
* Constructor bmpTest
*
*
* @param name
*
*/
public bmpTest (String name)
{
super(name);
}
/**
* Method testBasicBmp
*
*
* @throws Exception
*
*/
public void testBasicBmp ()
throws Exception
{
System.out.println(
"**************************************************************");
System.out.println(" testBasicBmp()");
CtsBmp bean = null;
try
{
Context ctx = new InitialContext();
CtsBmpHome home =
( CtsBmpHome ) new InitialContext().lookup("ejbcts/BMPBean");
System.out.println("create foo bean");
AccountPK pk = new AccountPK("1");
bean = home.create(pk, "foo");
}
catch (Exception ex)
{
ex.printStackTrace();
fail("testBasicBMP has failed!");
}
finally
{
System.out.println("Removing BMP bean");
bean.remove();
}
System.out.println(
"**************************************************************");
}
protected void setUp ()
throws Exception
{
if (deployed) return;
deployed = true;
}
protected void tearDown ()
{
}
}
/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/