Class DatabaseTestSystem

java.lang.Object
liquibase.extension.testing.testsystem.TestSystem
liquibase.extension.testing.testsystem.DatabaseTestSystem
All Implemented Interfaces:
Plugin, org.junit.rules.TestRule
Direct Known Subclasses:
CockroachTestSystem, DB2TestSystem, DB2zTestSystem, DerbyTestSystem, FirebirdTestSystem, H2TestSystem, HsqlTestSystem, InformixTestSystem, MariaDBTestSystem, MSSQLTestSystem, MySQLTestSystem, OracleTestSystem, PostgresTestSystem, SnowflakeTestSystem, SQLiteTestSystem, SybaseASATestSystem

public abstract class DatabaseTestSystem extends TestSystem
Base class for TestSystems for databases.
  • Field Details

  • Constructor Details

    • DatabaseTestSystem

      public DatabaseTestSystem(String shortName)
    • DatabaseTestSystem

      public DatabaseTestSystem(TestSystem.Definition definition)
  • Method Details

    • createWrapper

      @NotNull protected @NotNull DatabaseWrapper createWrapper() throws Exception
      Throws:
      Exception
    • createJdbcWrapper

      @NotNull protected @NotNull JdbcDatabaseWrapper createJdbcWrapper(String url) throws SQLException
      Throws:
      SQLException
    • createContainerWrapper

      protected abstract DatabaseWrapper createContainerWrapper() throws Exception
      Throws:
      Exception
    • start

      public void start() throws Exception
      Default implementation uses createWrapper() to manage the external system. Multiple calls to start() will be no-ops. Calls setup() after starting the wrapper.
      Specified by:
      start in class TestSystem
      Throws:
      Exception - if the system cannot be started or reached.
    • stop

      public void stop() throws Exception
      Default implementation uses createWrapper() to manage the external system, and calls DatabaseWrapper.stop()
      Specified by:
      stop in class TestSystem
      Throws:
      Exception
    • getDriverJar

      public String getDriverJar()
      Returns the driver library to use. Supports maven-style coordinate, like "com.h2database:h2:1.4.200". Default implementation uses the "driverJar" testSystem configuration value.
    • getConnection

      protected Connection getConnection(String url, String username, String password) throws SQLException
      Opens a connection to the given url, username, and password. This is not an end-user facing function because the url to use should be managed by the DatabaseWrapper, not the user.
      Throws:
      SQLException
    • getDriver

      protected Driver getDriver(String url) throws SQLException
      Returns:
      the Driver instance to use for the given url. Default implementation uses the value in getDriverJar() as needed and will download the library and manage the classloader as needed.
      Throws:
      SQLException
    • openSetupConnection

      protected Connection openSetupConnection() throws SQLException
      Opens a connection with valid permissions for the setup() logic.
      Throws:
      SQLException
    • getConnection

      public Connection getConnection() throws SQLException
      Returns the connection to this database. Will reuse a single connection rather than continually open new ones. Convenience method for getConnection(String, String) using getUsername() and getPassword()
      Throws:
      SQLException
    • getConnection

      public Connection getConnection(String username, String password) throws SQLException
      Returns the connection to this database. Will reuse a single connection for each username/password combo rather than continually open new ones.
      Throws:
      SQLException
    • getConnectionUrl

      public String getConnectionUrl()
      Return the url used to connect to this database. NOTE: this may be different than the 'url' configured value because the TestSystem implementations are free to tweak and control this URL based on other settings.
    • getUsername

      public String getUsername()
      Standard username to use when connecting. Returns "username" test system configuration.
    • getPassword

      public String getPassword()
      Standard password to use when connecting. Returns "password" test system configuration.
    • getCatalog

      public String getCatalog()
      Standard "catalog" to use for testing. Returns "catalog" test system configuration.
    • getAltCatalog

      public String getAltCatalog()
      Standard alt catalog to use for testing. Returns "altCatalog" test system configuration.
    • getAltSchema

      public String getAltSchema()
      Standard alt schema to use for testing. Returns "altSchema" test system configuration.
    • getAltTablespace

      public String getAltTablespace()
      Standard alt tablespace to use for testing. Returns "username" test system configuration.
    • getSetupUsername

      protected String getSetupUsername()
      "Privileged" username to use for setup(). Returns "setup.username" or "username" test system configuration.
    • getSetupPassword

      protected String getSetupPassword()
      "Privileged" password to use for setup(). Returns "setup.password" or "password" test system configuration.
    • getVersion

      protected String getVersion()
      Version of the database to test against."Privileged" username to use for setup(). Returns "version" test system configuration.
    • getImageName

      protected String getImageName()
      Docker image of the database to test against. Returns "imageName" test system configuration.
    • setup

      protected void setup() throws SQLException
      Sets up any needed catalogs/schemas/usernames/etc.
      Throws:
      SQLException
    • getSetupSql

      protected abstract String[] getSetupSql()
      Define SQL to run by setup()
    • executeSql

      public boolean executeSql(String sql) throws SQLException
      Throws:
      SQLException
    • execute

      public void execute(SqlStatement sqlStatement) throws SQLException, DatabaseException
      Throws:
      SQLException
      DatabaseException
    • getDatabaseFromFactory

      public Database getDatabaseFromFactory() throws SQLException, DatabaseException
      Throws:
      SQLException
      DatabaseException
    • execute

      public void execute(Change change) throws SQLException, DatabaseException
      Throws:
      SQLException
      DatabaseException
    • executeInverses

      public void executeInverses(Change change) throws SQLException, DatabaseException, RollbackImpossibleException
      Throws:
      SQLException
      DatabaseException
      RollbackImpossibleException