Class DatabaseConfigOverrides
DatabaseConfig instances for the
length of one test, and the means to put back what they replaced.
A connection that outlives a test - a fixed connection handed to a tester, one cached by a
CachingConnectionProvider, or one a test case keeps with
closeConnectionAfterTest off - carries its DatabaseConfig into whatever uses
it next. Applying a test's values with DatabaseConfig.setPropertiesByString(Properties)
alone leaves them there; applyTo(DatabaseConfig) remembers the value each one
replaced, and restore() puts those back.
Only the first value seen for a property on a given DatabaseConfig is remembered, so
applying the same values to a connection several times in one test, as the lifecycle does each
time it retrieves the connection, still restores what was there before the first.
Not thread-safe; a test's steps run sequentially on one thread.
- Since:
- 3.6.0
- Author:
- Jeff Jensen
-
Constructor Summary
ConstructorsConstructorDescriptionDatabaseConfigOverrides(Properties properties) Creates overrides for the given values. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTo(DatabaseConfig config) Applies the values to the given configuration, remembering each one's previous value forrestore().booleanhasAppliedTo(DatabaseConfig config) Returns whetherapplyTo(DatabaseConfig)has changed the given configuration since the lastrestore().booleanisEmpty()Returns whether there are no values to apply.voidrestore()Puts back, on every configurationapplyTo(DatabaseConfig)changed, the values it replaced.
-
Constructor Details
-
DatabaseConfigOverrides
Creates overrides for the given values.- Parameters:
properties- The property name and value pairs to apply, with names in the long or short formsDatabaseConfig.setPropertiesByString(Properties)accepts; copied, so later changes to it have no effect.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returns whether there are no values to apply.- Returns:
trueifapplyTo(DatabaseConfig)would change nothing.
-
hasAppliedTo
Returns whetherapplyTo(DatabaseConfig)has changed the given configuration since the lastrestore().- Parameters:
config- The configuration to ask about.- Returns:
trueif its values are in force andrestore()would put the replaced ones back.
-
applyTo
Applies the values to the given configuration, remembering each one's previous value forrestore(). Does nothing when there are no values. A failure part way leaves the values already applied in force, andrestore()still puts them back.- Parameters:
config- The configuration to apply the values to.- Throws:
DatabaseUnitException- If a value cannot be converted to its property's type.
-
restore
public void restore()Puts back, on every configurationapplyTo(DatabaseConfig)changed, the values it replaced. Does nothing when nothing was applied or it was already restored.
-