|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.dbunit.DbUnitModule
public class DbUnitModule
Module that provides support for managing database test data using DBUnit.
Loading of DbUnit data sets can be done by annotating a class or method with theDataSet
annotation. The name
of the data set files can be specified explicitly as an argument of the annotation. If no file name is specified, it looks
for a file in the same directory as the test class named: 'classname without packagename'.xml.
By annotating a method with the ExpectedDataSet
annotation or by calling the assertDbContentAsExpected(java.lang.reflect.Method, java.lang.Object)
method, the contents of the database can be compared with the contents of a dataset. The expected dataset can be
passed as an argument of the annotation. If no file name is specified it looks for a file in the same directory
as the test class that has following name: 'classname without packagename'.'test method name'-result.xml.
This module depends on the DatabaseModule
for database connection management.
Nested Class Summary | |
---|---|
protected class |
DbUnitModule.DbUnitListener
Test listener that is called while the test framework is running tests |
Field Summary | |
---|---|
protected Properties |
configuration
The unitils configuration |
protected Map<String,DbUnitDatabaseConnection> |
dbUnitDatabaseConnections
Objects that DbUnit uses to connect to the database and to cache some database metadata. |
protected Map<Class<? extends Annotation>,Map<String,String>> |
defaultAnnotationPropertyValues
Map holding the default configuration of the dbunit module annotations |
Constructor Summary | |
---|---|
DbUnitModule()
|
Method Summary | |
---|---|
void |
afterInit()
No after initialization needed for this module |
void |
assertDbContentAsExpected(Method testMethod,
Object testObject)
Compares the contents of the expected DbUnitDataSet with the contents of the database. |
protected void |
closeJdbcConnection()
Closes (i.e. return to the pool) the JDBC Connection that is currently in use by the DbUnitDatabaseConnection |
protected DbUnitDatabaseConnection |
createDbUnitConnection(String schemaName)
Creates a new instance of dbUnit's IDatabaseConnection |
protected org.dbunit.dataset.IDataSet |
getActualDataSet(String schemaName)
Gets the actual data set for the given schema. |
protected DatabaseModule |
getDatabaseModule()
|
protected MultiSchemaDataSet |
getDataSet(Class<?> testClass,
String[] dataSetFileNames,
DataSetFactory dataSetFactory)
Creates the dataset for the given file. |
MultiSchemaDataSet |
getDataSet(Method testMethod,
Object testObject)
Using the values of the method-level or class-level DataSet annotations, returns the data set for the
given test method. |
protected DataSetFactory |
getDataSetFactory(Class<? extends Annotation> annotationClass,
Method testMethod,
Class testClass)
Get the configured DataSetFactory for the given method |
protected DataSetFactory |
getDataSetFactory(Class<? extends DataSetFactory> dataSetFactoryClass)
Creates and initializes a data set factory of the given type. |
protected DataSetLoadStrategy |
getDataSetLoadStrategy(Method testMethod,
Class testClass)
Creates the DbUnit dataset operation for loading a data set for the given method. |
protected DataSetResolver |
getDataSetResolver()
|
DbUnitDatabaseConnection |
getDbUnitDatabaseConnection(String schemaName)
Gets the DbUnit connection or creates one if it does not exist yet. |
protected DataSetFactory |
getDefaultDataSetFactory()
|
protected String |
getDefaultDataSetFileName(Class<?> testClass,
String extension)
Gets the name of the default testdata file at class level The default name is constructed as follows: 'classname without packagename'.xml |
protected DataSetLoadStrategy |
getDefaultDataSetLoadStrategy()
|
protected DbSupport |
getDefaultDbSupport()
|
protected String |
getDefaultExpectedDataSetFileName(Method method,
Class<?> testClass,
String extension)
Gets the name of the expected dataset file. |
MultiSchemaDataSet |
getExpectedDataSet(Method testMethod,
Object testObject)
Returns the MultiSchemaDataSet that represents the state of a number of database tables after the given
Method has been executed. |
TestListener |
getTestListener()
Creates the test listener for this module. |
void |
init(Properties configuration)
Initializes the DbUnitModule using the given Configuration |
void |
insertDataSet(Class<?> testClass,
String... dataSetFileNames)
Inserts the dataset consisting of the given list of files into the database |
void |
insertDataSet(File dataSetFile)
Inserts the test data coming from the given DbUnit dataset file using the default DataSetLoadStrategy and DataSetFactory class. |
void |
insertDataSet(File dataSetFile,
Class<? extends DataSetFactory> dataSetFactoryClass,
Class<? extends DataSetLoadStrategy> dataSetLoadStrategyClass)
Inserts the test data coming from the given DbUnit dataset file. |
void |
insertDataSet(Method testMethod,
Object testObject)
This method will first try to load a method level defined dataset. |
protected void |
insertDataSet(MultiSchemaDataSet multiSchemaDataSet,
DataSetLoadStrategy dataSetLoadStrategy)
Loads the given multi schema dataset into the database, using the given loadstrategy |
void |
insertDefaultDataSet(Class<?> testClass)
Inserts the default dataset for the given test class into the database |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Map<Class<? extends Annotation>,Map<String,String>> defaultAnnotationPropertyValues
protected Map<String,DbUnitDatabaseConnection> dbUnitDatabaseConnections
protected Properties configuration
Constructor Detail |
---|
public DbUnitModule()
Method Detail |
---|
public void init(Properties configuration)
init
in interface Module
configuration
- The config, not nullpublic void afterInit()
afterInit
in interface Module
public DbUnitDatabaseConnection getDbUnitDatabaseConnection(String schemaName)
schemaName
- The schema name, not null
public void insertDataSet(Method testMethod, Object testObject)
DataSet
annotation. If specified using this annotation but not found, a UnitilsException
is
thrown.
testMethod
- The method, not nulltestObject
- The test object, not nullpublic void insertDefaultDataSet(Class<?> testClass)
testClass
- The test class for which the default dataset must be loadedpublic void insertDataSet(Class<?> testClass, String... dataSetFileNames)
testClass
- The test class for which the dataset must be loadeddataSetFileNames
- The names of the files that define the test datapublic void insertDataSet(File dataSetFile)
DataSetLoadStrategy
and DataSetFactory
class.
dataSetFile
- The test data set, not nullpublic void insertDataSet(File dataSetFile, Class<? extends DataSetFactory> dataSetFactoryClass, Class<? extends DataSetLoadStrategy> dataSetLoadStrategyClass)
dataSetFile
- The test data set, not nulldataSetFactoryClass
- The class of the factory that must be used to read this datasetdataSetLoadStrategyClass
- The class of the load strategy that must be used to load this datasetprotected void insertDataSet(MultiSchemaDataSet multiSchemaDataSet, DataSetLoadStrategy dataSetLoadStrategy)
multiSchemaDataSet
- The multi schema dataset that is inserted in the databasedataSetLoadStrategy
- The load strategy that is usedpublic void assertDbContentAsExpected(Method testMethod, Object testObject)
testMethod
- The test method, not nulltestObject
- The test object, not nullprotected org.dbunit.dataset.IDataSet getActualDataSet(String schemaName)
schemaName
- The schema to get the data set for, not null
public MultiSchemaDataSet getDataSet(Method testMethod, Object testObject)
DataSet
annotations, returns the data set for the
given test method. If no method-level or class-level DataSet
annotation is found, null is returned.
If a method-level DataSet
annotation is found this will be used, else the class-level will be used.
The value of the found annotation determines which files need to be used for the dataset. If one or more filenames are
explicitly specified, these names will be used. Filenames that start with '/' are treated absolute. Filenames
that do not start with '/', are relative to the current class.
If an empty filename ("") is specified, this method will look for a file named 'classname'.xml.
getDefaultDataSetFileName(java.lang.Class>, java.lang.String)
).
If a file is not found or could not be loaded (but was requested, because there is an annotation), an exception
is thrown.
testMethod
- The test method, not nulltestObject
- The test object, not null
DataSet
annotation is found.public MultiSchemaDataSet getExpectedDataSet(Method testMethod, Object testObject)
MultiSchemaDataSet
that represents the state of a number of database tables after the given
Method
has been executed.
testMethod
- The test method, not nulltestObject
- The test object, not null
protected MultiSchemaDataSet getDataSet(Class<?> testClass, String[] dataSetFileNames, DataSetFactory dataSetFactory)
testClass
- The test class, not nulldataSetFileNames
- The names of the files, (start with '/' for absolute names), not null, not emptydataSetFactory
- DataSetFactory responsible for creating the dataset file
protected DataSetLoadStrategy getDataSetLoadStrategy(Method testMethod, Class testClass)
testMethod
- The method, not nulltestClass
- The test class, not null
protected DbUnitDatabaseConnection createDbUnitConnection(String schemaName)
IDatabaseConnection
schemaName
- The schema name, not null
IDatabaseConnection
protected void closeJdbcConnection()
protected String getDefaultDataSetFileName(Class<?> testClass, String extension)
testClass
- The test class, not nullextension
- The configured extension of dataset files
protected String getDefaultExpectedDataSetFileName(Method method, Class<?> testClass, String extension)
method
- The test method, not nulltestClass
- The test class, not nullextension
- The configured extension of dataset files, not null
protected DataSetFactory getDefaultDataSetFactory()
DataSetFactory
class as configured in unitilsprotected DataSetFactory getDataSetFactory(Class<? extends Annotation> annotationClass, Method testMethod, Class testClass)
annotationClass
- The class of the annotation, i.e. DataSet.class or ExpectedDataSet.classtestMethod
- The method for which we need the configured DataSetFactorytestClass
- The class that is looked for class-level annotations
protected DataSetFactory getDataSetFactory(Class<? extends DataSetFactory> dataSetFactoryClass)
dataSetFactoryClass
- The type, not null
DataSetFactory
with the given classprotected DataSetLoadStrategy getDefaultDataSetLoadStrategy()
DataSetLoadStrategy
class as configured in unitilsprotected DataSetResolver getDataSetResolver()
protected DbSupport getDefaultDbSupport()
protected DatabaseModule getDatabaseModule()
public TestListener getTestListener()
Module
getTestListener
in interface Module
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |