Class DbTestHelper
java.lang.Object
com.reallifedeveloper.tools.test.database.dbunit.DbTestHelper
A helper class used by
AbstractDbTest. It could be used directly by a test class that for some reason cannot inherit from
AbstractDbTest.- Author:
- RealLifeDeveloper
-
Constructor Summary
ConstructorsConstructorDescriptionDbTestHelper(DataSource dataSource, org.dbunit.dataset.IDataSet dataSet, Optional<String> schemaName, Optional<org.dbunit.dataset.datatype.IDataTypeFactory> dataTypeFactory) Creates a newDbTestHelper, with test data provided by the givendataSetand using the givendataSourceto insert it. -
Method Summary
Modifier and TypeMethodDescriptionvoidclean()Cleans the database from test data after each test case.voidinit()Initializes the test data before each test case.static org.dbunit.dataset.IDataSetreadDataSetFromClasspath(@Nullable String dataSetDtdResourceName, String... dataSetResourceNames) Reads XML data set files from the classpath resources pointed to bydataSetResourceNames, optionally validating using the DTD pointed to bydataSetDtdResourceNameproperty.voidsetSetUpOperation(org.dbunit.operation.DatabaseOperation setUpOperation) Change the operation performed before executing each test.voidsetTearDownOperation(org.dbunit.operation.DatabaseOperation tearDownOperation) Change the operation performed after executing each test.
-
Constructor Details
-
DbTestHelper
public DbTestHelper(DataSource dataSource, org.dbunit.dataset.IDataSet dataSet, Optional<String> schemaName, Optional<org.dbunit.dataset.datatype.IDataTypeFactory> dataTypeFactory) Creates a newDbTestHelper, with test data provided by the givendataSetand using the givendataSourceto insert it. The database schema name may be provided (can benull), and the type of database can be defined usingdataTypeFactory(can also benull).- Parameters:
dataSource- theDataSourceto use when inserting test datadataSet- the DbUnit test data set to readschemaName- optional name of the database schemadataTypeFactory- an optionalIDataTypeFactory
-
-
Method Details
-
readDataSetFromClasspath
public static org.dbunit.dataset.IDataSet readDataSetFromClasspath(@Nullable String dataSetDtdResourceName, String... dataSetResourceNames) throws org.dbunit.dataset.DataSetException, IOException Reads XML data set files from the classpath resources pointed to bydataSetResourceNames, optionally validating using the DTD pointed to bydataSetDtdResourceNameproperty.The
dataSetDtdResourceNameparameter may benull, in which case no validation is performed.- Parameters:
dataSetDtdResourceName- the name of the resource containing the DTD for test data files, ornulldataSetResourceNames- the names of the resources containing test data- Returns:
- the test data set
- Throws:
org.dbunit.dataset.DataSetException- if some resource if malformedIOException- if reading a resource failed
-
init
Initializes the test data before each test case.- Throws:
Exception- if something goes wrong
-
clean
Cleans the database from test data after each test case.- Throws:
Exception- if something goes wrong
-
setSetUpOperation
public void setSetUpOperation(org.dbunit.operation.DatabaseOperation setUpOperation) Change the operation performed before executing each test.The default setup operation is
DatabaseOperation.CLEAN_INSERT.- Parameters:
setUpOperation- the new setup operation to use
-
setTearDownOperation
public void setTearDownOperation(org.dbunit.operation.DatabaseOperation tearDownOperation) Change the operation performed after executing each test.The default is to perform no cleanup after the test.
- Parameters:
tearDownOperation- the new teardown operation to use
-