diff --git a/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java b/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java index 2b1eb525e2..2069a7e776 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/extendshbm/ExtendsTest.java @@ -45,7 +45,7 @@ public class ExtendsTest extends UnitTestCase { cfg.addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" ); cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" ); - cfg.buildSessionFactory( getServiceRegistry() ); + cfg.buildSessionFactory( getServiceRegistry(cfg.getProperties()) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); @@ -101,7 +101,7 @@ public class ExtendsTest extends UnitTestCase { ); cfg.addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" ); - cfg.buildSessionFactory( getServiceRegistry() ); + cfg.buildSessionFactory( getServiceRegistry( cfg.getProperties() ) ); fail( "Should not be able to build sessionfactory without a Person" ); } @@ -117,7 +117,7 @@ public class ExtendsTest extends UnitTestCase { try { cfg.addResource( getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml" ); - cfg.buildSessionFactory( getServiceRegistry() ); + cfg.buildSessionFactory( getServiceRegistry( cfg.getProperties() ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Customer" ) ); assertNotNull( cfg.getClassMapping( "org.hibernate.test.extendshbm.Person" ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java index 5f607f8704..18b0cf9186 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MigrationTest.java @@ -27,7 +27,7 @@ public class MigrationTest extends UnitTestCase { v1cfg.addResource( resource1 ); new SchemaExport( v1cfg ).execute( false, true, true, false ); - SchemaUpdate v1schemaUpdate = new SchemaUpdate( getJdbcServices(), v1cfg ); + SchemaUpdate v1schemaUpdate = new SchemaUpdate( getJdbcServices( v1cfg.getProperties() ), v1cfg ); v1schemaUpdate.execute( true, true ); assertEquals( 0, v1schemaUpdate.getExceptions().size() ); @@ -35,11 +35,11 @@ public class MigrationTest extends UnitTestCase { Configuration v2cfg = new Configuration(); v2cfg.addResource( resource2 ); - SchemaUpdate v2schemaUpdate = new SchemaUpdate( getJdbcServices(), v2cfg ); + SchemaUpdate v2schemaUpdate = new SchemaUpdate( getJdbcServices( v2cfg.getProperties() ), v2cfg ); v2schemaUpdate.execute( true, true ); assertEquals( 0, v2schemaUpdate.getExceptions().size() ); - new SchemaExport( getJdbcServices(), v2cfg ).drop( false, true ); + new SchemaExport( getJdbcServices( v2cfg.getProperties() ), v2cfg ).drop( false, true ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/stats/StatsTest.java b/hibernate-core/src/test/java/org/hibernate/test/stats/StatsTest.java index daf8132c11..a84daa535c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/stats/StatsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/stats/StatsTest.java @@ -83,7 +83,7 @@ public class StatsTest extends FunctionalTestCase { Collection coll = getCfg().getCollectionMapping(Continent.class.getName() + ".countries"); coll.setFetchMode(FetchMode.JOIN); coll.setLazy(false); - SessionFactory sf = getCfg().buildSessionFactory( getServiceRegistry() ); + SessionFactory sf = getCfg().buildSessionFactory( getServiceRegistry( getCfg().getProperties()) ); stats = sf.getStatistics(); stats.clear(); stats.setStatisticsEnabled(true); @@ -105,7 +105,7 @@ public class StatsTest extends FunctionalTestCase { coll = getCfg().getCollectionMapping(Continent.class.getName() + ".countries"); coll.setFetchMode(FetchMode.SELECT); coll.setLazy(false); - sf = getCfg().buildSessionFactory( getServiceRegistry() ); + sf = getCfg().buildSessionFactory( getServiceRegistry( getCfg().getProperties() ) ); stats = sf.getStatistics(); stats.clear(); stats.setStatisticsEnabled(true); diff --git a/hibernate-core/src/test/java/org/hibernate/testing/junit/UnitTestCase.java b/hibernate-core/src/test/java/org/hibernate/testing/junit/UnitTestCase.java index 965008711f..058ddbdcd1 100644 --- a/hibernate-core/src/test/java/org/hibernate/testing/junit/UnitTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/testing/junit/UnitTestCase.java @@ -20,17 +20,20 @@ * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA - */ -package org.hibernate.testing.junit; + */ +package org.hibernate.testing.junit; import static org.hibernate.TestLogger.LOG; import java.util.Enumeration; import java.util.HashSet; +import java.util.Properties; import java.util.Set; import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; + +import org.hibernate.AssertionFailure; import org.hibernate.TestLogger; import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.spi.JdbcServices; @@ -48,6 +51,7 @@ import org.jboss.logging.Logger; public abstract class UnitTestCase extends junit.framework.TestCase { private ServiceRegistry serviceRegistry; + private Properties serviceRegistryProperties; public UnitTestCase(String string) { super( string ); @@ -93,19 +97,19 @@ public abstract class UnitTestCase extends junit.framework.TestCase { } } - protected ServiceRegistry getServiceRegistry() { + protected ServiceRegistry getServiceRegistry(Properties properties) { if ( serviceRegistry == null ) { - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); + serviceRegistryProperties = properties; + serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( properties ); + } + else if ( ! properties.equals( serviceRegistryProperties ) ) { + throw new AssertionFailure( "ServiceRegistry was already build using different properties." ); } return serviceRegistry; } - protected JdbcServices getJdbcServices() { - return getServiceRegistry().getService( JdbcServices.class ); - } - - protected ConnectionProvider getConnectionProvider() { - return getJdbcServices().getConnectionProvider(); + protected JdbcServices getJdbcServices(Properties properties) { + return getServiceRegistry( properties ).getService( JdbcServices.class ); } private static class FailureExpectedTestPassedException extends Exception { diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java index df6ab96b67..35a7aa74ad 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java @@ -73,7 +73,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm private void evictOrRemoveTest() throws Exception { Configuration cfg = createConfiguration(); InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( - getServiceRegistry(), cfg, getCacheTestSupport() + getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport() ); CacheAdapter localCache = getInfinispanCache(regionFactory); boolean invalidation = localCache.isClusteredInvalidation(); @@ -86,7 +86,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm cfg = createConfiguration(); regionFactory = CacheTestUtil.startRegionFactory( - getServiceRegistry(), cfg, getCacheTestSupport() + getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport() ); GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory, @@ -126,7 +126,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm private void evictOrRemoveAllTest(String configName) throws Exception { Configuration cfg = createConfiguration(); InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( - getServiceRegistry(), cfg, getCacheTestSupport() + getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport() ); CacheAdapter localCache = getInfinispanCache(regionFactory); @@ -138,7 +138,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm cfg = createConfiguration(); regionFactory = CacheTestUtil.startRegionFactory( - getServiceRegistry(), cfg, getCacheTestSupport() + getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport() ); CacheAdapter remoteCache = getInfinispanCache(regionFactory); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java index 32f1689e45..cf7a2e40ed 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java @@ -54,7 +54,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase if (getCollectionAccessStrategy() == null) { Configuration cfg = createConfiguration(); InfinispanRegionFactory rf = CacheTestUtil.startRegionFactory( - getServiceRegistry(), cfg, getCacheTestSupport() + getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport() ); // Sleep a bit to avoid concurrent FLUSH problem diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java index a3c85f2fb3..d455dfe273 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java @@ -60,7 +60,7 @@ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase if (getEntityAccessStrategy() == null) { Configuration cfg = createConfiguration(); InfinispanRegionFactory rf = CacheTestUtil.startRegionFactory( - getServiceRegistry(), cfg, getCacheTestSupport() + getServiceRegistry( cfg.getProperties() ), cfg, getCacheTestSupport() ); // Sleep a bit to avoid concurrent FLUSH problem diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java index 881af5e708..e794865308 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/query/QueryRegionImplTestCase.java @@ -92,7 +92,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase { private void putDoesNotBlockGetTest() throws Exception { Configuration cfg = createConfiguration(); - InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(getServiceRegistry(), cfg, getCacheTestSupport()); + InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(getServiceRegistry(cfg.getProperties()), cfg, getCacheTestSupport()); // Sleep a bit to avoid concurrent FLUSH problem avoidConcurrentFlush(); @@ -177,7 +177,7 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase { private void getDoesNotBlockPutTest() throws Exception { Configuration cfg = createConfiguration(); - InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(getServiceRegistry(), cfg, getCacheTestSupport()); + InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(getServiceRegistry(cfg.getProperties()), cfg, getCacheTestSupport()); // Sleep a bit to avoid concurrent FLUSH problem avoidConcurrentFlush(); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTestCase.java index 7392542279..39fc1804ed 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/timestamp/TimestampsRegionImplTestCase.java @@ -81,14 +81,14 @@ public class TimestampsRegionImplTestCase extends AbstractGeneralDataRegionTestC public void testClearTimestampsRegionInIsolated() throws Exception { Configuration cfg = createConfiguration(); InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory( - getServiceRegistry(), cfg, getCacheTestSupport() + getServiceRegistry(cfg.getProperties()), cfg, getCacheTestSupport() ); // Sleep a bit to avoid concurrent FLUSH problem avoidConcurrentFlush(); Configuration cfg2 = createConfiguration(); InfinispanRegionFactory regionFactory2 = CacheTestUtil.startRegionFactory( - getServiceRegistry(), cfg2, getCacheTestSupport() + getServiceRegistry(cfg2.getProperties()), cfg2, getCacheTestSupport() ); // Sleep a bit to avoid concurrent FLUSH problem avoidConcurrentFlush();