Package org.dbunit.database.rowcount
Class RowCountCheck
java.lang.Object
org.dbunit.database.rowcount.RowCountCheck
Compares a database's table row counts before and after a test, to catch a table the test
left dirty - either one it should have cleaned up and did not, or a reference table it wrongly
cleaned. Read-only: never modifies data.
Every method is a no-op, and never queries the connection, when
RowCountCheckConfiguration.isEnabled() is false - the check costs nothing
when a caller has not opted in.
- Since:
- 3.6.0
- Author:
- dbunit
-
Constructor Summary
ConstructorsConstructorDescriptionRowCountCheck(RowCountCheckConfiguration configuration) Creates a check using the given configuration. -
Method Summary
Modifier and TypeMethodDescriptioncapture(IDatabaseConnection connection) Captures the baseline row counts to laterverify(RowCountSnapshot, IDatabaseConnection)against, of every tableconnectionexposes that survives the configured exclude patterns.voidverify(RowCountSnapshot baseline, IDatabaseConnection connection) Verifies thatconnection's current row counts still matchbaseline.
-
Constructor Details
-
RowCountCheck
Creates a check using the given configuration.- Parameters:
configuration- resolves whether the check is enabled, the excluded table patterns, and theRowCounterto use.
-
-
Method Details
-
capture
public RowCountSnapshot capture(IDatabaseConnection connection) throws DatabaseUnitException, SQLException Captures the baseline row counts to laterverify(RowCountSnapshot, IDatabaseConnection)against, of every tableconnectionexposes that survives the configured exclude patterns.- Parameters:
connection- the connection to capture the baseline from.- Returns:
- the baseline snapshot, or
nullwhen the check is disabled. - Throws:
DatabaseUnitException- if enumerating or filtering the tables fails.SQLException- if counting a table's rows fails.
-
verify
public void verify(RowCountSnapshot baseline, IDatabaseConnection connection) throws DatabaseUnitException, SQLException Verifies thatconnection's current row counts still matchbaseline. A no-op that never queries the connection when the check is disabled or whenbaselineisnull- the latter meaning no baseline was captured, e.g. because the caller intentionally skippedcapture(IDatabaseConnection).- Parameters:
baseline- the baseline to compare against;nullto skip the check silently.connection- the connection to read the current row counts from.- Throws:
DatabaseUnitException- if enumerating or filtering the tables fails, or if any table's row count no longer matches the baseline (UnexpectedRowCountException).SQLException- if counting a table's rows fails.
-