|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.dbunit.DatabaseTestCase
org.dbunit.DBTestCase
org.dbunit.DefaultPrepAndExpectedTestCase
public class DefaultPrepAndExpectedTestCase
Test case base class supporting prep data and expected data. Prep data is the data needed for the test to run. Expected data is the data needed to compare if the test ran successfully. Use this class in two ways:
Configure a bean of its interface, injecting a IDatabaseTester and a DataFileLoader using the databaseTester and a dataFileLoader properties.
Obtain IDatabaseTester and DataFileLoader instances (possibly dependency injecting them into the test class) and set them accordingly, probably in a setup type of method, such as:
@Before
public void setDbunitTestDependencies() {
setDatabaseTester(databaseTester);
setDataFileLoader(dataFileLoader);
}
@Autowired
private PrepAndExpectedTestCase tc;
@Test
public void testExample() throws Exception {
String[] prepDataFiles = {}; // define prep files
String[] expectedDataFiles = {}; // define expected files
VerifyTableDefinition[] tables = {}; // define tables to verify
tc.preTest(tables, prepDataFiles, expectedDataFiles);
// execute test
tc.postTest();
}
@Override
protected void setUp() throws Exception {
setDatabaseTester(databaseTester);
setDataFileLoader(dataFileLoader);
String[] prepDataFiles = {}; //define prep files
String[] expectedDataFiles = {}; // define expected files
VerifyTableDefinition[] tables = {}; //define tables to verify
preTest(tables, prepDataFiles, expectedDataFiles);
// call this if overriding setUp() and databaseTester & dataFileLoader are already set.
super.setUp();
}
@Override
protected void tearDown() throws Exception {
postTest();
super.tearDown();
}
@Test
public void testExample() throws Exception {
// execute test
}
Note that it is unlikely that all test methods can share the same expected
data.
org.dbunit.DefaultPrepAndExpectedTestCaseDiIT,
org.dbunit.DefaultPrepAndExpectedTestCaseExtIT| Constructor Summary | |
|---|---|
DefaultPrepAndExpectedTestCase()
Create new instance. |
|
DefaultPrepAndExpectedTestCase(DataFileLoader dataFileLoader,
IDatabaseTester databaseTester)
Create new instance with specified dataFileLoader and databasetester. |
|
DefaultPrepAndExpectedTestCase(java.lang.String name)
Create new instance with specified test case name. |
|
| Method Summary | |
|---|---|
ITable |
applyColumnFilters(ITable table,
java.lang.String[] excludeColumns,
java.lang.String[] includeColumns)
Apply the specified exclude and include column filters to the specified table. |
void |
cleanupData()
Cleanup tables specified in prep and expected datasets, using the provided databaseTester. |
void |
configureTest(VerifyTableDefinition[] tables,
java.lang.String[] prepDataFiles,
java.lang.String[] expectedDataFiles)
Configure the test. |
IDatabaseTester |
getDatabaseTester()
Get the databaseTester. |
DataFileLoader |
getDataFileLoader()
Get the dataFileLoader. |
IDataSet |
getDataSet()
Returns the test dataset. |
IDataSet |
getExpectedDataset()
Get the expected dataset, created from the expectedDataFiles. |
IDataSet |
getPrepDataset()
Get the prep dataset, created from the prepDataFiles. |
VerifyTableDefinition[] |
getTableDefs()
Get the tableDefs. |
IDataSet |
makeCompositeDataSet(java.lang.String[] dataFiles)
Make a IDataSet from the specified files. |
IDatabaseTester |
newDatabaseTester()
Creates a new IDatabaseTester. |
void |
postTest()
Execute all post-test steps. |
void |
postTest(boolean verifyData)
Execute post-test steps. |
void |
preTest()
Execute pre-test steps. |
void |
preTest(VerifyTableDefinition[] tables,
java.lang.String[] prepDataFiles,
java.lang.String[] expectedDataFiles)
Convenience method to call configureTest() and preTest(). |
void |
setDatabaseTester(IDatabaseTester databaseTester)
Set the databaseTester. |
void |
setDataFileLoader(DataFileLoader dataFileLoader)
Set the dataFileLoader. |
void |
setExpectedDs(IDataSet expectedDs)
Set the expectedDs. |
void |
setPrepDs(IDataSet prepDs)
Set the prepDs. |
void |
setTableDefs(VerifyTableDefinition[] tableDefs)
Set the tableDefs. |
void |
setupData()
Use the provided databaseTester to prep the database with the provided prep dataset. |
void |
verifyData()
For the provided VerifyTableDefinitions, verify each table's actual results are as expected. |
void |
verifyData(ITable expectedTable,
ITable actualTable,
java.lang.String[] excludeColumns,
java.lang.String[] includeColumns)
For the specified expected and actual tables (and excluding and including the specified columns), verify the actual data is as expected. |
| Methods inherited from class org.dbunit.DBTestCase |
|---|
getConnection |
| Methods inherited from class org.dbunit.DatabaseTestCase |
|---|
closeConnection, getOperationListener, getSetUpOperation, getTearDownOperation, setUp, setUpDatabaseConfig, tearDown |
| Methods inherited from class junit.framework.TestCase |
|---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString |
| Methods inherited from class junit.framework.Assert |
|---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultPrepAndExpectedTestCase()
public DefaultPrepAndExpectedTestCase(DataFileLoader dataFileLoader,
IDatabaseTester databaseTester)
dataFileLoader - Load to use for loading the data files.databaseTester - Tester to use for database manipulation.public DefaultPrepAndExpectedTestCase(java.lang.String name)
name - The test case name.| Method Detail |
|---|
public IDatabaseTester newDatabaseTester()
throws java.lang.Exception
PropertiesBasedJdbcDatabaseTester. This implementation returns the databaseTester set by the
test.
newDatabaseTester in class DBTestCasejava.lang.Exception
public IDataSet getDataSet()
throws java.lang.Exception
getDataSet in class DatabaseTestCasejava.lang.Exception
public void configureTest(VerifyTableDefinition[] tables,
java.lang.String[] prepDataFiles,
java.lang.String[] expectedDataFiles)
throws java.lang.Exception
configureTest in interface PrepAndExpectedTestCasetables - Table definitions to verify after test execution.prepDataFiles - The prep data files to load as seed data.expectedDataFiles - The expected data files to load as expected data.
java.lang.Exception
public void preTest()
throws java.lang.Exception
preTest in interface PrepAndExpectedTestCasejava.lang.Exception
public void preTest(VerifyTableDefinition[] tables,
java.lang.String[] prepDataFiles,
java.lang.String[] expectedDataFiles)
throws java.lang.Exception
preTest in interface PrepAndExpectedTestCasetables - Table definitions to verify after test execution.prepDataFiles - The prep data files to load as seed data.expectedDataFiles - The expected data files to load as expected data.
java.lang.Exception
public void postTest()
throws java.lang.Exception
postTest in interface PrepAndExpectedTestCasejava.lang.Exception
public void postTest(boolean verifyData)
throws java.lang.Exception
postTest in interface PrepAndExpectedTestCaseverifyData - Specify true to perform verify data steps, false to not.
Useful to specify false when test has failure in progress
(e.g. an exception) and verifying data would fail, masking
original test failure.
java.lang.Exception
public void cleanupData()
throws java.lang.Exception
IDatabaseTester.onTearDown().
cleanupData in interface PrepAndExpectedTestCasejava.lang.Exception
public void setupData()
throws java.lang.Exception
IDatabaseTester.onSetup().
java.lang.Exception
public void verifyData()
throws java.lang.Exception
java.lang.Exception
public void verifyData(ITable expectedTable,
ITable actualTable,
java.lang.String[] excludeColumns,
java.lang.String[] includeColumns)
throws DatabaseUnitException
expectedTable - The expected table to compare the actual table to.actualTable - The actual table to compare to the expected table.excludeColumns - The column names to exclude from comparison. See
DefaultColumnFilter.excludeColumn(String)
.includeColumns - The column names to only include in comparison. See
DefaultColumnFilter.includeColumn(String)
.
DatabaseUnitException
public IDataSet makeCompositeDataSet(java.lang.String[] dataFiles)
throws DataSetException
IDataSet from the specified files.
dataFiles - Represents the array of dbUnit data files.
DataSetException - On dbUnit errors.
public ITable applyColumnFilters(ITable table,
java.lang.String[] excludeColumns,
java.lang.String[] includeColumns)
throws DataSetException
table - The table to apply the filters to.excludeColumns - The exclude filters; use null or empty array to mean exclude
none.includeColumns - The include filters; use null to mean include all.
DataSetExceptionpublic IDataSet getPrepDataset()
getPrepDataset in interface PrepAndExpectedTestCasepublic IDataSet getExpectedDataset()
getExpectedDataset in interface PrepAndExpectedTestCasepublic IDatabaseTester getDatabaseTester()
getDatabaseTester in class DatabaseTestCasedatabaseTester}.public void setDatabaseTester(IDatabaseTester databaseTester)
databaseTester - The databaseTester to set.databaseTester}.public DataFileLoader getDataFileLoader()
dataFileLoader}.public void setDataFileLoader(DataFileLoader dataFileLoader)
dataFileLoader - The dataFileLoader to set.dataFileLoader}.public void setPrepDs(IDataSet prepDs)
prepDs - The prepDs to set.prepDs}.public void setExpectedDs(IDataSet expectedDs)
expectedDs - The expectedDs to set.expectedDs}.public VerifyTableDefinition[] getTableDefs()
tableDefs}.public void setTableDefs(VerifyTableDefinition[] tableDefs)
tableDefs - The tableDefs to set.tableDefs}.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||