private void testMalformedSqlStateCode(SQLException sex) { try { throw this.trans.translate("task", sql, sex); } catch (UncategorizedSQLException ex) { // OK assertTrue("SQL is correct", sql.equals(ex.getSql())); assertTrue("Exception matches", sex.equals(ex.getSQLException())); } }
@Test public void invalidSqlStateCode() { SQLException sex = new SQLException("Message", "NO SUCH CODE", 1); try { throw this.trans.translate("task", sql, sex); } catch (UncategorizedSQLException ex) { // OK assertTrue("SQL is correct", sql.equals(ex.getSql())); assertTrue("Exception matches", sex.equals(ex.getSQLException())); } }
@Test public void testBatchUpdateWithBatchFailure() throws Exception { final String[] sql = {"A", "B", "C", "D"}; given(this.statement.executeBatch()).willThrow( new BatchUpdateException(new int[] {1, Statement.EXECUTE_FAILED, 1, Statement.EXECUTE_FAILED})); mockDatabaseMetaData(true); given(this.connection.createStatement()).willReturn(this.statement); JdbcTemplate template = new JdbcTemplate(this.dataSource, false); try { template.batchUpdate(sql); } catch (UncategorizedSQLException ex) { assertThat(ex.getSql(), equalTo("B; D")); } }