Class DbSetupRule
- java.lang.Object
-
- org.silverpeas.core.test.integration.rule.DbSetupRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
- Direct Known Subclasses:
DbUnitLoadingRule
public class DbSetupRule extends Object implements org.junit.rules.TestRule
A rule to set up the database before any integration tests implying the persistence engine of Silverpeas.- Author:
- mmoquillon
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DbSetupRule.TableRow
Class to extract data easily from a table row.
-
Constructor Summary
Constructors Modifier Constructor Description protected
DbSetupRule(String... sqlScripts)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.junit.runners.model.Statement
apply(org.junit.runners.model.Statement test, org.junit.runner.Description description)
static DbSetupRule
createDefaultTables()
Constructs a new instance of this rule by creating only the default tables (like UniqueId) required for the integration tests on database to run.static DbSetupRule
createTablesFrom(String... sqlScripts)
Constructs a new instance of this rule by specifying the SQL scripts containing the statements to create the different tables required by the integration test.static org.dbunit.dataset.IDataSet
getActualDataSet(Connection connection)
Gets the actual data set in the database so that you can check information persisted in the data source according to the operations that were performed in the behaviour of the test.static Connection
getSafeConnection()
Gets a new connection to the database that will be closed automatically closed at the end of test if it is not already done.Connection
getSafeConnectionFromDifferentThread()
Gets a new connection to the database that will be closed automatically closed at the end of test if it is not already done.static DbSetupRule.TableRow
getTableRowFor(org.dbunit.dataset.ITable table, String columnName, Object value)
static List<DbSetupRule.TableRow>
getTableRowsFor(org.dbunit.dataset.ITable table, String columnName, Object value)
DbSetupRule
loadInitialDataSetFrom(com.ninja_squad.dbsetup.operation.Operation... insertionOperation)
Loads the specified SQL scripts in order to insert into the database an initial data set before any test running.DbSetupRule
loadInitialDataSetFrom(String... sqlScripts)
Loads the specified SQL scripts in order to insert into the database an initial data set before any test running.List<SQLRequester.ResultLine>
mapJdbcSqlQueryResultAsListOfMappedValues(JdbcSqlQuery jdbcSqlQuery)
protected Connection
openSafeConnection()
Opens a new connection to the database that will be closed automatically closed at the end of test if it is not already done.protected void
performAfter(org.junit.runner.Description description)
protected void
performBefore(org.junit.runner.Description description)
-
-
-
Constructor Detail
-
DbSetupRule
protected DbSetupRule(String... sqlScripts)
-
-
Method Detail
-
createTablesFrom
public static DbSetupRule createTablesFrom(String... sqlScripts)
Constructs a new instance of this rule by specifying the SQL scripts containing the statements to create the different tables required by the integration test. The creation of the default tables, required by the tests, like UniqueId, are taken in charge automatically by this rule, so you don't have to specify them.In order to work fine, it is not recommended to insert an initial data set with these scripts. For doing a such purpose, please invoke one of the following methods:
loadInitialDataSetFrom(com.ninja_squad.dbsetup.operation.Operation...)
orloadInitialDataSetFrom(String...)
.- Parameters:
sqlScripts
- the path of the SQL scripts in the classpath and from which the database will be set up.- Returns:
- itself.
-
createDefaultTables
public static DbSetupRule createDefaultTables()
Constructs a new instance of this rule by creating only the default tables (like UniqueId) required for the integration tests on database to run.- Returns:
- itself.
-
loadInitialDataSetFrom
public DbSetupRule loadInitialDataSetFrom(String... sqlScripts)
Loads the specified SQL scripts in order to insert into the database an initial data set before any test running.- Parameters:
sqlScripts
- the path of the SQL scripts in the classpath and from which an initial data set will be inserted in the database.- Returns:
- itself.
-
loadInitialDataSetFrom
public DbSetupRule loadInitialDataSetFrom(com.ninja_squad.dbsetup.operation.Operation... insertionOperation)
Loads the specified SQL scripts in order to insert into the database an initial data set before any test running.- Parameters:
insertionOperation
- the operation to use for inserting an initial data set.- Returns:
- itself.
-
apply
public final org.junit.runners.model.Statement apply(org.junit.runners.model.Statement test, org.junit.runner.Description description)
- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
performBefore
protected void performBefore(org.junit.runner.Description description)
-
performAfter
protected void performAfter(org.junit.runner.Description description)
-
openSafeConnection
protected Connection openSafeConnection() throws SQLException
Opens a new connection to the database that will be closed automatically closed at the end of test if it is not already done.- Returns:
- a connection to the database.
- Throws:
SQLException
- on SQL error
-
getSafeConnection
public static Connection getSafeConnection() throws SQLException
Gets a new connection to the database that will be closed automatically closed at the end of test if it is not already done.- Returns:
- a connection to the database
- Throws:
SQLException
- on SQL error
-
getSafeConnectionFromDifferentThread
public Connection getSafeConnectionFromDifferentThread() throws SQLException
Gets a new connection to the database that will be closed automatically closed at the end of test if it is not already done.- Returns:
- a connection to the database
- Throws:
SQLException
- on SQL error
-
getActualDataSet
public static org.dbunit.dataset.IDataSet getActualDataSet(Connection connection)
Gets the actual data set in the database so that you can check information persisted in the data source according to the operations that were performed in the behaviour of the test.- Parameters:
connection
- a connection to the database- Returns:
- the actual data set.
- Throws:
Exception
- if an error occurs while fetching the data set in the database.
-
getTableRowFor
public static DbSetupRule.TableRow getTableRowFor(org.dbunit.dataset.ITable table, String columnName, Object value)
-
getTableRowsFor
public static List<DbSetupRule.TableRow> getTableRowsFor(org.dbunit.dataset.ITable table, String columnName, Object value)
-
mapJdbcSqlQueryResultAsListOfMappedValues
public List<SQLRequester.ResultLine> mapJdbcSqlQueryResultAsListOfMappedValues(JdbcSqlQuery jdbcSqlQuery) throws SQLException
- Throws:
SQLException
-
-