Class AbstractTransactionalJUnit4SpringContextTests

java.lang.Object
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests
All Implemented Interfaces:
Aware, ApplicationContextAware

@Transactional @Deprecated(since="7.0") public abstract class AbstractTransactionalJUnit4SpringContextTests extends AbstractJUnit4SpringContextTests
Deprecated.
since Spring Framework 7.0 in favor of the SpringExtension and JUnit Jupiter
Abstract transactional extension of AbstractJUnit4SpringContextTests 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 AbstractJUnit4SpringContextTests.

This class serves only as a convenience for extension.

NOTE: This class requires JUnit 4.12 or higher.

Since:
2.5
Author:
Sam Brannen, Juergen Hoeller
See Also:
  • Field Details

    • jdbcTemplate

      protected final JdbcTemplate jdbcTemplate
      Deprecated.
      The JdbcTemplate that this base class manages, available to subclasses.
      Since:
      3.2
  • Constructor Details

    • AbstractTransactionalJUnit4SpringContextTests

      public AbstractTransactionalJUnit4SpringContextTests()
      Deprecated.
  • Method Details

    • setDataSource

      @Autowired public void setDataSource(DataSource dataSource)
      Deprecated.
      Set the DataSource, typically provided via Dependency Injection.

      This method also instantiates the jdbcTemplate instance variable.

    • setSqlScriptEncoding

      public void setSqlScriptEncoding(String sqlScriptEncoding)
      Deprecated.
      Specify the encoding for SQL scripts, if different from the platform encoding.
      See Also:
    • countRowsInTable

      protected int countRowsInTable(String tableName)
      Deprecated.
      Convenience method for counting the rows in the given table.
      Parameters:
      tableName - table name to count rows in
      Returns:
      the number of rows in the table
      See Also:
    • countRowsInTableWhere

      protected int countRowsInTableWhere(String tableName, String whereClause)
      Deprecated.
      Convenience method for counting the rows in the given table, using the provided WHERE clause.

      See the Javadoc for JdbcTestUtils.countRowsInTableWhere(JdbcOperations, String, String) for details.

      Parameters:
      tableName - the name of the table to count rows in
      whereClause - the WHERE clause to append to the query
      Returns:
      the number of rows in the table that match the provided WHERE clause
      Since:
      3.2
      See Also:
    • deleteFromTables

      protected int deleteFromTables(String... names)
      Deprecated.
      Convenience method for deleting all rows from the specified tables.

      Use with caution outside of a transaction!

      Parameters:
      names - the names of the tables from which to delete
      Returns:
      the total number of rows deleted from all specified tables
      See Also:
    • deleteFromTableWhere

      protected int deleteFromTableWhere(String tableName, String whereClause, Object... args)
      Deprecated.
      Convenience method for deleting all rows from the given table, using the provided WHERE clause.

      Use with caution outside of a transaction!

      See the Javadoc for JdbcTestUtils.deleteFromTableWhere(JdbcOperations, String, String, Object...) for details.

      Parameters:
      tableName - the name of the table to delete rows from
      whereClause - the WHERE clause to append to the query
      args - 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.
      Returns:
      the number of rows deleted from the table
      Since:
      4.0
      See Also:
    • dropTables

      protected void dropTables(String... names)
      Deprecated.
      Convenience method for dropping all the specified tables.

      Use with caution outside of a transaction!

      Parameters:
      names - the names of the tables to drop
      Since:
      3.2
      See Also:
    • executeSqlScript

      protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException
      Deprecated.
      Execute the given SQL script.

      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.

      Parameters:
      sqlResourcePath - the Spring resource path for the SQL script
      continueOnError - whether to continue without throwing an exception in the event of an error
      Throws:
      DataAccessException - if there is an error executing a statement
      See Also: