|
||||||||||
| 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 java.util.Properties |
configuration
The unitils configuration |
protected java.lang.String |
databaseName
|
protected java.util.Map<java.lang.String,DbUnitDatabaseConnection> |
dbUnitDatabaseConnections
Objects that D513 bUnit uses to connect to the database and to cache some database metadata. |
protected java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.Map<java.lang.String,java.lang.String>> |
defaultAnnotationPropertyValues
Map holding the default configuration of the dbunit module annotations |
static java.lang.String |
PROPERTY_METAHANDLER
|
protected java.lang.String |
scriptExtension
|
| Constructor Summary | |
|---|---|
DbUnitModule()
|
|
| Method Summary | |
|---|---|
void |
afterInit()
No after initialization needed for this module |
void |
assertDbContentAsExpected(java.lang.reflect.Method testMethod,
java.lang.Object testObject)
Compares the contents of the expected DbUnitDataSet with the contents of the database. |
void |
assertExpectedDataSets(ExpectedDataSet expectedDataSetAnnotation,
java.lang.Object testObject,
java.lang.reflect.Method testMethod)
|
void |
assertMultipleExpectedDataSets(ExpectedDataSets expectedDataSets,
java.lang.Object testObject,
java.lang.reflect.Method testMethod)
|
protected void |
closeJdbcConnection()
Closes (i.e. return to the pool) the JDBC Connection that is currently in use by the DbUnitDatabaseConnection |
protected DbUnitDatabaseConnection |
createDbUnitConnection(java.lang.String schemaName)
Creates a new instance of dbUnit's IDatabaseConnection |
protected org.dbunit.dataset.IDataSet |
getActualDataSet(java.lang.String schemaName)
Gets the actual data set for the given schema. |
protected java.lang.String |
getCorrectFileName(java.lang.Class<?> testClass,
java.lang.reflect.Method method,
java.lang.String extension)
|
protected DatabaseModule |
getDatabaseModule()
|
protected MultiSchemaDataSet |
getDataSet(java.lang.Class<?> testClass,
java.lang.String[] dataSetFileNames,
DataSetFactory dataSetFactory)
Creates the dataset for the given file. |
MultiSchemaDataSet |
getDataSet(DataSet dataSet,
java.lang.reflect.Method testMethod,
java.lang.Class<?> testClass)
Using the values of the method-level or class-level DataSet annotations, returns the data set for the given test method. |
protected DataSetFactory |
getDataSetFactory(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
java.lang.reflect.Method testMethod,
java.lang.Class<?> testClass)
Get the configured DataSetFactory for the given method |
protected DataSetFactory |
getDataSetFactory(java.lang.Class<? extends DataSetFactory> dataSetFactoryClass)
Creates and initializes a data set factory of the given type. |
protected DataSetLoadStrategy |
getDataSetLoadStrategy(java.lang.reflect.Method testMethod,
java.lang.Class<?> testClass,
DataSet dataSet)
Creates the DbUnit dataset operation for loading a data set for the given method. |
protected DataSetResolver |
getDataSetResolver()
|
protected java.util.Map<java.lang.String,java.util.List<DataSet>> |
getDataSetsSorted(DataSets dataSets)
|
DbUnitDatabaseConnection |
getDbUnitDatabaseConnection(java.lang.String schemaName)
Gets the DbUnit connection or creates one if it does not exist yet. |
protected org.dbunit.database.IMetadataHandler |
getDefaultDatabaseMetaHandler()
|
protected DataSetFactory |
getDefaultDataSetFactory()
|
protected java.lang.String |
getDefaultDataSetFileNameClassLevel(java.lang.Class<?> testClass,
java.lang.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 java.lang.String |
getDefaultDataSetFileNameMethodLevel(java.lang.Class<?> testClass,
java.lang.reflect.Method method,
java.lang.String extension)
Gets the name of the default testdata file at class level The default name is constructed as follows: 'classname without packagename'-"testmethod".xml |
protected DataSetLoadStrategy |
getDefaultDataSetLoadStrategy()
|
protected DbSupport |
getDefaultDbSupport()
|
protected java.lang.String |
getDefaultExpectedDataSetFileName(java.lang.reflect.Method method,
java.lang.Class<?> testClass,
java.lang.String extension)
Gets the name of the expected dataset file. |
MultiSchemaDataSet |
getExpectedDataSet(ExpectedDataSet expectedDataSetAnnotation,
java.lang.reflect.Method testMethod,
java.lang.Object testObject)
Returns the MultiSchemaDataSet that represents the state of a number of database tables after the given Method
has been executed. |
protected ResourcePickingStrategie |
getResourcePickingStrategie()
use unitil property instead of hardcoding |
TestListener |
getTestListener()
|
protected java.io.File |
handleDataSetResource(ClassPathDataLocator locator,
java.lang.String nameResource,
ResourcePickingStrategie strategy,
java.lang.Class<?> testClass)
|
void |
init(java.util.Properties configuration)
Initializes the DbUnitModule using the given Configuration |
void |
insertDataSet(java.lang.Class<?> testClass,
java.lang.String... dataSetFileNames)
Inserts the dataset consisting of the given list of files into the database |
void |
insertDataSet(DataSet dataset,
java.lang.Object testObject,
java.lang.reflect.Method testMethod)
|
void |
insertDataSet(java.io.File dataSetFile)
Inserts the test data coming from the given DbUnit dataset file using the default DataSetLoadStrategy and
DataSetFactory class. |
void |
insertDataSet(java.io.File dataSetFile,
java.lang.Class<? extends DataSetFactory> dataSetFactoryClass,
java.lang.Class<? extends DataSetLoadStrategy> dataSetLoadStrategyClass)
Inserts the test data coming from the given DbUnit dataset file. |
void |
insertDataSet(java.lang.reflect.Method testMethod,
java.lang.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 |
insertDataSets(DataSets dataSets,
java.lang.Object testObject,
java.lang.reflect.Method testMethod)
|
void |
insertDefaultDataSet(java.lang.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 |
|---|
public static final java.lang.String PROPERTY_METAHANDLER
protected java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.Map<java.lang.String,java.lang.String>> defaultAnnotationPropertyValues
protected java.util.Map<java.lang.String,DbUnitDatabaseConnection> dbUnitDatabaseConnections
protected java.util.Properties configuration
protected java.lang.String databaseName
protected java.lang.String scriptExtension
| Constructor Detail |
|---|
public DbUnitModule()
| Method Detail |
|---|
public void init(java.util.Properties configuration)
init in interface Moduleconfiguration - The config, not nullpublic void afterInit()
afterInit in interface Modulepublic DbUnitDatabaseConnection getDbUnitDatabaseConnection(java.lang.String schemaName)
schemaName - The schema name, not null
public void insertDataSet(java.lang.reflect.Method testMethod,
java.lang.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 null
public void insertDataSets(DataSets dataSets,
java.lang.Object testObject,
java.lang.reflect.Method testMethod)
protected java.util.Map<java.lang.String,java.util.List<DataSet>> getDataSetsSorted(DataSets dataSets)
public void insertDataSet(DataSet dataset,
java.lang.Object testObject,
java.lang.reflect.Method testMethod)
public void insertDefaultDataSet(java.lang.Class<?> testClass)
testClass - The test class for which the default dataset must be loaded
public void insertDataSet(java.lang.Class<?> testClass,
java.lang.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(java.io.File dataSetFile)
DataSetLoadStrategy and
DataSetFactory class.
dataSetFile - The test data set, not null
public void insertDataSet(java.io.File dataSetFile,
java.lang.Class<? extends DataSetFactory> dataSetFactoryClass,
java.lang.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 dataset
protected void insertDataSet(MultiSchemaDataSet multiSchemaDataSet,
DataSetLoadStrategy dataSetLoadStrategy)
multiSchemaDataSet - The multi schema dataset that is inserted in the databasedataSetLoadStrategy - The load strategy that is used
public void assertDbContentAsExpected(java.lang.reflect.Method testMethod,
java.lang.Object testObject)
testMethod - The test method, not nulltestObject - The test object, not null
public void assertMultipleExpectedDataSets(ExpectedDataSets expectedDataSets,
java.lang.Object testObject,
java.lang.reflect.Method testMethod)
public void assertExpectedDataSets(ExpectedDataSet expectedDataSetAnnotation,
java.lang.Object testObject,
java.lang.reflect.Method testMethod)
protected org.dbunit.dataset.IDataSet getActualDataSet(java.lang.String schemaName)
schemaName - The schema to get the data set for, not null
public MultiSchemaDataSet getDataSet(DataSet dataSet,
java.lang.reflect.Method testMethod,
java.lang.Class<?> testClass)
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).
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(ExpectedDataSet expectedDataSetAnnotation,
java.lang.reflect.Method testMethod,
java.lang.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(java.lang.Class<?> testClass,
java.lang.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 java.io.File handleDataSetResource(ClassPathDataLocator locator,
java.lang.String nameResource,
ResourcePickingStrategie strategy,
java.lang.Class<?> testClass)
protected DataSetLoadStrategy getDataSetLoadStrategy(java.lang.reflect.Method testMethod,
java.lang.Class<?> testClass,
DataSet dataSet)
testMethod - The method, not nulltestClass - The test class, not null
protected DbUnitDatabaseConnection createDbUnitConnection(java.lang.String schemaName)
IDatabaseConnection
schemaName - The schema name, not null
IDatabaseConnectionprotected org.dbunit.database.IMetadataHandler getDefaultDatabaseMetaHandler()
protected void closeJdbcConnection()
protected java.lang.String getCorrectFileName(java.lang.Class<?> testClass,
java.lang.reflect.Method method,
java.lang.String extension)
protected java.lang.String getDefaultDataSetFileNameClassLevel(java.lang.Class<?> testClass,
java.lang.String extension)
testClass - The test class, not nullextension - The configured extension of dataset files
protected java.lang.String getDefaultDataSetFileNameMethodLevel(java.lang.Class<?> testClass,
java.lang.reflect.Method method,
java.lang.String extension)
testClass - method - extension -
String
protected java.lang.String getDefaultExpectedDataSetFileName(java.lang.reflect.Method method,
java.lang.Class<?> testClass,
java.lang.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 unitils
protected DataSetFactory getDataSetFactory(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass,
java.lang.reflect.Method testMethod,
java.lang.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(java.lang.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()
protected ResourcePickingStrategie getResourcePickingStrategie()
ResourcePickingStrategiepublic TestListener getTestListener()
getTestListener in interface Module
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||