Class AnnotatedTestConfiguration
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 Summary
Modifier and TypeMethodDescriptionstatic AnnotatedTestConfigurationfrom(Class<?> testClass, DbUnitConfig config, DbUnitPrep prep, DbUnitSetup setup, DbUnitExpected expected, DbUnitTearDown tearDown, DbUnitRowCountCheck rowCountCheck) Resolves a configuration from one test element's annotation instances.Returns the resolvedDatabaseConfigproperties to apply.Class<? extends DatabaseTesterFactory> Returns theDatabaseTesterFactoryimplementation to use when no tester field is declared.Returns theDataFileLoaderto use for every dataset file.String[]Returns the resolved, absolute classpath paths of the expected dataset files.Returns the failure handler to use for verification failures.Class<? extends PrepAndExpectedTestCase> Returns thePrepAndExpectedTestCaseimplementation to use for the prep/expected path when no test case field is declared.String[]Returns the resolved, absolute classpath paths of the prep dataset files.String[]Returns the resolved@DbUnitRowCountCheck.exclude()value.Returns the setup operation.Returns the teardown operation.Returns the resolved table definitions to verify.booleanReturns whether the connection this executor resolves - for the prep/expected path, the row count check, or parameter injection - is closed after each test.booleanReturns whether@DbUnitExpectedwas declared, switching the test onto the prep/expected path.booleanReturns whether@DbUnitRowCountCheckwas declared.booleanReturns the resolved@DbUnitRowCountCheck.enabled()value.booleanReturns whether@DbUnitSetupwas declared.booleanReturns whether@DbUnitTearDownwas declared.
-
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, ornullif absent.prep- The resolved@DbUnitPrep, ornullif absent.setup- The resolved@DbUnitSetup, ornullif absent.expected- The resolved@DbUnitExpected, ornullif absent.tearDown- The resolved@DbUnitTearDown, ornullif absent.rowCountCheck- The resolved@DbUnitRowCountCheck, ornullif 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
Returns theDataFileLoaderto use for every dataset file.- Returns:
- The data file loader.
-
getPrepDataFiles
Returns the resolved, absolute classpath paths of the prep dataset files.- Returns:
- The prep dataset paths; empty when no
@DbUnitPrepwas declared.
-
isSetupDeclared
public boolean isSetupDeclared()Returns whether@DbUnitSetupwas declared.A binding consults this, alongside
getPrepDataFiles()being non-empty, to decide whether to callsetSetUpOperationat all: with neither, the test runs with the tester's own pre-configured setup (matching pre-annotation behaviour); with@DbUnitSetupdeclared but no@DbUnitPrep, the operation is still applied - most usefullyDatabaseOperation.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/@DbUnitPrepdoes not carry onto a later method.- Returns:
- True when
@DbUnitSetupwas declared.
-
getSetUpOperation
Returns the setup operation.- Returns:
- The setup operation;
DatabaseOperation.CLEAN_INSERTwhen no@DbUnitSetupwas declared.
-
isExpected
public boolean isExpected()Returns whether@DbUnitExpectedwas declared, switching the test onto the prep/expected path.- Returns:
- True when
@DbUnitExpectedwas declared.
-
getExpectedDataFiles
Returns the resolved, absolute classpath paths of the expected dataset files.- Returns:
- The expected dataset paths; empty when
isExpected()is false.
-
getVerifyTableDefinitions
Returns the resolved table definitions to verify.- Returns:
- The table definitions; empty when
isExpected()is false.
-
isTearDownDeclared
public boolean isTearDownDeclared()Returns whether@DbUnitTearDownwas declared.On the setup/teardown path a binding consults this to decide whether to call
setTearDownOperationat all: with no@DbUnitTearDown,onTearDown()runs with the tester's own pre-configured teardown operation - e.g. one set in a@BeforeEachmethod - rather than a forcedDatabaseOperation.NONE, mirroring how an undeclared setup operation is handled (seeisSetupDeclared()). A binding driving a tester shared across methods should restore the operation afterward so a per-method@DbUnitTearDowndoes not carry onto a later method. On the prep/expected path the operation is applied regardless, sincecleanupData()always runs there and reads it from the tester lazily.- Returns:
- True when
@DbUnitTearDownwas declared.
-
getTearDownOperation
Returns the teardown operation.- Returns:
- The teardown operation;
DatabaseOperation.NONEwhen no@DbUnitTearDownwas declared.
-
getDatabaseConfigProperties
Returns the resolvedDatabaseConfigproperties to apply.- Returns:
- The properties; empty when none were declared.
-
getFailureHandler
Returns the failure handler to use for verification failures.- Returns:
- The failure handler, or
nullwhen 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
Returns theDatabaseTesterFactoryimplementation to use when no tester field is declared.- Returns:
- The factory class, or
nullwhen not set.
-
getPrepAndExpectedTestCaseClass
Returns thePrepAndExpectedTestCaseimplementation to use for the prep/expected path when no test case field is declared.- Returns:
- The test case class;
DefaultPrepAndExpectedTestCasewhen not set.
-
isRowCountCheckDeclared
public boolean isRowCountCheckDeclared()Returns whether@DbUnitRowCountCheckwas declared.A binding must consult this before overriding a resolved
RowCountCheck, to leave the row count check's ownDatabaseConfig/system-property-based resolution untouched when nothing was declared.- Returns:
- True when
@DbUnitRowCountCheckwas declared.
-
isRowCountCheckEnabled
public boolean isRowCountCheckEnabled()Returns the resolved@DbUnitRowCountCheck.enabled()value.- Returns:
- True to enable the check; meaningful only when
isRowCountCheckDeclared()is true.
-
getRowCountCheckExclude
Returns the resolved@DbUnitRowCountCheck.exclude()value.- Returns:
- The excluded table name patterns; meaningful only when
isRowCountCheckDeclared()is true.
-