From d85327a5e73b364966cf65f657d53dc309d9eac1 Mon Sep 17 00:00:00 2001 From: barreiro Date: Wed, 9 Aug 2017 18:08:10 +0100 Subject: [PATCH] HHH-11882 - Fix tests --- .../enhancement/access/MixedAccessTest.java | 2 -- .../enhancement/basic/BasicSessionTest.java | 8 ++++++-- .../enhancement/cascade/CascadeDeleteTest.java | 2 -- .../cascade/CascadeWithFkConstraintTest.java | 3 --- .../detached/DetachedGetIdentifierTest.java | 2 -- .../dirty/DirtyTrackingCollectionTest.java | 2 -- .../enhancement/eviction/EvictionTest.java | 2 -- .../javassist/EnhancerFileNotFoundTest.java | 5 ++--- .../bytecode/enhancement/join/HHH3949Test.java | 14 ++++++++------ .../lazy/HHH_10708/UnexpectedDeleteTest1.java | 2 -- .../lazy/HHH_10708/UnexpectedDeleteTest2.java | 2 -- .../lazy/HHH_10708/UnexpectedDeleteTest3.java | 2 -- .../lazy/LazyBasicFieldNotInitializedTest.java | 12 +++++++----- .../lazy/LazyCollectionDeletedTest.java | 12 +++++++----- .../lazy/LazyCollectionLoadingTest.java | 12 +++++++----- .../lazy/LazyLoadingIntegrationTest.java | 12 +++++++----- .../bytecode/enhancement/lazy/LazyLoadingTest.java | 12 +++++++----- .../lazy/LazyProxyOnEnhancedEntityTest.java | 2 -- .../lazy/basic/LazyBasicFieldAccessTest.java | 12 +++++++----- .../lazy/basic/LazyBasicPropertyAccessTest.java | 12 +++++++----- .../enhancement/lazy/cache/LazyInCacheTest.java | 12 +++++++----- .../enhancement/lazy/group/LazyGroupTest.java | 12 +++++++----- .../lazy/group/SimpleLazyGroupUpdateTest.java | 11 +++++++---- .../enhancement/lazyCache/InitFromCacheTest.java | 12 +++++++----- .../enhancement/merge/CompositeMergeTest.java | 2 -- .../enhancement/merge/MergeEnhancedEntityTest.java | 10 ++++++++-- .../OtherEntityEntryContextTest.java | 5 ++--- .../bytecode/enhancement/pk/EmbeddedPKTest.java | 5 ----- 28 files changed, 103 insertions(+), 98 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/access/MixedAccessTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/access/MixedAccessTest.java index 541c99f402..ecd0d737ad 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/access/MixedAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/access/MixedAccessTest.java @@ -54,8 +54,6 @@ public class MixedAccessTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - doInHibernate( this::sessionFactory, s -> { TestEntity testEntity = new TestEntity( "foo" ); testEntity.setParamsAsString( "{\"paramName\":\"paramValue\"}" ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/basic/BasicSessionTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/basic/BasicSessionTest.java index 591df2032d..696f1b4d21 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/basic/BasicSessionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/basic/BasicSessionTest.java @@ -6,6 +6,7 @@ */ package org.hibernate.test.bytecode.enhancement.basic; +import org.hibernate.cfg.Configuration; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.ManagedEntity; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; @@ -29,10 +30,13 @@ import static org.junit.Assert.assertSame; @RunWith( BytecodeEnhancerRunner.class ) public class BasicSessionTest extends BaseCoreFunctionalTestCase { + @Override + protected void configure(Configuration configuration) { + configuration.addAnnotatedClass( MyEntity.class ); + } + @Test public void test() { - buildSessionFactory( configuration -> configuration.addAnnotatedClass( MyEntity.class ) ); - doInHibernate( this::sessionFactory, s -> { s.save( new MyEntity( 1L ) ); s.save( new MyEntity( 2L ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeDeleteTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeDeleteTest.java index acca767b9e..7578d18ec0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeDeleteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeDeleteTest.java @@ -44,8 +44,6 @@ public class CascadeDeleteTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - // Create a Parent with one Child doInHibernate( this::sessionFactory, s -> { Parent p = new Parent(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTest.java index ca62b47ba8..723c481f94 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTest.java @@ -41,8 +41,6 @@ public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - // Create garage, add 2 cars to garage doInJPA( this::sessionFactory, em -> { @@ -64,7 +62,6 @@ public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase { @Test public void test() { - // Remove garage doInJPA( this::sessionFactory, em -> { Garage toRemoveGarage = em.find( Garage.class, garageId ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/detached/DetachedGetIdentifierTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/detached/DetachedGetIdentifierTest.java index ff976d370f..1a85ecbb75 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/detached/DetachedGetIdentifierTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/detached/DetachedGetIdentifierTest.java @@ -29,8 +29,6 @@ public class DetachedGetIdentifierTest extends BaseCoreFunctionalTestCase { @Test public void test() { - buildSessionFactory(); - SimpleEntity[] entities = new SimpleEntity[2]; entities[0] = new SimpleEntity(); entities[0].name = "test"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingCollectionTest.java index 66122ae77e..5b1c30927e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingCollectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingCollectionTest.java @@ -38,8 +38,6 @@ public class DirtyTrackingCollectionTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - doInJPA( this::sessionFactory, em -> { StringsEntity entity = new StringsEntity(); entity.id = 1L; diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/eviction/EvictionTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/eviction/EvictionTest.java index cfa3754260..c4fb1f42af 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/eviction/EvictionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/eviction/EvictionTest.java @@ -39,8 +39,6 @@ public class EvictionTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - // Create a Parent doInHibernate( this::sessionFactory, s -> { Parent p = new Parent(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/javassist/EnhancerFileNotFoundTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/javassist/EnhancerFileNotFoundTest.java index 0b8d4a42d4..b3fbb0c8dc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/javassist/EnhancerFileNotFoundTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/javassist/EnhancerFileNotFoundTest.java @@ -31,12 +31,11 @@ public class EnhancerFileNotFoundTest { public void test() throws Exception { Enhancer enhancer = new Enhancer( new DefaultEnhancementContext() ); try { - Class clazz = getClass().getClassLoader().loadClass( Hidden.class.getName() ); - String resourceName = clazz.getName().replace( '.', '/' ) + ".class"; + String resourceName = Hidden.class.getName().replace( '.', '/' ) + ".class"; URL url = getClass().getClassLoader().getResource( resourceName ); if ( url != null ) { Files.delete( Paths.get( url.toURI() ) ); - enhancer.loadCtClassFromClass( clazz ); + enhancer.loadCtClassFromClass( Hidden.class ); } fail( "Should throw FileNotFoundException!" ); } catch ( Exception expected ) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/join/HHH3949Test.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/join/HHH3949Test.java index 4b9064134e..0a79e2a599 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/join/HHH3949Test.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/join/HHH3949Test.java @@ -5,6 +5,7 @@ import org.hibernate.Session; import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOneOption; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -34,14 +35,15 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase { return new Class[]{Person.class, Vehicle.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + // see HHH-3949 for further details ^^^^^ + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - // see HHH-3949 for further details ^^^^^ - } ); - doInHibernate( this::sessionFactory, s -> { // it is important that the data associations remain as follows: diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest1.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest1.java index f098aa74cb..7fa975bd7d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest1.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest1.java @@ -41,8 +41,6 @@ public class UnexpectedDeleteTest1 extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - doInHibernate( this::sessionFactory, s -> { Bar bar1 = new Bar(); Bar bar2 = new Bar(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest2.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest2.java index 2d77a439a3..882ecbec8b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest2.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest2.java @@ -38,8 +38,6 @@ public class UnexpectedDeleteTest2 extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - doInHibernate( this::sessionFactory, s -> { Bar bar = new Bar(); Foo foo1 = new Foo(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest3.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest3.java index ed2aa73fcf..28205ed5ab 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest3.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTest3.java @@ -38,8 +38,6 @@ public class UnexpectedDeleteTest3 extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - doInHibernate( this::sessionFactory, s -> { Child child = new Child(); child.setId( 2L ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyBasicFieldNotInitializedTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyBasicFieldNotInitializedTest.java index 616a529de7..4137dd989d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyBasicFieldNotInitializedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyBasicFieldNotInitializedTest.java @@ -9,6 +9,7 @@ package org.hibernate.test.bytecode.enhancement.lazy; import org.hibernate.Hibernate; import org.hibernate.annotations.Persister; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.testing.TestForIssue; @@ -46,13 +47,14 @@ public class LazyBasicFieldNotInitializedTest extends BaseCoreFunctionalTestCase return new Class[]{TestEntity.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - } ); - doInHibernate( this::sessionFactory, s -> { TestEntity entity = new TestEntity(); entity.description = "desc"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyCollectionDeletedTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyCollectionDeletedTest.java index 21607d7c9e..357a844169 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyCollectionDeletedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyCollectionDeletedTest.java @@ -7,6 +7,7 @@ package org.hibernate.test.bytecode.enhancement.lazy; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -44,13 +45,14 @@ public class LazyCollectionDeletedTest extends BaseCoreFunctionalTestCase { return new Class[]{Post.class, Tag.class, AdditionalDetails.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - } ); - doInHibernate( this::sessionFactory, s -> { Post post = new Post(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyCollectionLoadingTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyCollectionLoadingTest.java index 7206037898..f61895cd5d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyCollectionLoadingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyCollectionLoadingTest.java @@ -9,6 +9,7 @@ package org.hibernate.test.bytecode.enhancement.lazy; import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOneOption; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.proxy.HibernateProxy; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; @@ -62,13 +63,14 @@ public class LazyCollectionLoadingTest extends BaseCoreFunctionalTestCase { return new Class[]{Parent.class, Child.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - } ); - doInHibernate( this::sessionFactory, s -> { Parent parent = new Parent(); parent.setChildren( new ArrayList<>() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyLoadingIntegrationTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyLoadingIntegrationTest.java index d736f42363..9e104ebf6f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyLoadingIntegrationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyLoadingIntegrationTest.java @@ -9,6 +9,7 @@ package org.hibernate.test.bytecode.enhancement.lazy; import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOneOption; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Assert; @@ -46,13 +47,14 @@ public class LazyLoadingIntegrationTest extends BaseCoreFunctionalTestCase { return new Class[]{Parent.class, Child.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - } ); - doInHibernate( this::sessionFactory, s -> { Parent parent = new Parent(); for ( int i = 0; i < CHILDREN_SIZE; i++ ) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyLoadingTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyLoadingTest.java index c31861a9d0..be6b565942 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyLoadingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyLoadingTest.java @@ -9,6 +9,7 @@ package org.hibernate.test.bytecode.enhancement.lazy; import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOneOption; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.proxy.HibernateProxy; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -55,13 +56,14 @@ public class LazyLoadingTest extends BaseCoreFunctionalTestCase { return new Class[]{Parent.class, Child.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - } ); - doInHibernate( this::sessionFactory, s -> { Parent parent = new Parent(); for ( int i = 0; i < CHILDREN_SIZE; i++ ) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyProxyOnEnhancedEntityTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyProxyOnEnhancedEntityTest.java index 1d9317974d..e6b07dbe7a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyProxyOnEnhancedEntityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/LazyProxyOnEnhancedEntityTest.java @@ -49,8 +49,6 @@ public class LazyProxyOnEnhancedEntityTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - doInJPA( this::sessionFactory, em -> { Child c = new Child(); em.persist( c ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicFieldAccessTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicFieldAccessTest.java index c3d92b956b..8abe6b77b0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicFieldAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicFieldAccessTest.java @@ -7,6 +7,7 @@ package org.hibernate.test.bytecode.enhancement.lazy.basic; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Assert; @@ -41,13 +42,14 @@ public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase { return new Class[]{LazyEntity.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - } ); - doInHibernate( this::sessionFactory, s -> { LazyEntity entity = new LazyEntity(); entity.setDescription( "desc" ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicPropertyAccessTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicPropertyAccessTest.java index 067aa7cf1c..6f01b3a903 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicPropertyAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicPropertyAccessTest.java @@ -7,6 +7,7 @@ package org.hibernate.test.bytecode.enhancement.lazy.basic; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Assert; @@ -44,13 +45,14 @@ public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase { return new Class[]{LazyEntity.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - } ); - doInHibernate( this::sessionFactory, s -> { LazyEntity entity = new LazyEntity(); entity.description = "desc"; diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/cache/LazyInCacheTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/cache/LazyInCacheTest.java index 9cc8a06196..6525394f94 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/cache/LazyInCacheTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/cache/LazyInCacheTest.java @@ -10,6 +10,7 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.Type; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Assert; @@ -44,13 +45,14 @@ public class LazyInCacheTest extends BaseCoreFunctionalTestCase { return new Class[]{Order.class, Product.class, Tag.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - } ); - Order order = new Order(); Product product = new Product(); order.products.add( product ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/LazyGroupTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/LazyGroupTest.java index 2694cb02a0..275c16b5b3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/LazyGroupTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/LazyGroupTest.java @@ -10,6 +10,7 @@ import org.hibernate.annotations.LazyGroup; import org.hibernate.annotations.LazyToOne; import org.hibernate.annotations.LazyToOneOption; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.proxy.HibernateProxy; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; @@ -51,13 +52,14 @@ public class LazyGroupTest extends BaseCoreFunctionalTestCase { return new Class[]{Child.class, Parent.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - } ); - doInHibernate( this::sessionFactory, s -> { Child c1 = new Child( "steve", "Hibernater" ); Child c2 = new Child( "sally", "Joe Mama" ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/SimpleLazyGroupUpdateTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/SimpleLazyGroupUpdateTest.java index 3e6b69e1c4..a86ca06319 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/SimpleLazyGroupUpdateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/group/SimpleLazyGroupUpdateTest.java @@ -9,6 +9,7 @@ package org.hibernate.test.bytecode.enhancement.lazy.group; import org.hibernate.annotations.LazyGroup; import org.hibernate.bytecode.enhance.spi.UnloadedClass; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext; @@ -46,12 +47,14 @@ public class SimpleLazyGroupUpdateTest extends BaseCoreFunctionalTestCase { return new Class[]{TestEntity.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); + configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" ); - } ); doInHibernate( this::sessionFactory, s -> { s.save( new TestEntity( 1L, "entity 1", "blah", REALLY_BIG_STRING ) ); } ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazyCache/InitFromCacheTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazyCache/InitFromCacheTest.java index 0ac708e0c9..57953024ea 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazyCache/InitFromCacheTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazyCache/InitFromCacheTest.java @@ -11,6 +11,7 @@ import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.Formula; import org.hibernate.cache.spi.entry.StandardCacheEntryImpl; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.cache.BaseRegion; @@ -51,13 +52,14 @@ public class InitFromCacheTest extends BaseCoreFunctionalTestCase { return new Class[]{Document.class}; } + @Override + protected void configure(Configuration configuration) { + configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" ); + configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" ); + } + @Before public void prepare() { - buildSessionFactory( configuration -> { - configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" ); - configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" ); - } ); - persister = sessionFactory().getMetamodel().entityPersister( Document.class ); assertTrue( persister.hasCache() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/merge/CompositeMergeTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/merge/CompositeMergeTest.java index e6f6670ae2..aa7686ab8c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/merge/CompositeMergeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/merge/CompositeMergeTest.java @@ -45,8 +45,6 @@ public class CompositeMergeTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - ParentEntity parent = new ParentEntity(); parent.description = "desc"; parent.address = new Address(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/merge/MergeEnhancedEntityTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/merge/MergeEnhancedEntityTest.java index b282932a84..acfff2416e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/merge/MergeEnhancedEntityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/merge/MergeEnhancedEntityTest.java @@ -9,6 +9,7 @@ package org.hibernate.test.bytecode.enhancement.merge; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,8 +42,6 @@ public class MergeEnhancedEntityTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - doInHibernate( this::sessionFactory, s -> { s.persist( new Person( 1L, "Sam" ) ); } ); @@ -74,6 +73,13 @@ public class MergeEnhancedEntityTest extends BaseCoreFunctionalTestCase { } ); } + @After + public void cleanup() { + doInHibernate( this::sessionFactory, s -> { + s.delete( new Person( 1L, "Sam" ) ); + } ); + } + // --- // @Entity diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/otherentityentrycontext/OtherEntityEntryContextTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/otherentityentrycontext/OtherEntityEntryContextTest.java index 17337b50ac..1acdba1663 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/otherentityentrycontext/OtherEntityEntryContextTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/otherentityentrycontext/OtherEntityEntryContextTest.java @@ -41,8 +41,6 @@ public class OtherEntityEntryContextTest extends BaseCoreFunctionalTestCase { @Before public void prepare() { - buildSessionFactory(); - // Create a Parent doInHibernate( this::sessionFactory, s -> { s.persist( new Parent( 1L, "first" ) ); @@ -73,7 +71,8 @@ public class OtherEntityEntryContextTest extends BaseCoreFunctionalTestCase { try { session2.update( p ); fail( "should have failed because p is already associated with a PersistenceContext that is still open." ); - } catch ( HibernateException expected ) { + } + catch ( HibernateException ignored ) { // expected } } ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/pk/EmbeddedPKTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/pk/EmbeddedPKTest.java index 18d75949a4..f0a20b5d41 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/pk/EmbeddedPKTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/pk/EmbeddedPKTest.java @@ -34,11 +34,6 @@ public class EmbeddedPKTest extends BaseCoreFunctionalTestCase { return new Class[]{WorkOrder.class, WorkOrderPK.class}; } - @Before - public void prepare() { - buildSessionFactory(); - } - @Test public void test() { TransactionUtil.doInHibernate( this::sessionFactory, s -> {