diff --git a/hibernate-core/src/test/java/org/hibernate/test/iterate/Item.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/iterate/Item.hbm.xml similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/iterate/Item.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/iterate/Item.hbm.xml index 5fb548995c..86aeb6d638 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/iterate/Item.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/iterate/Item.hbm.xml @@ -10,7 +10,7 @@ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> + package="org.hibernate.orm.test.iterate"> diff --git a/hibernate-core/src/test/java/org/hibernate/test/iterate/Item.java b/hibernate-core/src/test/java/org/hibernate/orm/test/iterate/Item.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/iterate/Item.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/iterate/Item.java index 2a724c2caf..7be739fad6 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/iterate/Item.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/iterate/Item.java @@ -6,7 +6,7 @@ */ //$Id: Item.java 6593 2005-04-28 15:52:26Z oneovthafew $ -package org.hibernate.test.iterate; +package org.hibernate.orm.test.iterate; /** diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/iterate/ScrollTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/iterate/ScrollTest.java new file mode 100644 index 0000000000..801e33c7ff --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/iterate/ScrollTest.java @@ -0,0 +1,72 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.orm.test.iterate; + +import org.hibernate.Hibernate; +import org.hibernate.ScrollableResults; +import org.hibernate.cfg.Environment; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.Setting; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +@DomainModel( + xmlMappings = "org/hibernate/orm/test/iterate/Item.hbm.xml" +) +@SessionFactory( + generateStatistics = true +) +@ServiceRegistry( + settings = { + @Setting(name = Environment.USE_QUERY_CACHE, value = "true"), + @Setting(name = Environment.CACHE_REGION_PREFIX, value = "foo"), + @Setting(name = Environment.USE_SECOND_LEVEL_CACHE, value = "true") + } +) +public class ScrollTest { + + @Test + public void testScroll(SessionFactoryScope scope) { + scope.inTransaction( + s -> { + Item i1 = new Item( "foo" ); + Item i2 = new Item( "bar" ); + s.persist( "Item", i1 ); + s.persist( "Item", i2 ); + } + ); + + scope.inTransaction( + s -> { + ScrollableResults sr = s.getNamedQuery( "Item.nameDesc" ).scroll(); + assertTrue( sr.next() ); + Item i1 = (Item) sr.get(); + assertTrue( sr.next() ); + Item i2 = (Item) sr.get(); + assertTrue( Hibernate.isInitialized( i1 ) ); + assertTrue( Hibernate.isInitialized( i2 ) ); + assertThat( i1.getName(), is( "foo" ) ); + assertThat( i2.getName(), is( "bar" ) ); + assertFalse( sr.next() ); + s.delete( i1 ); + s.delete( i2 ); + } + ); + + assertThat( scope.getSessionFactory().getStatistics().getEntityFetchCount(), is( 0L ) ); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/iterate/ScrollTest.java b/hibernate-core/src/test/java/org/hibernate/test/iterate/ScrollTest.java deleted file mode 100644 index 027a0d1d22..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/iterate/ScrollTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.test.iterate; - -import org.hibernate.Hibernate; -import org.hibernate.ScrollableResults; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class ScrollTest extends BaseCoreFunctionalTestCase { - public String[] getMappings() { - return new String[] { "iterate/Item.hbm.xml" }; - } - - public void configure(Configuration cfg) { - super.configure( cfg ); - cfg.setProperty( Environment.USE_QUERY_CACHE, "true" ); - cfg.setProperty( Environment.CACHE_REGION_PREFIX, "foo" ); - cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" ); - cfg.setProperty( Environment.GENERATE_STATISTICS, "true" ); - } - - @Test - public void testScroll() { - inTransaction( - s -> { - Item i1 = new Item( "foo" ); - Item i2 = new Item( "bar" ); - s.persist( "Item", i1 ); - s.persist( "Item", i2 ); - } - ); - - inTransaction( - s -> { - ScrollableResults sr = s.getNamedQuery( "Item.nameDesc" ).scroll(); - assertTrue( sr.next() ); - Item i1 = (Item) sr.get(); - assertTrue( sr.next() ); - Item i2 = (Item) sr.get(); - assertTrue( Hibernate.isInitialized( i1 ) ); - assertTrue( Hibernate.isInitialized( i2 ) ); - assertEquals( i1.getName(), "foo" ); - assertEquals( i2.getName(), "bar" ); - assertFalse( sr.next() ); - s.delete( i1 ); - s.delete( i2 ); - } - ); - - assertEquals( sessionFactory().getStatistics().getEntityFetchCount(), 0 ); - } - -}