From 8f6e4d56753576f30ba8cec5fae1693e316267f2 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 1 Feb 2017 09:31:44 +0000 Subject: [PATCH] HHH-11434 - prevent failures in some tests from freezing the whole test suite --- .../FilterInheritanceTest.java | 57 +++++++------------ 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/filter/subclass/MappedSuperclass/FilterInheritanceTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/filter/subclass/MappedSuperclass/FilterInheritanceTest.java index 5897464bdc..cd78535fa9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/filter/subclass/MappedSuperclass/FilterInheritanceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/filter/subclass/MappedSuperclass/FilterInheritanceTest.java @@ -34,53 +34,36 @@ public class FilterInheritanceTest extends BaseCoreFunctionalTestCase { @Override protected void prepareTest() throws Exception { doInHibernate( this::sessionFactory, session -> { - persistTestData(); - }); + Mammal mammal = new Mammal(); + mammal.setName( "unimportant" ); + session.persist( mammal ); + + Human human = new Human(); + human.setName( "unimportant" ); + session.persist( human ); + + Human human1 = new Human(); + human1.setName( "unimportant_1" ); + session.persist( human1 ); + } ); } @Override - protected void cleanupTest() throws Exception { - super.cleanupTest(); - doInHibernate( this::sessionFactory, session -> { - session.createQuery("delete from Human").executeUpdate(); - session.createQuery("delete from Mammal").executeUpdate(); - }); - } - - protected void persistTestData() { - Mammal mammal = new Mammal(); - mammal.setName( "unimportant" ); - session.persist( mammal ); - - Human human = new Human(); - human.setName( "unimportant" ); - session.persist( human ); - - Human human1 = new Human(); - human1.setName( "unimportant_1" ); - session.persist( human1 ); + protected boolean isCleanupTestDataRequired() { + return true; } @Test @TestForIssue(jiraKey = "HHH-8895") - public void testSlectFromHuman() throws Exception { - openSession(); - session.enableFilter( "nameFilter" ).setParameter( "name", "unimportant" ); - try { - transaction = session.beginTransaction(); + public void testSelectFromHuman() throws Exception { + doInHibernate( this::sessionFactory, session -> { + session.enableFilter( "nameFilter" ).setParameter( "name", "unimportant" ); + List humans = session.createQuery( "SELECT h FROM Human h" ).list(); assertThat( humans.size(), is( 1 ) ); Human human = (Human) humans.get( 0 ); - assertThat(human.getName(), is("unimportant")); - - transaction.commit(); - } - catch (Exception e) { - if ( transaction != null ) { - transaction.rollback(); - } - throw e; - } + assertThat( human.getName(), is( "unimportant" ) ); + } ); } }