[jboss-svn-commits] JBL Code SVN: r26453 - labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon May 11 05:35:13 EDT 2009
Author: whitingjr
Date: 2009-05-11 05:35:13 -0400 (Mon, 11 May 2009)
New Revision: 26453
Removed:
labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/EJB3IntegrationTest.java
labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/FixDBUnit.java
labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/TestUtil.java
labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/basedata.xml
Log:
Deleted: labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/EJB3IntegrationTest.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/EJB3IntegrationTest.java 2009-05-11 09:35:03 UTC (rev 26452)
+++ labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/EJB3IntegrationTest.java 2009-05-11 09:35:13 UTC (rev 26453)
@@ -1,155 +0,0 @@
-package auction.test;
-
-import java.util.List;
-import java.util.ArrayList;
-import java.io.InputStream;
-import java.io.File;
-import java.sql.Connection;
-
-import org.dbunit.dataset.*;
-import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.dbunit.operation.DatabaseOperation;
-import org.dbunit.database.*;
-import org.testng.annotations.*;
-import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
-
-import javax.naming.*;
-import javax.sql.DataSource;
-import javax.transaction.UserTransaction;
-import javax.persistence.EntityManagerFactory;
-
-public abstract class EJB3IntegrationTest {
-
- // Configuration options
- private String JNDI_DATASOURCE;
- private String JNDI_NAME_EMF;
- private String JNDI_NAME_USERTX;
-
- protected InitialContext jndi;
-
- protected String dataSetLocation;
- protected List<DatabaseOperation> beforeTestOperations
- = new ArrayList<DatabaseOperation>();
- protected List<DatabaseOperation> afterTestOperations
- = new ArrayList<DatabaseOperation>();
-
- private ReplacementDataSet dataSet;
-
- @BeforeTest(groups = "integration-persistence")
- @Parameters({"deploy_beans_xml", "scan_classpath",
- "jndi_datasource", "jndi_name_emf", "jndi_name_usertx"})
- public void startContainer(String deployBeansXml, String scanClasspath,
- String jndiDatasource, String jndiNameEMF, String jndiNameUserTx)
- throws Exception {
- // Set configuration options from TestNG parameters
- JNDI_DATASOURCE = jndiDatasource;
- JNDI_NAME_EMF = jndiNameEMF;
- JNDI_NAME_USERTX = jndiNameUserTx;
-
- // Boot the JBoss Microcontainer with EJB3 settings, automatically
- // loads ejb3-interceptors-aop.xml and embedded-jboss-beans.xml
- EJB3StandaloneBootstrap.boot(null);
-
- // Deploy custom stateless beans (datasource, mostly)
- EJB3StandaloneBootstrap.deployXmlResource(deployBeansXml);
-
- // Deploy all EJBs found on classpath (slow, scans all)
- //EJB3StandaloneBootstrap.scanClasspath();
-
- // Deploy all EJBs found on classpath (fast, scans only build directory)
- // This is a relative location, matching the substring end of one of java.class.path locations!
- // Print out System.getProperty("java.class.path") to understand this...
- EJB3StandaloneBootstrap.scanClasspath(scanClasspath.replace("/", File.separator));
-
- // Create InitialContext from jndi.properties
- jndi = new InitialContext();
- }
-
- @BeforeClass(groups = "integration-persistence")
- public void prepareDataSet() throws Exception {
-
- // Check if subclass has prepared everything
- prepareSettings();
- if (dataSetLocation == null)
- throw new RuntimeException(
- "Test subclass needs to prepare a dataset location"
- );
-
- // Load the base dataset file
- InputStream input =
- Thread.currentThread().getContextClassLoader()
- .getResourceAsStream(dataSetLocation);
-
- dataSet = new ReplacementDataSet(
- new FlatXmlDataSet(input)
- );
- dataSet.addReplacementObject("[NULL]", null);
- }
-
- @BeforeMethod(groups = "integration-persistence")
- public void beforeTestMethod() throws Exception {
- prepareSettings();
- for (DatabaseOperation op : beforeTestOperations ) {
- op.execute(getConnection(), dataSet);
- }
- }
-
- @AfterMethod(groups = "integration-persistence")
- public void afterTestMethod() throws Exception {
- for (DatabaseOperation op : afterTestOperations ) {
- op.execute(getConnection(), dataSet);
- }
- }
-
- // Convenience for subclasses
-
- protected UserTransaction getUserTransaction() throws Exception {
- return (UserTransaction)jndi.lookup(JNDI_NAME_USERTX);
- }
-
- protected EntityManagerFactory getEntityManagerFactory() throws Exception{
- return (EntityManagerFactory)jndi.lookup(JNDI_NAME_EMF);
- }
-
- @SuppressWarnings({"unchecked"})
- protected <T> T lookupLocalBean(Class<T> beanInterface, String beanImpl) {
- try {
- return (T)jndi.lookup(beanImpl + "/local");
- } catch (NamingException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- // Subclasses can/have to override the following methods
-
- protected IDatabaseConnection getConnection() throws Exception {
-
- // Get a JDBC connection from JNDI datasource
- Connection con = ((DataSource) jndi.lookup(JNDI_DATASOURCE)).getConnection();
-
- // Disable foreign key constraint checking
- // This really depends on the DBMS product... here for HSQL DB
- con.prepareStatement("set referential_integrity FALSE")
- .execute();
-
- IDatabaseConnection dbUnitCon =
- new DatabaseConnection( con);
-
- // TODO: Remove this once DBUnit works with the latest HSQL DB
- DatabaseConfig config = dbUnitCon.getConfig();
- config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new FixDBUnit());
-
- return dbUnitCon;
- }
-
- /**
- * Override this in a subclass. It will be called before each test
- * method. Use it to stack DBUnit <tt>DatabaseOperation</tt>'s with
- * the <tt>beforeTestOperations</tt> and <tt>afterTestOperations</tt>
- * lists. You can also modify the <tt>afterTestOperations</tt> list
- * <i>inside</i> a test method, if you require additional clean up
- * once the method completes.
- */
- protected abstract void prepareSettings();
-
-}
Deleted: labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/FixDBUnit.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/FixDBUnit.java 2009-05-11 09:35:03 UTC (rev 26452)
+++ labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/FixDBUnit.java 2009-05-11 09:35:13 UTC (rev 26453)
@@ -1,21 +0,0 @@
-package auction.test;
-
-import org.dbunit.dataset.datatype.*;
-
-import java.sql.Types;
-
-/**
- * TODO: Direct SQL is lots of fun. This fixes DBUnit with the latest HSQL DB.
- *
- * http://www.carbonfive.com/community/archives/2005/07/dbunit_hsql_and.html
- */
-public class FixDBUnit extends DefaultDataTypeFactory {
-
- public DataType createDataType(int sqlType, String sqlTypeName)
- throws DataTypeException {
- if (sqlType == Types.BOOLEAN) {
- return DataType.BOOLEAN;
- }
- return super.createDataType(sqlType, sqlTypeName);
- }
-}
Deleted: labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/TestUtil.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/TestUtil.java 2009-05-11 09:35:03 UTC (rev 26452)
+++ labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/TestUtil.java 2009-05-11 09:35:13 UTC (rev 26453)
@@ -1,137 +0,0 @@
-package auction.test;
-
-import javax.naming.*;
-import java.lang.reflect.Proxy;
-
-/**
- * Some helper methods for testing.
- *
- * @author Christian Bauer
- */
-public class TestUtil {
-
- public static String listJNDITree(String namespace) {
- StringBuffer buffer = new StringBuffer(4096);
- try {
- Context context = new InitialContext(); // From jndi.properties
- if (namespace!= null)
- context = (Context) context.lookup(namespace);
- buffer.append("Namespace: " + namespace +"\n");
- buffer.append("#####################################\n");
- list(context, " ", buffer, true);
- buffer.append("#####################################\n");
- }
- catch (NamingException e) {
- buffer.append("Failed to get InitialContext, " + e.toString(true));
- }
- return buffer.toString();
- }
-
- private static void list(Context ctx, String indent, StringBuffer buffer, boolean verbose) {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- try {
- NamingEnumeration ne = ctx.list("");
- while (ne.hasMore()) {
- NameClassPair pair = (NameClassPair) ne.next();
-
- String name = pair.getName();
- String className = pair.getClassName();
- boolean recursive = false;
- boolean isLinkRef = false;
- boolean isProxy = false;
- Class c = null;
- try {
- c = loader.loadClass(className);
-
- if (Context.class.isAssignableFrom(c))
- recursive = true;
- if (LinkRef.class.isAssignableFrom(c))
- isLinkRef = true;
-
- isProxy = Proxy.isProxyClass(c);
- }
- catch (ClassNotFoundException cnfe) {
- // If this is a $Proxy* class its a proxy
- if (className.startsWith("$Proxy")) {
- isProxy = true;
- // We have to get the class from the binding
- try {
- Object p = ctx.lookup(name);
- c = p.getClass();
- }
- catch (NamingException e) {
- Throwable t = e.getRootCause();
- if (t instanceof ClassNotFoundException) {
- // Get the class name from the exception msg
- String msg = t.getMessage();
- if (msg != null) {
- // Reset the class name to the CNFE class
- className = msg;
- }
- }
- }
- }
- }
-
- buffer.append(indent + " +- " + name);
-
- // Display reference targets
- if (isLinkRef) {
- // Get the
- try {
- Object obj = ctx.lookupLink(name);
-
- LinkRef link = (LinkRef) obj;
- buffer.append("[link -> ");
- buffer.append(link.getLinkName());
- buffer.append(']');
- }
- catch (Throwable t) {
- buffer.append("invalid]");
- }
- }
-
- // Display proxy interfaces
- if (isProxy) {
- buffer.append(" (proxy: " + pair.getClassName());
- if (c != null) {
- Class[] ifaces = c.getInterfaces();
- buffer.append(" implements ");
- for (int i = 0; i < ifaces.length; i++) {
- buffer.append(ifaces[i]);
- buffer.append(',');
- }
- buffer.setCharAt(buffer.length() - 1, ')');
- } else {
- buffer.append(" implements " + className + ")");
- }
- } else if (verbose) {
- buffer.append(" (class: " + pair.getClassName() + ")");
- }
-
- buffer.append('\n');
- if (recursive) {
- try {
- Object value = ctx.lookup(name);
- if (value instanceof Context) {
- Context subctx = (Context) value;
- list(subctx, indent + " | ", buffer, verbose);
- } else {
- buffer.append(indent + " | NonContext: " + value);
- buffer.append('\n');
- }
- }
- catch (Throwable t) {
- buffer.append("Failed to lookup: " + name + ", errmsg=" + t.getMessage());
- buffer.append('\n');
- }
- }
- }
- ne.close();
- }
- catch (NamingException ne) {
- buffer.append("error while listing context " + ctx.toString() + ": " + ne.toString(true));
- }
- }
-
-}
Deleted: labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/basedata.xml
===================================================================
--- labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/basedata.xml 2009-05-11 09:35:03 UTC (rev 26452)
+++ labs/jbosstm/workspace/whitingjr/HibernateWithInMemoryObjects/src/main/java/auction/test/basedata.xml 2009-05-11 09:35:13 UTC (rev 26453)
@@ -1,168 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
- Just a basic set of rows that are currently sufficient for all tests.
- In future, maybe several datasets are required.
--->
-<dataset>
-
- <BILLING_DETAILS
- BILLING_DETAILS_ID ="1"
- BILLING_DETAILS_TYPE ="CC"
- OBJ_VERSION ="0"
- OWNER ="John Doe"
- CREATED ="2006-09-23 13:45:00"
- USER_ID ="1"
- BA_ACCOUNT ="[NULL]"
- BA_BANKNAME ="[NULL]"
- BA_SWIFT ="[NULL]"
- />
-
- <CREDIT_CARD CREDIT_CARD_ID ="1"
- CC_TYPE ="MASTERCARD"
- CC_NUMBER ="123123123123"
- CC_EXP_MONTH ="08"
- CC_EXP_YEAR ="2010"
- />
-
- <USERS
- USER_ID ="1"
- OBJ_VERSION ="0"
- FIRSTNAME ="John"
- LASTNAME ="Doe"
- USERNAME ="johndoe"
- PASSWORD ="secret"
- EMAIL ="jd at mail.tld"
- RANK ="0"
- IS_ADMIN ="true"
- CREATED ="2006-09-23 13:45:00"
- HOME_STREET ="Foostreet"
- HOME_ZIPCODE ="22222"
- HOME_CITY ="Foocity"
- DEFAULT_BILLING_DETAILS_ID ="1"
- />
-
- <USERS
- USER_ID ="2"
- OBJ_VERSION ="0"
- FIRSTNAME ="Another"
- LASTNAME ="User"
- USERNAME ="anotheruser"
- PASSWORD ="secret"
- EMAIL ="anotheruser at mail.tld"
- RANK ="0"
- IS_ADMIN ="false"
- CREATED ="2006-09-23 13:45:00"
- HOME_STREET ="Foostreet"
- HOME_ZIPCODE ="22222"
- HOME_CITY ="Foocity"
- DEFAULT_BILLING_DETAILS_ID ="[NULL]"
- />
-
- <ADDRESS
- ADDRESS_ID ="1"
- OBJ_VERSION ="0"
- STREET ="Shippingstreet 1"
- ZIPCODE ="12345"
- CITY ="Shippingcity"
- />
-
- <ITEM
- ITEM_ID ="1"
- OBJ_VERSION ="0"
- ITEM_NAME ="Testitem 1"
- DESCRIPTION ="This is TestItem One."
- INITIAL_PRICE ="99"
- INITIAL_PRICE_CURRENCY ="USD"
- RESERVE_PRICE ="123"
- RESERVE_PRICE_CURRENCY ="USD"
- START_DATE ="2006-09-23 13:45:00"
- END_DATE ="2016-09-23 13:45:00"
- ITEM_STATE ="ACTIVE"
- APPROVED_BY_USER_ID ="1"
- APPROVAL_DATETIME ="2006-09-23 13:45:00"
- SELLER_ID ="1"
- SUCCESSFUL_BID_ID ="2"
- CREATED ="2006-09-23 13:45:00"
- />
-
- <ITEM
- ITEM_ID ="2"
- OBJ_VERSION ="0"
- ITEM_NAME ="Testitem 2"
- DESCRIPTION ="This is TestItem Two."
- INITIAL_PRICE ="111"
- INITIAL_PRICE_CURRENCY ="USD"
- RESERVE_PRICE ="222"
- RESERVE_PRICE_CURRENCY ="USD"
- START_DATE ="2006-09-23 13:45:00"
- END_DATE ="2016-09-23 13:45:00"
- ITEM_STATE ="DRAFT"
- APPROVED_BY_USER_ID ="1"
- APPROVAL_DATETIME ="2006-09-23 13:45:00"
- SELLER_ID ="1"
- SUCCESSFUL_BID_ID ="[NULL]"
- CREATED ="2006-09-23 13:45:00"
- />
-
- <BID
- BID_ID ="1"
- BID_AMOUNT ="100"
- BID_AMOUNT_CURRENCY ="USD"
- ITEM_ID ="1"
- BIDDER_ID ="1"
- BID_POSITION ="0"
- CREATED ="2006-09-23 13:46:00"
- />
-
- <BID
- BID_ID ="2"
- BID_AMOUNT ="124"
- BID_AMOUNT_CURRENCY ="USD"
- ITEM_ID ="1"
- BIDDER_ID ="1"
- BID_POSITION ="1"
- CREATED ="2006-09-23 13:47:00"
- />
-
- <CATEGORY
- CATEGORY_ID ="1"
- OBJ_VERSION ="0"
- CATEGORY_NAME ="Category One"
- CREATED ="2006-09-23 13:45:00"
- PARENT_CATEGORY_ID ="[NULL]"
- />
-
- <CATEGORY
- CATEGORY_ID ="2"
- OBJ_VERSION ="0"
- CATEGORY_NAME ="Category Two"
- CREATED ="2006-09-23 13:45:00"
- PARENT_CATEGORY_ID ="1"
- />
-
- <CATEGORIZED_ITEM
- CATEGORY_ID ="1"
- ITEM_ID ="1"
- ADDED_BY_USER ="johndoe"
- ADDED_ON ="2006-09-23 13:45:00"
- />
-
- <CATEGORIZED_ITEM
- CATEGORY_ID ="2"
- ITEM_ID ="1"
- ADDED_BY_USER ="johndoe"
- ADDED_ON ="2006-09-23 13:45:00"
- />
-
- <COMMENT
- COMMENT_ID ="1"
- OBJ_VERSION ="0"
- RATING ="OK"
- COMMENT_TEXT ="Just a comment."
- ABOUT_ITEM_ID ="1"
- FROM_USER_ID ="1"
- CREATED ="2006-09-23 13:47:00"
- />
-
-</dataset>
More information about the jboss-svn-commits
mailing list