User: d_jencks
Date: 01/09/11 21:55:38
Added: src/main/org/jboss/test/dbtest/test DbTypesUnitTestCase.java
Removed: src/main/org/jboss/test/dbtest/test Main.java
Log:
Changed naming scheme of tests to *UnitTestCase.java for short running tests and
*StressTestCase.java for lengthy tests. Made tests-unit and tests-stress targets in
build.xml
Revision Changes Path
1.1
jbosstest/src/main/org/jboss/test/dbtest/test/DbTypesUnitTestCase.java
Index: DbTypesUnitTestCase.java
===================================================================
package org.jboss.test.dbtest.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 javax.ejb.FinderException;
import java.util.Date;
import java.util.Properties;
import java.util.Collection;
import java.util.Iterator;
import java.util.Enumeration;
import org.jboss.test.dbtest.interfaces.AllTypes;
import org.jboss.test.dbtest.interfaces.AllTypesHome;
import org.jboss.test.dbtest.interfaces.MyObject;
import org.jboss.test.dbtest.interfaces.Record;
import org.jboss.test.dbtest.interfaces.RecordHome;
import junit.framework.*;
import org.jboss.test.util.Deploy;
public class DbTypesUnitTestCase
extends TestCase
{
static boolean deployed = false;
public DbTypesUnitTestCase(String name)
{
super(name);
}
public static void main(String arg[]) {
DbTypesUnitTestCase main = new DbTypesUnitTestCase("main");
try {
main.setUp();
} catch (Exception e) {
System.out.println("Setup failed:");
e.printStackTrace();
}
try {
main.testAllTypesBean();
System.out.println();
System.out.println("_____________________________________________");
System.out.println("Congratulations! Test completed");
System.out.println("Please report success to the mailing
list:");
System.out.println(" [EMAIL PROTECTED]");
System.out.println();
System.out.println("Don't forget to mention:");
System.out.println(" OS :");
System.out.println(" JDK vendor/version :");
System.out.println();
System.out.println(" JBoss version :");
System.out.println();
System.out.println(" Database name/version :");
System.out.println(" JDBC driver version :");
System.out.println();
System.out.println("And please include:");
System.out.println(" Your setup: relevant parts of
jboss.jcml");
System.out.println(" The type-mappings from jaws.xml or
standardjaws.xml if you changed them");
System.out.println();
System.out.println("Thanks very much!");
System.out.println();
} catch (Exception e) {
e.printStackTrace();
System.out.println();
System.out.println("_____________________________________________");
System.out.println("Sorry, test failed. Try again with
different settings!");
System.out.println("Thanks for your time...");
System.out.println();
}
}
public void testAllTypesBean() throws Exception {
int test = 0;
Context ctx = new InitialContext();
System.out.println();
System.out.print(++test+"- "+"Looking up the home AllTypes...");
AllTypesHome allTypesHome;
try {
allTypesHome = (AllTypesHome) ctx.lookup("AllTypes");
if (allTypesHome == null) throw new Exception("abort");
System.out.println("OK");
} catch (Exception e) {
System.out.println();
System.out.println("Could not lookup the context: the beans
are probably not deployed");
System.out.println("Check the server trace for details");
e.printStackTrace();
throw new Exception();
}
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"); else {
System.out.println();
System.out.println("Could not find or create the alltypes
bean");
System.out.println("Check the server trace for details");
throw new Exception();
}
System.out.println("Getting all the fields");
System.out.println(++test+"- "+"boolean " + allTypes.getBoolean() + "
OK");
System.out.println(++test+"- "+"byte " + allTypes.getByte() + " OK");
System.out.println(++test+"- "+"short " + allTypes.getShort() + " OK");
System.out.println(++test+"- "+"int " + allTypes.getInt() + " OK");
System.out.println(++test+"- "+"long " + allTypes.getLong() + " OK");
System.out.println(++test+"- "+"float " + allTypes.getFloat() + " OK");
System.out.println(++test+"- "+"double " + allTypes.getDouble() + "
OK");
System.out.println("No char test yet, bug in jdk");
System.out.println(++test+"- "+"String " + allTypes.getString() + "
OK");
System.out.println(++test+"- "+"Date " + allTypes.getDate() + " OK");
System.out.println(++test+"- "+"Time " + allTypes.getTime() + " OK");
System.out.println(++test+"- "+"Timestamp " + allTypes.getTimestamp()
+ " OK");
System.out.print(++test+"- "+"MyObject ");
MyObject obj = allTypes.getObject();
System.out.println("OK");
System.out.print(++test+"- "+"Creating Record beans and adding them to
the Collection in Alltypes..");
RecordHome recordHome = (RecordHome) ctx.lookup("Record");
Record[] record = new Record[3];
for (int i=0; i<3; i++) {
try {
record[i] = recordHome.findByPrimaryKey("bill " + i);
} catch (FinderException e) {
record[i] = recordHome.create("bill " + i);
}
record[i].setAddress("SanFrancisco, CA 9411"+i);
allTypes.addObjectToList(record[i]);
}
System.out.println("OK");
System.out.print(++test+"- "+"Getting them back..");
Collection collection = allTypes.getObjectList();
boolean ok = true;
for (int i=0; i<3; i++) ok = ok && collection.contains(record[i]);
if (ok) System.out.println("OK"); else {
System.out.println("failed");
throw new Exception("abort");
}
System.out.println("All basic tests passed; Now testing min/max values.");
System.out.println("This is just for information, it's okay if some fail.");
System.out.println("Not all DBs have a column type that supports 8-byte
numbers.");
// NOTE: In order from most likely to fail to least likely to fail
// Oracle in particular demonstrates cascading failures and
// we don't want to miss that
// Double
try {
allTypes.setDouble(Double.MIN_VALUE);
double d;
if((d = allTypes.getDouble()) == Double.MIN_VALUE)
System.out.println(++test+"- Double Min Value OK");
else
System.out.println(++test+"- Double Min Value Different ("+d+" <>
"+Double.MIN_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Double Min Value Failed");
}
try {
allTypes.setDouble(Double.MAX_VALUE);
double d;
if((d = allTypes.getDouble()) == Double.MAX_VALUE)
System.out.println(++test+"- Double Max Value OK");
else
System.out.println(++test+"- Double Max Value Different ("+d+" <>
"+Double.MAX_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Double Max Value Failed");
}
// Float
try {
allTypes.setFloat(Float.MIN_VALUE);
float f;
if((f = allTypes.getFloat()) == Float.MIN_VALUE)
System.out.println(++test+"- Float Min Value OK");
else
System.out.println(++test+"- Float Min Value Different ("+f+" <>
"+Float.MIN_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Float Min Value Failed");
}
try {
allTypes.setFloat(Float.MAX_VALUE);
float f;
if((f = allTypes.getFloat()) == Float.MAX_VALUE)
System.out.println(++test+"- Float Max Value OK");
else
System.out.println(++test+"- Float Max Value Different ("+f+" <>
"+Float.MAX_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Float Max Value Failed");
}
// Long
try {
allTypes.setLong(Long.MIN_VALUE);
long l;
if((l = allTypes.getLong()) == Long.MIN_VALUE)
System.out.println(++test+"- Long Min Value OK");
else
System.out.println(++test+"- Long Min Value Different ("+l+" <>
"+Long.MIN_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Long Min Value Failed");
}
try {
allTypes.setLong(Long.MAX_VALUE);
long l;
if((l = allTypes.getLong()) == Long.MAX_VALUE)
System.out.println(++test+"- Long Max Value OK");
else
System.out.println(++test+"- Long Max Value Different ("+l+" <>
"+Long.MAX_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Long Max Value Failed");
}
// Short
try {
allTypes.setShort(Short.MIN_VALUE);
short s;
if((s = allTypes.getShort()) == Short.MIN_VALUE)
System.out.println(++test+"- Short Min Value OK");
else
System.out.println(++test+"- Short Min Value Different ("+s+" <>
"+Short.MIN_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Short Min Value Failed");
}
try {
allTypes.setShort(Short.MAX_VALUE);
short s;
if((s = allTypes.getShort()) == Short.MAX_VALUE)
System.out.println(++test+"- Short Max Value OK");
else
System.out.println(++test+"- Short Max Value Different ("+s+" <>
"+Short.MAX_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Short Max Value Failed");
}
// Byte
try {
allTypes.setByte(Byte.MIN_VALUE);
byte b;
if((b = allTypes.getByte()) == Byte.MIN_VALUE)
System.out.println(++test+"- Byte Min Value OK");
else
System.out.println(++test+"- Byte Min Value Different ("+b+" <>
"+Byte.MIN_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Byte Min Value Failed");
}
try {
allTypes.setByte(Byte.MAX_VALUE);
byte b;
if((b = allTypes.getByte()) == Byte.MAX_VALUE)
System.out.println(++test+"- Byte Max Value OK");
else
System.out.println(++test+"- Byte Max Value Different ("+b+" <>
"+Byte.MAX_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Byte Max Value Failed");
}
// Int
try {
allTypes.setInt(Integer.MIN_VALUE);
int i;
if((i = allTypes.getInt()) == Integer.MIN_VALUE)
System.out.println(++test+"- Int Min Value OK");
else
System.out.println(++test+"- Int Min Value Different ("+i+" <>
"+Integer.MIN_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Int Min Value Failed");
}
try {
allTypes.setInt(Integer.MAX_VALUE);
int i;
if((i = allTypes.getInt()) == Integer.MAX_VALUE)
System.out.println(++test+"- Int Max Value OK");
else
System.out.println(++test+"- Int Max Value Different ("+i+" <>
"+Integer.MAX_VALUE+")");
} catch(Exception e) {
System.out.println(++test+"- Int Max Value Failed");
}
}
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,2001");
System.out.println("_____________________________________________");
System.out.println();
System.out.println("Welcome to the database test");
System.out.println("_____________________________________________");
System.out.println();
System.out.print("Deploying the bean...");
System.out.flush();
new org.jboss.jmx.client.Deployer().deploy("../deploy/dbtest.jar");
deployed = true;
System.out.println("done!");
*/
}
/**
* Setup the test suite.
*/
public static Test suite() {
TestSuite suite = new TestSuite();
// add a test case to deploy our support applications
String filename = "dbtest.jar";
suite.addTest(new Deploy.Deployer(filename));
suite.addTest(new TestSuite(DbTypesUnitTestCase.class));
// add a test case to undeploy our support applications
suite.addTest(new Deploy.Undeployer(filename));
return suite;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development