Class TestSystem
java.lang.Object
liquibase.extension.testing.testsystem.TestSystem
- All Implemented Interfaces:
Plugin
,org.junit.rules.TestRule
- Direct Known Subclasses:
DatabaseTestSystem
TestSystem implementations define and manage a connection to an external system to test.
Ideally the implementation can start and stop the test systems, but that is not necessary.
This implements
Instances should not be created directly, but via
This implements
TestRule
so it can control start/stop of the TestSystem in JUnit, but that may be removed as tests get converted to spock.
Instances should not be created directly, but via
TestSystemFactory
-
Nested Class Summary
-
Field Summary
Fields inherited from interface liquibase.plugin.Plugin
PRIORITY_DATABASE, PRIORITY_DEFAULT, PRIORITY_NOT_APPLICABLE, PRIORITY_SPECIALIZED
-
Constructor Summary
ModifierConstructorDescriptionprotected
TestSystem
(String name) Empty constructor for ServiceLocator to useprotected
TestSystem
(TestSystem.Definition definition) Constructor forTestSystemFactory
to use -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statement
apply
(org.junit.runners.model.Statement base, org.junit.runner.Description description) Allows test system to be auto-controlled by JUnit tests.Return configuration keys supported by this testSystem<T> T
getConfiguredValue
(String propertyName, Class<T> type) Convenience method forgetConfiguredValue(String, ConfigurationValueConverter, boolean)
<T> T
getConfiguredValue
(String propertyName, Class<T> type, boolean required) Convenience method forgetConfiguredValue(String, ConfigurationValueConverter, boolean)
<T> T
getConfiguredValue
(String propertyName, ConfigurationValueConverter<T> converter, boolean required) Returns the configured value for the given propertyName.Return the definition of this test system.getEnabledTestSystems
(String configuredTestSystems, String skippedTestSystems) Determine which test systems are considered enabled and should have tests run against them.boolean
Return whether this testSystem should/will keep running after the JVM interacting with it exits.int
getPriority
(TestSystem.Definition definition) Default implementation returns PRIORITY_DEFAULT if the name matches the given definition, without taking any profiles etc. into account.boolean
abstract void
start()
Starts the system if possible.abstract void
stop()
Stops the system if possible.toString()
-
Constructor Details
-
TestSystem
Empty constructor for ServiceLocator to use -
TestSystem
Constructor forTestSystemFactory
to use
-
-
Method Details
-
getEnabledTestSystems
public static List<String> getEnabledTestSystems(String configuredTestSystems, String skippedTestSystems) Determine which test systems are considered enabled and should have tests run against them.- Parameters:
configuredTestSystems
- the value of the "liquibase.sdk.testSystem.test" propertyskippedTestSystems
- the value of the "liquibase.sdk.testSystem.skip" property- Returns:
- the list of test system names that are enabled
-
getConfigurationKeys
Return configuration keys supported by this testSystem -
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description) Allows test system to be auto-controlled by JUnit tests.If the liquibase.sdk.testSystem.test configuration does NOT include the name of this test system, it skips the test.
If the liquibase.sdk.testSystem.test configuration DOES include the name of the test system, it will connect to a matching system if available or will start it as possible. If it starts the system, it will not stop it until JVM shutdown.Example:
\@Rule TestSystem testSystem = Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("mysql")
- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
getPriority
Default implementation returns PRIORITY_DEFAULT if the name matches the given definition, without taking any profiles etc. into account. -
shouldTest
public boolean shouldTest()- Returns:
- true if this TestSystem should have automated tests run against it
-
getDefinition
Return the definition of this test system. -
getKeepRunning
public boolean getKeepRunning()Return whether this testSystem should/will keep running after the JVM interacting with it exits. Default implementation returns the `keepRunning` test system configured value. -
getConfiguredValue
Convenience method forgetConfiguredValue(String, ConfigurationValueConverter, boolean)
-
getConfiguredValue
Convenience method forgetConfiguredValue(String, ConfigurationValueConverter, boolean)
-
getConfiguredValue
public <T> T getConfiguredValue(String propertyName, ConfigurationValueConverter<T> converter, boolean required) Returns the configured value for the given propertyName. It will check (in priority order):- properties set directly on this object
- liquibase.sdk.testSystem.[name].[profile(s)].propertyName in the order the profiles are set on this object
- liquibase.sdk.testSystem.[name].propertyName
- liquibase.sdk.testSystem.default.propertyName
If a value is not found, it will return null or throw anUnexpectedLiquibaseException
if 'required' is true. -
start
Starts the system if possible. Does not return until test system is reachable. If connecting to a running system, ensure the system can be reached. The lifetime of the started system should respect thegetKeepRunning()
configuration. If the keepRunning flag has an invalid value for this test system, throw anIllegalArgumentException
.- Throws:
Exception
- if the system cannot be started or reached.
-
stop
Stops the system if possible. Does not return until test system is down.- Throws:
Exception
-
toString
-