1
@Transactional
public Boolean save(final StudentLogEntry studentLogEntry) throws SQLException,DaoException{
boolean returnFlag = true;
String sqlInsert = "insert into STUDENT_DETAILS (INSERT_DATE,STUDENT_NAME,STUDENT_ID) values(SYSDATE,?,?)";
returnFlag = jdbcTemplate.execute(
sqlInsert,
new PreparedStatementCallback<Boolean>() {
Boolean b=false;
@Override
public Boolean doInPreparedStatement(PreparedStatement pst) {
try {
pst.setString(2, studentLogEntry.getStuName());
pst.setString(3, studentLogEntry.getStuId());
b=pst.execute();
} catch (SQLException e) {
clicklogger.info("SQLException has occurred while inserting studentlog ",e);
} catch (DataAccessException e) {
clicklogger.info("DataAccessException has occurred while inserting studentlog ",e);
}
return b;
}
}
);
return returnFlag;
}
내 프로젝트에 Spring 프레임 워크를 사용하고 있는데 위 코드에 대해 Junit 테스트 케이스를 작성했습니다. 그러나 나는 PreparedStatementCallback
을 다룰 수 없습니다. 내 테스트 케이스는 다음과 같습니다.PreparedStatementCallback 적용 범위에 대한 Junit 테스트 케이스
@Test
public void testSave() throws DaoException, SQLException {
studentDao.setJdbcTemplate(jdbcTemplate);
studentDao.setTransactionManager(transactionManager);
StudentLogEntry studentLogEntry = new StudentLogEntry();
studentLogEntry.getStuName("ABC");
studentLogEntry.getStuId("1234");
assertEquals("true",studentDao.save(studentLogEntry));
}
테스트를 실행하는 동안'save' 메소드를 디버깅하려 했습니까? 특히'jdbcTemplate.execute (...)'를 호출하십시오. –
예 테스트하는 동안 save 메소드를 디버깅했습니다. doInPreparedStatement 내부에 입력하면 컨트롤이 실패합니다. –