IN PROGRESS - BATCH-672: updated tests to use SimpleJdbcTemplate
This commit is contained in:
@@ -100,7 +100,9 @@ public class PlayerSummary {
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Player Summary: ID=" + id + " Year=" + year;
|
||||
return "Player Summary: ID=" + id + " Year=" + year + "[" + completes + ";" + attempts + ";" + passingYards +
|
||||
";" + passingTd + ";" + interceptions + ";" + rushes + ";" + rushYards + ";" + receptions +
|
||||
";" + receptionYards + ";" + totalTd;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
@@ -5,24 +5,29 @@ package org.springframework.batch.sample.domain.football.internal;
|
||||
|
||||
import org.springframework.batch.sample.domain.football.Player;
|
||||
import org.springframework.batch.sample.domain.football.PlayerDao;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JdbcPlayerDao extends JdbcDaoSupport implements PlayerDao {
|
||||
public class JdbcPlayerDao extends SimpleJdbcDaoSupport implements PlayerDao {
|
||||
|
||||
public static final String INSERT_PLAYER = "INSERT into players(player_id, " +
|
||||
"last_name, first_name, pos, year_of_birth, year_drafted)" +
|
||||
" values (?,?,?,?,?,?)";
|
||||
public static final String INSERT_PLAYER =
|
||||
"INSERT into players(player_id, last_name, first_name, pos, year_of_birth, year_drafted)" +
|
||||
" values (:id, :lastName, :firstName, :position, :birthYear, :debutYear)";
|
||||
|
||||
public void savePlayer(Player player) {
|
||||
|
||||
getJdbcTemplate().update(INSERT_PLAYER,
|
||||
new Object[]{player.getID(),player.getLastName(),
|
||||
player.getFirstName(), player.getPosition(),
|
||||
new Integer(player.getBirthYear()),
|
||||
new Integer(player.getDebutYear())});
|
||||
getSimpleJdbcTemplate().update(INSERT_PLAYER,
|
||||
// ToDo: new BeanPropertySqlParameterSource(player));
|
||||
new MapSqlParameterSource()
|
||||
.addValue("id", player.getID())
|
||||
.addValue("lastName", player.getLastName())
|
||||
.addValue("firstName",player.getFirstName())
|
||||
.addValue("position", player.getPosition())
|
||||
.addValue("birthYear", player.getBirthYear())
|
||||
.addValue("debutYear", player.getDebutYear()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,24 +4,35 @@ import org.springframework.batch.item.ClearFailedException;
|
||||
import org.springframework.batch.item.FlushFailedException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.football.PlayerSummary;
|
||||
import org.springframework.jdbc.core.support.JdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
|
||||
public class JdbcPlayerSummaryDao extends JdbcDaoSupport implements ItemWriter<PlayerSummary> {
|
||||
public class JdbcPlayerSummaryDao extends SimpleJdbcDaoSupport implements ItemWriter<PlayerSummary> {
|
||||
|
||||
private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID,YEAR_NO,COMPLETES,ATTEMPTS," +
|
||||
"PASSING_YARDS,PASSING_TD,INTERCEPTIONS,RUSHES,RUSH_YARDS,RECEPTIONS,RECEPTIONS_YARDS," +
|
||||
"TOTAL_TD) values(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
private static final String INSERT_SUMMARY =
|
||||
"INSERT into PLAYER_SUMMARY(ID, YEAR_NO, COMPLETES, ATTEMPTS, PASSING_YARDS, PASSING_TD, " +
|
||||
"INTERCEPTIONS, RUSHES, RUSH_YARDS, RECEPTIONS, RECEPTIONS_YARDS, TOTAL_TD) " +
|
||||
"values(:id, :year, :completes, :attempts, :passingYards, :passingTd, " +
|
||||
":interceptions, :rushes, :rushYards, :receptions, :receptionYards, :totalTd)";
|
||||
|
||||
public void write(PlayerSummary summary) {
|
||||
|
||||
Object[] args = new Object[]{summary.getId(), new Integer(summary.getYear()),
|
||||
new Integer(summary.getCompletes()), new Integer(summary.getAttempts()),
|
||||
new Integer(summary.getPassingYards()), new Integer(summary.getPassingTd()),
|
||||
new Integer(summary.getInterceptions()), new Integer(summary.getRushes()),
|
||||
new Integer(summary.getRushYards()), new Integer(summary.getReceptions()),
|
||||
new Integer(summary.getReceptionYards()), new Integer(summary.getTotalTd()) };
|
||||
MapSqlParameterSource args = new MapSqlParameterSource()
|
||||
.addValue("id", summary.getId())
|
||||
.addValue("year", summary.getYear())
|
||||
.addValue("completes", summary.getCompletes())
|
||||
.addValue("attempts", summary.getAttempts())
|
||||
.addValue("passingYards", summary.getPassingYards())
|
||||
.addValue("passingTd", summary.getPassingTd())
|
||||
.addValue("interceptions", summary.getInterceptions())
|
||||
.addValue("rushes", summary.getRushes())
|
||||
.addValue("rushYards", summary.getRushYards())
|
||||
.addValue("receptions", summary.getReceptions())
|
||||
.addValue("receptionYards", summary.getReceptionYards())
|
||||
.addValue("totalTd", summary.getTotalTd());
|
||||
|
||||
getSimpleJdbcTemplate().update(INSERT_SUMMARY, args);
|
||||
|
||||
getJdbcTemplate().update(INSERT_SUMMARY, args);
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.batch.sample.domain.football.PlayerSummary;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
|
||||
/**
|
||||
* RowMapper used to map a ResultSet to a (@link PlayerSummary)
|
||||
@@ -27,12 +27,12 @@ import org.springframework.jdbc.core.RowMapper;
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class PlayerSummaryMapper implements RowMapper {
|
||||
public class PlayerSummaryMapper implements ParameterizedRowMapper<PlayerSummary> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
|
||||
*/
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
public PlayerSummary mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
|
||||
PlayerSummary summary = new PlayerSummary();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.sample.support.ItemTrackingItemWriter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -24,24 +24,24 @@ public class SkipSampleFunctionalTests extends AbstractValidatingBatchLauncherTe
|
||||
|
||||
int before = -1;
|
||||
|
||||
JdbcTemplate jdbcTemplate;
|
||||
SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
ItemTrackingItemWriter<?> writer;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void onSetUp() throws Exception {
|
||||
before = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
}
|
||||
|
||||
protected void validatePostConditions() throws Exception {
|
||||
|
||||
int after = jdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from TRADE");
|
||||
// 5 input records, 1 skipped => 4 written to output
|
||||
assertEquals(before + 4, after);
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -37,9 +36,8 @@ import org.springframework.batch.sample.domain.trade.Trade;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -56,23 +54,21 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
private List<Trade> trades;
|
||||
private int activeRow = 0;
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
private Map<String, Double> credits = new HashMap<String, Double>();
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void onSetUp() throws Exception {
|
||||
// super.onSetUp();
|
||||
jdbcTemplate.update("delete from TRADE");
|
||||
List<Map<?, ?>> list = jdbcTemplate.queryForList("select name, CREDIT from customer");
|
||||
for (Iterator<Map<?,?>> iterator = list.iterator(); iterator.hasNext();) {
|
||||
Map<?,?> map = iterator.next();
|
||||
credits.put((String) map.get("NAME"), new Double(((Number)map.get("CREDIT")).doubleValue()));
|
||||
simpleJdbcTemplate.update("delete from TRADE");
|
||||
List<Map<String, Object>> list = simpleJdbcTemplate.queryForList("select name, CREDIT from customer");
|
||||
for (Map<String, Object> map : list) {
|
||||
credits.put((String) map.get("NAME"), ((Number) map.get("CREDIT")).doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +81,10 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
|
||||
// assertTrue(((Resource)applicationContext.getBean("customerFileLocator")).exists());
|
||||
|
||||
customers = new ArrayList<Customer>() {{add(new Customer("customer1", (credits.get("customer1").doubleValue() - 98.34)));
|
||||
add(new Customer("customer2", (credits.get("customer2").doubleValue() - 18.12 - 12.78)));
|
||||
add(new Customer("customer3", (credits.get("customer3").doubleValue() - 109.25)));
|
||||
add(new Customer("customer4", (credits.get("customer4").doubleValue() - 123.39)));}};
|
||||
customers = new ArrayList<Customer>() {{add(new Customer("customer1", (credits.get("customer1") - 98.34)));
|
||||
add(new Customer("customer2", (credits.get("customer2") - 18.12 - 12.78)));
|
||||
add(new Customer("customer3", (credits.get("customer3") - 109.25)));
|
||||
add(new Customer("customer4", credits.get("customer4") - 123.39));}};
|
||||
|
||||
trades = new ArrayList<Trade>() {{add(new Trade("UK21341EAH45", 978, new BigDecimal("98.34"), "customer1"));
|
||||
add(new Trade("UK21341EAH46", 112, new BigDecimal("18.12"), "customer2"));
|
||||
@@ -97,10 +93,10 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
add(new Trade("UK21341EAH49", 854, new BigDecimal("123.39"), "customer4"));}};
|
||||
|
||||
// check content of the trade table
|
||||
jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
|
||||
simpleJdbcTemplate.getJdbcOperations().query(GET_TRADES, new RowCallbackHandler() {
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Trade trade = (Trade)trades.get(activeRow++);
|
||||
Trade trade = trades.get(activeRow++);
|
||||
|
||||
assertTrue(trade.getIsin().equals(rs.getString(1)));
|
||||
assertTrue(trade.getQuantity() == rs.getLong(2));
|
||||
@@ -113,10 +109,10 @@ public class TradeJobFunctionalTests extends AbstractValidatingBatchLauncherTest
|
||||
|
||||
// check content of the customer table
|
||||
activeRow = 0;
|
||||
jdbcTemplate.query(GET_CUSTOMERS, new RowCallbackHandler() {
|
||||
simpleJdbcTemplate.getJdbcOperations().query(GET_CUSTOMERS, new RowCallbackHandler() {
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
Customer customer = (Customer)customers.get(activeRow++);
|
||||
Customer customer = customers.get(activeRow++);
|
||||
|
||||
assertEquals(customer.getName(),rs.getString(1));
|
||||
assertEquals(customer.getCredit(), rs.getDouble(2), .01);
|
||||
|
||||
@@ -13,11 +13,8 @@ import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.sample.common.StagingItemReader;
|
||||
import org.springframework.batch.sample.common.StagingItemWriter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -31,7 +28,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
@ContextConfiguration()
|
||||
public class StagingItemReaderTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
@@ -45,13 +42,9 @@ public class StagingItemReaderTests {
|
||||
private Long jobId = 11L;
|
||||
|
||||
|
||||
public JdbcOperations getJdbcTemplate() {
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -70,23 +63,23 @@ public class StagingItemReaderTests {
|
||||
@After
|
||||
public void onTearDownAfterTransaction() throws Exception {
|
||||
reader.close(null);
|
||||
getJdbcTemplate().update("DELETE FROM BATCH_STAGING");
|
||||
simpleJdbcTemplate.update("DELETE FROM BATCH_STAGING");
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
public void testReaderUpdatesProcessIndicator() throws Exception {
|
||||
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
String before = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { id }, String.class);
|
||||
long id = simpleJdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
jobId);
|
||||
String before = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, id);
|
||||
assertEquals(StagingItemWriter.NEW, before);
|
||||
|
||||
String item = reader.read();
|
||||
assertEquals("FOO", item);
|
||||
|
||||
String after = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { id }, String.class);
|
||||
String after = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, id);
|
||||
assertEquals(StagingItemWriter.DONE, after);
|
||||
|
||||
}
|
||||
@@ -98,11 +91,11 @@ public class StagingItemReaderTests {
|
||||
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
txTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus transactionStatus) {
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
long id = simpleJdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
jobId);
|
||||
String before =
|
||||
(String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { id }, String.class);
|
||||
simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, id);
|
||||
assertEquals(StagingItemWriter.DONE, before);
|
||||
return null;
|
||||
}
|
||||
@@ -119,8 +112,8 @@ public class StagingItemReaderTests {
|
||||
|
||||
txTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus transactionStatus) {
|
||||
int count = getJdbcTemplate().queryForInt("SELECT COUNT(*) from BATCH_STAGING where JOB_ID=? AND PROCESSED=?",
|
||||
new Object[] { jobId, StagingItemWriter.NEW });
|
||||
int count = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING where JOB_ID=? AND PROCESSED=?",
|
||||
jobId, StagingItemWriter.NEW);
|
||||
assertEquals(4, count);
|
||||
|
||||
Object item = reader.read();
|
||||
@@ -178,10 +171,10 @@ public class StagingItemReaderTests {
|
||||
final Long idToUse = (Long)txTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus transactionStatus) {
|
||||
|
||||
long id = getJdbcTemplate().queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
new Object[] { jobId });
|
||||
String before = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { id }, String.class);
|
||||
long id = simpleJdbcTemplate.queryForLong("SELECT MIN(ID) from BATCH_STAGING where JOB_ID=?",
|
||||
jobId);
|
||||
String before = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, id);
|
||||
assertEquals(StagingItemWriter.NEW, before);
|
||||
|
||||
Object item = reader.read();
|
||||
@@ -200,8 +193,8 @@ public class StagingItemReaderTests {
|
||||
txTemplate.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus transactionStatus) {
|
||||
|
||||
String after = (String) getJdbcTemplate().queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
new Object[] { idToUse }, String.class);
|
||||
String after = simpleJdbcTemplate.queryForObject("SELECT PROCESSED from BATCH_STAGING where ID=?",
|
||||
String.class, idToUse);
|
||||
assertEquals(StagingItemWriter.NEW, after);
|
||||
|
||||
Object item = reader.read();
|
||||
|
||||
@@ -26,10 +26,8 @@ import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.sample.common.StagingItemWriter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -38,23 +36,19 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@ContextConfiguration()
|
||||
public class StagingItemWriterTests {
|
||||
|
||||
private JdbcOperations jdbcTemplate;
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private StagingItemWriter<String> writer;
|
||||
|
||||
public JdbcOperations getJdbcTemplate() {
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void onSetUpBeforeTransaction() throws Exception {
|
||||
StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(new Long(12L),
|
||||
StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(12L,
|
||||
new JobParameters(), "testJob")));
|
||||
writer.beforeStep(stepExecution);
|
||||
}
|
||||
@@ -62,9 +56,9 @@ public class StagingItemWriterTests {
|
||||
@Transactional
|
||||
@Test
|
||||
public void testProcessInsertsNewItem() throws Exception {
|
||||
int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) from BATCH_STAGING");
|
||||
int before = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING");
|
||||
writer.write("FOO");
|
||||
int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) from BATCH_STAGING");
|
||||
int after = simpleJdbcTemplate.queryForInt("SELECT COUNT(*) from BATCH_STAGING");
|
||||
assertEquals(before + 1, after);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.sample.domain.football.Player;
|
||||
import org.springframework.batch.sample.domain.football.internal.JdbcPlayerDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -48,14 +47,14 @@ public class JdbcPlayerDaoIntegrationTests {
|
||||
|
||||
private static final String GET_PLAYER = "SELECT * from PLAYERS";
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void init(DataSource dataSource) {
|
||||
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
playerDao = new JdbcPlayerDao();
|
||||
playerDao.setJdbcTemplate(this.jdbcTemplate);
|
||||
playerDao.setDataSource(dataSource);
|
||||
|
||||
player = new Player();
|
||||
player.setID("AKFJDL00");
|
||||
@@ -71,7 +70,7 @@ public class JdbcPlayerDaoIntegrationTests {
|
||||
@Before
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
|
||||
jdbcTemplate.execute("delete from PLAYERS");
|
||||
simpleJdbcTemplate.getJdbcOperations().execute("delete from PLAYERS");
|
||||
|
||||
}
|
||||
|
||||
@@ -80,7 +79,7 @@ public class JdbcPlayerDaoIntegrationTests {
|
||||
|
||||
playerDao.savePlayer(player);
|
||||
|
||||
jdbcTemplate.query(GET_PLAYER, new RowCallbackHandler(){
|
||||
simpleJdbcTemplate.getJdbcOperations().query(GET_PLAYER, new RowCallbackHandler(){
|
||||
|
||||
public void processRow(ResultSet rs) throws SQLException {
|
||||
assertEquals(rs.getString("PLAYER_ID"), "AKFJDL00");
|
||||
|
||||
@@ -23,10 +23,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.sample.domain.football.PlayerSummary;
|
||||
import org.springframework.batch.sample.domain.football.internal.JdbcPlayerSummaryDao;
|
||||
import org.springframework.batch.sample.domain.football.internal.PlayerSummaryMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -44,14 +42,14 @@ public class JdbcPlayerSummaryDaoIntegrationTests {
|
||||
|
||||
private PlayerSummary summary;
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public void init(DataSource dataSource) {
|
||||
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||||
playerSummaryDao = new JdbcPlayerSummaryDao();
|
||||
playerSummaryDao.setJdbcTemplate(this.jdbcTemplate);
|
||||
playerSummaryDao.setDataSource(dataSource);
|
||||
|
||||
summary = new PlayerSummary();
|
||||
summary.setId("AikmTr00");
|
||||
@@ -72,7 +70,7 @@ public class JdbcPlayerSummaryDaoIntegrationTests {
|
||||
@Before
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
|
||||
jdbcTemplate.execute("delete from PLAYER_SUMMARY");
|
||||
simpleJdbcTemplate.getJdbcOperations().execute("delete from PLAYER_SUMMARY");
|
||||
|
||||
}
|
||||
|
||||
@@ -81,10 +79,11 @@ public class JdbcPlayerSummaryDaoIntegrationTests {
|
||||
|
||||
playerSummaryDao.write(summary);
|
||||
|
||||
PlayerSummary testSummary = (PlayerSummary) jdbcTemplate.queryForObject("SELECT * FROM PLAYER_SUMMARY",
|
||||
PlayerSummary testSummary = simpleJdbcTemplate.queryForObject("SELECT * FROM PLAYER_SUMMARY",
|
||||
new PlayerSummaryMapper());
|
||||
|
||||
assertEquals(testSummary, summary);
|
||||
assertEquals(summary, testSummary);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user