Non transient exception (#563)
* non transient data access exception examples * change to derby db * change to in memory derby db * delete failed test * fix invalidresource test
This commit is contained in:
parent
7c34948ade
commit
67f24c25af
|
@ -17,22 +17,27 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
|||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { Cause1NonTransientConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class InvalidResourceUsageExceptionTest {
|
||||
@Autowired
|
||||
private IFooService fooService;
|
||||
@Autowired
|
||||
private IFooService fooService;
|
||||
|
||||
@Autowired
|
||||
private DataSource restDataSource;
|
||||
@Autowired
|
||||
private DataSource restDataSource;
|
||||
|
||||
@Test(expected = InvalidDataAccessResourceUsageException.class)
|
||||
public void whenRetrievingDataUserNoSelectRights_thenInvalidResourceUsageException() {
|
||||
fooService.findAll();
|
||||
}
|
||||
@Test(expected = InvalidDataAccessResourceUsageException.class)
|
||||
public void whenRetrievingDataUserNoSelectRights_thenInvalidResourceUsageException() {
|
||||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(restDataSource);
|
||||
jdbcTemplate.execute("revoke select from tutorialuser");
|
||||
|
||||
@Test(expected = BadSqlGrammarException.class)
|
||||
public void whenIncorrectSql_thenBadSqlGrammarException() {
|
||||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(restDataSource);
|
||||
fooService.findAll();
|
||||
|
||||
jdbcTemplate.queryForObject("select * fro foo where id=3", Integer.class);
|
||||
}
|
||||
jdbcTemplate.execute("grant select to tutorialuser");
|
||||
}
|
||||
|
||||
@Test(expected = BadSqlGrammarException.class)
|
||||
public void whenIncorrectSql_thenBadSqlGrammarException() {
|
||||
final JdbcTemplate jdbcTemplate = new JdbcTemplate(restDataSource);
|
||||
|
||||
jdbcTemplate.queryForObject("select * fro foo where id=3", Integer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package org.baeldung.ex.nontransientdataaccessexception;
|
||||
|
||||
import org.baeldung.ex.nontransientexception.cause.Cause1NonTransientConfig;
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.persistence.service.IFooService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.PermissionDeniedDataAccessException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { Cause1NonTransientConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class PermissionDeniedException {
|
||||
|
||||
@Autowired
|
||||
private IFooService fooService;
|
||||
|
||||
@Test(expected = PermissionDeniedDataAccessException.class)
|
||||
public void whenRetrievingDataUserNoSelectRights_thenPermissionDeniedException() {
|
||||
final Foo foo = new Foo("foo");
|
||||
fooService.create(foo);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue