|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.seam.mock.AbstractSeamTest
org.jboss.seam.mock.AbstractDBUnitSeamTest
public abstract class AbstractDBUnitSeamTest
Utility for integration testing with Seam and DBUnit datasets.
Subclass this class instead of SeamTest if you need to insert or clean data in your database before and after a test. You need to implement prepareDBUnitOperations() and add instances of DataSetOperations to the * beforeTestOperations and afterTestOperations lists. An example:
public class MyTest extends DBUnitSeamTest { protected void prepareDBUnitOperations() { beforeTestOperations.add( new DataSetOperation("my/datasets/BaseData.xml") ); beforeTestOperations.add( new DataSetOperation("my/datasets/AdditionalData.xml", DatabaseOperation.INSERT) ); } ... // Various test methods with @Test annotation }
Note that DataSetOperation defaults to DatabaseOperation.CLEAN_INSERT if no other operation is specified as a constructor argument. The above example cleans all tables defined in BaseData.xml, then inserts all rows declared in BaseData.xml, then inserts all the rows declared in AdditionalData.xml. This executes before every each test method is invoked. If you require extra cleanup after a test method executes, add operations to the afterTestOperations list.
A test class obtains the database connection for loading and cleaning of datasets in one of the following ways:
Referential integrity checks (foreign keys) will be or have to be disabled on the database connection used for DBUnit operations. This makes adding circular references in datasets easier. Referential integrity checks are enabled again after the connection has been used.
Note that the methods disableReferentialIntegrity(), enableReferentialIntegrity(), and editConfig() are implemented for HSQL DB. If you want to run unit tests on any other DBMS, you need to override these methods and implement them for your DBMS.
Nested Class Summary | |
---|---|
static class |
AbstractDBUnitSeamTest.Database
|
protected class |
AbstractDBUnitSeamTest.DataSetOperation
|
Nested classes/interfaces inherited from class org.jboss.seam.mock.AbstractSeamTest |
---|
AbstractSeamTest.ComponentTest, AbstractSeamTest.FacesRequest, AbstractSeamTest.NonFacesRequest |
Field Summary | |
---|---|
protected List<AbstractDBUnitSeamTest.DataSetOperation> |
afterTestOperations
|
protected List<AbstractDBUnitSeamTest.DataSetOperation> |
beforeTestOperations
|
Fields inherited from class org.jboss.seam.mock.AbstractSeamTest |
---|
seamFilter, servletContext, session |
Constructor Summary | |
---|---|
protected |
AbstractDBUnitSeamTest()
|
protected |
AbstractDBUnitSeamTest(String datasourceJndiName)
|
Method Summary | |
---|---|
void |
begin()
|
protected void |
disableReferentialIntegrity(org.dbunit.database.IDatabaseConnection con)
Override this method if you aren't using HSQL DB. |
protected void |
editConfig(org.dbunit.database.DatabaseConfig config)
Override this method if you require DBUnit configuration features or additional properties. |
protected void |
enableReferentialIntegrity(org.dbunit.database.IDatabaseConnection con)
Override this method if you aren't using HSQL DB. |
void |
end()
|
protected URL |
getBinaryDirFullpath()
Resolves the binary dir location with the help of the classloader, we need the absolute full path of that directory. |
protected byte[] |
getBinaryFile(String filename)
|
protected org.dbunit.database.IDatabaseConnection |
getConnection()
Override this method if you want to provide your own DBUnit IDatabaseConnection instance. |
protected URL |
getResourceURL(String resource)
|
protected abstract void |
prepareDBUnitOperations()
Implement this in a subclass. |
void |
setBinaryDir(String binaryDir)
|
void |
setDatabase(String database)
|
void |
setDatasourceJndiName(String datasourceJndiName)
|
void |
setupClass()
Setup this test class instance Must be run for each test class instance (e.g. |
Methods inherited from class org.jboss.seam.mock.AbstractSeamTest |
---|
cleanupClass, createSeamFilter, createServletContext, getELResolvers, getField, getInitialContext, getInstance, getInstance, getSession, getUserTransaction, initServletContext, installMockTransport, isLongRunningConversation, isSessionInvalid, lookup, setField, startJbossEmbeddedIfNecessary, startSeam, stopSeam |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected List<AbstractDBUnitSeamTest.DataSetOperation> beforeTestOperations
protected List<AbstractDBUnitSeamTest.DataSetOperation> afterTestOperations
Constructor Detail |
---|
protected AbstractDBUnitSeamTest()
protected AbstractDBUnitSeamTest(String datasourceJndiName)
Method Detail |
---|
public void setDatasourceJndiName(String datasourceJndiName)
public void setBinaryDir(String binaryDir)
public void setDatabase(String database)
public void setupClass() throws Exception
AbstractSeamTest
setupClass
in class AbstractSeamTest
Exception
public void begin()
begin
in class AbstractSeamTest
public void end()
end
in class AbstractSeamTest
protected org.dbunit.database.IDatabaseConnection getConnection()
protected void disableReferentialIntegrity(org.dbunit.database.IDatabaseConnection con)
con
- A DBUnit connection wrapper, which is used afterwards for dataset operationsprotected void enableReferentialIntegrity(org.dbunit.database.IDatabaseConnection con)
con
- A DBUnit connection wrapper, before it is used by the application againprotected void editConfig(org.dbunit.database.DatabaseConfig config)
Called after a connection has been obtaind and before the connection is used. Can be a NOOP method if no additional settings are necessary for your DBUnit/DBMS setup.
config
- A DBUnit DatabaseConfig object for setting properties and featuresprotected URL getBinaryDirFullpath()
protected URL getResourceURL(String resource)
protected byte[] getBinaryFile(String filename) throws Exception
Exception
protected abstract void prepareDBUnitOperations()
Use it to stack DBUnit DataSetOperation's with the beforeTestOperations and afterTestOperations lists.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |