List of usage examples for org.springframework.dao UncategorizedDataAccessException getCause
public synchronized Throwable getCause()
From source file:org.springframework.jdbc.core.JdbcTemplateTests.java
public void testBogusUpdate() throws Exception { final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?"; final int idParam = 6666; // It's because Integers aren't canonical SQLException sex = new SQLException("bad update"); MockControl ctrlPreparedStatement = MockControl.createControl(PreparedStatement.class); PreparedStatement mockPreparedStatement = (PreparedStatement) ctrlPreparedStatement.getMock(); mockPreparedStatement.setInt(1, idParam); ctrlPreparedStatement.setVoidCallable(); mockPreparedStatement.executeUpdate(); ctrlPreparedStatement.setThrowable(sex); mockPreparedStatement.close();/* w ww . j ava2 s.c o m*/ ctrlPreparedStatement.setVoidCallable(); mockConnection.prepareStatement(sql); ctrlConnection.setReturnValue(mockPreparedStatement); ctrlPreparedStatement.replay(); replay(); Dispatcher d = new Dispatcher(idParam, sql); JdbcTemplate template = new JdbcTemplate(mockDataSource); try { template.update(d); fail("Bogus update should throw exception"); } catch (UncategorizedDataAccessException ex) { // pass assertTrue("Correct exception", ex instanceof UncategorizedSQLException); assertTrue("Root cause is correct", ex.getCause() == sex); //assertTrue("no update occurred", !je.getDataWasUpdated()); } ctrlPreparedStatement.verify(); }