BATCH-1891: Migrate usage of deprecated classes

This commit is contained in:
Chris Schaefer
2012-09-16 23:30:12 -04:00
committed by Dave Syer
parent b1246f99b1
commit d0e0334674
58 changed files with 282 additions and 253 deletions

View File

@@ -53,11 +53,9 @@ import org.springframework.batch.retry.RetryListener;
import org.springframework.batch.retry.listener.RetryListenerSupport;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.dao.DeadlockLoserDataAccessException;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.PlatformTransactionManager;
@@ -150,14 +148,14 @@ public class StepParserTests {
@Test(expected = BeanDefinitionParsingException.class)
public void testTaskletStepWithBadStepListener() throws Exception {
String contextLocation = "org/springframework/batch/core/configuration/xml/StepParserBadStepListenerTests-context.xml";
new XmlBeanFactory(new ClassPathResource(contextLocation));
new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/StepParserBadStepListenerTests-context.xml");
}
@Test(expected = BeanDefinitionParsingException.class)
public void testTaskletStepWithBadRetryListener() throws Exception {
String contextLocation = "org/springframework/batch/core/configuration/xml/StepParserBadRetryListenerTests-context.xml";
new XmlBeanFactory(new ClassPathResource(contextLocation));
new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/StepParserBadRetryListenerTests-context.xml");
}
@Test

View File

@@ -14,7 +14,7 @@ import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -22,7 +22,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class JobLauncherIntegrationTests {
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
private JobLauncher jobLauncher;
@@ -32,7 +32,7 @@ public class JobLauncherIntegrationTests {
@Autowired
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new SimpleJdbcTemplate(dataSource);
jdbcTemplate = new JdbcTemplate(dataSource);
}
@Test

View File

@@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

View File

@@ -31,7 +31,7 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -49,11 +49,11 @@ public class RestartIntegrationTests {
@Autowired
private Job job;
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Test

View File

@@ -26,7 +26,7 @@ import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -44,11 +44,11 @@ public class VanillaIntegrationTests {
@Autowired
private Job job;
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Test

View File

@@ -37,7 +37,7 @@ import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -61,11 +61,11 @@ public abstract class AbstractJobDaoTests {
protected Date jobExecutionStartTime = new Date(System.currentTimeMillis());
protected SimpleJdbcTemplate simpleJdbcTemplate;
protected JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
/*
@@ -98,14 +98,14 @@ public abstract class AbstractJobDaoTests {
@Transactional @Test
public void testVersionIsNotNullForJob() throws Exception {
int version = simpleJdbcTemplate.queryForInt("select version from BATCH_JOB_INSTANCE where JOB_INSTANCE_ID="
int version = jdbcTemplate.queryForInt("select version from BATCH_JOB_INSTANCE where JOB_INSTANCE_ID="
+ jobInstance.getId());
assertEquals(0, version);
}
@Transactional @Test
public void testVersionIsNotNullForJobExecution() throws Exception {
int version = simpleJdbcTemplate.queryForInt("select version from BATCH_JOB_EXECUTION where JOB_EXECUTION_ID="
int version = jdbcTemplate.queryForInt("select version from BATCH_JOB_EXECUTION where JOB_EXECUTION_ID="
+ jobExecution.getId());
assertEquals(0, version);
}
@@ -221,7 +221,7 @@ public abstract class AbstractJobDaoTests {
// Create job.
jobInstance = jobInstanceDao.createJobInstance(testJob, jobParameters);
List<Map<String, Object>> jobs = simpleJdbcTemplate.queryForList(
List<Map<String, Object>> jobs = jdbcTemplate.queryForList(
"SELECT * FROM BATCH_JOB_INSTANCE where JOB_INSTANCE_ID=?",
jobInstance.getId());
assertEquals(1, jobs.size());

View File

@@ -25,7 +25,6 @@ import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
/**
@@ -64,12 +63,12 @@ public class JdbcJobDaoQueryTests extends TestCase {
public void testTablePrefix() throws Exception {
jobExecutionDao.setTablePrefix("FOO_");
jobExecutionDao.setJdbcTemplate(new SimpleJdbcTemplate(new JdbcTemplate() {
jobExecutionDao.setJdbcTemplate(new JdbcTemplate() {
public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException {
list.add(sql);
return 1;
}
}));
});
JobExecution jobExecution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "testJob"));
jobExecutionDao.saveJobExecution(jobExecution);

View File

@@ -34,7 +34,7 @@ public class JdbcJobDaoTests extends AbstractJobDaoTests {
.addExitDescription(LONG_STRING));
jobExecutionDao.updateJobExecution(jobExecution);
List<Map<String, Object>> executions = simpleJdbcTemplate.queryForList(
List<Map<String, Object>> executions = jdbcTemplate.queryForList(
"SELECT * FROM BATCH_JOB_EXECUTION where JOB_INSTANCE_ID=?",
jobInstance.getId());
assertEquals(1, executions.size());

View File

@@ -4,10 +4,10 @@ import javax.sql.DataSource;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
import org.springframework.batch.support.JdbcTestUtils;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "sql-dao-test.xml" })
@@ -22,11 +22,11 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
@Autowired
private JobInstanceDao jobInstanceDao;
private SimpleJdbcTemplate simpleJdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
@@ -36,9 +36,9 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
@Override
protected JobExecutionDao getJobExecutionDao() {
SimpleJdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT",
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS",
"BATCH_JOB_INSTANCE");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT",
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS",
"BATCH_JOB_INSTANCE");
return jobExecutionDao;
}

View File

@@ -14,21 +14,21 @@ import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
import org.springframework.batch.support.JdbcTestUtils;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "sql-dao-test.xml")
public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
private SimpleJdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Autowired
@@ -38,9 +38,9 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
private JobExecutionDao jobExecutionDao;
protected JobInstanceDao getJobInstanceDao() {
SimpleJdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT",
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION",
"BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS", "BATCH_JOB_INSTANCE");
JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT",
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION",
"BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS", "BATCH_JOB_INSTANCE");
return jobInstanceDao;
}

View File

@@ -3,8 +3,7 @@ package org.springframework.batch.core.repository.dao;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
@@ -13,7 +12,7 @@ import org.springframework.batch.item.ExecutionContext;
/**
* Tests for {@link MapExecutionContextDao}.
*/
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class MapExecutionContextDaoTests extends AbstractExecutionContextDaoTests {
@Override

View File

@@ -1,29 +1,24 @@
package org.springframework.batch.core.repository.dao;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import static org.junit.Assert.*;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class MapJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
@Override

View File

@@ -1,9 +1,9 @@
package org.springframework.batch.core.repository.dao;
import org.junit.runner.RunWith;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class MapJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
protected JobInstanceDao getJobInstanceDao() {

View File

@@ -7,7 +7,7 @@ import static org.junit.Assert.assertNull;
import java.util.Date;
import org.junit.Test;
import org.junit.internal.runners.JUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
@@ -15,7 +15,7 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.SimpleJobRepository;
@RunWith(JUnit4ClassRunner.class)
@RunWith(JUnit4.class)
public class MapStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
protected StepExecutionDao getStepExecutionDao() {

View File

@@ -31,10 +31,10 @@ 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.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.jdbc.SimpleJdbcTestUtils;
import org.springframework.batch.support.JdbcTestUtils;
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -46,18 +46,18 @@ public class TablePrefixTests {
@Autowired
private Job job;
private SimpleJdbcTemplate simpleJdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Test
public void testJobLaunch() throws Exception {
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
assertEquals(1, SimpleJdbcTestUtils.countRowsInTable(simpleJdbcTemplate, "PREFIX_JOB_INSTANCE"));
assertEquals(1, JdbcTestUtils.countRowsInTable(jdbcTemplate, "PREFIX_JOB_INSTANCE"));
}
public static class TestTasklet implements Tasklet {

View File

@@ -36,7 +36,7 @@ import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
@@ -55,11 +55,11 @@ public class ListPreparedStatementSetterTests {
StepExecution stepExecution;
private SimpleJdbcTemplate simpleJdbcTemplate;
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Autowired
@@ -86,7 +86,7 @@ public class ListPreparedStatementSetterTests {
public void testSetValues() {
final List<String> results = new ArrayList<String>();
simpleJdbcTemplate.getJdbcOperations().query("SELECT NAME from T_FOOS where ID > ? and ID < ?", pss,
jdbcTemplate.query("SELECT NAME from T_FOOS where ID > ? and ID < ?", pss,
new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
results.add(rs.getString(1));
@@ -107,12 +107,12 @@ public class ListPreparedStatementSetterTests {
@Test
public void testXmlConfiguration() throws Exception {
this.simpleJdbcTemplate.update("create table FOO (ID integer, NAME varchar(40), VALUE integer)");
this.jdbcTemplate.update("create table FOO (ID integer, NAME varchar(40), VALUE integer)");
try {
this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 0, "zero", 0);
this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 1, "one", 1);
this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 2, "two", 2);
this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 3, "three", 3);
this.jdbcTemplate.update("insert into FOO values (?,?,?)", 0, "zero", 0);
this.jdbcTemplate.update("insert into FOO values (?,?,?)", 1, "one", 1);
this.jdbcTemplate.update("insert into FOO values (?,?,?)", 2, "two", 2);
this.jdbcTemplate.update("insert into FOO values (?,?,?)", 3, "three", 3);
JobParametersBuilder builder = new JobParametersBuilder().addLong("min.id", 1L).addLong("max.id", 2L);
JobExecution jobExecution = this.jobLauncher.run(this.job, builder.toJobParameters());
@@ -126,7 +126,7 @@ public class ListPreparedStatementSetterTests {
assertEquals(new Foo(2, "two", 2), foos.get(1));
}
finally {
this.simpleJdbcTemplate.update("drop table FOO");
this.jdbcTemplate.update("drop table FOO");
}
}

View File

@@ -136,10 +136,8 @@ public class AsyncStepScopeIntegrationTests implements BeanFactoryAware {
taskExecutor.execute(task);
}
int i = 0;
for (FutureTask<String> task : tasks) {
assertEquals("foo", task.get());
i++;
}
// Don't close the outer scope until all tasks are finished. This should