use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class JdbcTemplateTests method testStaticResultSetClosed.
@Test
public void testStaticResultSetClosed() throws Exception {
ResultSet resultSet2 = mock(ResultSet.class);
reset(this.preparedStatement);
given(this.preparedStatement.executeQuery()).willReturn(resultSet2);
given(this.connection.createStatement()).willReturn(this.statement);
try {
this.template.query("my query", new ResultSetExtractor<Object>() {
@Override
public Object extractData(ResultSet rs) {
throw new InvalidDataAccessApiUsageException("");
}
});
fail("Should have thrown InvalidDataAccessApiUsageException");
} catch (InvalidDataAccessApiUsageException idaauex) {
// ok
}
try {
this.template.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
return con.prepareStatement("my query");
}
}, new ResultSetExtractor<Object>() {
@Override
public Object extractData(ResultSet rs2) {
throw new InvalidDataAccessApiUsageException("");
}
});
fail("Should have thrown InvalidDataAccessApiUsageException");
} catch (InvalidDataAccessApiUsageException idaauex) {
// ok
}
verify(this.resultSet).close();
verify(resultSet2).close();
verify(this.preparedStatement).close();
verify(this.connection, atLeastOnce()).close();
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class EntityManagerFactoryUtilsTests method testTranslatesIllegalStateException.
@Test
public void testTranslatesIllegalStateException() {
IllegalStateException ise = new IllegalStateException();
DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ise);
assertSame(ise, dex.getCause());
assertTrue(dex instanceof InvalidDataAccessApiUsageException);
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class DataAccessUtilsTests method exceptionTranslationWithTranslation.
@Test
public void exceptionTranslationWithTranslation() {
MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator();
RuntimeException in = new RuntimeException("in");
InvalidDataAccessApiUsageException out = new InvalidDataAccessApiUsageException("out");
mpet.addTranslation(in, out);
assertSame(out, DataAccessUtils.translateIfNecessary(in, mpet));
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class EntityManagerFactoryUtilsTests method testTranslatesIllegalArgumentException.
@Test
public void testTranslatesIllegalArgumentException() {
IllegalArgumentException iae = new IllegalArgumentException();
DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(iae);
assertSame(iae, dex.getCause());
assertTrue(dex instanceof InvalidDataAccessApiUsageException);
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class PersistenceExceptionTranslationAdvisorTests method createProxy.
protected RepositoryInterface createProxy(RepositoryInterfaceImpl target) {
MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator();
mpet.addTranslation(persistenceException1, new InvalidDataAccessApiUsageException("", persistenceException1));
ProxyFactory pf = new ProxyFactory(target);
pf.addInterface(RepositoryInterface.class);
addPersistenceExceptionTranslation(pf, mpet);
return (RepositoryInterface) pf.getProxy();
}
Aggregations