Package org.dbunit

Interface PrepAndExpectedTestCase

All Known Implementing Classes:
DefaultPrepAndExpectedTestCase

public interface PrepAndExpectedTestCase
Test case supporting prep data and expected data.
Since:
2.4.8
Version:
$Revision$ $Date$
Author:
Jeff Jensen jeffjensen AT users.sourceforge.net, Last changed by: $Author$
  • Method Details

    • configureTest

      void configureTest(VerifyTableDefinition[] verifyTableDefinitions, String[] prepDataFiles, String[] expectedDataFiles) throws Exception
      Configure the test. Call this method before performing the test steps.
      Parameters:
      verifyTableDefinitions - Table definitions to verify after test execution.
      prepDataFiles - The prep data files (as classpath resources) to load and insert contents into the database as seed data.
      expectedDataFiles - The expected data files (as classpath resources) to load as expected data and verify actual data matches at test end.
      Throws:
      Exception - if the test cannot be configured.
    • configureTest

      default void configureTest(PrepAndExpectedTestData testData) throws Exception
      Configure the test from a PrepAndExpectedTestData bundle instead of the three separate array arguments. Equivalent to calling configureTest(VerifyTableDefinition[], String[], String[]) with the bundle's three values.
      Parameters:
      testData - The verification definitions and prep and expected data files for this test.
      Throws:
      Exception - If the test cannot be configured.
      Since:
      3.6.0
    • preTest

      void preTest() throws Exception
      Execute pre-test steps. Call this method before performing the test steps.
      Throws:
      Exception - if the pre-test steps fail.
    • preTest

      void preTest(VerifyTableDefinition[] verifyTables, String[] prepDataFiles, String[] expectedDataFiles) throws Exception
      Convenience method to call configureTest() and preTest().
      Parameters:
      verifyTables - Table definitions to verify after test execution.
      prepDataFiles - The prep data files (as classpath resources) to load and insert contents into the database as seed data.
      expectedDataFiles - The expected data files (as classpath resources) to load as expected data and verify actual data matches at test end.
      Throws:
      Exception - if the pre-test steps fail.
    • preTest

      default void preTest(PrepAndExpectedTestData testData) throws Exception
      Convenience method to call configureTest() and preTest(), taking a PrepAndExpectedTestData bundle instead of the three separate array arguments. Equivalent to calling preTest(VerifyTableDefinition[], String[], String[]) with the bundle's three values.
      Parameters:
      testData - The verification definitions and prep and expected data files for this test.
      Throws:
      Exception - If the pre-test steps fail.
      Since:
      3.6.0
    • runTest

      Object runTest(VerifyTableDefinition[] verifyTables, String[] prepDataFiles, String[] expectedDataFiles, PrepAndExpectedTestCaseSteps testSteps) throws Exception
      Run the DbUnit test.
      Parameters:
      verifyTables - Table definitions to verify after test execution.
      prepDataFiles - The prep data files (as classpath resources) to load and insert contents into the database as seed data.
      expectedDataFiles - The expected data files (as classpath resources) to load as expected data and verify actual data matches at test end.
      testSteps - The test steps to run.
      Returns:
      User defined object from running the test steps.
      Throws:
      Exception - if the test steps fail.
      Since:
      2.5.2
    • runTest

      default Object runTest(PrepAndExpectedTestData testData, PrepAndExpectedTestCaseSteps testSteps) throws Exception
      Run the DbUnit test from a PrepAndExpectedTestData bundle instead of the three separate array arguments. Equivalent to calling runTest(VerifyTableDefinition[], String[], String[], PrepAndExpectedTestCaseSteps) with the bundle's three values and the given test steps.
      Parameters:
      testData - The verification definitions and prep and expected data files for this test.
      testSteps - The test steps to run.
      Returns:
      The user-defined object from running the test steps.
      Throws:
      Exception - If the test steps fail.
      Since:
      3.6.0
    • postTest

      void postTest() throws Exception
      Execute all post-test steps. Call this method after performing the test steps.
      Throws:
      Exception - if the post-test steps fail.
    • postTest

      void postTest(boolean verifyData) throws Exception
      Execute post-test steps. Call this method after performing the test steps.
      Parameters:
      verifyData - 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.
      Throws:
      Exception - if the post-test steps fail.
    • verifyData

      void verifyData() throws Exception
      For the provided VerifyTableDefinitions, verify each table's actual results are as expected.
      Throws:
      Exception - if verifying the data fails.
    • cleanupData

      void cleanupData() throws Exception
      Cleanup tables specified in prep and expected datasets, using the provided databaseTester. See IDatabaseTester.onTearDown().
      Throws:
      Exception - if cleaning up the data fails.
    • getPrepDataset

      IDataSet getPrepDataset()
      Get the prep dataset, created from the prepDataFiles.
      Returns:
      The prep dataset.
    • getExpectedDataset

      IDataSet getExpectedDataset()
      Get the expected dataset, created from the expectedDataFiles.
      Returns:
      The expected dataset.
    • getDatabaseTester

      default IDatabaseTester getDatabaseTester()
      Get the databaseTester this test case uses.

      Default method for binary compatibility with implementations predating this method; they report having no databaseTester of their own rather than failing to compile. An implementation backed by setDatabaseTester(IDatabaseTester) should override this to return the value that method was last called with, the way DefaultPrepAndExpectedTestCase does - doing so lets a caller resolving a tester on this test case's behalf (e.g. org.dbunit.junit.jupiter.DbUnitExtension) keep the two in sync instead of silently driving two different testers.

      Returns:
      The databaseTester, or null if none is set or this implementation does not support reporting one.
      Since:
      3.6.0
    • setDatabaseTester

      default void setDatabaseTester(IDatabaseTester databaseTester)
      Set the databaseTester this test case uses.

      Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support being given a databaseTester after construction, so a caller can invoke it unconditionally regardless of implementation. Override it, alongside getDatabaseTester(), to accept a tester resolved after construction - e.g. from a @DbUnitTester field or a DatabaseTesterFactory - the way DefaultPrepAndExpectedTestCase does.

      Parameters:
      databaseTester - The databaseTester to use.
      Since:
      3.6.0
    • getReusableConnection

      default IDatabaseConnection getReusableConnection() throws Exception
      Returns the connection this test case's own steps use for the current test, resolving one from getDatabaseTester() first if it has not already.

      Default method for binary compatibility with implementations predating this method; its default body simply asks getDatabaseTester() for a connection independently on every call - the same connection-identity limitation this method exists to let a caller avoid. Override it, memoizing the result the way DefaultPrepAndExpectedTestCase does, so repeated calls - and a caller resolving a connection on this test case's behalf - reuse the same connection object instead of each opening a new one.

      org.dbunit.annotation's AnnotatedTestExecutor calls this - instead of asking getDatabaseTester() for a connection of its own - to resolve a Connection/IDatabaseConnection parameter injection on the prep/expected path, so the injected connection is the same one this test case's own setup/verify/cleanup steps use rather than a second, independently-opened one. For a tester whose getConnection() is not itself idempotent (e.g. a plain JdbcDatabaseTester), a non-overriding implementation still returns a usable connection, just not necessarily the same physical one this test case uses internally.

      Returns:
      The connection to reuse, or null if getDatabaseTester() returns none.
      Throws:
      Exception - On dbUnit errors.
      Since:
      3.6.0
    • setDataFileLoader

      default void setDataFileLoader(DataFileLoader dataFileLoader)
      Set the DataFileLoader this test case uses to load prepDataFiles/expectedDataFiles.

      Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support being given a loader after construction. Override it to receive a loader resolved after construction the way DefaultPrepAndExpectedTestCase does.

      org.dbunit.annotation's AnnotatedTestExecutor calls this on a @DbUnitTestCase-injected instance whenever @DbUnitConfig.dataFileLoader() names a non-default loader, and throws IllegalStateException if this method is not overridden - a silent no-op there would otherwise leave the instance loading with whatever loader it was already constructed with.

      Parameters:
      dataFileLoader - The dataFileLoader to use.
      Since:
      3.6.0
    • setFailureHandler

      default void setFailureHandler(FailureHandler failureHandler)
      Set the FailureHandler this test case hands verifyData()'s assertion failures to.

      Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support being given a failure handler after construction. Override it to receive a handler resolved after construction the way DefaultPrepAndExpectedTestCase does.

      org.dbunit.annotation's AnnotatedTestExecutor calls this on a @DbUnitTestCase-injected instance whenever @DbUnitConfig.failureHandler() is set, and throws IllegalStateException if this method is not overridden - a silent no-op there would otherwise leave the configured handler applied nowhere.

      Parameters:
      failureHandler - The failureHandler to use.
      Since:
      3.6.0
    • setCloseConnectionAfterTest

      default void setCloseConnectionAfterTest(boolean closeConnectionAfterTest)
      Set whether this test case closes its connection after each test.

      Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support this being set after construction. Override it to receive a value resolved after construction the way DefaultPrepAndExpectedTestCase does.

      org.dbunit.annotation's AnnotatedTestExecutor calls this on a @DbUnitTestCase-injected instance whenever @DbUnitConfig.closeConnectionAfterTest() is false, and logs a warning if this method is not overridden - unlike the other @DbUnitConfig-driven setters this is not a complete no-op even then, since that executor's own connection (for the row count check or parameter injection) still honors the value regardless; only this test case's own connection handling might not.

      Parameters:
      closeConnectionAfterTest - True to close the connection after each test, false to leave it open.
      Since:
      3.6.0
    • setDatabaseConfigProperties

      default void setDatabaseConfigProperties(Properties databaseConfigProperties)
      Set DatabaseConfig property name/value pairs for this test case to apply to its connection.

      Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support this being set after construction. Override it to apply properties resolved after construction the way DefaultPrepAndExpectedTestCase does.

      org.dbunit.annotation's AnnotatedTestExecutor calls this on a @DbUnitTestCase-injected instance whenever @DbUnitConfig.properties()/propertiesProvider() is non-empty, and throws IllegalStateException if this method is not overridden - on the prep/expected path this is the only route to the connection at all, so a silent no-op here would otherwise apply the configured properties nowhere.

      Parameters:
      databaseConfigProperties - The properties to apply; null or empty applies none.
      Since:
      3.6.0
    • setRowCountCheckOverride

      default void setRowCountCheckOverride(boolean enabled, String[] exclude)
      Set the enabled flag and excluded table patterns this test case resolves its row count check from, instead of its connection's DatabaseConfig.

      Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support a row count check override. Override it, alongside clearRowCountCheckOverride(), to apply an override resolved after construction the way DefaultPrepAndExpectedTestCase does.

      org.dbunit.annotation's AnnotatedTestExecutor calls this on a @DbUnitTestCase-injected instance whenever @DbUnitRowCountCheck is declared, and throws IllegalStateException if this method is not overridden - a silent no-op here would otherwise leave the check silently never running for this test at all.

      Parameters:
      enabled - Whether the check is enabled.
      exclude - The excluded table patterns; null is treated as empty (excludes none).
      Since:
      3.6.0
    • clearRowCountCheckOverride

      default void clearRowCountCheckOverride()
      Clear a previously set row count check override, returning to resolving it from this test case's connection's DatabaseConfig.

      Default method for binary compatibility with implementations predating this method; it is a no-op for one that does not support a row count check override. Override it, alongside setRowCountCheckOverride(boolean, String[]), the way DefaultPrepAndExpectedTestCase does.

      Unlike setRowCountCheckOverride(boolean, String[]), AnnotatedTestExecutor calls this unconditionally whenever @DbUnitRowCountCheck is absent, regardless of whether this method is overridden - nothing was explicitly requested in that case, so there is nothing to fail loud about; it is purely defensive, resetting a test case reused across several tests (e.g. a @DbUnitTestCase static field) so an earlier test's override does not silently carry over.

      Since:
      3.6.0