diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java b/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java index cf601cabb48..88a067fa7ab 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java @@ -33,17 +33,18 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; /** - * Abstract {@link Transactional transactional} extension of + * Abstract {@linkplain Transactional transactional} extension of * {@link AbstractJUnit4SpringContextTests} which adds convenience functionality * for JDBC access. Expects a {@link DataSource} bean and a * {@link PlatformTransactionManager} bean to be defined in the Spring - * {@link ApplicationContext application context}. + * {@linkplain ApplicationContext application context}. * - *

This class exposes a {@link JdbcTemplate} and provides an easy way - * to {@link #countRowsInTable(String) count the number of rows in a table}, - * {@link #deleteFromTables(String...) delete from tables}, and - * {@link #executeSqlScript(String, boolean) execute SQL scripts} within a - * transaction. + *

This class exposes a {@link JdbcTemplate} and provides an easy way to + * {@linkplain #countRowsInTable count the number of rows in a table} + * (potentially {@linkplain #countRowsInTableWhere with a WHERE clause}), + * {@linkplain #deleteFromTables delete from tables}, + * {@linkplain #dropTables drop tables}, and + * {@linkplain #executeSqlScript execute SQL scripts} within a transaction. * *

Concrete subclasses must fulfill the same requirements outlined in * {@link AbstractJUnit4SpringContextTests}. @@ -86,6 +87,7 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst /** * The {@code JdbcTemplate} that this base class manages, available to subclasses. + * @since 3.2 */ protected JdbcTemplate jdbcTemplate; @@ -120,6 +122,19 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); } + /** + * Count the rows in the given table, using the provided {@code WHERE} clause. + *

See the Javadoc for {@link JdbcTestUtils#countRowsInTableWhere()} for details. + * @param tableName the name of the table to count rows in + * @param whereClause the {@code WHERE} clause to append to the query + * @return the number of rows in the table that match the provided + * {@code WHERE} clause + * @since 3.2 + */ + protected int countRowsInTableWhere(String tableName, String whereClause) { + return JdbcTestUtils.countRowsInTableWhere(this.jdbcTemplate, tableName, whereClause); + } + /** * Convenience method for deleting all rows from the specified tables. Use * with caution outside of a transaction! @@ -130,6 +145,16 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names); } + /** + * Convenience method for dropping all of the specified tables. Use + * with caution outside of a transaction! + * @param names the names of the tables to drop + * @since 3.2 + */ + protected void dropTables(String... names) { + JdbcTestUtils.dropTables(this.jdbcTemplate, names); + } + /** * Execute the given SQL script. Use with caution outside of a transaction! *

The script will normally be loaded by classpath. There should be one diff --git a/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTransactionalTestNGSpringContextTests.java b/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTransactionalTestNGSpringContextTests.java index 50209940228..6ded8dcaf56 100644 --- a/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTransactionalTestNGSpringContextTests.java +++ b/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTransactionalTestNGSpringContextTests.java @@ -32,17 +32,18 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; /** - * Abstract {@link Transactional transactional} extension of + * Abstract {@linkplain Transactional transactional} extension of * {@link AbstractTestNGSpringContextTests} which adds convenience functionality * for JDBC access. Expects a {@link DataSource} bean and a * {@link PlatformTransactionManager} bean to be defined in the Spring - * {@link ApplicationContext application context}. + * {@linkplain ApplicationContext application context}. * - *

This class exposes a {@link JdbcTemplate} and provides an easy way - * to {@link #countRowsInTable(String) count the number of rows in a table}, - * {@link #deleteFromTables(String...) delete from tables}, and - * {@link #executeSqlScript(String, boolean) execute SQL scripts} within a - * transaction. + *

This class exposes a {@link JdbcTemplate} and provides an easy way to + * {@linkplain #countRowsInTable count the number of rows in a table} + * (potentially {@linkplain #countRowsInTableWhere with a WHERE clause}), + * {@linkplain #deleteFromTables delete from tables}, + * {@linkplain #dropTables drop tables}, and + * {@linkplain #executeSqlScript execute SQL scripts} within a transaction. * *

Concrete subclasses must fulfill the same requirements outlined in * {@link AbstractTestNGSpringContextTests}. @@ -77,6 +78,7 @@ public abstract class AbstractTransactionalTestNGSpringContextTests extends Abst /** * The {@code JdbcTemplate} that this base class manages, available to subclasses. + * @since 3.2 */ protected JdbcTemplate jdbcTemplate; @@ -111,6 +113,19 @@ public abstract class AbstractTransactionalTestNGSpringContextTests extends Abst return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName); } + /** + * Count the rows in the given table, using the provided {@code WHERE} clause. + *

See the Javadoc for {@link JdbcTestUtils#countRowsInTableWhere()} for details. + * @param tableName the name of the table to count rows in + * @param whereClause the {@code WHERE} clause to append to the query + * @return the number of rows in the table that match the provided + * {@code WHERE} clause + * @since 3.2 + */ + protected int countRowsInTableWhere(String tableName, String whereClause) { + return JdbcTestUtils.countRowsInTableWhere(this.jdbcTemplate, tableName, whereClause); + } + /** * Convenience method for deleting all rows from the specified tables. Use * with caution outside of a transaction! @@ -121,6 +136,16 @@ public abstract class AbstractTransactionalTestNGSpringContextTests extends Abst return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names); } + /** + * Convenience method for dropping all of the specified tables. Use + * with caution outside of a transaction! + * @param names the names of the tables to drop + * @since 3.2 + */ + protected void dropTables(String... names) { + JdbcTestUtils.dropTables(this.jdbcTemplate, names); + } + /** * Execute the given SQL script. Use with caution outside of a transaction! *

The script will normally be loaded by classpath. There should be one diff --git a/spring-test/src/main/java/org/springframework/test/jdbc/JdbcTestUtils.java b/spring-test/src/main/java/org/springframework/test/jdbc/JdbcTestUtils.java index 4dc8a1c9755..6006d2e3d09 100644 --- a/spring-test/src/main/java/org/springframework/test/jdbc/JdbcTestUtils.java +++ b/spring-test/src/main/java/org/springframework/test/jdbc/JdbcTestUtils.java @@ -74,7 +74,7 @@ public class JdbcTestUtils { * @param tableName the name of the table to count rows in * @param whereClause the {@code WHERE} clause to append to the query * @return the number of rows in the table that match the provided - * {@code WHERE} clause + * {@code WHERE} clause * @since 3.2 */ public static int countRowsInTableWhere(JdbcTemplate jdbcTemplate, String tableName, String whereClause) { @@ -111,7 +111,7 @@ public class JdbcTestUtils { * Drop the specified tables. * * @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations - * @param tableNames the names of the tables to drop + * @param tableNames the names of the tables to drop * @since 3.2 */ public static void dropTables(JdbcTemplate jdbcTemplate, String... tableNames) { diff --git a/src/dist/changelog.txt b/src/dist/changelog.txt index 7ceedb8d1d4..d42c161f374 100644 --- a/src/dist/changelog.txt +++ b/src/dist/changelog.txt @@ -33,6 +33,7 @@ Changes in version 3.2 M2 (2012-08-xx) * deprecated SimpleJdbcTestUtils in favor of JdbcTestUtils (SPR-9235) * introduced countRowsInTableWhere() and dropTables() in JdbcTestUtils (SPR-9235) * introduced JdbcTemplate in tx base classes in the TestContext framework (SPR-8990) +* introduced countRowsInTableWhere() and dropTables() in tx base test classes (SPR-9665) Changes in version 3.2 M1 (2012-05-28)