BATCH-1940: Replace org.springframework.batch.support.JdbcTestUtils with org.springframework.test.jdbc.JdbcTestUtils
This commit is contained in:
committed by
Michael Minella
parent
e9680c7f61
commit
a6ab68bbbb
@@ -35,7 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "sql-dao-test.xml" })
|
||||
|
||||
@@ -13,11 +13,11 @@ import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
|
||||
@@ -30,11 +30,11 @@ import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.database.support.AbstractSqlPagingQueryProvider;
|
||||
import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package org.springframework.batch.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Util class based off {@link org.springframework.test.jdbc.SimpleJdbcTestUtils} but for JdbcTemplate
|
||||
* rather than the deprecated SimpleJdbcTemplate.
|
||||
*
|
||||
* This class should be removed when Batch uses Spring 3.2 - see:
|
||||
* https://jira.springsource.org/browse/SPR-9235
|
||||
* </p>
|
||||
*/
|
||||
public final class JdbcTestUtils {
|
||||
private static final Log LOG = LogFactory.getLog(JdbcTestUtils.class);
|
||||
|
||||
private JdbcTestUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the rows in the given table.
|
||||
* @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations
|
||||
* @param tableName table name to count rows in
|
||||
* @return the number of rows in the table
|
||||
*/
|
||||
public static int countRowsInTable(JdbcOperations jdbcTemplate, String tableName) {
|
||||
return jdbcTemplate.queryForInt("SELECT COUNT(0) FROM " + tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all rows from the specified tables.
|
||||
* @param jdbcTemplate the SimpleJdbcTemplate with which to perform JDBC operations
|
||||
* @param tableNames the names of the tables from which to delete
|
||||
* @return the total number of rows deleted from all specified tables
|
||||
*/
|
||||
public static int deleteFromTables(JdbcOperations jdbcTemplate, String... tableNames) {
|
||||
int totalRowCount = 0;
|
||||
for (String tableName : tableNames) {
|
||||
int rowCount = jdbcTemplate.update("DELETE FROM " + tableName);
|
||||
totalRowCount += rowCount;
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("Deleted " + rowCount + " rows from table " + tableName);
|
||||
}
|
||||
}
|
||||
return totalRowCount;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml")
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.database.support.HsqlPagingQueryProvider;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "JpaPagingItemReaderCommonTests-context.xml")
|
||||
|
||||
@@ -24,10 +24,9 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -40,7 +39,7 @@ public class ParallelJobFunctionalTests {
|
||||
@Autowired
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteExcep
|
||||
import org.springframework.batch.core.repository.JobRestartException;
|
||||
import org.springframework.batch.sample.common.SkipCheckingListener;
|
||||
import org.springframework.batch.sample.domain.trade.internal.TradeWriter;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
@@ -167,7 +167,7 @@ public class SkipSampleFunctionalTests {
|
||||
private void validateLaunchWithSkips(JobExecution jobExecution) {
|
||||
// Step1: 9 input records, 1 skipped in read, 1 skipped in write =>
|
||||
// 7 written to output
|
||||
assertEquals(7, JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE"));
|
||||
assertEquals(7, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "TRADE"));
|
||||
|
||||
// Step2: 7 input records, 1 skipped on process, 1 on write => 5 written
|
||||
// to output
|
||||
@@ -178,7 +178,7 @@ public class SkipSampleFunctionalTests {
|
||||
assertEquals(1, SkipCheckingListener.getProcessSkips());
|
||||
|
||||
// Both steps contained skips
|
||||
assertEquals(2, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG"));
|
||||
assertEquals(2, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "ERROR_LOG"));
|
||||
|
||||
assertEquals("2 records were skipped!", jdbcTemplate.queryForObject(
|
||||
"SELECT MESSAGE from ERROR_LOG where JOB_NAME = ? and STEP_NAME = ?", String.class, "skipJob", "step1"));
|
||||
@@ -197,13 +197,13 @@ public class SkipSampleFunctionalTests {
|
||||
private void validateLaunchWithoutSkips(JobExecution jobExecution) {
|
||||
|
||||
// Step1: 5 input records => 5 written to output
|
||||
assertEquals(5, JdbcTestUtils.countRowsInTable(jdbcTemplate, "TRADE"));
|
||||
assertEquals(5, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "TRADE"));
|
||||
|
||||
// Step2: 5 input records => 5 written to output
|
||||
assertEquals(5, jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE where VERSION=?", 1));
|
||||
|
||||
// Neither step contained skips
|
||||
assertEquals(0, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG"));
|
||||
assertEquals(0, JdbcTestUtils.countRowsInTable((JdbcTemplate) jdbcTemplate, "ERROR_LOG"));
|
||||
|
||||
assertEquals(new BigDecimal("270.75"), jobExecution.getExecutionContext().get(TradeWriter.TOTAL_AMOUNT_KEY));
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.batch.support.JdbcTestUtils;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
|
||||
Reference in New Issue
Block a user