User: fleury
Date: 00/08/14 08:13:24
Modified: src/java/org/jboss/zol/testbean/client EjbossClient.java
Log:
new client
Revision Changes Path
1.15 +217 -198 zola/src/java/org/jboss/zol/testbean/client/EjbossClient.java
Index: EjbossClient.java
===================================================================
RCS file:
/products/cvs/ejboss/zola/src/java/org/jboss/zol/testbean/client/EjbossClient.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- EjbossClient.java 2000/08/12 00:50:11 1.14
+++ EjbossClient.java 2000/08/14 15:13:23 1.15
@@ -30,16 +30,16 @@
/**
- * Sample client for the jboss container.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Id: EjbossClient.java,v 1.14 2000/08/12 00:50:11 fleury Exp $
- */
+* Sample client for the jboss container.
+*
+* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+* @version $Id: EjbossClient.java,v 1.15 2000/08/14 15:13:23 fleury Exp $
+*/
public class EjbossClient {
-
+
public EjbossClient() {
}
-
+
public void doSomeTesting() {
try {
System.out.println("_____________________________________________");
@@ -51,28 +51,28 @@
System.out.println("Welcome to the test Suite v1.0");
System.out.println("_____________________________________________");
System.out.println();
+
+ int test = 0;
- int test = 0;
+ System.out.print(++test+"- "+"Trying the context...");
- System.out.print(++test+"- "+"Trying the context...");
-
- Context ctx = new InitialContext();
+ 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");
+ (StatelessSessionHome) ctx.lookup("nextgen.StatelessSession");
if (statelessSessionHome!= null ) System.out.println("ok");
System.out.print(++test+"- "+"Calling create on
StatelessSessionHome...");
StatelessSession statelessSession =
- statelessSessionHome.create();
+ 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");
@@ -86,129 +86,148 @@
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");
+ statelessSession.callBusinessMethodD();
+ System.out.println("ERROR, no exception was thrown");
}
catch (BusinessMethodException e) {
- System.out.println("Caught BusinessMethodException OK");
+ System.out.println("Caught BusinessMethodException OK");
}
catch (Exception e) {
- System.out.println("ERROR, type "+e.getClass());
- }
+ 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");
+ statelessSession.testClassLoading();
+ System.out.println("OK");
}
catch (BusinessMethodException e) {
- System.out.println("Failed");
+ System.out.println("Failed");
}
catch (Exception e) {
- System.out.println("ERROR, type "+e.getClass());
+ 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.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");
- // */
- ///*
+ */
+ ///*
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");
+ (StatefulSessionHome) ctx.lookup("nextgen.StatefulSession");
if (statefulSessionHome!= null ) System.out.println("ok");
- System.out.print(++test+"- "+"Calling create on StatefulSessionHome
with name Marc...");
+ System.out.print(++test+"- "+"Calling create on StatefulSessionHome
with name Marc...");
StatefulSession statefulSession =
- statefulSessionHome.create("Marc");
+ statefulSessionHome.create("Marc");
if (statefulSession != null) System.out.println("ok");
- System.out.print(++test+"- "+"Calling getEJBHome() on
StatefulSession...");
+ 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... ");
+ 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("***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()));
- 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("***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()));
+ 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) (for
second bean)...");
- statefulSessionHome.remove(statefulSession2.getHandle());
-
+ 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");
+ }
//*/
-
+
///*
- System.out.println();
+ 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;
@@ -217,17 +236,17 @@
}
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");
+
+ 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");
+ enterpriseEntityHome.create("Marc");
System.out.println("I Really should not make it here");
throw new Exception ("DuplicateKey not seen");
}
@@ -236,28 +255,28 @@
}
System.out.print(++test+"- "+"Calling getEJBHome() on EntityCMP...");
if (enterpriseEntity.getEJBHome() != null) System.out.println("ok");
- else throw new Exception ("new home not 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... ");
+ 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(++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 (EJBObject
from entity) on enterpriseEntity...");
+ System.out.println(enterpriseEntity.callBusinessMethodB());
+
+
System.out.print(++test+"- "+"Calling method createEntity on
enterpriseEntity... ");
EnterpriseEntity marc2 = enterpriseEntity.createEntity("marc2");
System.out.println("OK");
@@ -270,41 +289,41 @@
System.out.print(++test+"- "+"Calling EnterpriseEntity.remove() for
marc...");
enterpriseEntity.remove();
System.out.println("ok");
-
-
+
+
System.out.println();
System.out.println();
System.out.println();
-
-
- System.out.println();
+
+
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");
-
+ else throw new Exception("Null Home");
+
System.out.print(++test+"- "+"Calling business methodA on BMP bean...");
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 findCollectionKeys....");
Collection pks = bmpHome.findCollectionKeys(3);
Iterator pkIterator = pks.iterator();
@@ -313,7 +332,7 @@
System.out.println((String)currentBean.getPrimaryKey());
}
System.out.println("ok");
-
+
System.out.println(++test+"- "+"calling findEnumeratedKeys....");
Enumeration pksEnumeration = bmpHome.findEnumeratedKeys(3);
while (pksEnumeration.hasMoreElements()) {
@@ -321,116 +340,116 @@
System.out.println((String)currentBean.getPrimaryKey());
}
System.out.println("ok");
-
+
///*
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+"- "+"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);
- }
-
+
+ // 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);
+ }
+
// Now remove it
System.out.println(++test+"- "+"Removing the bean...");
pkBean.remove();
try {
- System.out.println(++test+"- "+"I should not find it...");
+ 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");
}
-
-
+
+
System.out.println();
System.out.println();
System.out.println();
System.out.println("Test OK, "+test+" tests run, congratulations");
- //*/
-
-
-
- /*
+ //*/
+
+
+
+ /*
System.out.println("Speed test now (1000 iterations) ...");
Date startDate = new Date();
for (int i = 0; i<1000 ; i++) {
- hello1.sayHello();
+ hello1.sayHello();
}
Date finishDate = new Date();
System.out.println("Test finished and took : "+
- (finishDate.getTime()-startDate.getTime())+
- " milliSeconds");
-
-
+ (finishDate.getTime()-startDate.getTime())+
+ " milliSeconds");
+
+
synchronized (this) {
-
- try {
-
- wait(10000);
- }
- catch (Exception e) {e.printStackTrace();};
+
+ try {
+
+ wait(10000);
}
-
+ catch (Exception e) {e.printStackTrace();};
+ }
+
System.out.println("Make it talk again (activation test) ...");
System.out.println(hello1.sayHello());
*/
-
+
} catch (Exception e ) {
-
+
e.printStackTrace();
}
}
-
+
public static void main(String[] arguments) {
-
+
EjbossClient client = new EjbossClient();
-
+
client.doSomeTesting();
}
}