From 112150566c6aa548b473f07bda7e6b4f5d95594e Mon Sep 17 00:00:00 2001 From: dsyer Date: Wed, 19 Dec 2007 21:06:31 +0000 Subject: [PATCH] Re-instate tests for optimistic locking in step dao --- .../repository/dao/AbstractStepDaoTests.java | 41 +- .../dao/JdbcStepDaoPrefixTests.java | 6 - .../repository/dao/MockJdbcTemplate.java | 383 ------------------ 3 files changed, 19 insertions(+), 411 deletions(-) delete mode 100644 spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MockJdbcTemplate.java diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java index dd43e7a69..d9065ffbb 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java @@ -216,28 +216,25 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour stepDao.save(execution); assertEquals(2, stepDao.getStepExecutionCount(step1.getId())); } - -// Commenting out, since hibernate dao's are being deprecated for m4. -// public void testUpdateStepExecutionVersion() throws Exception { -// int before = stepExecution.getVersion().intValue(); -// stepDao.update(stepExecution); -// int after = stepExecution.getVersion().intValue(); -// assertEquals("StepExecution version not updated", before+1, after); -// } + + public void testUpdateStepExecutionVersion() throws Exception { + int before = stepExecution.getVersion().intValue(); + stepDao.update(stepExecution); + int after = stepExecution.getVersion().intValue(); + assertEquals("StepExecution version not updated", before+1, after); + } -// This test currently fails because it's expecting behaviour in the stepExecution that was lost because of -// how SVN handles file renaming, it should be relevant once the code is reintroduced. -// public void testUpdateStepExecutionOptimisticLocking() throws Exception { -// stepExecution.incrementVersion(); // not really allowed outside dao code -// try { -// stepDao.update(stepExecution); -// fail("Expected OptimisticLockingFailureException"); -// } -// catch (OptimisticLockingFailureException e) { -// // expected -// assertTrue("Exception message should contain step execution id: "+e.getMessage(), e.getMessage().indexOf(""+stepExecution.getId())>=0); -// assertTrue("Exception message should contain step execution version: "+e.getMessage(), e.getMessage().indexOf(""+stepExecution.getVersion())>=0); -// } -// } + public void testUpdateStepExecutionOptimisticLocking() throws Exception { + stepExecution.incrementVersion(); // not really allowed outside dao code + try { + stepDao.update(stepExecution); + fail("Expected OptimisticLockingFailureException"); + } + catch (OptimisticLockingFailureException e) { + // expected + assertTrue("Exception message should contain step execution id: "+e.getMessage(), e.getMessage().indexOf(""+stepExecution.getId())>=0); + assertTrue("Exception message should contain step execution version: "+e.getMessage(), e.getMessage().indexOf(""+stepExecution.getVersion())>=0); + } + } } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java index fd63efe97..eb7164013 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java @@ -171,17 +171,11 @@ public class JdbcStepDaoPrefixTests extends TestCase { return 1; } - /* (non-Javadoc) - * @see org.springframework.jdbc.core.JdbcTemplate#update(java.lang.String, java.lang.Object[], int[]) - */ public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException { this.sql = sql; return 1; } - /* (non-Javadoc) - * @see org.springframework.jdbc.core.JdbcTemplate#query(java.lang.String, java.lang.Object[], int[], org.springframework.jdbc.core.RowMapper) - */ public List query(String sql, Object[] args, RowMapper rowMapper) throws DataAccessException { this.sql = sql; return null; diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MockJdbcTemplate.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MockJdbcTemplate.java deleted file mode 100644 index b923b3340..000000000 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MockJdbcTemplate.java +++ /dev/null @@ -1,383 +0,0 @@ -package org.springframework.batch.execution.repository.dao; - -import java.util.List; -import java.util.Map; - -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.BatchPreparedStatementSetter; -import org.springframework.jdbc.core.CallableStatementCallback; -import org.springframework.jdbc.core.CallableStatementCreator; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.JdbcOperations; -import org.springframework.jdbc.core.PreparedStatementCallback; -import org.springframework.jdbc.core.PreparedStatementCreator; -import org.springframework.jdbc.core.PreparedStatementSetter; -import org.springframework.jdbc.core.ResultSetExtractor; -import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.core.StatementCallback; -import org.springframework.jdbc.support.KeyHolder; -import org.springframework.jdbc.support.rowset.SqlRowSet; - -public class MockJdbcTemplate implements JdbcOperations { - - private String sqlStatement = ""; - - public String getSqlStatement() { - return sqlStatement; - } - - public int[] batchUpdate(String[] sql) throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public int[] batchUpdate(String sql, BatchPreparedStatementSetter pss) - throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public Map call(CallableStatementCreator csc, List declaredParameters) - throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public Object execute(ConnectionCallback action) throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public Object execute(StatementCallback action) throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public void execute(String sql) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - } - - public Object execute(PreparedStatementCreator psc, - PreparedStatementCallback action) throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public Object execute(String sql, PreparedStatementCallback action) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object execute(CallableStatementCreator csc, - CallableStatementCallback action) throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public Object execute(String callString, CallableStatementCallback action) - throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public Object query(String sql, ResultSetExtractor rse) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public void query(String sql, RowCallbackHandler rch) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - } - - public List query(String sql, RowMapper rowMapper) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object query(PreparedStatementCreator psc, ResultSetExtractor rse) - throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public void query(PreparedStatementCreator psc, RowCallbackHandler rch) - throws DataAccessException { - // TODO Auto-generated method stub - } - - public List query(PreparedStatementCreator psc, RowMapper rowMapper) - throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public Object query(String sql, PreparedStatementSetter pss, - ResultSetExtractor rse) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object query(String sql, Object[] args, ResultSetExtractor rse) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public void query(String sql, PreparedStatementSetter pss, - RowCallbackHandler rch) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - } - - public void query(String sql, Object[] args, RowCallbackHandler rch) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - } - - public List query(String sql, PreparedStatementSetter pss, - RowMapper rowMapper) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public List query(String sql, Object[] args, RowMapper rowMapper) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object query(String sql, Object[] args, int[] argTypes, - ResultSetExtractor rse) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public void query(String sql, Object[] args, int[] argTypes, - RowCallbackHandler rch) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - } - - public List query(String sql, Object[] args, int[] argTypes, - RowMapper rowMapper) throws DataAccessException { - // TODO Auto-generated method stub - return null; - } - - public int queryForInt(String sql) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public int queryForInt(String sql, Object[] args) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public int queryForInt(String sql, Object[] args, int[] argTypes) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public List queryForList(String sql) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public List queryForList(String sql, Class elementType) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public List queryForList(String sql, Object[] args) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public List queryForList(String sql, Object[] args, Class elementType) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public List queryForList(String sql, Object[] args, int[] argTypes) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public List queryForList(String sql, Object[] args, int[] argTypes, - Class elementType) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public long queryForLong(String sql) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public long queryForLong(String sql, Object[] args) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public long queryForLong(String sql, Object[] args, int[] argTypes) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public Map queryForMap(String sql) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Map queryForMap(String sql, Object[] args) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Map queryForMap(String sql, Object[] args, int[] argTypes) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object queryForObject(String sql, RowMapper rowMapper) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object queryForObject(String sql, Class requiredType) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object queryForObject(String sql, Object[] args, RowMapper rowMapper) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object queryForObject(String sql, Object[] args, Class requiredType) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object queryForObject(String sql, Object[] args, int[] argTypes, - RowMapper rowMapper) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public Object queryForObject(String sql, Object[] args, int[] argTypes, - Class requiredType) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public SqlRowSet queryForRowSet(String sql) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public SqlRowSet queryForRowSet(String sql, Object[] args) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public SqlRowSet queryForRowSet(String sql, Object[] args, int[] argTypes) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return null; - } - - public int update(String sql) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public int update(PreparedStatementCreator psc) throws DataAccessException { - // TODO Auto-generated method stub - return 0; - } - - public int update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) - throws DataAccessException { - // TODO Auto-generated method stub - return 0; - } - - public int update(String sql, PreparedStatementSetter pss) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public int update(String sql, Object[] args) throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - - public int update(String sql, Object[] args, int[] argTypes) - throws DataAccessException { - // TODO Auto-generated method stub - sqlStatement = sql; - return 0; - } - -}