Class TestSystem

  • All Implemented Interfaces:
    Plugin, org.junit.rules.TestRule
    Direct Known Subclasses:

    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 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
    • 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.
        configuredTestSystems - the value of the "liquibase.sdk.testSystem.test" property
        skippedTestSystems - the value of the "liquibase.sdk.testSystem.skip" property
        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.


         TestSystem testSystem = Scope.getCurrentScope().getSingleton(TestSystemFactory.class).getTestSystem("mysql")
        Specified by:
        apply in interface org.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()
        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,
                                        ConfigurationValueConverter<T> converter,
                                        boolean required)
        Returns the configured value for the given propertyName. It will check (in priority order):
        1. properties set directly on this object
        2. liquibase.sdk.testSystem.[name].[profile(s)].propertyName in the order the profiles are set on this object
        3. liquibase.sdk.testSystem.[name].propertyName
        4. liquibase.sdk.testSystem.default.propertyName

        If a value is not found, it will return null or throw an UnexpectedLiquibaseException 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 the getKeepRunning() configuration. If the keepRunning flag has an invalid value for this test system, throw an IllegalArgumentException.
        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.