From fcc63d9ab0d4e2206d1d1d92ca2b24f1e38e5f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 31 Mar 2021 16:51:42 +0200 Subject: [PATCH] HHH-14529 Stop using two separate BootstrapServiceRegistries for the same SessionFactory in BaseCoreFunctionalTestCase --- .../collections/BasicTypeCollectionTest.java | 5 ++--- .../mapping/basic/BitSetTypeTest.java | 5 ++--- .../mapping/basic/BitSetUserTypeTest.java | 5 ++--- .../bulkid/AbstractBulkCompositeIdTest.java | 5 ++--- .../test/bulkid/AbstractBulkIdTest.java | 5 ++--- .../SQLServerDialectCollationTest.java | 9 +++++---- ...SQLServerDialectTempTableCollationTest.java | 10 +++++----- .../functional/SQLServerDialectTest.java | 5 ++--- .../TenantResolverConfigurationTest.java | 5 ++--- .../junit4/BaseCoreFunctionalTestCase.java | 18 ++++++------------ 10 files changed, 30 insertions(+), 42 deletions(-) diff --git a/documentation/src/test/java/org/hibernate/userguide/collections/BasicTypeCollectionTest.java b/documentation/src/test/java/org/hibernate/userguide/collections/BasicTypeCollectionTest.java index 8def4aedf7..edf53fcb33 100644 --- a/documentation/src/test/java/org/hibernate/userguide/collections/BasicTypeCollectionTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/collections/BasicTypeCollectionTest.java @@ -51,12 +51,11 @@ public class BasicTypeCollectionTest extends BaseCoreFunctionalTestCase { } @Override - protected Configuration constructAndConfigureConfiguration() { - Configuration configuration = super.constructAndConfigureConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> { typeContributions.contributeType( new CommaDelimitedStringsType() ); } ); - return configuration; } //tag::collections-comma-delimited-collection-example[] diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetTypeTest.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetTypeTest.java index d7e4264633..baa87e38aa 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetTypeTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetTypeTest.java @@ -32,14 +32,13 @@ public class BitSetTypeTest extends BaseCoreFunctionalTestCase { } @Override - protected Configuration constructAndConfigureConfiguration() { - Configuration configuration = super.constructAndConfigureConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); //tag::basic-custom-type-register-BasicType-example[] configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> { typeContributions.contributeType( BitSetType.INSTANCE ); } ); //end::basic-custom-type-register-BasicType-example[] - return configuration; } @Test diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetUserTypeTest.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetUserTypeTest.java index a0c7fd7293..6a7a7ffb52 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetUserTypeTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/BitSetUserTypeTest.java @@ -36,14 +36,13 @@ public class BitSetUserTypeTest extends BaseCoreFunctionalTestCase { } @Override - protected Configuration constructAndConfigureConfiguration() { - Configuration configuration = super.constructAndConfigureConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); //tag::basic-custom-type-register-UserType-example[] configuration.registerTypeContributor( (typeContributions, serviceRegistry) -> { typeContributions.contributeType( BitSetUserType.INSTANCE, "bitset"); } ); //end::basic-custom-type-register-UserType-example[] - return configuration; } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/bulkid/AbstractBulkCompositeIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/bulkid/AbstractBulkCompositeIdTest.java index 4b468ccd13..a3c4d5138f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bulkid/AbstractBulkCompositeIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bulkid/AbstractBulkCompositeIdTest.java @@ -33,13 +33,12 @@ public abstract class AbstractBulkCompositeIdTest extends BaseCoreFunctionalTest } @Override - protected Configuration constructConfiguration() { - Configuration configuration = super.constructConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); Class strategyClass = getMultiTableBulkIdStrategyClass(); if ( strategyClass != null ) { configuration.setProperty( AvailableSettings.HQL_BULK_ID_STRATEGY, strategyClass.getName() ); } - return configuration; } protected abstract Class getMultiTableBulkIdStrategyClass(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bulkid/AbstractBulkIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/bulkid/AbstractBulkIdTest.java index eeef7b9a67..fddbd710ee 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bulkid/AbstractBulkIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bulkid/AbstractBulkIdTest.java @@ -32,10 +32,9 @@ public abstract class AbstractBulkIdTest extends BaseCoreFunctionalTestCase { } @Override - protected Configuration constructConfiguration() { - Configuration configuration = super.constructConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); configuration.setProperty( AvailableSettings.HQL_BULK_ID_STRATEGY, getMultiTableBulkIdStrategyClass().getName() ); - return configuration; } protected abstract Class getMultiTableBulkIdStrategyClass(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectCollationTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectCollationTest.java index 02eeb5602d..0de04ac854 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectCollationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectCollationTest.java @@ -47,15 +47,16 @@ import static org.junit.Assert.fail; public class SQLServerDialectCollationTest extends BaseCoreFunctionalTestCase { @Override - protected Configuration constructConfiguration() { - Configuration configuration = super.constructConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); configuration.setProperty( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString() ); - return configuration; } + @Override protected void buildSessionFactory() { BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry(); - StandardServiceRegistryImpl _serviceRegistry = buildServiceRegistry( bootRegistry, constructConfiguration() ); + StandardServiceRegistryImpl _serviceRegistry = + buildServiceRegistry( bootRegistry, constructAndConfigureConfiguration( bootRegistry ) ); try { try { diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTempTableCollationTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTempTableCollationTest.java index 0322f9284f..de42411816 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTempTableCollationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTempTableCollationTest.java @@ -43,10 +43,9 @@ public class SQLServerDialectTempTableCollationTest extends BaseCoreFunctionalTe private boolean collationChanged; @Override - protected Configuration constructConfiguration() { - Configuration configuration = super.constructConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); configuration.setProperty( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString() ); - return configuration; } @Override @@ -56,7 +55,7 @@ public class SQLServerDialectTempTableCollationTest extends BaseCoreFunctionalTe BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry(); StandardServiceRegistryImpl serviceRegistry = buildServiceRegistry( bootRegistry, - constructConfiguration() + constructAndConfigureConfiguration( bootRegistry ) ); try { TransactionUtil.doWithJDBC( @@ -92,7 +91,8 @@ public class SQLServerDialectTempTableCollationTest extends BaseCoreFunctionalTe @Override protected void buildSessionFactory() { BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry(); - StandardServiceRegistryImpl serviceRegistry = buildServiceRegistry( bootRegistry, constructConfiguration() ); + StandardServiceRegistryImpl serviceRegistry = + buildServiceRegistry( bootRegistry, constructAndConfigureConfiguration( bootRegistry ) ); try { try { diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTest.java index c1ba41ed72..98643877b7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTest.java @@ -44,10 +44,9 @@ import static org.junit.Assert.assertTrue; public class SQLServerDialectTest extends BaseCoreFunctionalTestCase { @Override - protected Configuration constructConfiguration() { - Configuration configuration = super.constructConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); configuration.setProperty( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString() ); - return configuration; } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/TenantResolverConfigurationTest.java b/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/TenantResolverConfigurationTest.java index e8423e6a4a..18aacf5428 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/TenantResolverConfigurationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/TenantResolverConfigurationTest.java @@ -24,10 +24,9 @@ public class TenantResolverConfigurationTest extends BaseCoreFunctionalTestCase private TestCurrentTenantIdentifierResolver currentTenantResolver = new TestCurrentTenantIdentifierResolver(); @Override - protected Configuration constructAndConfigureConfiguration() { - Configuration configuration = super.constructAndConfigureConfiguration(); + protected void configure(Configuration configuration) { + super.configure( configuration ); configuration.setCurrentTenantIdentifierResolver( currentTenantResolver ); - return configuration; } @Test diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index ebd52c8ee2..d3dee0e2c4 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -112,11 +112,11 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { protected void buildSessionFactory(Consumer configurationAdapter) { // for now, build the configuration to get all the property settings - configuration = constructAndConfigureConfiguration(); + BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry(); + configuration = constructAndConfigureConfiguration( bootRegistry ); if ( configurationAdapter != null ) { configurationAdapter.accept(configuration); } - BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry(); serviceRegistry = buildServiceRegistry( bootRegistry, configuration ); // this is done here because Configuration does not currently support 4.0 xsd afterConstructAndConfigureConfiguration( configuration ); @@ -145,14 +145,8 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { buildSessionFactory( configurationAdapter ); } - protected Configuration buildConfiguration() { - Configuration cfg = constructAndConfigureConfiguration(); - afterConstructAndConfigureConfiguration( cfg ); - return cfg; - } - - protected Configuration constructAndConfigureConfiguration() { - Configuration cfg = constructConfiguration(); + protected Configuration constructAndConfigureConfiguration(BootstrapServiceRegistry bootstrapServiceRegistry) { + Configuration cfg = constructConfiguration( bootstrapServiceRegistry ); configure( cfg ); return cfg; } @@ -163,8 +157,8 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { afterConfigurationBuilt( cfg ); } - protected Configuration constructConfiguration() { - Configuration configuration = new Configuration(); + protected Configuration constructConfiguration(BootstrapServiceRegistry bootstrapServiceRegistry) { + Configuration configuration = new Configuration( bootstrapServiceRegistry ); configuration.setProperty( AvailableSettings.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() ); configuration.setProperty( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" ); if ( createSchema() ) {