diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/SubClassTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/SubClassTest.java new file mode 100644 index 0000000000..b1f2dc1979 --- /dev/null +++ b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/SubClassTest.java @@ -0,0 +1,78 @@ +package org.hibernate.test.annotations.filter.subclass; + +import junit.framework.Assert; + +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +public abstract class SubClassTest extends BaseCoreFunctionalTestCase{ + + @Override + protected void prepareTest() throws Exception { + openSession(); + session.beginTransaction(); + + persistTestData(); + + session.getTransaction().commit(); + session.close(); + } + + protected abstract void persistTestData(); + + @Override + protected void cleanupTest() throws Exception { + openSession(); + session.beginTransaction(); + + session.createQuery("delete from Human").executeUpdate(); + + session.getTransaction().commit(); + session.close(); + } + + @Test + public void testIqFilter(){ + openSession(); + session.beginTransaction(); + + assertCount(3); + session.enableFilter("iqRange").setParameter("min", 101).setParameter("max", 140); + assertCount(1); + + session.getTransaction().commit(); + session.close(); + } + + @Test + public void testPregnantFilter(){ + openSession(); + session.beginTransaction(); + + assertCount(3); + session.enableFilter("pregnantOnly"); + assertCount(1); + + session.getTransaction().commit(); + session.close(); + } + @Test + public void testNonHumanFilter(){ + openSession(); + session.beginTransaction(); + + assertCount(3); + session.enableFilter("ignoreSome").setParameter("name", "Homo Sapiens"); + assertCount(0); + + session.getTransaction().commit(); + session.close(); + } + + + private void assertCount(long expected){ + long count = (Long) session.createQuery("select count(h) from Human h").uniqueResult(); + Assert.assertEquals(expected, count); + } + +} diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/joined/JoinedSubClassTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/joined/JoinedSubClassTest.java index a03b96f1da..96b0bb027f 100644 --- a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/joined/JoinedSubClassTest.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/joined/JoinedSubClassTest.java @@ -2,19 +2,10 @@ package org.hibernate.test.annotations.filter.subclass.joined; import junit.framework.Assert; -import org.hibernate.cfg.Configuration; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.test.annotations.filter.subclass.SubClassTest; import org.junit.Test; -public class JoinedSubClassTest extends BaseCoreFunctionalTestCase{ - - - - @Override - protected void afterConfigurationBuilt(Configuration configuration) { - configuration.setProperty("hibernate.show_sql", "true"); - super.afterConfigurationBuilt(configuration); - } +public class JoinedSubClassTest extends SubClassTest{ @Override protected Class[] getAnnotatedClasses() { @@ -22,71 +13,27 @@ public class JoinedSubClassTest extends BaseCoreFunctionalTestCase{ } @Override - protected void prepareTest() throws Exception { + protected void cleanupTest() throws Exception { + super.cleanupTest(); openSession(); session.beginTransaction(); + session.createQuery("delete from Club").executeUpdate(); + + session.getTransaction().commit(); + session.close(); + } + + @Override + protected void persistTestData() { Club club = new Club(); club.setName("Mensa applicants"); club.getMembers().add(createHuman(club, false, 90)); club.getMembers().add(createHuman(club, false, 100)); club.getMembers().add(createHuman(club, true, 110)); session.persist(club); - - session.getTransaction().commit(); - session.close(); } - @Override - protected void cleanupTest() throws Exception { - openSession(); - session.beginTransaction(); - - session.createQuery("delete from Human").executeUpdate(); - session.createQuery("delete from Club").executeUpdate(); - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testIqFilter(){ - openSession(); - session.beginTransaction(); - - assertCount(3); - session.enableFilter("iqRange").setParameter("min", 101).setParameter("max", 140); - assertCount(1); - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testPregnantFilter(){ - openSession(); - session.beginTransaction(); - - assertCount(3); - session.enableFilter("pregnantOnly"); - assertCount(1); - - session.getTransaction().commit(); - session.close(); - } - @Test - public void testNonHumanFilter(){ - openSession(); - session.beginTransaction(); - - assertCount(3); - session.enableFilter("ignoreSome").setParameter("name", "Homo Sapiens"); - assertCount(0); - - session.getTransaction().commit(); - session.close(); - } - @Test public void testClub(){ openSession(); @@ -119,9 +66,5 @@ public class JoinedSubClassTest extends BaseCoreFunctionalTestCase{ return human; } - private void assertCount(long expected){ - long count = (Long) session.createQuery("select count(h) from Human h").uniqueResult(); - Assert.assertEquals(expected, count); - } } diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/singletable/SingleTableTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/singletable/SingleTableTest.java index c4b0b6eedd..4f5b48957f 100644 --- a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/singletable/SingleTableTest.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/singletable/SingleTableTest.java @@ -1,93 +1,31 @@ package org.hibernate.test.annotations.filter.subclass.singletable; -import junit.framework.Assert; +import org.hibernate.test.annotations.filter.subclass.SubClassTest; -import org.hibernate.cfg.Configuration; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -public class SingleTableTest extends BaseCoreFunctionalTestCase{ +public class SingleTableTest extends SubClassTest{ - @Override - protected void afterConfigurationBuilt(Configuration configuration) { - configuration.setProperty("hibernate.show_sql", "true"); - super.afterConfigurationBuilt(configuration); - } - @Override protected Class[] getAnnotatedClasses() { return new Class[]{Animal.class, Mammal.class, Human.class}; } @Override - protected void prepareTest() throws Exception { + protected void persistTestData() { createHuman(false, 90); createHuman(false, 100); createHuman(true, 110); } - @Override - protected void cleanupTest() throws Exception { - openSession(); - session.beginTransaction(); - - session.createQuery("delete from Human").executeUpdate(); - - session.getTransaction().commit(); - session.close(); - } - @Test - public void testIqFilter(){ - session.beginTransaction(); - - assertCount(3); - session.enableFilter("iqRange").setParameter("min", 101).setParameter("max", 140); - assertCount(1); - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testPregnantFilter(){ - session.beginTransaction(); - - assertCount(3); - session.enableFilter("pregnantOnly"); - assertCount(1); - - session.getTransaction().commit(); - session.close(); - } - @Test - public void testNonHumanFilter(){ - session.beginTransaction(); - - assertCount(3); - session.enableFilter("ignoreSome").setParameter("name", "Homo Sapiens"); - assertCount(0); - - session.getTransaction().commit(); - session.close(); - } - private void createHuman(boolean pregnant, int iq){ - openSession(); - session.beginTransaction(); Human human = new Human(); human.setName("Homo Sapiens"); human.setPregnant(pregnant); human.setIq(iq); session.persist(human); - session.getTransaction().commit(); } - private void assertCount(long expected){ - long count = (Long) session.createQuery("select count(h) from Human h").uniqueResult(); - Assert.assertEquals(expected, count); - } } diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/tableperclass/TablePerClassTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/tableperclass/TablePerClassTest.java index 9e083e38c7..8587ad47ed 100644 --- a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/tableperclass/TablePerClassTest.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/filter/subclass/tableperclass/TablePerClassTest.java @@ -1,93 +1,27 @@ package org.hibernate.test.annotations.filter.subclass.tableperclass; -import junit.framework.Assert; - -import org.hibernate.cfg.Configuration; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -public class TablePerClassTest extends BaseCoreFunctionalTestCase{ - - - - @Override - protected void afterConfigurationBuilt(Configuration configuration) { - configuration.setProperty("hibernate.show_sql", "true"); - super.afterConfigurationBuilt(configuration); - } +import org.hibernate.test.annotations.filter.subclass.SubClassTest; +public class TablePerClassTest extends SubClassTest{ @Override protected Class[] getAnnotatedClasses() { return new Class[]{Animal.class, Mammal.class, Human.class}; } @Override - protected void prepareTest() throws Exception { + protected void persistTestData() { createHuman(false, 90); createHuman(false, 100); createHuman(true, 110); } - @Override - protected void cleanupTest() throws Exception { - openSession(); - session.beginTransaction(); - - session.createQuery("delete from Human").executeUpdate(); - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testIqFilter(){ - session.beginTransaction(); - - assertCount(3); - session.enableFilter("iqRange").setParameter("min", 101).setParameter("max", 140); - assertCount(1); - - session.getTransaction().commit(); - session.close(); - } - - @Test - public void testPregnantFilter(){ - session.beginTransaction(); - - assertCount(3); - session.enableFilter("pregnantOnly"); - assertCount(1); - - session.getTransaction().commit(); - session.close(); - } - @Test - public void testNonHumanFilter(){ - session.beginTransaction(); - - assertCount(3); - session.enableFilter("ignoreSome").setParameter("name", "Homo Sapiens"); - assertCount(0); - - session.getTransaction().commit(); - session.close(); - } - private void createHuman(boolean pregnant, int iq){ - openSession(); - session.beginTransaction(); Human human = new Human(); human.setName("Homo Sapiens"); human.setPregnant(pregnant); human.setIq(iq); session.persist(human); - session.getTransaction().commit(); } - private void assertCount(long expected){ - long count = (Long) session.createQuery("select count(h) from Human h").uniqueResult(); - Assert.assertEquals(expected, count); - } }