Class AnnotatedTestConfiguration

java.lang.Object
org.dbunit.annotation.runtime.AnnotatedTestConfiguration

public class AnnotatedTestConfiguration extends Object
Immutable configuration resolved from one test element's org.dbunit.annotation instances, ready for AnnotatedTestExecutor to drive - no dataset has been applied to a database yet, but every dataset path is normalized, every provider and catalog has been consulted, and every reflective instantiation that can fail (a provider or comparer with no accessible no-arg constructor, conflicting inline-value-and-provider attributes) has already happened.

Not intended for direct use by test code; this is machinery consumed by a binding such as DbUnitExtension. Building one is JUnit-free: from(java.lang.Class<?>, org.dbunit.annotation.DbUnitConfig, org.dbunit.annotation.DbUnitPrep, org.dbunit.annotation.DbUnitSetup, org.dbunit.annotation.DbUnitExpected, org.dbunit.annotation.DbUnitTearDown, org.dbunit.annotation.DbUnitRowCountCheck) takes the already-resolved annotation instances (method-level, else class-level - a binding's job, since only it knows how to search for them) rather than an ExtensionContext.

Since:
3.6.0
Author:
Jeff Jensen
  • Method Details

    • from

      public static AnnotatedTestConfiguration from(Class<?> testClass, DbUnitConfig config, DbUnitPrep prep, DbUnitSetup setup, DbUnitExpected expected, DbUnitTearDown tearDown, DbUnitRowCountCheck rowCountCheck)
      Resolves a configuration from one test element's annotation instances.
      Parameters:
      testClass - The test class; used to resolve dataset paths relative to its package.
      config - The resolved @DbUnitConfig, or null if absent.
      prep - The resolved @DbUnitPrep, or null if absent.
      setup - The resolved @DbUnitSetup, or null if absent.
      expected - The resolved @DbUnitExpected, or null if absent.
      tearDown - The resolved @DbUnitTearDown, or null if absent.
      rowCountCheck - The resolved @DbUnitRowCountCheck, or null if absent.
      Returns:
      The resolved configuration.
      Throws:
      IllegalStateException - If two mutually exclusive attributes are both set, or if a named provider, catalog, or comparer class cannot be instantiated.
    • getDataFileLoader

      public DataFileLoader getDataFileLoader()
      Returns the DataFileLoader to use for every dataset file.
      Returns:
      The data file loader.
    • getPrepDataFiles

      public String[] getPrepDataFiles()
      Returns the resolved, absolute classpath paths of the prep dataset files.
      Returns:
      The prep dataset paths; empty when no @DbUnitPrep was declared.
    • isSetupDeclared

      public boolean isSetupDeclared()
      Returns whether @DbUnitSetup was declared.

      A binding consults this, alongside getPrepDataFiles() being non-empty, to decide whether to call setSetUpOperation at all: with neither, the test runs with the tester's own pre-configured setup (matching pre-annotation behaviour); with @DbUnitSetup declared but no @DbUnitPrep, the operation is still applied - most usefully DatabaseOperation.NONE - to whatever dataset the tester already has, rather than leaving a tester with no dataset at all to run its unrelated default operation against. Either way a binding driving a tester shared across methods should restore the tester's dataset and operations afterward, so a per-method @DbUnitSetup/@DbUnitPrep does not carry onto a later method.

      Returns:
      True when @DbUnitSetup was declared.
    • getSetUpOperation

      public DatabaseOperation getSetUpOperation()
      Returns the setup operation.
      Returns:
      The setup operation; DatabaseOperation.CLEAN_INSERT when no @DbUnitSetup was declared.
    • isExpected

      public boolean isExpected()
      Returns whether @DbUnitExpected was declared, switching the test onto the prep/expected path.
      Returns:
      True when @DbUnitExpected was declared.
    • getExpectedDataFiles

      public String[] getExpectedDataFiles()
      Returns the resolved, absolute classpath paths of the expected dataset files.
      Returns:
      The expected dataset paths; empty when isExpected() is false.
    • getVerifyTableDefinitions

      public VerifyTableDefinition[] getVerifyTableDefinitions()
      Returns the resolved table definitions to verify.
      Returns:
      The table definitions; empty when isExpected() is false.
    • isTearDownDeclared

      public boolean isTearDownDeclared()
      Returns whether @DbUnitTearDown was declared.

      On the setup/teardown path a binding consults this to decide whether to call setTearDownOperation at all: with no @DbUnitTearDown, onTearDown() runs with the tester's own pre-configured teardown operation - e.g. one set in a @BeforeEach method - rather than a forced DatabaseOperation.NONE, mirroring how an undeclared setup operation is handled (see isSetupDeclared()). A binding driving a tester shared across methods should restore the operation afterward so a per-method @DbUnitTearDown does not carry onto a later method. On the prep/expected path the operation is applied regardless, since cleanupData() always runs there and reads it from the tester lazily.

      Returns:
      True when @DbUnitTearDown was declared.
    • getTearDownOperation

      public DatabaseOperation getTearDownOperation()
      Returns the teardown operation.
      Returns:
      The teardown operation; DatabaseOperation.NONE when no @DbUnitTearDown was declared.
    • getDatabaseConfigProperties

      public Properties getDatabaseConfigProperties()
      Returns the resolved DatabaseConfig properties to apply.
      Returns:
      The properties; empty when none were declared.
    • getFailureHandler

      public FailureHandler getFailureHandler()
      Returns the failure handler to use for verification failures.
      Returns:
      The failure handler, or null when not set - leaving dbUnit's own default in effect.
    • isCloseConnectionAfterTest

      public boolean isCloseConnectionAfterTest()
      Returns whether the connection this executor resolves - for the prep/expected path, the row count check, or parameter injection - is closed after each test.
      Returns:
      True to close the connection after each test.
    • getDatabaseTesterFactory

      public Class<? extends DatabaseTesterFactory> getDatabaseTesterFactory()
      Returns the DatabaseTesterFactory implementation to use when no tester field is declared.
      Returns:
      The factory class, or null when not set.
    • getPrepAndExpectedTestCaseClass

      public Class<? extends PrepAndExpectedTestCase> getPrepAndExpectedTestCaseClass()
      Returns the PrepAndExpectedTestCase implementation to use for the prep/expected path when no test case field is declared.
      Returns:
      The test case class; DefaultPrepAndExpectedTestCase when not set.
    • isRowCountCheckDeclared

      public boolean isRowCountCheckDeclared()
      Returns whether @DbUnitRowCountCheck was declared.

      A binding must consult this before overriding a resolved RowCountCheck, to leave the row count check's own DatabaseConfig/system-property-based resolution untouched when nothing was declared.

      Returns:
      True when @DbUnitRowCountCheck was declared.
    • isRowCountCheckEnabled

      public boolean isRowCountCheckEnabled()
      Returns the resolved @DbUnitRowCountCheck.enabled() value.
      Returns:
      True to enable the check; meaningful only when isRowCountCheckDeclared() is true.
    • getRowCountCheckExclude

      public String[] getRowCountCheckExclude()
      Returns the resolved @DbUnitRowCountCheck.exclude() value.
      Returns:
      The excluded table name patterns; meaningful only when isRowCountCheckDeclared() is true.