User: fleury
Date: 00/09/26 17:46:36
Added: src/main/org/jboss/test/testbean/test Main.java
Log:
Added src for TestBean from ZOLA
Revision Changes Path
1.1 jbosstest/src/main/org/jboss/test/testbean/test/Main.java
Index: Main.java
===================================================================
package org.jboss.test.testbean.test;
import java.rmi.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.ejb.DuplicateKeyException;
import javax.ejb.Handle;
import javax.ejb.EJBMetaData;
import java.util.Date;
import java.util.Properties;
import java.util.Collection;
import java.util.Iterator;
import java.util.Enumeration;
import org.jboss.test.testbean.interfaces.StatelessSessionHome;
import org.jboss.test.testbean.interfaces.StatelessSession;
import org.jboss.test.testbean.interfaces.StatefulSessionHome;
import org.jboss.test.testbean.interfaces.StatefulSession;
import org.jboss.test.testbean.interfaces.EntityBMPHome;
import org.jboss.test.testbean.interfaces.EntityBMP;
import org.jboss.test.testbean.interfaces.EnterpriseEntityHome;
import org.jboss.test.testbean.interfaces.EnterpriseEntity;
import org.jboss.test.testbean.interfaces.EntityPKHome;
import org.jboss.test.testbean.interfaces.EntityPK;
import org.jboss.test.testbean.interfaces.BusinessMethodException;
import org.jboss.test.testbean.interfaces.AComplexPK;
import org.jboss.test.testbean.interfaces.TxSessionHome;
import org.jboss.test.testbean.interfaces.TxSession;
import org.jboss.test.testbean.interfaces.BMTStatefulHome;
import org.jboss.test.testbean.interfaces.BMTStateful;
import org.jboss.test.testbean.interfaces.BMTStatelessHome;
import org.jboss.test.testbean.interfaces.BMTStateless;
import org.jboss.test.testbean2.interfaces.AllTypes;
import org.jboss.test.testbean2.interfaces.AllTypesHome;
import org.jboss.test.testbean2.interfaces.MyObject;
/**
* Sample client for the jboss container.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @version $Id: Main.java,v 1.1 2000/09/27 00:46:35 fleury Exp $
*/
public class Main
extends junit.framework.TestCase
{
static boolean deployed = false;
static int test = 0;
static Date startDate = new Date();
public Main(String name) {
super(name);
}
public void testStatelessBean()
throws Exception
{
System.out.print(++test+"- "+"Trying the context...");
Context ctx = new InitialContext();
System.out.println("OK");
///*
System.out.println();
System.out.println("Test Stateless Bean");
System.out.println("===================");
System.out.println();
System.out.print(++test+"- "+"Looking up the home
nextgen.StatelessSession...");
StatelessSessionHome statelessSessionHome =
(StatelessSessionHome) ctx.lookup("nextgen.StatelessSession");
if (statelessSessionHome!= null ) System.out.println("ok");
System.out.print(++test+"- "+"Calling create on StatelessSessionHome...");
StatelessSession statelessSession =
statelessSessionHome.create();
if (statelessSession != null) System.out.println("ok");
System.out.print(++test+"- "+"Calling getEJBHome() on StatelessSession...");
if (statelessSession.getEJBHome() != null) System.out.println("ok");
else throw new Exception ("Null home not OK");
System.out.print(++test+"- "+"Calling Business Method A on
StatelessSession... ");
statelessSession.callBusinessMethodA();
System.out.println("ok");
System.out.println(++test+"- "+"Calling Business Method B on
StatelessSession... ");
System.out.println(statelessSession.callBusinessMethodB());
System.out.println(++test+"- "+"Calling Business Method B(String) on
StatelessSession... ");
System.out.println(statelessSession.callBusinessMethodB("of wisdom"));
System.out.println(++test+"- "+"Calling Business Method C on
StatelessSession... ");
System.out.println(statelessSession.callBusinessMethodC());
System.out.println(++test+"- "+"Calling Business Method D on
StatelessSession... ");
try {
statelessSession.callBusinessMethodD();
System.out.println("ERROR, no exception was thrown");
}
catch (BusinessMethodException e) {
System.out.println("Caught BusinessMethodException OK");
}
catch (Exception e) {
System.out.println("ERROR, type "+e.getClass());
}
System.out.print(++test+"- "+"Calling Business Method E (getEJBObject) on
StatelessSession... ");
System.out.println(statelessSession.callBusinessMethodE());
System.out.print(++test+"- "+"Calling testClassLoading on
StatelessSession... ");
try {
statelessSession.testClassLoading();
System.out.println("OK");
}
catch (BusinessMethodException e) {
System.out.println("Failed");
}
catch (Exception e) {
System.out.println("ERROR, type "+e.getClass());
}
System.out.println("***Testing the various local Object class calls");
System.out.print(++test+"- "+"toString ... ");
System.out.println(statelessSession.toString());
System.out.print(++test+"- "+"hashCode ... ");
System.out.println(statelessSession.hashCode());
System.out.print(++test+"- "+"equals (same object) ... ");
System.out.println(statelessSession.equals(statelessSession));
System.out.print(++test+"- "+"equals (another object) (true under same
home)... ");
System.out.println(statelessSession.equals(statelessSessionHome.create()));
System.out.println("***Testing the various local EJBObject class calls");
System.out.print(++test+"- "+"Get Primary Key ... ");
System.out.println(statelessSession.getPrimaryKey());
System.out.print(++test+"- "+"Get Handle ... ");
Handle statelessHandle = statelessSession.getHandle();
if (statelessHandle != null) System.out.println("OK");
System.out.print(++test+"- "+"Serialize handle and deserialize..");
MarshalledObject mo = new MarshalledObject(statelessHandle);
Handle handle2 = (Handle) mo.get();
StatelessSession statelessSession2 = (StatelessSession)
handle2.getEJBObject();
if (statelessSession2 != null) System.out.println("OK");
System.out.println(++test+"- "+"Calling businessMethodB on it...");
System.out.println(statelessSession2.callBusinessMethodB());
System.out.println(++test+"- "+"They should be
identical..."+statelessSession.isIdentical(statelessSession2));
System.out.println("***Testing the various local EJBHome class calls");
System.out.print(++test+"- "+"Getting the metaData...");
EJBMetaData statelessMetaData = statelessSessionHome.getEJBMetaData();
if (statelessMetaData != null) System.out.println("OK");
else System.out.println("NULL METADATA");
System.out.println(++test+"- "+"Is stateless Session?
"+statelessMetaData.isStatelessSession());
System.out.println(++test+"- "+"The remote class is
"+statelessMetaData.getRemoteInterfaceClass());
System.out.println("");
System.out.print(++test+"- "+"Calling StatelessSession.remove()...");
statelessSession.remove();
System.out.println("ok");
}
public void testStatefulBean()
throws Exception
{
Context ctx = new InitialContext();
System.out.println();
System.out.println("Test Stateful Bean");
System.out.println("==================");
System.out.println();
System.out.print(++test+"- "+"Looking up the home
nextgen.StatefulSession...");
StatefulSessionHome statefulSessionHome =
(StatefulSessionHome) ctx.lookup("nextgen.StatefulSession");
if (statefulSessionHome!= null ) System.out.println("ok");
System.out.print(++test+"- "+"Calling create on StatefulSessionHome with
name Marc...");
StatefulSession statefulSession =
statefulSessionHome.create("Marc");
if (statefulSession != null) System.out.println("ok");
System.out.print(++test+"- "+"Calling getEJBHome() on
StatefulSession...");
if (statefulSession.getEJBHome() != null) System.out.println("ok");
else throw new Exception ("null home not ok");
System.out.println(++test+"- "+"Calling Business Method A on
StatefulSession... ");
System.out.println(statefulSession.callBusinessMethodA());
System.out.println(++test+"- "+"Calling Business Method A (state) on
StatefulSession... ");
System.out.println(statefulSession.callBusinessMethodA());
System.out.print(++test+"- "+"Calling Business Method B (EJBObject) on
StatefulSession... ");
System.out.println(statefulSession.callBusinessMethodB());
System.out.println(++test+"- "+"Calling Business Method B(String) on
StatefulSession... ");
System.out.println(statefulSession.callBusinessMethodB("of wisdom"));
System.out.println("***Testing the various local Object class calls");
System.out.print(++test+"- "+"toString ... ");
System.out.println(statefulSession.toString());
System.out.print(++test+"- "+"hashCode ... ");
System.out.println(statefulSession.hashCode());
System.out.print(++test+"- "+"equals (same object) ... ");
System.out.println(statefulSession.equals(statefulSession));
System.out.print(++test+"- "+"equals (another object) (false under same
home)... ");
System.out.println(statefulSession.equals(statefulSessionHome.create("marc4")));
System.out.println("***Testing the various local EJBObject class calls");
System.out.print(++test+"- "+"Get Primary Key ... ");
System.out.println(statefulSession.getPrimaryKey());
System.out.print(++test+"- "+"Get Handle ... ");
Handle statefulHandle = statefulSession.getHandle();
if (statefulHandle != null) System.out.println("OK");
System.out.print(++test+"- "+"Serialize handle and deserialize....");
MarshalledObject mo2 = new MarshalledObject(statefulHandle);
Handle statefulHandle2 = (Handle) mo2.get();
StatefulSession statefulSession2 = (StatefulSession)
statefulHandle2.getEJBObject();
if (statefulSession2 != null) System.out.println("OK");
System.out.println(++test+"- "+"Calling businessMethodB on it...");
System.out.println(statefulSession2.callBusinessMethodB());
System.out.println(++test+"- "+"They should be
identical..."+statefulSession.isIdentical(statefulSession2));
System.out.print(++test+"- "+"Calling StatefulSession.remove()...");
statefulSession.remove();
System.out.println("ok");
System.out.print(++test+"- "+"Calling StatefulHome.remove(Handle) (this
should fail)...");
try {
statefulSessionHome.remove(statefulSession2.getHandle());
System.out.println("NOT OK");
}
catch (Exception e) {
System.out.println("not found OK");
}
System.out.print(++test+"- "+"Creating a 3rd bean and calling it...");
StatefulSession ss3 = statefulSessionHome.create("marc3");
System.out.println(ss3.callBusinessMethodA());
System.out.print(++test+"- "+"Calling StatefulSession.remove(Handle) on a
third bean...");
Handle statefulHandle3 = ss3.getHandle();
statefulSessionHome.remove(statefulHandle3);
System.out.println("OK");
System.out.print(++test+"- "+"I should not be able to remove it
directly...");
try {
ss3.remove();
System.out.println("NOT OK");
} catch (Exception e) {
System.out.println("OK");
}
}
public void testEntityBeanCMP()
throws Exception
{
Context ctx = new InitialContext();
System.out.println();
System.out.println();
System.out.println("Test Entity Bean CMP");
System.out.println("====================");
System.out.println();
System.out.println(++test+"- "+"Looking up the home
nextgen.EnterpriseEntity...ok");
EnterpriseEntityHome enterpriseEntityHome = (EnterpriseEntityHome)
ctx.lookup("nextgen.EnterpriseEntity");
System.out.print(++test+"- "+"Calling find on EnterpriseEntityHome with name
Marc...");
EnterpriseEntity enterpriseEntity = null;
try {
enterpriseEntity = enterpriseEntityHome.findByPrimaryKey("Marc");
}
catch (Exception e) {System.out.println(e.getMessage());}
if (enterpriseEntity == null) {
System.out.println("not found OK");
System.out.print(++test+"- "+"Calling create on EnterpriseEntityHome
with name Marc...");
enterpriseEntity = enterpriseEntityHome.create("Marc");
}
if (enterpriseEntity != null) System.out.println("ok");
System.out.print(++test+"- "+"Calling for duplicate create and
DuplicateKeyException...");
try {
enterpriseEntityHome.create("Marc");
System.out.println("I Really should not make it here");
throw new Exception ("DuplicateKey not seen");
}
catch (DuplicateKeyException dke) {
System.out.println("ok");
}
System.out.print(++test+"- "+"Calling getEJBHome() on EntityCMP...");
if (enterpriseEntity.getEJBHome() != null) System.out.println("ok");
else throw new Exception ("new home not ok");
System.out.print(++test+"- "+"Getting a new reference with findByPK...");
EnterpriseEntity enterpriseEntity2 = null;
try {
enterpriseEntity2 = enterpriseEntityHome.findByPrimaryKey("Marc");
}
catch (Exception re) {
re.printStackTrace();
}
if (enterpriseEntity2 != null) System.out.println("ok");
else System.out.println("not ok");
System.out.println(++test+"- "+"Calling Business Method A on
enterpriseEntity... ");
System.out.println(enterpriseEntity.callBusinessMethodA());
System.out.println(++test+"- "+"Calling Business Method A (again to ejbLoad
if TypeC) on enterpriseEntity... ");
System.out.println(enterpriseEntity.callBusinessMethodA());
System.out.println(++test+"- "+"Calling Business Method B (EJBObject from
entity) on enterpriseEntity...");
System.out.println(enterpriseEntity.callBusinessMethodB());
System.out.println(++test+"- "+"Calling Business Method B(String) on
EnterpriseEntity... ");
System.out.println(enterpriseEntity.callBusinessMethodB("of wisdom"));
System.out.print(++test+"- "+"Calling getOtherField (non pk) on
enterpriseEntity...");
System.out.println("value: "+enterpriseEntity.getOtherField());
System.out.print(++test+"- "+"Calling setOtherField(4) on
enterpriseEntity...");
enterpriseEntity.setOtherField(4);
System.out.println("OK");
System.out.print(++test+"- "+"Calling getOtherField() on enterpriseEntity
(should be 4)...");
int value = enterpriseEntity.getOtherField();
if (value == 4) System.out.println("value is "+value+", OK");
else System.out.println("NOT OK value is "+value);
System.out.println("***Testing the various local Object class calls");
System.out.print(++test+"- "+"toString ... ");
System.out.println(enterpriseEntity.toString());
System.out.print(++test+"- "+"hashCode ... ");
System.out.println(enterpriseEntity.hashCode());
System.out.print(++test+"- "+"equals (same object) ... ");
System.out.println(enterpriseEntity.equals(enterpriseEntity));
System.out.print(++test+"- "+"equals (another object) (true for this
case)... ");
System.out.println(enterpriseEntity.equals(enterpriseEntity2));
System.out.println("***Testing the various local EJBObject class calls");
System.out.print(++test+"- "+"Get Primary Key ... ");
System.out.println(enterpriseEntity.getPrimaryKey());
System.out.print(++test+"- "+"Get Handle ... ");
Handle entityHandle = enterpriseEntity.getHandle();
if (entityHandle != null) System.out.println("OK");
System.out.print(++test+"- "+"Serialize handle and deserialize....");
MarshalledObject mo3 = new MarshalledObject(entityHandle);
Handle entityHandle3 = (Handle) mo3.get();
EnterpriseEntity enterpriseEntity3 = (EnterpriseEntity)
entityHandle3.getEJBObject();
if (enterpriseEntity3 != null) System.out.println("OK");
System.out.println(++test+"- "+"Calling businessMethodA on it...");
System.out.println(enterpriseEntity3.callBusinessMethodB());
System.out.println(++test+"- "+"They should be
identical..."+enterpriseEntity.isIdentical(enterpriseEntity3));
System.out.print(++test+"- "+"Calling entityHome.remove(Handle)...");
enterpriseEntityHome.remove(enterpriseEntity3.getHandle());
System.out.println("OK");
System.out.print(++test+"- "+"Calling enterpriseEntity.remove()
(should fail)...");
try {
enterpriseEntity.remove();
System.out.println("NOT OK");
}
catch (Exception e) {
System.out.println("OK");
}
System.out.print(++test+"- "+"Calling EnterpriseEntity.create() for
marc6...");
EnterpriseEntity marc6 = enterpriseEntityHome.create("marc6");
System.out.println("ok");
System.out.print(++test+"- "+"Calling method createEntity on
enterpriseEntity... ");
EnterpriseEntity marc2 = marc6.createEntity("marc2");
System.out.println("OK");
System.out.print(++test+"- "+"removing by PK on home (marc2)...");
enterpriseEntityHome.remove(marc2.getPrimaryKey());
System.out.println("ok");
System.out.print(++test+"- "+"Calling enterpriseEntity.remove() (marc6)...");
marc6.remove();
System.out.println("ok");
System.out.println();
System.out.println();
System.out.println();
}
public void testEntityBeanBMP()
throws Exception
{
Context ctx = new InitialContext();
System.out.println();
System.out.println();
System.out.println("Test Entity Bean BMP");
System.out.println("====================");
System.out.println();
System.out.print(++test+"- "+"Looking up home for nextgen.EntityBMP...");
EntityBMPHome bmpHome = (EntityBMPHome) ctx.lookup("nextgen.EntityBMP");
if (bmpHome != null )System.out.println("ok");
// the current test will always return
System.out.print(++test+"- "+"Calling create on the home...");
EntityBMP bmpBean = bmpHome.create("Marc");
if (bmpBean!= null) System.out.println("ok");
// Let's call a business method to see the flow of server calls
System.out.print(++test+"- "+"Calling getEJBHome() on EntityBMP...");
if (bmpBean.getEJBHome() != null) System.out.println("ok");
else throw new Exception("Null Home");
System.out.println(++test+"- "+"Calling business methodA on BMP bean...");
System.out.println(bmpBean.callBusinessMethodA());
System.out.println(++test+"- "+"Calling business methodB (B2B) on BMP bean
and it says ");
System.out.println(bmpBean.callBusinessMethodB());
System.out.println(++test+"- "+"Calling Business Method B(String) on BMP... ");
System.out.println(bmpBean.callBusinessMethodB("of wisdom"));
System.out.println(++test+"- "+"calling findCollectionKeys....");
Collection pks = bmpHome.findCollectionKeys(3);
Iterator pkIterator = pks.iterator();
while (pkIterator.hasNext()) {
EntityBMP currentBean = (EntityBMP)pkIterator.next();
System.out.println((String)currentBean.getPrimaryKey());
}
System.out.println("ok");
System.out.println(++test+"- "+"calling findEnumeratedKeys....");
Enumeration pksEnumeration = bmpHome.findEnumeratedKeys(3);
while (pksEnumeration.hasMoreElements()) {
EntityBMP currentBean = (EntityBMP)pksEnumeration.nextElement();
System.out.println((String)currentBean.getPrimaryKey());
}
System.out.println("ok");
}
public void testEntityBeanPK()
throws Exception
{
Context ctx = new InitialContext();
System.out.println();
System.out.println();
System.out.println("Test Entity Bean PK");
System.out.println("====================");
System.out.println();
System.out.print(++test+"- "+"Looking up home for nextgen.EntityPK...");
EntityPKHome pkHome = (EntityPKHome) ctx.lookup("nextgen.EntityPK");
if (pkHome != null )System.out.println("ok");
System.out.print(++test+"- "+"Calling find on the home...");
EntityPK pkBean = null;
// Let's try to find the instance
try {
pkBean = pkHome.findByPrimaryKey(new AComplexPK(true, 10, 100, 1000.0,
"Marc"));
} catch (Exception e) {
System.out.println("not found");
System.out.print(++test+"- "+"Did not find the instance will create
it...");
pkBean = pkHome.create(true, 10,100, 1000.0, "Marc");
}
if (pkBean!= null) System.out.println("ok");
System.out.print(++test+"- "+"Retrieving other field...");
if (pkBean.getOtherField() == 0) {
System.out.println("0, ok");
} else {
System.out.println("failed");
}
System.out.print(++test+"- "+"Setting it to 4...");
pkBean.setOtherField(4);
System.out.println("ok");
System.out.print(++test+"- "+"Findind it again ... ") ;
// Now we should be able to find it
pkBean = pkHome.findByPrimaryKey(new AComplexPK(true, 10, 100,1000.0,
"Marc"));
if (pkBean != null) System.out.println("ok");
// check if the other field has been saved
System.out.print(++test+"- "+"Retrieving other field again, should be 4...");
int newValue = pkBean.getOtherField();
if (newValue == 4) {
System.out.println("4, ok");
} else {
System.out.println("failed, value is " + newValue);
}
// Get a new EJBObject for this guy
// Now we should be able to find it
System.out.print(++test+"- "+"gettting a new reference ... ") ;
EntityPK pkBean2 = pkHome.findByPrimaryKey(new AComplexPK(true, 10,
100,1000.0, "Marc"));
if (pkBean2 != null) System.out.println("ok");
System.out.print(++test+"- "+"Retrieving other field again, should be
4...");
int newValue2 = pkBean2.getOtherField();
if (newValue2 == 4) {
System.out.println("4, ok");
} else {
System.out.println("failed, value is " + newValue2);
}
// Now remove it
System.out.println(++test+"- "+"Removing the bean...");
pkBean.remove();
try {
System.out.println(++test+"- "+"I should not find it...");
pkBean = pkHome.findByPrimaryKey(new AComplexPK(true, 10, 100, 1000.0,
"Marc"));
} catch (Exception e) {
System.out.println("not found, OK");
}
}
public void testTxSession()
throws Exception
{
Context ctx = new InitialContext();
System.out.println();
System.out.println();
System.out.println("Test TxSession");
System.out.println("==============");
System.out.println();
System.out.print(++test+"- "+"Looking up home for nextgen.TxSession...");
TxSessionHome txHome = (TxSessionHome) ctx.lookup("nextgen.TxSession");
if (txHome != null )System.out.println("ok");
System.out.print(++test+"- "+"Calling create on the home...");
TxSession txBean = null;
// Let's try to create the instance
try {
txBean = txHome.create();
} catch (Exception e) {
e.printStackTrace();
}
if (txBean!= null) System.out.println("ok");
System.out.print(++test+"- "+"calling supports... ");
System.out.println(txBean.txSupports());
System.out.print(++test+"- "+"calling required... ");
System.out.println(txBean.txRequired());
System.out.print(++test+"- "+"calling requiresNew... ");
System.out.println(txBean.txRequiresNew());
System.out.print(++test+"- "+"calling not supported... ");
System.out.println(txBean.txNotSupported());
System.out.print(++test+"- "+"calling mandatory (should get an
exception)...");
try {
System.out.println(txBean.txMandatory());
} catch (Exception e) {
System.out.println("got Exception, ok");
}
System.out.print(++test+"- "+"calling requiredToSupports... ");
System.out.println(txBean.requiredToSupports());
System.out.print(++test+"- "+"calling requiredToNotSupported... ");
System.out.println(txBean.requiredToNotSupported());
System.out.print(++test+"- "+"calling requiredToRequiresNew... ");
System.out.println(txBean.requiredToRequiresNew());
}
public void testAllTypesBean()
throws Exception
{
Context ctx = new InitialContext();
System.out.println();
System.out.println();
System.out.println("Test AllTypesBean");
System.out.println("=================");
System.out.println();
System.out.print(++test+"- "+"Looking up the home AllTypes...");
AllTypesHome allTypesHome = (AllTypesHome) ctx.lookup("AllTypes");
if (allTypesHome!= null ) System.out.println("ok");
System.out.print(++test+"- "+"Calling findByPrimaryKey on AllTypesHome with
name seb...");
AllTypes allTypes = null;
try {
allTypes = allTypesHome.findByPrimaryKey("seb");
}
catch (Exception e) {System.out.println(e.getMessage());}
if (allTypes == null) {
System.out.println("not found OK");
System.out.print(++test+"- "+"Calling create on AllTypesHome with name
seb...");
allTypes = allTypesHome.create("seb");
}
if (allTypes != null) System.out.println("ok");
System.out.print(++test+"- "+"Calling business method A an AllTypes
(B2B with external ejb-ref)...");
System.out.println("OK, result is" + allTypes.callBusinessMethodA());
System.out.println("Getting all the fields");
System.out.println(++test+"- "+"boolean " + allTypes.getBoolean());
System.out.println(++test+"- "+"byte " + allTypes.getByte());
System.out.println(++test+"- "+"short " + allTypes.getShort());
System.out.println(++test+"- "+"int " + allTypes.getInt());
System.out.println(++test+"- "+"long " + allTypes.getLong());
System.out.println(++test+"- "+"float " + allTypes.getFloat());
System.out.println(++test+"- "+"double " + allTypes.getDouble());
System.out.println("No char test yet, bug in jdk");
System.out.println(++test+"- "+"String " + allTypes.getString());
System.out.println(++test+"- "+"Date " + allTypes.getDate());
System.out.println(++test+"- "+"Timestamp " + allTypes.getTimestamp());
System.out.print(++test+"- "+"MyObject ");
MyObject obj = allTypes.getObject();
System.out.println("OK");
System.out.print(++test+"- "+"getting handle of stateful...");
Handle sfHandle = allTypes.getStateful();
System.out.println("OK");
System.out.print(++test+"- "+"getting the bean back from the
handle...");
StatefulSession sfBean = (StatefulSession)sfHandle.getEJBObject();
System.out.println("OK");
System.out.print(++test+"- "+"calling business method A on stateful:
");
System.out.println("OK, result is " + sfBean.callBusinessMethodA());
System.out.print(++test+"- "+"adding the stateful bean as an object in
AllTypes..");
allTypes.addObjectToList(sfBean);
System.out.println("OK");
System.out.print(++test+"- "+"getting handle of stateless...");
Handle slHandle = allTypes.getStateless();
System.out.println("OK");
System.out.print(++test+"- "+"getting the bean back from the
handle...");
StatelessSession slBean = (StatelessSession)slHandle.getEJBObject();
System.out.println("OK");
System.out.print(++test+"- "+"calling business method B on stateless:
");
System.out.println("OK, result is " + slBean.callBusinessMethodB());
System.out.print(++test+"- "+"adding the stateless bean as an object
in AllTypes..");
allTypes.addObjectToList(slBean);
System.out.println("OK");
System.out.print(++test+"- "+"getting handle of entity...");
Handle eeHandle = allTypes.getEntity();
System.out.println("OK");
System.out.print(++test+"- "+"getting the bean back from the
handle...");
EnterpriseEntity eeBean = (EnterpriseEntity)eeHandle.getEJBObject();
System.out.println("OK");
System.out.print(++test+"- "+"calling business method A on stateless:
");
System.out.println("OK, result is" + eeBean.callBusinessMethodA());
System.out.print(++test+"- "+"adding the entity bean as an object in
AllTypes..");
allTypes.addObjectToList(eeBean);
System.out.println("OK");
System.out.print(++test+"- "+"Getting the list of objects back (should
contain the 3 beans)...");
Collection coll = allTypes.getObjectList();
System.out.println("OK");
System.out.print(++test+"- "+"stateful bean ");
if (coll.contains(sfBean)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"stateless bean ");
if (coll.contains(slBean)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"entity bean ");
if (coll.contains(eeBean)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.println("Testing automatically generated finders");
System.out.print(++test+"- "+"findAll()..");
coll = allTypesHome.findAll();
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByPrimaryKey()...");
AllTypes result = allTypesHome.findByPrimaryKey("seb");
if (result.equals(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByABoolean()..");
coll = allTypesHome.findByABoolean(allTypes.getBoolean());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByAByte()..");
coll = allTypesHome.findByAByte(allTypes.getByte());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByAShort()..");
coll = allTypesHome.findByAShort(allTypes.getShort());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByAnInt()..");
coll = allTypesHome.findByAnInt(allTypes.getInt());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByALong()..");
coll = allTypesHome.findByALong(allTypes.getLong());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByAFloat()..");
coll = allTypesHome.findByAFloat(allTypes.getFloat());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByADouble()..");
coll = allTypesHome.findByADouble(allTypes.getDouble());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.println("No Char test yet, bug in jdk");
System.out.print(++test+"- "+"findByAString()..");
coll = allTypesHome.findByAString(allTypes.getString());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByADate()..");
coll = allTypesHome.findByADate(allTypes.getDate());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByATimestamp()..");
coll = allTypesHome.findByATimestamp(allTypes.getTimestamp());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByAnObject()..");
coll = allTypesHome.findByAnObject(allTypes.getObject());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByStatefulSession()..");
coll =
allTypesHome.findByStatefulSession((StatefulSession)allTypes.getStateful().getEJBObject());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByStatelessSession()..");
coll =
allTypesHome.findByStatelessSession((StatelessSession)allTypes.getStateless().getEJBObject());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByEnterpriseEntity()..");
coll =
allTypesHome.findByEnterpriseEntity((EnterpriseEntity)allTypes.getEntity().getEJBObject());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.println("Testing finders defined in jaws.xml");
System.out.print(++test+"- "+"findByMinInt()..");
coll = allTypesHome.findByMinInt(0);
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
System.out.print(++test+"- "+"findByIntAndDouble()..");
coll = allTypesHome.findByIntAndDouble(allTypes.getInt(),
allTypes.getDouble());
if (coll.contains(allTypes)) System.out.println("OK"); else
System.out.println("FAILED");
}
public void testBeanManagedTransactionDemarcation()
throws Exception
{
Context ctx = new InitialContext();
System.out.println();
System.out.println();
System.out.println("Test Bean Managed Transaction Demarcation");
System.out.println("=========================================");
System.out.println();
System.out.print(++test+"- "+"Looking up the home BMTStateful...");
BMTStatefulHome bmtSFHome = (BMTStatefulHome) ctx.lookup("BMTStateful");
if (bmtSFHome != null ) System.out.println("ok");
System.out.print(++test+"- "+"Calling create on BMTStatefulHome...");
BMTStateful bmtSF = bmtSFHome.create();
System.out.println("OK");
System.out.println(++test+"- "+"Can the bean access its
UserTransaction");
System.out.println(bmtSF.txExists());
System.out.println(++test+"- "+"Testing commit on UserTransaction");
System.out.println(bmtSF.txCommit());
System.out.println(++test+"- "+"Testing rollback on UserTransaction");
System.out.println(bmtSF.txRollback());
System.out.print(++test+"- "+"Beginning a transaction...");
System.out.println(bmtSF.txBegin());
System.out.print(++test+"- "+"Committing the transaction in another
call...");
System.out.println(bmtSF.txEnd());
System.out.print(++test+"- "+"Creating a table for real db w/ tx
test...");
bmtSF.createTable();
System.out.println("OK, field value is:");
System.out.println(bmtSF.getDbField());
System.out.print(++test+"- "+"Updating the field in a transaction,
commit...");
bmtSF.dbCommit();
System.out.println("OK, field value is:");
System.out.println(bmtSF.getDbField());
System.out.print(++test+"- "+"Updating the field in a transaction,
rollback...");
bmtSF.dbRollback();
System.out.println("OK, field value is:");
System.out.println(bmtSF.getDbField());
System.out.print(++test+"- "+"Now dropping the table...");
bmtSF.dropTable();
System.out.println("OK");
System.out.print(++test+"- "+"Looking up the home BMTStateful...");
BMTStatelessHome bmtSLHome = (BMTStatelessHome) ctx.lookup("BMTStateless");
if (bmtSLHome != null ) System.out.println("ok");
System.out.print(++test+"- "+"Calling create on BMTStatelessHome...");
BMTStateless bmtSL = bmtSLHome.create();
System.out.println("OK");
System.out.println(++test+"- "+"Can the bean access its
UserTransaction");
System.out.println(bmtSL.txExists());
System.out.println(++test+"- "+"Testing commit on UserTransaction");
System.out.println(bmtSL.txCommit());
System.out.println(++test+"- "+"Testing rollback on UserTransaction");
System.out.println(bmtSL.txRollback());
System.out.print(++test+"- "+"Beginning a transaction (container
should throw an exception)...");
try {
System.out.print(bmtSL.txBegin());
System.out.println(" ... FAILED");
} catch (RemoteException e) {
System.out.println(" ... OK, exception message: "+
e.getMessage());
}
//*/
System.out.println();
System.out.println();
System.out.println();
System.out.println("Test OK, "+test+" tests run, congratulations");
Date finishDate = new Date();
System.out.println("Tests took
"+(finishDate.getTime()-startDate.getTime())+" milliseconds");
/*
System.out.println("Speed test now (1000 iterations) ...");
Date startDate = new Date();
for (int i = 0; i<1000 ; i++) {
hello1.sayHello();
}
Date finishDate = new Date();
System.out.println("Test finished and took : "+
(finishDate.getTime()-startDate.getTime())+
" milliSeconds");
synchronized (this) {
try {
wait(10000);
}
catch (Exception e) {e.printStackTrace();};
}
System.out.println("Make it talk again (activation test) ...");
System.out.println(hello1.sayHello());
*/
}
protected void setUp()
throws Exception
{
if (deployed) return;
System.out.println("_____________________________________________");
System.out.println();
System.out.println("jBoss, the EJB Open Source Server");
System.out.println("Copyright (C), The jBoss Organization, 2000");
System.out.println("_____________________________________________");
System.out.println();
System.out.println("Welcome to the test Suite v1.4");
System.out.println("_____________________________________________");
System.out.println();
System.out.print("Deploying test beans...");
System.out.flush();
new org.jboss.jmx.client.Deployer().deploy("../deploy/testbean.jar");
new org.jboss.jmx.client.Deployer().deploy("../deploy/testbean2.jar");
deployed = true;
System.out.println("done!");
}
}