HHH-11882 - Fix tests

This commit is contained in:
barreiro 2017-08-09 18:08:10 +01:00 committed by Andrea Boriero
parent cfb910fb37
commit d85327a5e7
28 changed files with 103 additions and 98 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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";

View File

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

View File

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

View File

@ -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 ) {

View File

@ -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:

View File

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

View File

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

View File

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

View File

@ -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";

View File

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

View File

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

View File

@ -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++ ) {

View File

@ -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++ ) {

View File

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

View File

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

View File

@ -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";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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

View File

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

View File

@ -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 -> {