Re-enable additional tests

This commit is contained in:
Andrea Boriero 2021-06-25 12:43:45 +02:00
parent cf449a986e
commit fcee504c99
4 changed files with 74 additions and 67 deletions

View File

@ -10,7 +10,7 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="org.hibernate.test.iterate">
package="org.hibernate.orm.test.iterate">
<class name="Item" table="NamedItem" entity-name="Item">
<id name="name"/>

View File

@ -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;
/**

View File

@ -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 ) );
}
}

View File

@ -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 );
}
}