11package ru .javawebinar .topjava .service ;
22
3+ import org .junit .Assume ;
34import org .junit .Before ;
45import org .junit .Test ;
56import org .springframework .beans .factory .annotation .Autowired ;
67import org .springframework .cache .CacheManager ;
8+ import org .springframework .context .annotation .Lazy ;
79import org .springframework .dao .DataAccessException ;
810import ru .javawebinar .topjava .UserTestData ;
911import ru .javawebinar .topjava .model .Role ;
1012import ru .javawebinar .topjava .model .User ;
13+ import ru .javawebinar .topjava .repository .JpaUtil ;
1114import ru .javawebinar .topjava .util .exception .NotFoundException ;
1215
1316import javax .validation .ConstraintViolationException ;
1417import java .util .Date ;
1518import java .util .List ;
1619import java .util .Set ;
17- import ru .javawebinar .topjava .repository .JpaUtil ;
1820
1921import static org .junit .Assert .assertThrows ;
2022import static ru .javawebinar .topjava .UserTestData .*;
@@ -28,12 +30,15 @@ public abstract class AbstractUserServiceTest extends AbstractServiceTest {
2830 private CacheManager cacheManager ;
2931
3032 @ Autowired
33+ @ Lazy
3134 protected JpaUtil jpaUtil ;
3235
3336 @ Before
3437 public void setup () {
3538 cacheManager .getCache ("users" ).clear ();
36- jpaUtil .clear2ndLevelHibernateCache ();
39+ if (isJpaBased ()) {
40+ jpaUtil .clear2ndLevelHibernateCache ();
41+ }
3742 }
3843
3944 @ Test
@@ -95,6 +100,7 @@ public void getAll() {
95100
96101 @ Test
97102 public void createWithException () throws Exception {
103+ Assume .assumeTrue ("Validation not supported (JPA only)" , isJpaBased ());
98104 validateRootCause (ConstraintViolationException .class , () -> service .create (new User (null , " " , "mail@yandex.ru" , "password" , Role .USER )));
99105 validateRootCause (ConstraintViolationException .class , () -> service .create (new User (null , "User" , " " , "password" , Role .USER )));
100106 validateRootCause (ConstraintViolationException .class , () -> service .create (new User (null , "User" , "mail@yandex.ru" , " " , Role .USER )));
0 commit comments