Class TestSystem
- java.lang.Object
-
- liquibase.extension.testing.testsystem.TestSystem
-
- All Implemented Interfaces:
Plugin
,org.junit.rules.TestRule
- Direct Known Subclasses:
DatabaseTestSystem
public abstract class TestSystem extends Object implements org.junit.rules.TestRule, Plugin
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 implementsTestRule
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 viaTestSystemFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TestSystem.Definition
-
Field Summary
-
Fields inherited from interface liquibase.plugin.Plugin
PRIORITY_DATABASE, PRIORITY_DEFAULT, PRIORITY_NOT_APPLICABLE, PRIORITY_SPECIALIZED
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TestSystem(String name)
Empty constructor for ServiceLocator to useprotected
TestSystem(TestSystem.Definition definition)
Constructor forTestSystemFactory
to use
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.SortedSet<String>
getConfigurationKeys()
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.TestSystem.Definition
getDefinition()
Return the definition of this test system.static List<String>
getEnabledTestSystems(String configuredTestSystems, String skippedTestSystems)
Determine which test systems are considered enabled and should have tests run against them.boolean
getKeepRunning()
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.boolean
shouldTest()
abstract void
start()
Starts the system if possible.abstract void
stop()
Stops the system if possible.String
toString()
-
-
-
Constructor Detail
-
TestSystem
protected TestSystem(String name)
Empty constructor for ServiceLocator to use
-
TestSystem
protected TestSystem(TestSystem.Definition definition)
Constructor forTestSystemFactory
to use
-
-
Method Detail
-
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
public SortedSet<String> 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
public int getPriority(TestSystem.Definition definition)
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
public TestSystem.Definition 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
public <T> T getConfiguredValue(String propertyName, Class<T> type)
Convenience method forgetConfiguredValue(String, ConfigurationValueConverter, boolean)
-
getConfiguredValue
public <T> T getConfiguredValue(String propertyName, Class<T> type, boolean required)
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
public abstract void start() throws Exception
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
public abstract void stop() throws Exception
Stops the system if possible. Does not return until test system is down.- Throws:
Exception
-
-