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
,SQLiteTestSystem
,SybaseASATestSystem
public abstract class DatabaseTestSystem extends TestSystem
Base class forTestSystem
s for databases.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class liquibase.extension.testing.testsystem.TestSystem
TestSystem.Definition
-
-
Field Summary
Fields Modifier and Type Field Description protected DatabaseWrapper
wrapper
-
Fields inherited from interface liquibase.plugin.Plugin
PRIORITY_DATABASE, PRIORITY_DEFAULT, PRIORITY_NOT_APPLICABLE, PRIORITY_SPECIALIZED
-
-
Constructor Summary
Constructors Constructor Description DatabaseTestSystem(String shortName)
DatabaseTestSystem(TestSystem.Definition definition)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract DatabaseWrapper
createContainerWrapper()
protected @NotNull JdbcDatabaseWrapper
createJdbcWrapper(String url)
protected @NotNull DatabaseWrapper
createWrapper()
void
execute(Change change)
void
execute(SqlStatement sqlStatement)
void
executeInverses(Change change)
boolean
executeSql(String sql)
String
getAltCatalog()
Standard alt catalog to use for testing.String
getAltSchema()
Standard alt schema to use for testing.String
getAltTablespace()
Standard alt tablespace to use for testing.String
getCatalog()
Standard "catalog" to use for testing.Connection
getConnection()
Returns the connection to this database.Connection
getConnection(String username, String password)
Returns the connection to this database.protected Connection
getConnection(String url, String username, String password)
Opens a connection to the given url, username, and password.String
getConnectionUrl()
Return the url used to connect to this database.Database
getDatabaseFromFactory()
protected Driver
getDriver(String url)
String
getDriverJar()
Returns the driver library to use.protected String
getImageName()
Docker image of the database to test against.String
getPassword()
Standard password to use when connecting.protected String
getSetupPassword()
"Privileged" password to use forsetup()
.protected abstract String[]
getSetupSql()
Define SQL to run bysetup()
protected String
getSetupUsername()
"Privileged" username to use forsetup()
.String
getUsername()
Standard username to use when connecting.protected String
getVersion()
Version of the database to test against."Privileged" username to use forsetup()
.protected Connection
openSetupConnection()
Opens a connection with valid permissions for thesetup()
logic.protected void
setup()
Sets up any needed catalogs/schemas/usernames/etc.void
start()
Default implementation usescreateWrapper()
to manage the external system.void
stop()
Default implementation usescreateWrapper()
to manage the external system, and callsDatabaseWrapper.stop()
-
Methods inherited from class liquibase.extension.testing.testsystem.TestSystem
apply, getConfigurationKeys, getConfiguredValue, getConfiguredValue, getConfiguredValue, getDefinition, getEnabledTestSystems, getKeepRunning, getPriority, shouldTest, toString
-
-
-
-
Field Detail
-
wrapper
protected DatabaseWrapper wrapper
-
-
Constructor Detail
-
DatabaseTestSystem
public DatabaseTestSystem(String shortName)
-
DatabaseTestSystem
public DatabaseTestSystem(TestSystem.Definition definition)
-
-
Method Detail
-
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 usescreateWrapper()
to manage the external system. Multiple calls to start() will be no-ops. Callssetup()
after starting the wrapper.- Specified by:
start
in classTestSystem
- Throws:
Exception
- if the system cannot be started or reached.
-
stop
public void stop() throws Exception
Default implementation usescreateWrapper()
to manage the external system, and callsDatabaseWrapper.stop()
- Specified by:
stop
in classTestSystem
- 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 thesetup()
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 forgetConnection(String, String)
usinggetUsername()
andgetPassword()
- 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 forsetup()
. Returns "setup.username" or "username" test system configuration.
-
getSetupPassword
protected String getSetupPassword()
"Privileged" password to use forsetup()
. Returns "setup.password" or "password" test system configuration.
-
getVersion
protected String getVersion()
Version of the database to test against."Privileged" username to use forsetup()
. 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
-
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
-
-