@TestExecutionListeners(listeners={ServletTestExecutionListener.class,DirtiesContextBeforeModesTestExecutionListener.class,ApplicationEventsTestExecutionListener.class,DependencyInjectionTestExecutionListener.class,DirtiesContextTestExecutionListener.class,TransactionalTestExecutionListener.class,SqlScriptsTestExecutionListener.class,EventPublishingTestExecutionListener.class}, inheritListeners=false) @Transactional public abstract class AbstractTransactionalTestNGSpringContextTests extends AbstractTestNGSpringContextTests
AbstractTestNGSpringContextTests which adds convenience functionality
 for JDBC access. Expects a DataSource bean and a
 PlatformTransactionManager bean to be defined in the Spring
 application context.
 This class exposes a JdbcTemplate and provides an easy way to
 count the number of rows in a table
 (potentially with a WHERE clause),
 delete from tables,
 drop tables, and
 execute SQL scripts within a transaction.
 
Concrete subclasses must fulfill the same requirements outlined in
 AbstractTestNGSpringContextTests.
 
This class explicitly registers the following TestExecutionListener
 implementations. If you want to switch to using the default set of
 listeners, see the class-level Javadoc for
 @TestExecutionListeners for details.
 
AbstractTestNGSpringContextTests, 
ContextConfiguration, 
TestExecutionListeners, 
TransactionalTestExecutionListener, 
SqlScriptsTestExecutionListener, 
Transactional, 
Commit, 
Rollback, 
BeforeTransaction, 
AfterTransaction, 
JdbcTestUtils, 
AbstractTransactionalJUnit4SpringContextTests| Modifier and Type | Field and Description | 
|---|---|
| protected JdbcTemplate | jdbcTemplateThe  JdbcTemplatethat this base class manages, available to subclasses. | 
applicationContext, logger| Constructor and Description | 
|---|
| AbstractTransactionalTestNGSpringContextTests() | 
| Modifier and Type | Method and Description | 
|---|---|
| protected int | countRowsInTable(String tableName)Convenience method for counting the rows in the given table. | 
| protected int | countRowsInTableWhere(String tableName,
                     String whereClause)Convenience method for counting the rows in the given table, using the
 provided  WHEREclause. | 
| protected int | deleteFromTables(String... names)Convenience method for deleting all rows from the specified tables. | 
| protected int | deleteFromTableWhere(String tableName,
                    String whereClause,
                    Object... args)Convenience method for deleting all rows from the given table, using the
 provided  WHEREclause. | 
| protected void | dropTables(String... names)Convenience method for dropping all the specified tables. | 
| protected void | executeSqlScript(String sqlResourcePath,
                boolean continueOnError)Execute the given SQL script. | 
| void | setDataSource(DataSource dataSource)Set the  DataSource, typically provided via Dependency Injection. | 
| void | setSqlScriptEncoding(String sqlScriptEncoding)Specify the encoding for SQL scripts, if different from the platform encoding. | 
run, setApplicationContext, springTestContextAfterTestClass, springTestContextAfterTestMethod, springTestContextBeforeTestClass, springTestContextBeforeTestMethod, springTestContextPrepareTestInstanceprotected final JdbcTemplate jdbcTemplate
JdbcTemplate that this base class manages, available to subclasses.public AbstractTransactionalTestNGSpringContextTests()
@Autowired public void setDataSource(DataSource dataSource)
DataSource, typically provided via Dependency Injection.
 This method also instantiates the jdbcTemplate instance variable.
public void setSqlScriptEncoding(String sqlScriptEncoding)
protected int countRowsInTable(String tableName)
tableName - table name to count rows inJdbcTestUtils.countRowsInTable(org.springframework.jdbc.core.JdbcTemplate, java.lang.String)protected int countRowsInTableWhere(String tableName, String whereClause)
WHERE clause.
 See the Javadoc for JdbcTestUtils.countRowsInTableWhere(org.springframework.jdbc.core.JdbcTemplate, java.lang.String, java.lang.String) for details.
tableName - the name of the table to count rows inwhereClause - the WHERE clause to append to the queryWHERE clauseJdbcTestUtils.countRowsInTableWhere(org.springframework.jdbc.core.JdbcTemplate, java.lang.String, java.lang.String)protected int deleteFromTables(String... names)
Use with caution outside of a transaction!
names - the names of the tables from which to deleteJdbcTestUtils.deleteFromTables(org.springframework.jdbc.core.JdbcTemplate, java.lang.String...)protected int deleteFromTableWhere(String tableName, String whereClause, Object... args)
WHERE clause.
 Use with caution outside of a transaction!
See the Javadoc for JdbcTestUtils.deleteFromTableWhere(org.springframework.jdbc.core.JdbcTemplate, java.lang.String, java.lang.String, java.lang.Object...) for details.
tableName - the name of the table to delete rows fromwhereClause - the WHERE clause to append to the queryargs - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain
 SqlParameterValue
 objects which indicate not only the argument value but also the SQL type
 and optionally the scale.JdbcTestUtils.deleteFromTableWhere(org.springframework.jdbc.core.JdbcTemplate, java.lang.String, java.lang.String, java.lang.Object...)protected void dropTables(String... names)
Use with caution outside of a transaction!
names - the names of the tables to dropJdbcTestUtils.dropTables(org.springframework.jdbc.core.JdbcTemplate, java.lang.String...)protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException
Use with caution outside of a transaction!
The script will normally be loaded by classpath.
Do not use this method to execute DDL if you expect rollback.
sqlResourcePath - the Spring resource path for the SQL scriptcontinueOnError - whether to continue without throwing an
 exception in the event of an errorDataAccessException - if there is an error executing a statementResourceDatabasePopulator, 
setSqlScriptEncoding(java.lang.String)