From 11f4d8dcda5208ebdceae4298f8f22265872e053 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 3 Oct 2025 13:23:57 -0600 Subject: [PATCH] Drop JUnit 4 usage --- .../agroal/AgroalConnectionProviderTest.java | 69 +++-- .../test/agroal/AgroalSkipAutoCommitTest.java | 64 +++-- .../AgroalTransactionIsolationConfigTest.java | 16 +- .../test/c3p0/C3P0ConnectionProviderTest.java | 71 +++-- .../c3p0/C3P0DefaultIsolationLevelTest.java | 93 +++---- .../c3p0/C3P0DifferentIsolationLevelTest.java | 91 +++---- .../c3p0/C3P0EmptyIsolationLevelTest.java | 87 +++--- .../C3p0TransactionIsolationConfigTest.java | 31 +-- .../test/c3p0/JdbcCompatibilityTest.java | 5 +- .../OracleSQLCallableStatementProxyTest.java | 113 ++++---- .../test/c3p0/StatementCacheTest.java | 107 ++++---- ...ParallelTestingC3P0ConnectionProvider.java | 8 + hibernate-core/hibernate-core.gradle | 4 + hibernate-envers/hibernate-envers.gradle | 4 + hibernate-graalvm/hibernate-graalvm.gradle | 5 + .../HikariCPConnectionProviderTest.java | 67 +++-- .../hikaricp/HikariCPSkipAutoCommitTest.java | 98 +++---- .../HikariTransactionIsolationConfigTest.java | 20 +- ...ernate-integrationtest-java-modules.gradle | 5 + .../jcache/JCacheClasspathConfigUriTest.java | 52 ++-- .../jcache/JCacheConfigRelativePathTest.java | 51 ++-- .../orm/test/jcache/JCacheConfigUrlTest.java | 67 ++--- ...sactionalCacheConcurrencyStrategyTest.java | 159 ++++++----- .../test/jcache/LegacyRegionNamingTests.java | 85 ++++++ .../test/jcache/MissingCacheStrategyTest.java | 222 ++++++--------- .../hibernate/orm/test/jcache/TestHelper.java | 14 + .../stat/MicrometerCacheStatisticsTest.java | 252 +++++++++--------- .../test/stat/MicrometerStatisticsTest.java | 207 +++++++------- hibernate-spatial/hibernate-spatial.gradle | 5 + .../testing/cache/CachingRegionFactory.java | 7 + .../BaseTransactionIsolationConfigTest.java | 123 +++++++++ .../orm/junit/DomainModelExtension.java | 33 ++- .../junit/DomainModelParameterResolver.java | 2 +- .../orm/junit/SessionFactoryExtension.java | 2 +- .../orm/junit/SettingConfiguration.java | 2 + .../src/main/groovy/local.java-module.gradle | 3 +- 36 files changed, 1209 insertions(+), 1035 deletions(-) create mode 100644 hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/LegacyRegionNamingTests.java create mode 100644 hibernate-testing/src/main/java/org/hibernate/testing/orm/common/BaseTransactionIsolationConfigTest.java diff --git a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalConnectionProviderTest.java b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalConnectionProviderTest.java index 727e5bfbd22b..82a1a8d3b3f0 100644 --- a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalConnectionProviderTest.java +++ b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalConnectionProviderTest.java @@ -4,47 +4,54 @@ */ package org.hibernate.test.agroal; +import org.hibernate.agroal.internal.AgroalConnectionProvider; +import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess; +import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess; -import org.hibernate.engine.jdbc.spi.JdbcServices; -import org.hibernate.agroal.internal.AgroalConnectionProvider; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Brett Meyer */ -public class AgroalConnectionProviderTest extends BaseCoreFunctionalTestCase { +public class AgroalConnectionProviderTest { @Test - public void testAgroalConnectionProvider() throws Exception { - JdbcServices jdbcServices = serviceRegistry().requireService( JdbcServices.class ); - ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( - ConnectionProviderJdbcConnectionAccess.class, - jdbcServices.getBootstrapJdbcConnectionAccess() - ); - assertTyping( AgroalConnectionProvider.class, connectionAccess.getConnectionProvider() ); + @ServiceRegistry + @DomainModel + @SessionFactory + public void testAgroalConnectionProvider(ServiceRegistryScope registryScope, SessionFactoryScope factoryScope) throws Exception { + final SessionFactoryImplementor sessionFactory = factoryScope.getSessionFactory(); + + var serviceRegistry = registryScope.getRegistry(); + + JdbcServices jdbcServices = serviceRegistry.requireService( JdbcServices.class ); + var connectionAccess = assertTyping( ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess() ); + assertThat( connectionAccess ).isInstanceOf( ConnectionProviderJdbcConnectionAccess.class ); + var agroalConnectionProvider = assertTyping( AgroalConnectionProvider.class, connectionAccess.getConnectionProvider() ); - AgroalConnectionProvider agroalConnectionProvider = (AgroalConnectionProvider) connectionAccess.getConnectionProvider(); // For simplicity's sake, using the following in hibernate.properties: // hibernate.agroal.maxSize 2 // hibernate.agroal.minSize 2 List conns = new ArrayList<>(); for ( int i = 0; i < 2; i++ ) { Connection conn = agroalConnectionProvider.getConnection(); - assertNotNull( conn ); - assertFalse( conn.isClosed() ); + assertThat( conn ).isNotNull(); + assertThat( conn.isClosed() ).isFalse(); conns.add( conn ); } @@ -54,15 +61,22 @@ public void testAgroalConnectionProvider() throws Exception { } catch (SQLException e) { // expected - assertTrue( e.getMessage().contains( "timeout" ) ); + assertThat( e.getMessage() ).contains( "timeout" ); } for ( Connection conn : conns ) { agroalConnectionProvider.closeConnection( conn ); - assertTrue( conn.isClosed() ); + assertThat( conn.isClosed() ).isTrue(); } - releaseSessionFactory(); + // NOTE : The JUnit 5 infrastructure versus the JUnit 4 infrastructure causes the + // StandardServiceRegistry (the SF registry's parent) to be created with auto-closure disabled. + // That is not the normal process. + // So here we explicitly close the parent. + sessionFactory.close(); + ( (ServiceRegistryImplementor) serviceRegistry ).destroy(); + assert serviceRegistry.getParentServiceRegistry() != null : "Expecting parent service registry"; + ( (ServiceRegistryImplementor) serviceRegistry.getParentServiceRegistry() ).destroy(); try { agroalConnectionProvider.getConnection(); @@ -70,8 +84,7 @@ public void testAgroalConnectionProvider() throws Exception { } catch (Exception e) { // expected - assertTrue( e.getMessage() + " does not contain 'closed' or 'shutting down'", - e.getMessage().contains( "closed" ) || e.getMessage().contains( "shutting down" ) ); + assertThat( e.getMessage() ).containsAnyOf( "closed", "shutting down" ); } } } diff --git a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalSkipAutoCommitTest.java b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalSkipAutoCommitTest.java index 7939778ccaa5..11c3eff6f8a7 100644 --- a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalSkipAutoCommitTest.java +++ b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalSkipAutoCommitTest.java @@ -4,58 +4,63 @@ */ package org.hibernate.test.agroal; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Configuration; import org.hibernate.test.agroal.util.PreparedStatementSpyConnectionProvider; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; +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.hibernate.testing.orm.junit.SettingProvider; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import org.junit.jupiter.api.Test; + import java.sql.Connection; import java.util.List; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.cfg.JdbcSettings.AUTOCOMMIT; +import static org.hibernate.cfg.JdbcSettings.CONNECTION_PROVIDER; +import static org.hibernate.cfg.JdbcSettings.CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * @author Vlad Mihalcea */ -public class AgroalSkipAutoCommitTest extends BaseCoreFunctionalTestCase { - - private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(); - - @Override - protected void configure(Configuration configuration) { - configuration.getProperties().put( AvailableSettings.CONNECTION_PROVIDER, connectionProvider ); - configuration.getProperties().put( AvailableSettings.CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT, Boolean.TRUE ); - configuration.getProperties().put( AvailableSettings.AUTOCOMMIT, Boolean.FALSE.toString() ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{ City.class }; - } +public class AgroalSkipAutoCommitTest { + private static final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(); + private static final SettingProvider.Provider connectionProviderProvider = () -> connectionProvider; @Test - public void test() { + @ServiceRegistry( + settings = { + @Setting( name = CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT, value = "true" ), + @Setting( name = AUTOCOMMIT, value = "false" ) + }, + settingProviders = @SettingProvider(settingName = CONNECTION_PROVIDER, provider = ConnectionProviderProvider.class) + ) + @DomainModel( annotatedClasses = City.class ) + @SessionFactory + public void test(SessionFactoryScope factoryScope) { + factoryScope.getSessionFactory(); connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( (session) -> { City city = new City(); city.setId( 1L ); city.setName( "Cluj-Napoca" ); session.persist( city ); - assertTrue( connectionProvider.getAcquiredConnections().isEmpty() ); - assertTrue( connectionProvider.getReleasedConnections().isEmpty() ); + assertThat( connectionProvider.getAcquiredConnections().isEmpty() ).isTrue(); + assertThat( connectionProvider.getReleasedConnections().isEmpty() ).isTrue(); } ); verifyConnections(); connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( (session) -> { City city = session.find( City.class, 1L ); - assertEquals( "Cluj-Napoca", city.getName() ); + assertThat( city.getName() ).isEqualTo( "Cluj-Napoca" ); } ); verifyConnections(); } @@ -101,4 +106,11 @@ public void setName(String name) { this.name = name; } } + + public static class ConnectionProviderProvider implements SettingProvider.Provider { + @Override + public PreparedStatementSpyConnectionProvider getSetting() { + return connectionProvider; + } + } } diff --git a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalTransactionIsolationConfigTest.java b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalTransactionIsolationConfigTest.java index be8b8dc972bb..8499ec48fb3a 100644 --- a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalTransactionIsolationConfigTest.java +++ b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/AgroalTransactionIsolationConfigTest.java @@ -10,18 +10,22 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.test.agroal.util.GradleParallelTestingAgroalConnectionProvider; -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.common.connections.BaseTransactionIsolationConfigTest; +import org.hibernate.testing.orm.common.BaseTransactionIsolationConfigTest; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.hibernate.testing.orm.junit.SkipForDialect; /** * @author Steve Ebersole */ -@SkipForDialect(value = TiDBDialect.class, comment = "Doesn't support SERIALIZABLE isolation") -@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase cannot change isolation level in autocommit mode") -@SkipForDialect(value = GaussDBDialect.class, comment = "GaussDB does not support SERIALIZABLE isolation") +@SkipForDialect(dialectClass = TiDBDialect.class, + reason = "Doesn't support SERIALIZABLE isolation") +@SkipForDialect(dialectClass = AltibaseDialect.class, + reason = "Altibase cannot change isolation level in autocommit mode") +@SkipForDialect(dialectClass = GaussDBDialect.class, + reason = "GaussDB does not support SERIALIZABLE isolation") public class AgroalTransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest { @Override - protected ConnectionProvider getConnectionProviderUnderTest() { + protected ConnectionProvider getConnectionProviderUnderTest(ServiceRegistryScope registryScope) { return new GradleParallelTestingAgroalConnectionProvider(); } } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java index e852749220a0..2217769d3d60 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0ConnectionProviderTest.java @@ -4,55 +4,49 @@ */ package org.hibernate.test.c3p0; -import java.lang.management.ManagementFactory; -import java.util.Set; -import javax.management.MBeanServer; -import javax.management.ObjectName; - import org.hibernate.c3p0.internal.C3P0ConnectionProvider; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SkipForDialect; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import java.lang.management.ManagementFactory; +import java.util.Set; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping; /** * @author Strong Liu */ @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "JtdsConnection.isValid not implemented") -public class C3P0ConnectionProviderTest extends BaseCoreFunctionalTestCase { - - @Override - protected void releaseSessionFactory() { - super.releaseSessionFactory(); - try { - //c3p0 does not close physical connections right away, so without this hack a connection leak false alarm is triggered. - Thread.sleep( 100 ); - } - catch ( InterruptedException e ) { - } - } - +@ServiceRegistry +@DomainModel +@SessionFactory +public class C3P0ConnectionProviderTest { @Test - public void testC3P0isDefaultWhenThereIsC3P0Properties() { - JdbcServices jdbcServices = serviceRegistry().requireService( JdbcServices.class ); - ConnectionProviderJdbcConnectionAccess connectionAccess = - assertTyping( + public void testC3P0isDefaultWhenThereIsC3P0Properties(ServiceRegistryScope registryScope) throws Exception { + var serviceRegistry = registryScope.getRegistry(); + var jdbcServices = serviceRegistry.requireService( JdbcServices.class ); + var connectionAccess = assertTyping( ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess() - ); - assertTrue( connectionAccess.getConnectionProvider() instanceof C3P0ConnectionProvider ); + ); + assertThat( connectionAccess.getConnectionProvider() ).isInstanceOf( C3P0ConnectionProvider.class ); } @Test - public void testHHH6635() throws Exception { + public void testHHH6635(SessionFactoryScope factoryScope) throws Exception { + var sf = factoryScope.getSessionFactory(); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); Set set = mBeanServer.queryNames( null, null ); boolean mbeanfound = false; @@ -63,29 +57,30 @@ public void testHHH6635() throws Exception { // see according c3p0 settings in META-INF/persistence.xml int actual_minPoolSize = (Integer) mBeanServer.getAttribute( obj, "minPoolSize" ); - assertEquals( 0, actual_minPoolSize ); + assertThat( actual_minPoolSize ).isEqualTo( 0 ); int actual_initialPoolSize = (Integer) mBeanServer.getAttribute( obj, "initialPoolSize" ); - assertEquals( 0, actual_initialPoolSize ); + assertThat( actual_initialPoolSize ).isEqualTo( 0 ); int actual_maxPoolSize = (Integer) mBeanServer.getAttribute( obj, "maxPoolSize" ); - assertEquals( 800, actual_maxPoolSize ); + assertThat( actual_maxPoolSize ).isEqualTo( 800 ); int actual_maxStatements = (Integer) mBeanServer.getAttribute( obj, "maxStatements" ); - assertEquals( 50, actual_maxStatements ); + assertThat( actual_maxStatements ).isEqualTo( 50 ); int actual_maxIdleTime = (Integer) mBeanServer.getAttribute( obj, "maxIdleTime" ); - assertEquals( 300, actual_maxIdleTime ); + assertThat( actual_maxIdleTime ).isEqualTo( 300 ); int actual_idleConnectionTestPeriod = (Integer) mBeanServer.getAttribute( obj, "idleConnectionTestPeriod" ); - assertEquals( 3000, actual_idleConnectionTestPeriod ); + assertThat( actual_idleConnectionTestPeriod ).isEqualTo( 3000 ); + break; } } - assertTrue( "PooledDataSource BMean not found, please verify version of c3p0", mbeanfound ); + assertThat( mbeanfound ).as( "PooledDataSource BMean not found, please verify version of c3p0" ).isTrue(); } } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0DefaultIsolationLevelTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0DefaultIsolationLevelTest.java index ab5f7019bfc1..5b6fbfb192e7 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0DefaultIsolationLevelTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0DefaultIsolationLevelTest.java @@ -4,64 +4,50 @@ */ package org.hibernate.test.c3p0; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Map; import jakarta.persistence.Entity; import jakarta.persistence.Id; - -import org.hibernate.boot.SessionFactoryBuilder; import org.hibernate.dialect.H2Dialect; - -import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; -import org.hibernate.testing.jdbc.SQLStatementInterceptor; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.RequiresDialect; +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.hibernate.testing.orm.junit.SettingProvider; +import org.junit.jupiter.api.Test; +import java.sql.Connection; +import java.sql.SQLException; + +import static org.assertj.core.api.Assertions.assertThat; import static org.hibernate.cfg.JdbcSettings.CONNECTION_PROVIDER; import static org.hibernate.cfg.JdbcSettings.ISOLATION; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@SuppressWarnings("JUnitMalformedDeclaration") @JiraKey(value = "HHH-12749") @RequiresDialect(H2Dialect.class) -public class C3P0DefaultIsolationLevelTest extends - BaseNonConfigCoreFunctionalTestCase { - - private C3P0ProxyConnectionProvider connectionProvider; - private SQLStatementInterceptor sqlStatementInterceptor; - - @Override - protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) { - sqlStatementInterceptor = new SQLStatementInterceptor( sfb ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Person.class, - }; - } - - @Override - protected void addSettings(Map settings) { - connectionProvider = new C3P0ProxyConnectionProvider(); - settings.put( CONNECTION_PROVIDER, connectionProvider ); - settings.put( ISOLATION, "READ_COMMITTED" ); - } +@ServiceRegistry( + settings = @Setting( name = ISOLATION, value = "READ_COMMITTED" ), + settingProviders = @SettingProvider( settingName = CONNECTION_PROVIDER, provider = C3P0DefaultIsolationLevelTest.ConnectionProviderProvider.class ) +) +@DomainModel(annotatedClasses = C3P0DefaultIsolationLevelTest.Person.class) +@SessionFactory(useCollectingStatementInspector = true) +public class C3P0DefaultIsolationLevelTest { + private static final C3P0ProxyConnectionProvider connectionProvider = new C3P0ProxyConnectionProvider(); @Test - public void testStoredProcedureOutParameter() throws SQLException { - clearSpies(); + public void testStoredProcedureOutParameter(SessionFactoryScope factoryScope) throws SQLException { + var sqlCollector = factoryScope.getCollectingStatementInspector(); + sqlCollector.clear(); + connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( (session) -> { Person person = new Person(); person.id = 1L; person.name = "Vlad Mihalcea"; @@ -69,29 +55,25 @@ public void testStoredProcedureOutParameter() throws SQLException { session.persist( person ); } ); - assertEquals( 1, sqlStatementInterceptor.getSqlQueries().size() ); - assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).toLowerCase().startsWith( "insert into" ) ); + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); + assertThat( sqlCollector.getSqlQueries().get( 0 ).toLowerCase() ).startsWith( "insert into " ); Connection connectionSpy = connectionProvider.getConnectionSpyMap().keySet().iterator().next(); verify( connectionSpy, never() ).setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED ); - clearSpies(); + sqlCollector.clear(); + connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( (session) -> { Person person = session.find( Person.class, 1L ); - - assertEquals( "Vlad Mihalcea", person.name ); + assertThat( person.name ).isEqualTo( "Vlad Mihalcea" ); } ); - assertEquals( 1, sqlStatementInterceptor.getSqlQueries().size() ); - assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).toLowerCase().startsWith( "select" ) ); + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); + assertThat( sqlCollector.getSqlQueries().get( 0 ).toLowerCase() ).startsWith( "select " ); connectionSpy = connectionProvider.getConnectionSpyMap().keySet().iterator().next(); verify( connectionSpy, never() ).setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED ); } - private void clearSpies() { - sqlStatementInterceptor.getSqlQueries().clear(); - connectionProvider.clear(); - } @Entity(name = "Person") public static class Person { @@ -102,4 +84,11 @@ public static class Person { private String name; } + + public static class ConnectionProviderProvider implements SettingProvider.Provider { + @Override + public C3P0ProxyConnectionProvider getSetting() { + return connectionProvider; + } + } } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0DifferentIsolationLevelTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0DifferentIsolationLevelTest.java index abad38b9a664..8def43a7e5e6 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0DifferentIsolationLevelTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0DifferentIsolationLevelTest.java @@ -4,64 +4,51 @@ */ package org.hibernate.test.c3p0; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Map; import jakarta.persistence.Entity; import jakarta.persistence.Id; - -import org.hibernate.boot.SessionFactoryBuilder; import org.hibernate.dialect.H2Dialect; - -import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; -import org.hibernate.testing.jdbc.SQLStatementInterceptor; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.RequiresDialect; +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.hibernate.testing.orm.junit.SettingProvider; +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.sql.SQLException; +import static org.assertj.core.api.Assertions.assertThat; import static org.hibernate.cfg.JdbcSettings.CONNECTION_PROVIDER; import static org.hibernate.cfg.JdbcSettings.ISOLATION; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@SuppressWarnings("JUnitMalformedDeclaration") @JiraKey(value = "HHH-12749") @RequiresDialect(H2Dialect.class) -public class C3P0DifferentIsolationLevelTest extends - BaseNonConfigCoreFunctionalTestCase { +@ServiceRegistry( + settings = @Setting( name = ISOLATION, value = "REPEATABLE_READ" ), + settingProviders = @SettingProvider( settingName = CONNECTION_PROVIDER, provider = C3P0DifferentIsolationLevelTest.ConnectionProviderProvider.class ) +) +@DomainModel(annotatedClasses = C3P0DifferentIsolationLevelTest.Person.class) +@SessionFactory(useCollectingStatementInspector = true) +public class C3P0DifferentIsolationLevelTest { - private C3P0ProxyConnectionProvider connectionProvider; - private SQLStatementInterceptor sqlStatementInterceptor; - - @Override - protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) { - sqlStatementInterceptor = new SQLStatementInterceptor( sfb ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Person.class, - }; - } - - @Override - protected void addSettings(Map settings) { - connectionProvider = new C3P0ProxyConnectionProvider(); - settings.put( CONNECTION_PROVIDER, connectionProvider ); - settings.put( ISOLATION, "REPEATABLE_READ" ); - } + private static final C3P0ProxyConnectionProvider connectionProvider = new C3P0ProxyConnectionProvider(); @Test - public void testStoredProcedureOutParameter() throws SQLException { - clearSpies(); + public void testStoredProcedureOutParameter(SessionFactoryScope factoryScope) throws SQLException { + var sqlCollector = factoryScope.getCollectingStatementInspector(); + sqlCollector.clear(); + connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( (session) -> { Person person = new Person(); person.id = 1L; person.name = "Vlad Mihalcea"; @@ -69,30 +56,26 @@ public void testStoredProcedureOutParameter() throws SQLException { session.persist( person ); } ); - assertEquals( 1, sqlStatementInterceptor.getSqlQueries().size() ); - assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).toLowerCase().startsWith( "insert into" ) ); + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); + assertThat( sqlCollector.getSqlQueries().get( 0 ).toLowerCase() ).startsWith( "insert into " ); Connection connectionSpy = connectionProvider.getConnectionSpyMap().keySet().iterator().next(); verify( connectionSpy, times(1) ).setTransactionIsolation( Connection.TRANSACTION_REPEATABLE_READ ); - clearSpies(); + sqlCollector.clear(); + connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( (session) -> { Person person = session.find( Person.class, 1L ); - assertEquals( "Vlad Mihalcea", person.name ); + assertThat( person.name ).isEqualTo( "Vlad Mihalcea" ); } ); - assertEquals( 1, sqlStatementInterceptor.getSqlQueries().size() ); - assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).toLowerCase().startsWith( "select" ) ); + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); + assertThat( sqlCollector.getSqlQueries().get( 0 ).toLowerCase() ).startsWith( "select " ); connectionSpy = connectionProvider.getConnectionSpyMap().keySet().iterator().next(); verify( connectionSpy, times(1) ).setTransactionIsolation( Connection.TRANSACTION_REPEATABLE_READ ); } - private void clearSpies() { - sqlStatementInterceptor.getSqlQueries().clear(); - connectionProvider.clear(); - } - @Entity(name = "Person") public static class Person { @@ -102,4 +85,10 @@ public static class Person { private String name; } + public static class ConnectionProviderProvider implements SettingProvider.Provider { + @Override + public C3P0ProxyConnectionProvider getSetting() { + return connectionProvider; + } + } } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0EmptyIsolationLevelTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0EmptyIsolationLevelTest.java index a7708b6273b7..b579f14f2ca2 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0EmptyIsolationLevelTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3P0EmptyIsolationLevelTest.java @@ -6,61 +6,49 @@ import jakarta.persistence.Entity; import jakarta.persistence.Id; -import org.hibernate.boot.SessionFactoryBuilder; import org.hibernate.dialect.H2Dialect; -import org.hibernate.testing.RequiresDialect; -import org.hibernate.testing.jdbc.SQLStatementInterceptor; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; +import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; -import org.junit.Test; +import org.hibernate.testing.orm.junit.RequiresDialect; +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.hibernate.testing.orm.junit.SettingProvider; +import org.junit.jupiter.api.Test; import java.sql.Connection; import java.sql.SQLException; -import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; import static org.hibernate.cfg.JdbcSettings.CONNECTION_PROVIDER; import static org.hibernate.cfg.JdbcSettings.ISOLATION; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** * @author Vlad Mihalcea */ +@SuppressWarnings("JUnitMalformedDeclaration") @JiraKey(value = "HHH-12749") @RequiresDialect(H2Dialect.class) -public class C3P0EmptyIsolationLevelTest extends - BaseNonConfigCoreFunctionalTestCase { +@ServiceRegistry( + settings = @Setting( name = ISOLATION, value = "" ), + settingProviders = @SettingProvider( settingName = CONNECTION_PROVIDER, provider = C3P0EmptyIsolationLevelTest.ConnectionProviderProvider.class ) +) +@DomainModel(annotatedClasses = C3P0EmptyIsolationLevelTest.Person.class) +@SessionFactory(useCollectingStatementInspector = true) +public class C3P0EmptyIsolationLevelTest { - private C3P0ProxyConnectionProvider connectionProvider; - private SQLStatementInterceptor sqlStatementInterceptor; - - @Override - protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) { - sqlStatementInterceptor = new SQLStatementInterceptor( sfb ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Person.class, - }; - } - - @Override - protected void addSettings(Map settings) { - connectionProvider = new C3P0ProxyConnectionProvider(); - settings.put( CONNECTION_PROVIDER, connectionProvider ); - settings.put( ISOLATION, "" ); - } + private static final C3P0ProxyConnectionProvider connectionProvider = new C3P0ProxyConnectionProvider(); @Test - public void testStoredProcedureOutParameter() throws SQLException { - clearSpies(); + public void testStoredProcedureOutParameter(SessionFactoryScope factoryScope) throws SQLException { + var sqlCollector = factoryScope.getCollectingStatementInspector(); + sqlCollector.clear(); + connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( (session) -> { Person person = new Person(); person.id = 1L; person.name = "Vlad Mihalcea"; @@ -68,37 +56,38 @@ public void testStoredProcedureOutParameter() throws SQLException { session.persist( person ); } ); - assertEquals( 1, sqlStatementInterceptor.getSqlQueries().size() ); - assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).toLowerCase().startsWith( "insert into" ) ); + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); + assertThat( sqlCollector.getSqlQueries().get( 0 ) ).startsWithIgnoringCase( "insert into " ); Connection connectionSpy = connectionProvider.getConnectionSpyMap().keySet().iterator().next(); verify( connectionSpy, never() ).setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED ); - clearSpies(); + sqlCollector.clear(); + connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( (session) -> { Person person = session.find( Person.class, 1L ); - assertEquals( "Vlad Mihalcea", person.name ); + assertThat( person.name ).isEqualTo( "Vlad Mihalcea" ); } ); - assertEquals( 1, sqlStatementInterceptor.getSqlQueries().size() ); - assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).toLowerCase().startsWith( "select" ) ); + assertThat( sqlCollector.getSqlQueries() ).hasSize( 1 ); + assertThat( sqlCollector.getSqlQueries().get( 0 ) ).startsWithIgnoringCase( "select " ); connectionSpy = connectionProvider.getConnectionSpyMap().keySet().iterator().next(); verify( connectionSpy, never() ).setTransactionIsolation( Connection.TRANSACTION_READ_COMMITTED ); } - private void clearSpies() { - sqlStatementInterceptor.getSqlQueries().clear(); - connectionProvider.clear(); - } - @Entity(name = "Person") public static class Person { - @Id private Long id; - private String name; } + public static class ConnectionProviderProvider implements SettingProvider.Provider { + @Override + public C3P0ProxyConnectionProvider getSetting() { + return connectionProvider; + } + } + } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3p0TransactionIsolationConfigTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3p0TransactionIsolationConfigTest.java index 37acc98e93c7..1df9d5aec87d 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3p0TransactionIsolationConfigTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/C3p0TransactionIsolationConfigTest.java @@ -4,8 +4,6 @@ */ package org.hibernate.test.c3p0; -import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.c3p0.internal.C3P0ConnectionProvider; import org.hibernate.community.dialect.AltibaseDialect; import org.hibernate.community.dialect.GaussDBDialect; @@ -15,29 +13,26 @@ import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.test.c3p0.util.GradleParallelTestingC3P0ConnectionProvider; -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.common.connections.BaseTransactionIsolationConfigTest; -import org.junit.Before; +import org.hibernate.testing.orm.common.BaseTransactionIsolationConfigTest; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.hibernate.testing.orm.junit.SkipForDialect; /** * @author Steve Ebersole */ -@SkipForDialect(value = TiDBDialect.class, comment = "Doesn't support SERIALIZABLE isolation") -@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase cannot change isolation level in autocommit mode") -@SkipForDialect(value = SybaseASEDialect.class, comment = "JtdsConnection.isValid not implemented") -@SkipForDialect(value = GaussDBDialect.class, comment = "GaussDB does not support SERIALIZABLE isolation") -public class C3p0TransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest { - private StandardServiceRegistry ssr; - - @Before - public void setUp() { - ssr = new StandardServiceRegistryBuilder().build(); - } +@SkipForDialect(dialectClass = TiDBDialect.class, reason = "Doesn't support SERIALIZABLE isolation") +@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Altibase cannot change isolation level in autocommit mode") +@SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "JtdsConnection.isValid not implemented") +@SkipForDialect(dialectClass = GaussDBDialect.class, reason = "GaussDB does not support SERIALIZABLE isolation") +@ServiceRegistry +public class C3p0TransactionIsolationConfigTest + extends BaseTransactionIsolationConfigTest { @Override - protected ConnectionProvider getConnectionProviderUnderTest() { + protected ConnectionProvider getConnectionProviderUnderTest(ServiceRegistryScope registryScope) { C3P0ConnectionProvider provider = new GradleParallelTestingC3P0ConnectionProvider(); - provider.injectServices( (ServiceRegistryImplementor) ssr ); + provider.injectServices( (ServiceRegistryImplementor) registryScope.getRegistry() ); return provider; } } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/JdbcCompatibilityTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/JdbcCompatibilityTest.java index 09c1aceb20cb..fc0401ed67a7 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/JdbcCompatibilityTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/JdbcCompatibilityTest.java @@ -23,10 +23,9 @@ * * @author Vlad Mihalcea */ +@SuppressWarnings("JUnitMalformedDeclaration") @RequiresDialect(value = SQLServerDialect.class) -@DomainModel( - annotatedClasses = { IrrelevantEntity.class } -) +@DomainModel(annotatedClasses = IrrelevantEntity.class) @SessionFactory public class JdbcCompatibilityTest { diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/OracleSQLCallableStatementProxyTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/OracleSQLCallableStatementProxyTest.java index aa9da49f04dc..6ccfa89549ed 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/OracleSQLCallableStatementProxyTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/OracleSQLCallableStatementProxyTest.java @@ -4,9 +4,6 @@ */ package org.hibernate.test.c3p0; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.List; import jakarta.persistence.Entity; import jakarta.persistence.EntityResult; import jakarta.persistence.FieldResult; @@ -16,79 +13,61 @@ import jakarta.persistence.SqlResultSetMapping; import jakarta.persistence.SqlResultSetMappings; import jakarta.persistence.StoredProcedureParameter; - -import org.hibernate.cfg.Configuration; import org.hibernate.dialect.OracleDialect; - import org.hibernate.test.c3p0.util.GradleParallelTestingC3P0ConnectionProvider; -import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Before; -import org.junit.Test; +import org.hibernate.testing.orm.junit.RequiresDialect; +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.SettingProvider; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.junit.Assert.assertEquals; +import java.sql.Statement; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.cfg.JdbcSettings.CONNECTION_PROVIDER; /** * @author Vlad Mihalcea */ +@SuppressWarnings("JUnitMalformedDeclaration") @RequiresDialect(OracleDialect.class) @JiraKey(value = "HHH-10256") -public class OracleSQLCallableStatementProxyTest extends - BaseCoreFunctionalTestCase { - - protected void configure(Configuration configuration) { - configuration.setProperty( - org.hibernate.cfg.AvailableSettings.CONNECTION_PROVIDER, - GradleParallelTestingC3P0ConnectionProvider.class - ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Person.class, - }; - } - - @Before - public void init() { - doInHibernate( this::sessionFactory, session -> { - session.doWork( connection -> { - - Statement statement = null; - try { - statement = connection.createStatement(); +@ServiceRegistry(settingProviders = @SettingProvider( settingName = CONNECTION_PROVIDER, provider = GradleParallelTestingC3P0ConnectionProvider.SettingProviderImpl.class )) +@DomainModel(annotatedClasses = OracleSQLCallableStatementProxyTest.Person.class) +@SessionFactory +public class OracleSQLCallableStatementProxyTest { + @BeforeEach + void prepareDatabase(SessionFactoryScope factoryScope) { + factoryScope.inTransaction( (session) -> { + session.doWork( (connection) -> { + try (Statement statement = connection.createStatement()) { statement.executeUpdate( - "CREATE OR REPLACE FUNCTION fn_person ( " + - " personId IN NUMBER) " + - " RETURN SYS_REFCURSOR " + - "IS " + - " persons SYS_REFCURSOR; " + - "BEGIN " + - " OPEN persons FOR " + - " SELECT " + - " p.id AS \"p.id\", " + - " p.name AS \"p.name\", " + - " p.nickName AS \"p.nickName\" " + - " FROM person p " + - " WHERE p.id = personId; " + - " RETURN persons; " + - "END;" + """ + CREATE OR REPLACE FUNCTION fn_person ( \ + personId IN NUMBER) \ + RETURN SYS_REFCURSOR \ + IS \ + persons SYS_REFCURSOR; \ + BEGIN \ + OPEN persons FOR \ + SELECT \ + p.id AS "p.id", \ + p.name AS "p.name", \ + p.nickName AS "p.nickName" \ + FROM person p \ + WHERE p.id = personId; \ + RETURN persons; \ + END;""" ); } - catch (SQLException ignore) { - } - finally { - if ( statement != null ) { - statement.close(); - } - } } ); - } ); - doInHibernate( this::sessionFactory, session -> { Person person1 = new Person(); person1.setId( 1L ); person1.setName( "John Doe" ); @@ -97,14 +76,20 @@ public void init() { } ); } + @AfterEach + void cleanupDatabase(SessionFactoryScope factoryScope) { + factoryScope.dropData(); + } + @Test - public void testStoredProcedureOutParameter() { - doInHibernate( this::sessionFactory, session -> { + public void testStoredProcedureOutParameter(SessionFactoryScope factoryScope) { + factoryScope.inTransaction( (session) -> { + //noinspection unchecked List persons = session .createNamedStoredProcedureQuery( "getPerson" ) .setParameter(1, 1L) .getResultList(); - assertEquals(1, persons.size()); + assertThat( persons ).hasSize( 1 ); } ); } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/StatementCacheTest.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/StatementCacheTest.java index d63a74ee90b1..7abf1166471b 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/StatementCacheTest.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/StatementCacheTest.java @@ -4,83 +4,76 @@ */ package org.hibernate.test.c3p0; -import java.util.List; - import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; - import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SybaseASEDialect; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.JiraKey; +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.SkipForDialect; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.orm.junit.JiraKey; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests that when using cached prepared statement with batching enabled doesn't bleed over into new transactions. * * @author Shawn Clowater */ +@JiraKey(value = "HHH-7193") @SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "JtdsConnection.isValid not implemented") -public class StatementCacheTest extends BaseCoreFunctionalTestCase { +@SkipForDialect(dialectClass = SQLServerDialect.class, + reason = "started failing after upgrade to c3p0 0.10") +@ServiceRegistry +@DomainModel( annotatedClasses = IrrelevantEntity.class) +@SessionFactory +public class StatementCacheTest { @Test - @JiraKey(value = "HHH-7193") - @SkipForDialect(dialectClass = SQLServerDialect.class, - reason = "started failing after upgrade to c3p0 0.10") - public void testStatementCaching() { - inSession( - session -> { - session.beginTransaction(); + public void testStatementCaching(SessionFactoryScope factoryScope) { + factoryScope.inSession( (session) -> { + session.beginTransaction(); - //save 2 new entities, one valid, one invalid (neither should be persisted) - IrrelevantEntity irrelevantEntity = new IrrelevantEntity(); - irrelevantEntity.setName( "valid 1" ); - session.persist( irrelevantEntity ); - //name is required - irrelevantEntity = new IrrelevantEntity(); - session.persist( irrelevantEntity ); - try { - session.flush(); - Assert.fail( "Validation exception did not occur" ); - } - catch (Exception e) { - //this is expected roll the transaction back - session.getTransaction().rollback(); - } - } - ); + //save 2 new entities, one valid, one invalid (neither should be persisted) + IrrelevantEntity irrelevantEntity = new IrrelevantEntity(); + irrelevantEntity.setName( "valid 1" ); + session.persist( irrelevantEntity ); + //name is required + irrelevantEntity = new IrrelevantEntity(); + session.persist( irrelevantEntity ); + try { + session.flush(); + fail( "Validation exception did not occur" ); + } + catch (Exception e) { + //this is expected roll the transaction back + session.getTransaction().rollback(); + } + } ); - inTransaction( - session -> { - //save a new entity and commit it - IrrelevantEntity irrelevantEntity = new IrrelevantEntity(); - irrelevantEntity.setName( "valid 2" ); - session.persist( irrelevantEntity ); - session.flush(); - } - ); + factoryScope.inTransaction( session -> { + //save a new entity and commit it + IrrelevantEntity irrelevantEntity = new IrrelevantEntity(); + irrelevantEntity.setName( "valid 2" ); + session.persist( irrelevantEntity ); + session.flush(); + } ); // only one entity should have been inserted to the database // (if the statement in the cache wasn't cleared then it would have inserted both entities) - inTransaction( - session -> { - CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); - CriteriaQuery criteria = criteriaBuilder.createQuery( IrrelevantEntity.class ); - criteria.from( IrrelevantEntity.class ); - List results = session.createQuery( criteria ).list(); - -// Criteria criteria = session.createCriteria( IrrelevantEntity.class ); -// List results = criteria.list(); - Assert.assertEquals( 1, results.size() ); - } - ); - } + factoryScope.inTransaction( session -> { + CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( IrrelevantEntity.class ); + criteria.from( IrrelevantEntity.class ); + List results = session.createQuery( criteria ).list(); - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{ IrrelevantEntity.class }; + assertThat( results ).hasSize( 1 ); + } ); } } diff --git a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/util/GradleParallelTestingC3P0ConnectionProvider.java b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/util/GradleParallelTestingC3P0ConnectionProvider.java index 93b2899c29cc..8ec0f284e49a 100644 --- a/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/util/GradleParallelTestingC3P0ConnectionProvider.java +++ b/hibernate-c3p0/src/test/java/org/hibernate/test/c3p0/util/GradleParallelTestingC3P0ConnectionProvider.java @@ -6,6 +6,7 @@ import org.hibernate.HibernateException; import org.hibernate.c3p0.internal.C3P0ConnectionProvider; +import org.hibernate.testing.orm.junit.SettingProvider; import java.util.Map; @@ -20,4 +21,11 @@ public void configure(Map properties) throws HibernateException resolveFromSettings( properties ); super.configure( properties ); } + + public static class SettingProviderImpl implements SettingProvider.Provider { + @Override + public GradleParallelTestingC3P0ConnectionProvider getSetting() { + return new GradleParallelTestingC3P0ConnectionProvider(); + } + } } diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index 51b0672b2a2f..191bdb8e9041 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -49,6 +49,10 @@ dependencies { testImplementation project(':hibernate-ant') testImplementation project(':hibernate-scan-jandex') + // todo : to get rid of these + testImplementation testLibs.junit4 + testImplementation testLibs.junit4Engine + testImplementation testLibs.shrinkwrap testImplementation testLibs.shrinkwrapDescriptors testImplementation jakartaLibs.cdi diff --git a/hibernate-envers/hibernate-envers.gradle b/hibernate-envers/hibernate-envers.gradle index 78c6e30cf156..9698b3983b19 100644 --- a/hibernate-envers/hibernate-envers.gradle +++ b/hibernate-envers/hibernate-envers.gradle @@ -26,6 +26,10 @@ dependencies { testImplementation project( ':hibernate-testing' ) + // todo : to get rid of these + testImplementation testLibs.junit4 + testImplementation testLibs.junit4Engine + testAnnotationProcessor project( ':hibernate-processor' ) } diff --git a/hibernate-graalvm/hibernate-graalvm.gradle b/hibernate-graalvm/hibernate-graalvm.gradle index ffccff5f1552..3a1c936272ce 100644 --- a/hibernate-graalvm/hibernate-graalvm.gradle +++ b/hibernate-graalvm/hibernate-graalvm.gradle @@ -17,4 +17,9 @@ dependencies { testImplementation project( ':hibernate-core' ) testImplementation libs.jandex + + // todo : to get rid of these + testImplementation testLibs.junit4 + testImplementation testLibs.junit4Engine + } diff --git a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPConnectionProviderTest.java b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPConnectionProviderTest.java index 4ff145bd85bc..247e8028cc6c 100644 --- a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPConnectionProviderTest.java +++ b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPConnectionProviderTest.java @@ -13,67 +13,82 @@ import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.hikaricp.internal.HikariCPConnectionProvider; +import org.hibernate.service.spi.ServiceRegistryImplementor; +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.SkipForDialect; +import org.junit.jupiter.api.Test; -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping; +import static org.junit.jupiter.api.Assertions.fail; -import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; /** * @author Brett Meyer */ -@SkipForDialect(value = SybaseDialect.class, comment = "The jTDS driver doesn't implement Connection#isValid so this fails") -public class HikariCPConnectionProviderTest extends BaseCoreFunctionalTestCase { +@SuppressWarnings("JUnitMalformedDeclaration") +@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "The jTDS driver doesn't implement Connection#isValid so this fails") +@ServiceRegistry +@SessionFactory +public class HikariCPConnectionProviderTest { @Test - public void testHikariCPConnectionProvider() throws Exception { - JdbcServices jdbcServices = serviceRegistry().getService( JdbcServices.class ); - ConnectionProviderJdbcConnectionAccess connectionAccess = assertTyping( + public void testHikariCPConnectionProvider(SessionFactoryScope factoryScope) throws Exception { + var serviceRegistry = factoryScope.getSessionFactory().getServiceRegistry(); + var jdbcServices = serviceRegistry.requireService( JdbcServices.class ); + var connectionAccess = assertTyping( ConnectionProviderJdbcConnectionAccess.class, jdbcServices.getBootstrapJdbcConnectionAccess() ); - assertTyping( HikariCPConnectionProvider.class, connectionAccess.getConnectionProvider() ); + var hikariProvider = assertTyping( + HikariCPConnectionProvider.class, + connectionAccess.getConnectionProvider() + ); - HikariCPConnectionProvider hikariCP = (HikariCPConnectionProvider) connectionAccess.getConnectionProvider(); // For simplicity's sake, using the following in hibernate.properties: // hibernate.hikari.minimumPoolSize 2 // hibernate.hikari.maximumPoolSize 2 - final List conns = new ArrayList(); + final List conns = new ArrayList<>(); for ( int i = 0; i < 2; i++ ) { - Connection conn = hikariCP.getConnection(); - assertNotNull( conn ); - assertFalse( conn.isClosed() ); + Connection conn = hikariProvider.getConnection(); + assertThat( conn ).isNotNull(); + assertThat( conn.isClosed() ).isFalse(); conns.add( conn ); } try { - hikariCP.getConnection(); + hikariProvider.getConnection(); fail( "SQLException expected -- no more connections should have been available in the pool." ); } catch (SQLException e) { // expected - assertTrue( e.getMessage().contains( "Connection is not available, request timed out after" ) ); + assertThat( e.getMessage() ).contains( "Connection is not available, request timed out after" ); } for ( Connection conn : conns ) { - hikariCP.closeConnection( conn ); - assertTrue( conn.isClosed() ); + hikariProvider.closeConnection( conn ); + assertThat( conn.isClosed() ).isTrue(); } - releaseSessionFactory(); + // NOTE : The JUnit 5 infrastructure versus the JUnit 4 infrastructure causes the + // StandardServiceRegistry (the SF registry's parent) to be created with auto-closure disabled. + // That is not the normal process. + // So here we explicitly close the parent. + factoryScope.getSessionFactory().close(); + serviceRegistry.destroy(); + assert serviceRegistry.getParentServiceRegistry() != null : "Expecting parent service registry"; + ( (ServiceRegistryImplementor) serviceRegistry.getParentServiceRegistry() ).destroy(); + try { - hikariCP.getConnection(); + hikariProvider.getConnection(); fail( "Exception expected -- the pool should have been shutdown." ); } catch (Exception e) { // expected - assertTrue( e.getMessage().contains( "has been closed" ) ); + assertThat( e.getMessage() ).contains( "has been closed" ); } } } diff --git a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPSkipAutoCommitTest.java b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPSkipAutoCommitTest.java index e9dccfec3db6..5b6bb94f6add 100644 --- a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPSkipAutoCommitTest.java +++ b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariCPSkipAutoCommitTest.java @@ -4,91 +4,86 @@ */ package org.hibernate.test.hikaricp; -import java.sql.Connection; -import java.util.List; import jakarta.persistence.Entity; import jakarta.persistence.Id; - -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Configuration; - -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - import org.hibernate.dialect.SybaseDialect; import org.hibernate.orm.test.util.PreparedStatementSpyConnectionProvider; +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.hibernate.testing.orm.junit.SettingProvider; +import org.hibernate.testing.orm.junit.SkipForDialect; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import java.sql.Connection; +import java.util.List; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.cfg.JdbcSettings.CONNECTION_PROVIDER; +import static org.hibernate.cfg.JdbcSettings.CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT; /** * @author Vlad Mihalcea */ -@SkipForDialect(value = SybaseDialect.class, comment = "The jTDS driver doesn't implement Connection#isValid so this fails") -public class HikariCPSkipAutoCommitTest extends BaseCoreFunctionalTestCase { - - private PreparedStatementSpyConnectionProvider connectionProvider = - new PreparedStatementSpyConnectionProvider(); - - @Override - protected void configure(Configuration configuration) { - configuration.getProperties().put( - AvailableSettings.CONNECTION_PROVIDER, - connectionProvider - ); - configuration.getProperties().put( AvailableSettings.CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT, Boolean.TRUE ); - configuration.getProperties().put( "hibernate.hikari.autoCommit", Boolean.FALSE.toString() ); - } - - @Override - public void releaseSessionFactory() { - super.releaseSessionFactory(); +@SuppressWarnings("JUnitMalformedDeclaration") +@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "The jTDS driver doesn't implement Connection#isValid so this fails") +@ServiceRegistry( + settings = { + @Setting( name = CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT, value = "true" ), + @Setting( name = "hibernate.hikari.autoCommit", value = "false" ) + }, + settingProviders = @SettingProvider( settingName = CONNECTION_PROVIDER, provider = HikariCPSkipAutoCommitTest.ConnectionProviderProvider.class) +) +@DomainModel( annotatedClasses = HikariCPSkipAutoCommitTest.City.class ) +@SessionFactory +public class HikariCPSkipAutoCommitTest { + private static final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(); + + @AfterAll + static void afterAll() { connectionProvider.stop(); } - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - City.class, - }; - } - @Test - public void test() { + public void testIt(SessionFactoryScope factoryScope) throws Exception { + // force creation of the SF + factoryScope.getSessionFactory(); + connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + + factoryScope.inTransaction( session -> { City city = new City(); city.setId( 1L ); city.setName( "Cluj-Napoca" ); session.persist( city ); - assertTrue( connectionProvider.getAcquiredConnections().isEmpty() ); - assertTrue( connectionProvider.getReleasedConnections().isEmpty() ); + assertThat( connectionProvider.getAcquiredConnections() ).isEmpty(); + assertThat( connectionProvider.getReleasedConnections() ).isEmpty(); } ); verifyConnections(); connectionProvider.clear(); - doInHibernate( this::sessionFactory, session -> { + factoryScope.inTransaction( session -> { City city = session.find( City.class, 1L ); - assertEquals( "Cluj-Napoca", city.getName() ); + assertThat( city.getName() ).isEqualTo( "Cluj-Napoca" ); } ); verifyConnections(); } private void verifyConnections() { - assertTrue( connectionProvider.getAcquiredConnections().isEmpty() ); + assertThat( connectionProvider.getAcquiredConnections() ).isEmpty(); List connections = connectionProvider.getReleasedConnections(); - assertEquals( 1, connections.size() ); + assertThat( connections ).hasSize( 1 ); try { List setAutoCommitCalls = connectionProvider.spyContext.getCalls( Connection.class.getMethod( "setAutoCommit", boolean.class ), connections.get( 0 ) ); - assertTrue( "setAutoCommit should never be called", setAutoCommitCalls.isEmpty() ); + assertThat( setAutoCommitCalls ).as( "setAutoCommit should never be called" ).isEmpty(); } catch (NoSuchMethodException e) { throw new RuntimeException( e ); @@ -119,4 +114,11 @@ public void setName(String name) { this.name = name; } } + + public static class ConnectionProviderProvider implements SettingProvider.Provider { + @Override + public PreparedStatementSpyConnectionProvider getSetting() { + return connectionProvider; + } + } } diff --git a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariTransactionIsolationConfigTest.java b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariTransactionIsolationConfigTest.java index 74c16ab7b4ec..237d3071c15e 100644 --- a/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariTransactionIsolationConfigTest.java +++ b/hibernate-hikaricp/src/test/java/org/hibernate/test/hikaricp/HikariTransactionIsolationConfigTest.java @@ -11,19 +11,25 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.test.hikaricp.util.GradleParallelTestingHikariCPConnectionProvider; -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.common.connections.BaseTransactionIsolationConfigTest; +import org.hibernate.testing.orm.common.BaseTransactionIsolationConfigTest; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.hibernate.testing.orm.junit.SkipForDialect; /** * @author Steve Ebersole */ -@SkipForDialect(value = SybaseDialect.class, comment = "The jTDS driver doesn't implement Connection#getNetworkTimeout() so this fails") -@SkipForDialect(value = TiDBDialect.class, comment = "Doesn't support SERIALIZABLE isolation") -@SkipForDialect(value = AltibaseDialect.class, comment = "Altibase cannot change isolation level in autocommit mode") -@SkipForDialect(value = GaussDBDialect.class, comment = "GaussDB does not support SERIALIZABLE isolation") +@SkipForDialect(dialectClass = SybaseDialect.class, + matchSubTypes = true, + reason = "The jTDS driver doesn't implement Connection#getNetworkTimeout() so this fails") +@SkipForDialect(dialectClass = TiDBDialect.class, + reason = "Doesn't support SERIALIZABLE isolation") +@SkipForDialect(dialectClass = AltibaseDialect.class, + reason = "Altibase cannot change isolation level in autocommit mode") +@SkipForDialect(dialectClass = GaussDBDialect.class, + reason = "GaussDB does not support SERIALIZABLE isolation") public class HikariTransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest { @Override - protected ConnectionProvider getConnectionProviderUnderTest() { + protected ConnectionProvider getConnectionProviderUnderTest(ServiceRegistryScope registryScope) { return new GradleParallelTestingHikariCPConnectionProvider(); } } diff --git a/hibernate-integrationtest-java-modules/hibernate-integrationtest-java-modules.gradle b/hibernate-integrationtest-java-modules/hibernate-integrationtest-java-modules.gradle index ee5022c60447..78c72e02f3ed 100644 --- a/hibernate-integrationtest-java-modules/hibernate-integrationtest-java-modules.gradle +++ b/hibernate-integrationtest-java-modules/hibernate-integrationtest-java-modules.gradle @@ -23,6 +23,11 @@ dependencies { api project( ':hibernate-core' ) api project( ':hibernate-envers' ) implementation project( ':hibernate-scan-jandex' ) + + // todo : to get rid of these + testImplementation testLibs.junit4 + testImplementation testLibs.junit4Engine + //Provide the jakarta.cdi module, as it's required by module jakarta.transaction //but not provided as transitive dependency of Narayana. testRuntimeOnly( jakartaLibs.cdi ) diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheClasspathConfigUriTest.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheClasspathConfigUriTest.java index 6a00633f003b..17f35274f0da 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheClasspathConfigUriTest.java +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheClasspathConfigUriTest.java @@ -4,40 +4,32 @@ */ package org.hibernate.orm.test.jcache; -import java.util.Map; -import org.hibernate.cache.jcache.ConfigSettings; -import org.hibernate.cfg.Environment; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.orm.test.jcache.domain.Product; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; - -public class JCacheClasspathConfigUriTest - extends BaseNonConfigCoreFunctionalTestCase { - - @Override - protected void addSettings(Map settings) { - settings.put( Environment.CACHE_REGION_FACTORY, "jcache" ); - settings.put( ConfigSettings.CONFIG_URI, "classpath://hibernate-config/ehcache/jcache-ehcache-config.xml" ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{ - Product.class - }; - } - +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.hibernate.cache.jcache.ConfigSettings.CONFIG_URI; +import static org.hibernate.cfg.CacheSettings.CACHE_REGION_FACTORY; + +@ServiceRegistry(settings = { + @Setting(name=CACHE_REGION_FACTORY, value = "jcache"), + @Setting(name= CONFIG_URI, value = "classpath://hibernate-config/ehcache/jcache-ehcache-config.xml") +}) +@DomainModel(annotatedClasses = Product.class) +@SessionFactory +public class JCacheClasspathConfigUriTest { @Test - public void test() { - Product product = new Product(); - product.setName( "Acme" ); - product.setPriceCents( 100L ); - - doInHibernate( this::sessionFactory, session -> { + public void test(SessionFactoryScope factoryScope) { + factoryScope.inTransaction( (session) -> { + Product product = new Product(); + product.setName( "Acme" ); + product.setPriceCents( 100L ); session.persist( product ); } ); } diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheConfigRelativePathTest.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheConfigRelativePathTest.java index b4fb4e0db386..3fcd1f9b29ad 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheConfigRelativePathTest.java +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheConfigRelativePathTest.java @@ -4,39 +4,34 @@ */ package org.hibernate.orm.test.jcache; -import java.util.Map; -import org.hibernate.cache.jcache.ConfigSettings; -import org.hibernate.cfg.Environment; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.orm.test.jcache.domain.Product; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; - -public class JCacheConfigRelativePathTest - extends BaseNonConfigCoreFunctionalTestCase { - - @Override - protected void addSettings(Map settings) { - settings.put( Environment.CACHE_REGION_FACTORY, "jcache" ); - settings.put( ConfigSettings.CONFIG_URI, "/hibernate-config/ehcache/jcache-ehcache-config.xml" ); - } - - protected Class[] getAnnotatedClasses() { - return new Class[] { - Product.class - }; - } - +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.hibernate.cache.jcache.ConfigSettings.CONFIG_URI; +import static org.hibernate.cfg.CacheSettings.CACHE_REGION_FACTORY; + +@SuppressWarnings("JUnitMalformedDeclaration") +@ServiceRegistry(settings = { + @Setting(name=CACHE_REGION_FACTORY, value = "jcache"), + @Setting(name= CONFIG_URI, value = "/hibernate-config/ehcache/jcache-ehcache-config.xml") +}) +@DomainModel(annotatedClasses = Product.class) +@SessionFactory +public class JCacheConfigRelativePathTest { @Test - public void test() { - Product product = new Product(); - product.setName( "Acme" ); - product.setPriceCents( 100L ); + public void test(SessionFactoryScope factoryScope) { + factoryScope.inTransaction( (session) -> { + Product product = new Product(); + product.setName( "Acme" ); + product.setPriceCents( 100L ); - doInHibernate( this::sessionFactory, session -> { session.persist( product ); } ); } diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheConfigUrlTest.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheConfigUrlTest.java index a1a6b0c4006e..d2f663e67a92 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheConfigUrlTest.java +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheConfigUrlTest.java @@ -4,44 +4,47 @@ */ package org.hibernate.orm.test.jcache; -import java.util.Map; - -import org.hibernate.cache.jcache.ConfigSettings; -import org.hibernate.cfg.Environment; - -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.orm.test.jcache.domain.Product; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; - -public class JCacheConfigUrlTest - extends BaseNonConfigCoreFunctionalTestCase { - - @Override - protected void addSettings(Map settings) { - settings.put( Environment.CACHE_REGION_FACTORY, "jcache" ); - settings.put( - ConfigSettings.CONFIG_URI, - "file://" + Thread.currentThread().getContextClassLoader().getResource( "hibernate-config/ehcache/jcache-ehcache-config.xml" ).getPath() - ); - } - - protected Class[] getAnnotatedClasses() { - return new Class[] { - Product.class - }; - } +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.hibernate.testing.orm.junit.SettingProvider; +import org.junit.jupiter.api.Test; + +import java.net.URL; + +import static org.hibernate.cache.jcache.ConfigSettings.CONFIG_URI; +import static org.hibernate.cfg.CacheSettings.CACHE_REGION_FACTORY; + +@ServiceRegistry( + settings = @Setting(name = CACHE_REGION_FACTORY, value = "jcache"), + settingProviders = @SettingProvider( settingName = CONFIG_URI, provider = JCacheConfigUrlTest.ConfigUrlProvider.class) +) +@DomainModel(annotatedClasses = Product.class) +@SessionFactory +public class JCacheConfigUrlTest { @Test - public void test() { - Product product = new Product(); - product.setName( "Acme" ); - product.setPriceCents( 100L ); + public void test(SessionFactoryScope factoryScope) { + factoryScope.inTransaction( (session) -> { + Product product = new Product(); + product.setName( "Acme" ); + product.setPriceCents( 100L ); - doInHibernate( this::sessionFactory, session -> { session.persist( product ); } ); } + public static class ConfigUrlProvider implements SettingProvider.Provider { + @Override + public String getSetting() { + final URL configUrl = Thread.currentThread() + .getContextClassLoader() + .getResource( "hibernate-config/ehcache/jcache-ehcache-config.xml" ); + assert configUrl != null; + return "file://" + configUrl.getPath(); + } + } } diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheTransactionalCacheConcurrencyStrategyTest.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheTransactionalCacheConcurrencyStrategyTest.java index d6475cb336ec..2a3c728eb187 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheTransactionalCacheConcurrencyStrategyTest.java +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/JCacheTransactionalCacheConcurrencyStrategyTest.java @@ -4,74 +4,94 @@ */ package org.hibernate.orm.test.jcache; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; - import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.boot.SessionFactoryBuilder; -import org.hibernate.cfg.Environment; - -import org.hibernate.testing.jdbc.SQLStatementInterceptor; +import org.hibernate.testing.jdbc.SQLStatementInspector; import org.hibernate.testing.jta.TestingJtaBootstrap; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.junit.Assert.assertEquals; +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.hibernate.testing.orm.junit.SettingConfiguration; +import org.junit.jupiter.api.Test; -public class JCacheTransactionalCacheConcurrencyStrategyTest - extends BaseNonConfigCoreFunctionalTestCase { +import java.util.ArrayList; +import java.util.List; - private SQLStatementInterceptor sqlStatementInterceptor; +import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.cfg.CacheSettings.CACHE_REGION_FACTORY; +import static org.hibernate.cfg.TransactionSettings.ENABLE_LAZY_LOAD_NO_TRANS; +import static org.hibernate.cfg.TransactionSettings.TRANSACTION_COORDINATOR_STRATEGY; + +@SuppressWarnings("JUnitMalformedDeclaration") +@ServiceRegistry( + settings = { + @Setting( name = CACHE_REGION_FACTORY, value = "jcache"), + @Setting( name = TRANSACTION_COORDINATOR_STRATEGY, value = "jta"), + @Setting( name = ENABLE_LAZY_LOAD_NO_TRANS, value = "true"), + }, + settingConfigurations = @SettingConfiguration(configurer = TestingJtaBootstrap.class) +) +@DomainModel(annotatedClasses = { + JCacheTransactionalCacheConcurrencyStrategyTest.Parent.class, + JCacheTransactionalCacheConcurrencyStrategyTest.Child.class +}) +@SessionFactory(useCollectingStatementInspector = true) +public class JCacheTransactionalCacheConcurrencyStrategyTest { - @Override - protected void configureSessionFactoryBuilder(SessionFactoryBuilder sfb) { - sqlStatementInterceptor = new SQLStatementInterceptor( sfb ); - } + @Test + public void testTransactional(SessionFactoryScope factoryScope) { + final SQLStatementInspector sqlCollector = factoryScope.getCollectingStatementInspector(); - @Override - protected void addSettings(Map settings) { - settings.put( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" ); + factoryScope.inTransaction( (session) -> { + Parent parent = new Parent( 1, "first" ); + for ( int i = 0; i < 2; i++ ) { + final Child child = new Child( i, "child #" + i, parent ); + parent.addChild( child ); + } + session.persist( parent ); + } ); - TestingJtaBootstrap.prepare( settings ); - settings.put( Environment.TRANSACTION_COORDINATOR_STRATEGY, "jta" ); - settings.put( Environment.CACHE_REGION_FACTORY, "jcache" ); - } + factoryScope.inTransaction( (session) -> { + sqlCollector.clear(); - protected Class[] getAnnotatedClasses() { - return new Class[] { - Parent.class, - Child.class - }; + Parent parent = session.find( Parent.class, 1 ); + assertThat( sqlCollector.getSqlQueries() ).isEmpty(); + assertThat( parent.getChildren() ).hasSize( 2 ); + } ); } @Entity(name = "Parent") @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) public static class Parent { - @Id - @GeneratedValue - private Long id; + private Integer id; + private String name; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent") @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) - private List children = new ArrayList(); + private List children = new ArrayList<>(); + + public Parent() { + } - public Long getId() { + public Parent(Integer id, String name) { + this.id = id; + this.name = name; + } + + public Integer getId() { return id; } - public void setId(Long id) { + public void setId(Integer id) { this.id = id; } @@ -90,26 +110,36 @@ Child addChild() { return c; } + void addChild(Child c) { + children.add( c ); + } } @Entity(name = "Child") @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) public static class Child { - @Id - @GeneratedValue - private Long id; + private Integer id; + private String name; - @ManyToOne( - fetch = FetchType.LAZY - ) + @ManyToOne(fetch = FetchType.LAZY) private Parent parent; - public Long getId() { + public Child() { + } + + public Child(Integer id, String name, Parent parent) { + this.id = id; + this.name = name; + this.parent = parent; + parent.addChild(this); + } + + public Integer getId() { return id; } - public void setId(Long id) { + public void setId(Integer id) { this.id = id; } @@ -123,37 +153,4 @@ public void setParent(Parent parent) { } - @Test - public void testTransactional() { - Parent parent = new Parent(); - - doInHibernate( this::sessionFactory, session -> { - for ( int i = 0; i < 2; i++ ) { - parent.addChild(); - - session.persist( parent ); - } - } ); - - doInHibernate( this::sessionFactory, session -> { - sqlStatementInterceptor.getSqlQueries().clear(); - - Parent _parent = session.find( Parent.class, parent.getId() ); - - assertEquals( 0, sqlStatementInterceptor.getSqlQueries().size() ); - - assertEquals( 2, _parent.getChildren().size() ); - } ); - - doInHibernate( this::sessionFactory, session -> { - sqlStatementInterceptor.getSqlQueries().clear(); - - Parent _parent = session.find( Parent.class, parent.getId() ); - - assertEquals( 2, _parent.getChildren().size() ); - - assertEquals( 0, sqlStatementInterceptor.getSqlQueries().size() ); - } ); - } - } diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/LegacyRegionNamingTests.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/LegacyRegionNamingTests.java new file mode 100644 index 000000000000..05d5c26b7864 --- /dev/null +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/LegacyRegionNamingTests.java @@ -0,0 +1,85 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.orm.test.jcache; + +import org.hibernate.cache.spi.SecondLevelCacheLogger; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.testing.orm.junit.Logger; +import org.hibernate.testing.orm.junit.MessageKeyInspection; +import org.hibernate.testing.orm.junit.MessageKeyWatcher; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.hibernate.orm.test.jcache.TestHelper.queryRegionLegacyNames1; +import static org.hibernate.orm.test.jcache.TestHelper.queryRegionLegacyNames2; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("JUnitMalformedDeclaration") +@MessageKeyInspection( messageKey = "HHH90001007", + logger = @Logger( loggerName = SecondLevelCacheLogger.LOGGER_NAME ) ) +public class LegacyRegionNamingTests { + @Test + public void testMissingCacheStrategyFailLegacyNames1(MessageKeyWatcher watcher) { + checkLegacyNameHandling( watcher, queryRegionLegacyNames1, queryRegionLegacyNames2 ); + } + + @Test + public void testMissingCacheStrategyFailLegacyNames2(MessageKeyWatcher watcher) { + checkLegacyNameHandling( watcher, queryRegionLegacyNames2, queryRegionLegacyNames1 ); + } + + private void checkLegacyNameHandling( + MessageKeyWatcher watcher, + String[] existingLegacyCaches, + String[] nonExistingLegacyCaches) { + watcher.reset(); + + // make sure that the regions used for model caches exist + TestHelper.preBuildDomainCaches(); + + // and that caches exist with legacy configurations + for ( int i = 0; i < TestHelper.queryRegionNames.length; ++i ) { + String legacyName = existingLegacyCaches[i]; + TestHelper.createCache( legacyName ); + } + + // and then lets make sure that the region names we think + // are non-existent really do not exist + verifyNonExistence( nonExistingLegacyCaches, TestHelper.queryRegionNames ); + + // and now let's try to build the standard testing SessionFactory + try ( SessionFactoryImplementor ignored = TestHelper.buildSessionFactoryWithMissingCacheStrategy( "fail" ) ) { + // The session-factory should start successfully : if we reach this line, we're good + + // Logs should have been to notify that legacy cache names are being used + for ( String regionName : existingLegacyCaches ) { + verifyWarningForRegion( regionName, watcher ); + } + + // and these caches still shouldn't exist + verifyNonExistence( nonExistingLegacyCaches, TestHelper.queryRegionNames ); + } + } + + private void verifyWarningForRegion(String regionName, MessageKeyWatcher watcher) { + for ( String triggeredMessage : watcher.getTriggeredMessages() ) { + if ( triggeredMessage.contains( "[" + regionName + "]" ) ) { + return; + } + } + fail( "Warning about legacy region name was not triggered for - %s", regionName ); + } + + private static void verifyNonExistence(String[]... regionNameGroups) { + for ( String[] regionNameGroup : regionNameGroups ) { + for ( String regionName : regionNameGroup ) { + assertThat( TestHelper.getCache( regionName ) ).isNull(); + } + } + } +} diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/MissingCacheStrategyTest.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/MissingCacheStrategyTest.java index b079a604fdd6..a442ddfd164b 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/MissingCacheStrategyTest.java +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/MissingCacheStrategyTest.java @@ -4,31 +4,20 @@ */ package org.hibernate.orm.test.jcache; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Consumer; - -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cache.CacheException; -import org.hibernate.cache.jcache.ConfigSettings; import org.hibernate.cache.spi.SecondLevelCacheLogger; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.service.spi.ServiceException; +import org.hibernate.testing.orm.junit.Logger; +import org.hibernate.testing.orm.junit.LoggingInspections; +import org.hibernate.testing.orm.junit.LoggingInspectionsScope; +import org.hibernate.testing.orm.junit.MessageKeyWatcher; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.testing.logger.LoggerInspectionRule; -import org.hibernate.testing.logger.Triggerable; -import org.junit.Rule; -import org.junit.Test; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; /** * Tests around {@link org.hibernate.cache.jcache.MissingCacheStrategy} @@ -36,158 +25,97 @@ * @author Steve Ebersole * @author Yoann Rodiere */ -public class MissingCacheStrategyTest extends BaseUnitTestCase { - - @Rule - public LoggerInspectionRule logInspection = new LoggerInspectionRule( SecondLevelCacheLogger.L2CACHE_LOGGER ); - - @Test - public void testMissingCacheStrategyDefault() { - doTestMissingCacheStrategyCreateWarn( - ignored -> { } // default settings - ); - } - - @Test - public void testMissingCacheStrategyFail() { - // first, lets make sure that the region names we think are non-existent really do not exist +@SuppressWarnings("JUnitMalformedDeclaration") +@LoggingInspections(messages = { + @LoggingInspections.Message( messageKey = "HHH90001006", + loggers = @Logger( loggerName = SecondLevelCacheLogger.LOGGER_NAME ) + ), + @LoggingInspections.Message( messageKey = "HHH90001007", + loggers = @Logger( loggerName = SecondLevelCacheLogger.LOGGER_NAME ) + ) +}) +public class MissingCacheStrategyTest { + @BeforeEach + public void preCheckCaches() { + // make sure that the region names we think are non-existent really do not exist for ( String regionName : TestHelper.allDomainRegionNames ) { - assertThat( TestHelper.getCache( regionName ), nullValue() ); - } - - // and now let's try to build the standard testing SessionFactory, without pre-defining caches - try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( - builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" ) - ) ) { - fail(); - } - catch (ServiceException expected) { - assertTyping( CacheException.class, expected.getCause() ); - assertThat( expected.getMessage(), startsWith( "Unable to create requested service [" + org.hibernate.cache.spi.CacheImplementor.class.getName() + "]" ) ); - assertThat( expected.getCause().getMessage(), startsWith( "On-the-fly creation of JCache Cache objects is not supported" ) ); - } - catch (CacheException expected) { - assertThat( expected.getMessage(), equalTo( "On-the-fly creation of JCache Cache objects is not supported" ) ); + assertThat( TestHelper.getCache( regionName ) ).isNull(); } } @Test - public void testMissingCacheStrategyCreate() { - // first, lets make sure that the region names we think are non-existent really do not exist - for ( String regionName : TestHelper.allDomainRegionNames ) { - assertThat( TestHelper.getCache( regionName ), nullValue() ); - } - - // and now let's try to build the standard testing SessionFactory, without pre-defining caches - try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( - builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "create" ) - ) ) { - // The caches should have been created automatically - for ( String regionName : TestHelper.allDomainRegionNames ) { - assertThat( "Cache '" + regionName + "' should have been created", - TestHelper.getCache( regionName ), notNullValue() ); - } - } + void testMissingCacheStrategyDefault(LoggingInspectionsScope loggingInspectionsScope) { + checkCreateWarnStrategy( loggingInspectionsScope, "" ); } @Test - public void testMissingCacheStrategyCreateWarn() { - doTestMissingCacheStrategyCreateWarn( - builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "create-warn" ) - ); + void testMissingCacheStrategyCreateWarn(LoggingInspectionsScope loggingInspectionsScope) { + checkCreateWarnStrategy( loggingInspectionsScope, "create-warn" ); } - private void doTestMissingCacheStrategyCreateWarn(Consumer additionalSettings) { - Map triggerables = new HashMap<>(); + /** + * Centralized checks for the create-warn and default (which is create-warn) strategies. + * Makes sure we get WARN logging. + */ + private void checkCreateWarnStrategy( + LoggingInspectionsScope loggingInspectionsScope, + String strategyName) { + assertThat( loggingInspectionsScope ).isNotNull(); + final MessageKeyWatcher messageKeyWatcher = loggingInspectionsScope.getWatcher( + "HHH90001006", + SecondLevelCacheLogger.LOGGER_NAME + ); + messageKeyWatcher.reset(); - // first, lets make sure that the region names we think are non-existent really do not exist - for ( String regionName : TestHelper.allDomainRegionNames ) { - assertThat( TestHelper.getCache( regionName ), nullValue() ); - triggerables.put( - regionName, - logInspection.watchForLogMessages( - "HHH90001006: Missing cache region [" + TestHelper.prefix( regionName ) + "] was created" - ) - ); - } + try ( SessionFactoryImplementor ignored = TestHelper.buildSessionFactoryWithMissingCacheStrategy( strategyName ) ) { + assertThat( messageKeyWatcher.wasTriggered() ).isTrue(); - try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( additionalSettings ) ) { for ( String regionName : TestHelper.allDomainRegionNames ) { - // The caches should have been created automatically - assertThat( - "Cache '" + regionName + "' should have been created", - TestHelper.getCache( regionName ), notNullValue() - ); - // Logs should have been triggered - assertTrue( - "Cache '" + regionName + "' should have triggered a warning", - triggerables.get( regionName ).wasTriggered() - ); + // The cache should have been created automatically + assertThat( TestHelper.getCache( regionName ) ) + .as( () -> String.format( "Cache %s not found", regionName ) ) + .isNotNull(); + + // and the message should have been logged + checkForRegionCreationWarning( messageKeyWatcher, regionName ); } } } - @Test - public void testMissingCacheStrategyFailLegacyNames1() { - doTestMissingCacheStrategyFailLegacyNames( TestHelper.queryRegionLegacyNames1, TestHelper.queryRegionLegacyNames2 ); - } + private void checkForRegionCreationWarning(MessageKeyWatcher messageKeyWatcher, String regionName) { + for ( int i = 0; i < messageKeyWatcher.getTriggeredMessages().size(); i++ ) { + final String message = messageKeyWatcher.getTriggeredMessages().get( i ); + if ( message.contains( "[hibernate.test." + regionName + "]" ) ) { + return; + } + } - @Test - public void testMissingCacheStrategyFailLegacyNames2() { - doTestMissingCacheStrategyFailLegacyNames( TestHelper.queryRegionLegacyNames2, TestHelper.queryRegionLegacyNames1 ); + fail( "No warning for auto creation of region " + regionName ); } - private void doTestMissingCacheStrategyFailLegacyNames(String[] existingLegacyCaches, String[] nonExistingLegacyCaches) { - Map triggerables = new HashMap<>(); - - // first, lets make sure that the regions used for model caches exist - TestHelper.preBuildDomainCaches(); - - // and that caches exist with legacy configurations - for ( int i = 0; i < TestHelper.queryRegionNames.length; ++i ) { - String currentName = TestHelper.queryRegionNames[i]; - String legacyName = existingLegacyCaches[i]; - - TestHelper.createCache( legacyName ); - - // This is used later for log-related assertions - triggerables.put( - legacyName, - logInspection.watchForLogMessages( - "HHH90001007: Using legacy cache name [" + legacyName + - "] because configuration could not be found for cache [" + currentName + "]." - ) - ); + @Test + public void testMissingCacheStrategyFail() { + try ( SessionFactoryImplementor ignored = TestHelper.buildSessionFactoryWithMissingCacheStrategy( "fail" ) ) { + fail( "Excepting failure due to missing cache strategy = fail" ); } - - // and then lets make sure that the region names we think are non-existent really do not exist - for ( String regionName : nonExistingLegacyCaches ) { - assertThat( TestHelper.getCache( regionName ), nullValue() ); + catch (ServiceException expected) { + assertThat( expected.getCause() ).isInstanceOf( CacheException.class ); + assertThat( expected.getMessage() ).startsWith( "Unable to create requested service [" + org.hibernate.cache.spi.CacheImplementor.class.getName() + "]" ); + assertThat( expected.getCause().getMessage() ).startsWith( "On-the-fly creation of JCache Cache objects is not supported [" ); } - for ( String regionName : TestHelper.queryRegionNames ) { - assertThat( TestHelper.getCache( regionName ), nullValue() ); + catch (CacheException expected) { + assertThat( expected.getMessage() ).startsWith( "On-the-fly creation of JCache Cache objects is not supported [" ); } + } - // and now let's try to build the standard testing SessionFactory - try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( - builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" ) - ) ) { - // The session should start successfully (if we reach this line, we're good) - - // Logs should have been to notify that legacy cache names are being used - for ( String regionName : existingLegacyCaches ) { - assertTrue( - "Use of cache '" + regionName + "' should have triggered a warning", - triggerables.get( regionName ).wasTriggered() - ); - } - - // and these caches still shouldn't exist - for ( String regionName : nonExistingLegacyCaches ) { - assertThat( TestHelper.getCache( regionName ), nullValue() ); - } - for ( String regionName : TestHelper.queryRegionNames ) { - assertThat( TestHelper.getCache( regionName ), nullValue() ); + @Test + public void testMissingCacheStrategyCreate() { + try ( SessionFactoryImplementor ignored = TestHelper.buildSessionFactoryWithMissingCacheStrategy( "create" ) ) { + // The caches should have been created automatically + for ( String regionName : TestHelper.allDomainRegionNames ) { + assertThat( TestHelper.getCache( regionName ) ) + .as( () -> String.format( "Cache %s should have been created", regionName ) ) + .isNotNull(); } } } diff --git a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/TestHelper.java b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/TestHelper.java index de87cd98c3f0..ae924b35b693 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/TestHelper.java +++ b/hibernate-jcache/src/test/java/org/hibernate/orm/test/jcache/TestHelper.java @@ -17,6 +17,7 @@ import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cache.jcache.ConfigSettings; import org.hibernate.cache.jcache.JCacheHelper; import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.support.RegionNameQualifier; @@ -99,6 +100,19 @@ public static SessionFactoryImplementor buildStandardSessionFactory() { return buildStandardSessionFactory( ignored -> { } ); } + public static SessionFactoryImplementor buildSessionFactoryWithMissingCacheStrategy(String missingCacheStrategy) { + final StandardServiceRegistry ssr = getStandardServiceRegistryBuilder() + .applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, missingCacheStrategy ) + .build(); + try { + return (SessionFactoryImplementor) new MetadataSources( ssr ).buildMetadata().buildSessionFactory(); + } + catch (Throwable t) { + ssr.close(); + throw t; + } + } + public static SessionFactoryImplementor buildStandardSessionFactory(Consumer additionalSettings) { final StandardServiceRegistryBuilder ssrb = getStandardServiceRegistryBuilder(); diff --git a/hibernate-micrometer/src/test/java/org/hibernate/test/stat/MicrometerCacheStatisticsTest.java b/hibernate-micrometer/src/test/java/org/hibernate/test/stat/MicrometerCacheStatisticsTest.java index 18d7ac284cee..4d525486e0c1 100644 --- a/hibernate-micrometer/src/test/java/org/hibernate/test/stat/MicrometerCacheStatisticsTest.java +++ b/hibernate-micrometer/src/test/java/org/hibernate/test/stat/MicrometerCacheStatisticsTest.java @@ -4,180 +4,170 @@ */ package org.hibernate.test.stat; -import java.util.List; -import java.util.Map; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import jakarta.persistence.Cacheable; import jakarta.persistence.ElementCollection; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; - -import org.hibernate.Session; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.NaturalId; import org.hibernate.annotations.NaturalIdCache; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.stat.HibernateMetrics; - import org.hibernate.testing.cache.CachingRegionFactory; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +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.hibernate.testing.orm.junit.SettingProvider; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; +import java.util.List; + +import static org.hibernate.cfg.CacheSettings.CACHE_REGION_FACTORY; +import static org.hibernate.cfg.CacheSettings.USE_QUERY_CACHE; +import static org.hibernate.cfg.CacheSettings.USE_SECOND_LEVEL_CACHE; +import static org.hibernate.cfg.PersistenceSettings.SESSION_FACTORY_NAME_IS_JNDI; +import static org.hibernate.cfg.StatisticsSettings.GENERATE_STATISTICS; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Erin Schnabel * @author Steve Ebersole */ -public class MicrometerCacheStatisticsTest extends BaseNonConfigCoreFunctionalTestCase { - - @Override - protected void applyMetadataSources(MetadataSources metadataSources) { - super.applyMetadataSources( metadataSources ); - metadataSources.addAnnotatedClass( Person.class ); - metadataSources.addAnnotatedClass( Account.class ); - metadataSources.addAnnotatedClass( AccountId.class ); - } +@SuppressWarnings("JUnitMalformedDeclaration") +@ServiceRegistry( + settings = { + @Setting( name = USE_SECOND_LEVEL_CACHE, value = "true" ), + @Setting( name = USE_QUERY_CACHE, value = "true" ), + @Setting( name = GENERATE_STATISTICS, value = "true" ), + @Setting( name = SESSION_FACTORY_NAME_IS_JNDI, value = "false" ), + }, + settingProviders = @SettingProvider( settingName = CACHE_REGION_FACTORY, + provider = CachingRegionFactory.SettingProvider.class ) +) +@DomainModel(annotatedClasses = { + MicrometerCacheStatisticsTest.Person.class, + Account.class, + AccountId.class +}) +@SessionFactory( sessionFactoryName = "something" ) +public class MicrometerCacheStatisticsTest { private static final String REGION = "TheRegion"; - private static final String PREFIX = "test"; - - private SimpleMeterRegistry registry = new SimpleMeterRegistry(); - private HibernateMetrics hibernateMetrics; - - @Override - protected void configureStandardServiceRegistryBuilder(StandardServiceRegistryBuilder ssrb) { - super.configureStandardServiceRegistryBuilder( ssrb ); - ssrb.applySetting( AvailableSettings.USE_SECOND_LEVEL_CACHE, true ); - ssrb.applySetting( AvailableSettings.USE_QUERY_CACHE, true ); - ssrb.applySetting( AvailableSettings.CACHE_REGION_FACTORY, new CachingRegionFactory() ); - ssrb.applySetting( AvailableSettings.GENERATE_STATISTICS, "true" ); - } - @Override - protected void addSettings(Map settings) { - super.addSettings( settings ); - settings.put( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" ); - settings.put( AvailableSettings.USE_QUERY_CACHE, "true" ); - settings.put( AvailableSettings.CACHE_REGION_FACTORY, new CachingRegionFactory() ); - - settings.put( AvailableSettings.GENERATE_STATISTICS, "true" ); - settings.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" ); - settings.put( AvailableSettings.SESSION_FACTORY_NAME, "something" ); - settings.put( AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, "false" ); - } + private final SimpleMeterRegistry registry = new SimpleMeterRegistry(); - @Before - public void setUpMetrics() { - hibernateMetrics = new HibernateMetrics(sessionFactory(), - sessionFactory().getName(), - Tags.empty() ); + @BeforeEach + public void setUpMetrics(SessionFactoryScope factoryScope) { + var sessionFactory = factoryScope.getSessionFactory(); + var hibernateMetrics = new HibernateMetrics( + sessionFactory, + sessionFactory.getName(), + Tags.empty() + ); hibernateMetrics.bindTo( registry ); } - @After - public void cleanUpMetrics() { + @AfterEach + public void cleanUpMetrics(SessionFactoryScope factoryScope) { registry.clear(); + factoryScope.dropData(); } @Test - public void testMicrometerMetrics() { - Assert.assertNotNull(registry.get("hibernate.sessions.open").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.sessions.closed").functionCounter()); + public void testMicrometerMetrics(SessionFactoryScope factoryScope) { + assertNotNull(registry.get("hibernate.sessions.open").functionCounter()); + assertNotNull(registry.get("hibernate.sessions.closed").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.transactions").tags("result", "success").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.transactions").tags("result", "failure").functionCounter()); + assertNotNull(registry.get("hibernate.transactions").tags("result", "success").functionCounter()); + assertNotNull(registry.get("hibernate.transactions").tags("result", "failure").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.optimistic.failures").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.flushes").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.connections.obtained").functionCounter()); + assertNotNull(registry.get("hibernate.optimistic.failures").functionCounter()); + assertNotNull(registry.get("hibernate.flushes").functionCounter()); + assertNotNull(registry.get("hibernate.connections.obtained").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.statements").tags("status", "prepared").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.statements").tags("status", "closed").functionCounter()); + assertNotNull(registry.get("hibernate.statements").tags("status", "prepared").functionCounter()); + assertNotNull(registry.get("hibernate.statements").tags("status", "closed").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.second.level.cache.requests").tags("result", "hit", "region", REGION)); - Assert.assertNotNull(registry.get("hibernate.second.level.cache.requests").tags("result", "miss", "region", REGION)); - Assert.assertNotNull(registry.get("hibernate.second.level.cache.puts").tags("region", REGION).functionCounter()); + assertNotNull(registry.get("hibernate.second.level.cache.requests").tags("result", "hit", "region", REGION)); + assertNotNull(registry.get("hibernate.second.level.cache.requests").tags("result", "miss", "region", REGION)); + assertNotNull(registry.get("hibernate.second.level.cache.puts").tags("region", REGION).functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.deletes").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.fetches").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.inserts").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.loads").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.updates").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.upserts").functionCounter()); + assertNotNull(registry.get("hibernate.entities.deletes").functionCounter()); + assertNotNull(registry.get("hibernate.entities.fetches").functionCounter()); + assertNotNull(registry.get("hibernate.entities.inserts").functionCounter()); + assertNotNull(registry.get("hibernate.entities.loads").functionCounter()); + assertNotNull(registry.get("hibernate.entities.updates").functionCounter()); + assertNotNull(registry.get("hibernate.entities.upserts").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.deletes").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.fetches").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.loads").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.recreates").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.updates").functionCounter()); + assertNotNull(registry.get("hibernate.collections.deletes").functionCounter()); + assertNotNull(registry.get("hibernate.collections.fetches").functionCounter()); + assertNotNull(registry.get("hibernate.collections.loads").functionCounter()); + assertNotNull(registry.get("hibernate.collections.recreates").functionCounter()); + assertNotNull(registry.get("hibernate.collections.updates").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.natural.id.requests").tags("result", "hit").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.natural.id.requests").tags("result", "miss").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.natural.id.puts").functionCounter()); + assertNotNull(registry.get("hibernate.cache.natural.id.requests").tags("result", "hit").functionCounter()); + assertNotNull(registry.get("hibernate.cache.natural.id.requests").tags("result", "miss").functionCounter()); + assertNotNull(registry.get("hibernate.cache.natural.id.puts").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.query.natural.id.executions").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.query.natural.id.executions.max").timeGauge()); + assertNotNull(registry.get("hibernate.query.natural.id.executions").functionCounter()); + assertNotNull(registry.get("hibernate.query.natural.id.executions.max").timeGauge()); - Assert.assertNotNull(registry.get("hibernate.query.executions").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.query.executions.max").timeGauge()); + assertNotNull(registry.get("hibernate.query.executions").functionCounter()); + assertNotNull(registry.get("hibernate.query.executions.max").timeGauge()); - Assert.assertNotNull(registry.get("hibernate.cache.update.timestamps.requests").tags("result", "hit").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.update.timestamps.requests").tags("result", "miss").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.update.timestamps.puts").functionCounter()); + assertNotNull(registry.get("hibernate.cache.update.timestamps.requests").tags("result", "hit").functionCounter()); + assertNotNull(registry.get("hibernate.cache.update.timestamps.requests").tags("result", "miss").functionCounter()); + assertNotNull(registry.get("hibernate.cache.update.timestamps.puts").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.requests").tags("result", "hit").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.requests").tags("result", "miss").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.puts").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.plan").tags("result", "hit").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.plan").tags("result", "miss").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.requests").tags("result", "hit").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.requests").tags("result", "miss").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.puts").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.plan").tags("result", "hit").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.plan").tags("result", "miss").functionCounter()); // prepare some test data... - Session session = openSession(); - session.beginTransaction(); - Person person = new Person( 1, "testAcct"); - session.persist( person ); - session.getTransaction().commit(); - session.close(); - - Assert.assertEquals( 1, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.entities.inserts").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.cache.natural.id.puts").functionCounter().count(), 0); - Assert.assertEquals(2, registry.get("hibernate.second.level.cache.puts").tags("region", REGION).functionCounter().count(), 0); - - final String queryString = "select p from Person p"; - inTransaction( - // Only way to generate query region (to be accessible via stats) is to execute the query - s -> s.createQuery( queryString ).setCacheable( true ).setCacheRegion( REGION ).list() - ); - - Assert.assertEquals( 2, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); - Assert.assertEquals( 2, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); - Assert.assertEquals( 0, registry.get("hibernate.entities.deletes").functionCounter().count(), 0 ); - Assert.assertEquals( 2, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.cache.natural.id.puts").functionCounter().count(), 0); - Assert.assertEquals(3, registry.get("hibernate.second.level.cache.puts").tags("region", REGION).functionCounter().count(), 0); + factoryScope.inTransaction( (session) -> { + Person person = new Person( 1, "testAcct"); + session.persist( person ); + } ); + + assertEquals( 1, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.entities.inserts").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.cache.natural.id.puts").functionCounter().count(), 0); + assertEquals(2, registry.get("hibernate.second.level.cache.puts").tags("region", REGION).functionCounter().count(), 0); + + factoryScope.inTransaction( (session) -> { + final String queryString = "select p from Person p"; + // Only way to generate query region (to be accessible via stats) is to execute the query + session.createQuery( queryString ).setCacheable( true ).setCacheRegion( REGION ).list(); + } ); + + assertEquals( 2, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); + assertEquals( 2, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); + assertEquals( 0, registry.get("hibernate.entities.deletes").functionCounter().count(), 0 ); + assertEquals( 2, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.cache.natural.id.puts").functionCounter().count(), 0); + assertEquals(3, registry.get("hibernate.second.level.cache.puts").tags("region", REGION).functionCounter().count(), 0); // clean up - session = openSession(); - session.beginTransaction(); - session.remove( person ); - session.getTransaction().commit(); - session.close(); - - Assert.assertEquals( 3, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); - Assert.assertEquals( 3, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.entities.deletes").functionCounter().count(), 0 ); - Assert.assertEquals( 3, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); + factoryScope.inTransaction( (session) -> { + session.remove( session.find( Person.class, 1 ) ); + }); + + assertEquals( 3, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); + assertEquals( 3, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.entities.deletes").functionCounter().count(), 0 ); + assertEquals( 3, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); } @Entity( name = "Person" ) diff --git a/hibernate-micrometer/src/test/java/org/hibernate/test/stat/MicrometerStatisticsTest.java b/hibernate-micrometer/src/test/java/org/hibernate/test/stat/MicrometerStatisticsTest.java index 1a11206dd4b4..12bc5c0feb17 100644 --- a/hibernate-micrometer/src/test/java/org/hibernate/test/stat/MicrometerStatisticsTest.java +++ b/hibernate-micrometer/src/test/java/org/hibernate/test/stat/MicrometerStatisticsTest.java @@ -4,21 +4,28 @@ */ package org.hibernate.test.stat; -import org.hibernate.Session; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; -import org.hibernate.stat.HibernateMetrics; - -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - import io.micrometer.core.instrument.Tags; import io.micrometer.core.instrument.search.MeterNotFoundException; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; - +import org.hibernate.stat.HibernateMetrics; +import org.hibernate.testing.cache.CachingRegionFactory; +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.hibernate.testing.orm.junit.SettingProvider; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hibernate.cfg.CacheSettings.CACHE_REGION_FACTORY; +import static org.hibernate.cfg.CacheSettings.USE_QUERY_CACHE; +import static org.hibernate.cfg.CacheSettings.USE_SECOND_LEVEL_CACHE; +import static org.hibernate.cfg.PersistenceSettings.SESSION_FACTORY_NAME_IS_JNDI; +import static org.hibernate.cfg.StatisticsSettings.GENERATE_STATISTICS; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -27,115 +34,111 @@ * @author Erin Schnabel * @author Donnchadh O Donnabhain */ -public class MicrometerStatisticsTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Account.class, AccountId.class }; - } - - private SimpleMeterRegistry registry = new SimpleMeterRegistry(); - private HibernateMetrics hibernateMetrics; - - @Override - protected void configure(Configuration configuration) { - super.configure( configuration ); - - configuration.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" ); - configuration.setProperty( Environment.USE_QUERY_CACHE, "false" ); - configuration.setProperty( Environment.GENERATE_STATISTICS, "true" ); - configuration.setProperty( Environment.SESSION_FACTORY_NAME, "something" ); - configuration.setProperty( Environment.SESSION_FACTORY_NAME_IS_JNDI, "false" ); - } - - @Before - public void setUpMetrics() { - hibernateMetrics = new HibernateMetrics(sessionFactory(), - sessionFactory().getName(), - Tags.empty() ); +@SuppressWarnings("JUnitMalformedDeclaration") +@ServiceRegistry( + settings = { + @Setting( name = USE_SECOND_LEVEL_CACHE, value = "false" ), + @Setting( name = USE_QUERY_CACHE, value = "false" ), + @Setting( name = GENERATE_STATISTICS, value = "true" ), + @Setting( name = SESSION_FACTORY_NAME_IS_JNDI, value = "false" ), + }, + settingProviders = @SettingProvider( settingName = CACHE_REGION_FACTORY, + provider = CachingRegionFactory.SettingProvider.class ) +) +@DomainModel(annotatedClasses = {Account.class, AccountId.class}) +@SessionFactory( sessionFactoryName = "something" ) +public class MicrometerStatisticsTest { + + private final SimpleMeterRegistry registry = new SimpleMeterRegistry(); + + @BeforeEach + public void setUpMetrics(SessionFactoryScope factoryScope) { + final var sessionFactory = factoryScope.getSessionFactory(); + var hibernateMetrics = new HibernateMetrics( + sessionFactory, + sessionFactory.getName(), + Tags.empty() + ); hibernateMetrics.bindTo( registry ); } - @After - public void cleanUpMetrics() { + @AfterEach + public void cleanUpMetrics(SessionFactoryScope factoryScope) { registry.clear(); + factoryScope.dropData(); } @Test - public void testMicrometerMetrics() { - Assert.assertNotNull(registry.get("hibernate.sessions.open").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.sessions.closed").functionCounter()); + public void testMicrometerMetrics(SessionFactoryScope factoryScope) { + assertNotNull(registry.get("hibernate.sessions.open").functionCounter()); + assertNotNull(registry.get("hibernate.sessions.closed").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.transactions").tags("result", "success").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.transactions").tags("result", "failure").functionCounter()); + assertNotNull(registry.get("hibernate.transactions").tags("result", "success").functionCounter()); + assertNotNull(registry.get("hibernate.transactions").tags("result", "failure").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.optimistic.failures").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.flushes").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.connections.obtained").functionCounter()); + assertNotNull(registry.get("hibernate.optimistic.failures").functionCounter()); + assertNotNull(registry.get("hibernate.flushes").functionCounter()); + assertNotNull(registry.get("hibernate.connections.obtained").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.statements").tags("status", "prepared").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.statements").tags("status", "closed").functionCounter()); + assertNotNull(registry.get("hibernate.statements").tags("status", "prepared").functionCounter()); + assertNotNull(registry.get("hibernate.statements").tags("status", "closed").functionCounter()); // Second level cache disabled verifyMeterNotFoundException("hibernate.second.level.cache.requests"); verifyMeterNotFoundException("hibernate.second.level.cache.puts"); - Assert.assertNotNull(registry.get("hibernate.entities.deletes").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.fetches").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.inserts").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.loads").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.updates").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.entities.upserts").functionCounter()); - - Assert.assertNotNull(registry.get("hibernate.collections.deletes").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.fetches").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.loads").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.recreates").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.collections.updates").functionCounter()); - - Assert.assertNotNull(registry.get("hibernate.cache.natural.id.requests").tags("result", "hit").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.natural.id.requests").tags("result", "miss").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.natural.id.puts").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.query.natural.id.executions").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.query.natural.id.executions.max").timeGauge()); - - Assert.assertNotNull(registry.get("hibernate.query.executions").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.query.executions.max").timeGauge()); - - Assert.assertNotNull(registry.get("hibernate.cache.update.timestamps.requests").tags("result", "hit").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.update.timestamps.requests").tags("result", "miss").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.update.timestamps.puts").functionCounter()); - - Assert.assertNotNull(registry.get("hibernate.cache.query.requests").tags("result", "hit").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.requests").tags("result", "miss").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.puts").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.plan").tags("result", "hit").functionCounter()); - Assert.assertNotNull(registry.get("hibernate.cache.query.plan").tags("result", "miss").functionCounter()); + assertNotNull(registry.get("hibernate.entities.deletes").functionCounter()); + assertNotNull(registry.get("hibernate.entities.fetches").functionCounter()); + assertNotNull(registry.get("hibernate.entities.inserts").functionCounter()); + assertNotNull(registry.get("hibernate.entities.loads").functionCounter()); + assertNotNull(registry.get("hibernate.entities.updates").functionCounter()); + assertNotNull(registry.get("hibernate.entities.upserts").functionCounter()); + + assertNotNull(registry.get("hibernate.collections.deletes").functionCounter()); + assertNotNull(registry.get("hibernate.collections.fetches").functionCounter()); + assertNotNull(registry.get("hibernate.collections.loads").functionCounter()); + assertNotNull(registry.get("hibernate.collections.recreates").functionCounter()); + assertNotNull(registry.get("hibernate.collections.updates").functionCounter()); + + assertNotNull(registry.get("hibernate.cache.natural.id.requests").tags("result", "hit").functionCounter()); + assertNotNull(registry.get("hibernate.cache.natural.id.requests").tags("result", "miss").functionCounter()); + assertNotNull(registry.get("hibernate.cache.natural.id.puts").functionCounter()); + assertNotNull(registry.get("hibernate.query.natural.id.executions").functionCounter()); + assertNotNull(registry.get("hibernate.query.natural.id.executions.max").timeGauge()); + + assertNotNull(registry.get("hibernate.query.executions").functionCounter()); + assertNotNull(registry.get("hibernate.query.executions.max").timeGauge()); + + assertNotNull(registry.get("hibernate.cache.update.timestamps.requests").tags("result", "hit").functionCounter()); + assertNotNull(registry.get("hibernate.cache.update.timestamps.requests").tags("result", "miss").functionCounter()); + assertNotNull(registry.get("hibernate.cache.update.timestamps.puts").functionCounter()); + + assertNotNull(registry.get("hibernate.cache.query.requests").tags("result", "hit").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.requests").tags("result", "miss").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.puts").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.plan").tags("result", "hit").functionCounter()); + assertNotNull(registry.get("hibernate.cache.query.plan").tags("result", "miss").functionCounter()); // prepare some test data... - Session session = openSession(); - session.beginTransaction(); - Account account = new Account( new AccountId( 1), "testAcct"); - session.persist( account ); - session.getTransaction().commit(); - session.close(); - - Assert.assertEquals( 1, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.entities.inserts").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); + factoryScope.inTransaction( (session) -> { + Account account = new Account( new AccountId(1), "testAcct"); + session.persist( account ); + } ); + + assertEquals( 1, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.entities.inserts").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); // clean up - session = openSession(); - session.beginTransaction(); - session.remove( account ); - session.getTransaction().commit(); - session.close(); - - Assert.assertEquals( 2, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); - Assert.assertEquals( 2, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); - Assert.assertEquals( 1, registry.get("hibernate.entities.deletes").functionCounter().count(), 0 ); - Assert.assertEquals( 2, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); + factoryScope.inTransaction( (session) -> { + session.remove( session.find( Account.class, new AccountId(1) ) ); + } ); + + assertEquals( 2, registry.get("hibernate.sessions.open").functionCounter().count(), 0 ); + assertEquals( 2, registry.get("hibernate.sessions.closed").functionCounter().count(), 0 ); + assertEquals( 1, registry.get("hibernate.entities.deletes").functionCounter().count(), 0 ); + assertEquals( 2, registry.get("hibernate.transactions").tags("result", "success").functionCounter().count(), 0 ); } void verifyMeterNotFoundException(String name) { diff --git a/hibernate-spatial/hibernate-spatial.gradle b/hibernate-spatial/hibernate-spatial.gradle index c414ba9094b0..02d9ebb87097 100644 --- a/hibernate-spatial/hibernate-spatial.gradle +++ b/hibernate-spatial/hibernate-spatial.gradle @@ -19,6 +19,11 @@ dependencies { testImplementation project( ':hibernate-testing' ) testImplementation project( ':hibernate-ant' ) testImplementation project( path: ':hibernate-core', configuration: 'tests' ) + + // todo : to get rid of these + testImplementation testLibs.junit4 + testImplementation testLibs.junit4Engine + testImplementation jakartaLibs.validation testImplementation libs.jandex testImplementation libs.classmate diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/CachingRegionFactory.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/CachingRegionFactory.java index 7bdebf81f213..4479f6fbb845 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/CachingRegionFactory.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/CachingRegionFactory.java @@ -80,4 +80,11 @@ protected StorageAccess createTimestampsRegionStorageAccess( @Override protected void releaseFromUse() { } + + public static class SettingProvider implements org.hibernate.testing.orm.junit.SettingProvider.Provider { + @Override + public CachingRegionFactory getSetting() { + return new CachingRegionFactory(); + } + } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/common/BaseTransactionIsolationConfigTest.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/common/BaseTransactionIsolationConfigTest.java new file mode 100644 index 000000000000..8726ddfe0243 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/common/BaseTransactionIsolationConfigTest.java @@ -0,0 +1,123 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.testing.orm.common; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Environment; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.internal.util.PropertiesHelper; +import org.hibernate.service.spi.Configurable; +import org.hibernate.service.spi.Startable; +import org.hibernate.service.spi.Stoppable; +import org.hibernate.testing.orm.junit.BaseUnitTest; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +/** + * @author Steve Ebersole + */ +@BaseUnitTest +@ServiceRegistry +public abstract class BaseTransactionIsolationConfigTest { + protected abstract ConnectionProvider getConnectionProviderUnderTest(ServiceRegistryScope registryScope); + + @Test + public void testSettingIsolationAsNumeric(ServiceRegistryScope registryScope) throws Exception { + Properties properties = Environment.getProperties(); + properties.put( AvailableSettings.ISOLATION, Connection.TRANSACTION_SERIALIZABLE ); + + ConnectionProvider provider = getConnectionProviderUnderTest( registryScope ); + + try { + ( (Configurable) provider ).configure( PropertiesHelper.map( properties ) ); + + if ( provider instanceof Startable ) { + ( (Startable) provider ).start(); + } + + Connection connection = provider.getConnection(); + assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() ); + provider.closeConnection( connection ); + } + finally { + ( (Stoppable) provider ).stop(); + } + } + + @Test + public void testSettingIsolationAsNumericString(ServiceRegistryScope registryScope) throws Exception { + Properties properties = Environment.getProperties(); + properties.put( AvailableSettings.ISOLATION, Integer.toString( Connection.TRANSACTION_SERIALIZABLE ) ); + + ConnectionProvider provider = getConnectionProviderUnderTest( registryScope ); + + try { + ( (Configurable) provider ).configure( PropertiesHelper.map( properties ) ); + + if ( provider instanceof Startable ) { + ( (Startable) provider ).start(); + } + + Connection connection = provider.getConnection(); + assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() ); + provider.closeConnection( connection ); + } + finally { + ( (Stoppable) provider ).stop(); + } + } + + @Test + public void testSettingIsolationAsName(ServiceRegistryScope registryScope) throws Exception { + Properties properties = Environment.getProperties(); + properties.put( AvailableSettings.ISOLATION, "TRANSACTION_SERIALIZABLE" ); + + ConnectionProvider provider = getConnectionProviderUnderTest( registryScope ); + + try { + ( (Configurable) provider ).configure( PropertiesHelper.map( properties ) ); + + if ( provider instanceof Startable ) { + ( (Startable) provider ).start(); + } + + Connection connection = provider.getConnection(); + assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() ); + provider.closeConnection( connection ); + } + finally { + ( (Stoppable) provider ).stop(); + } + } + + @Test + public void testSettingIsolationAsNameAlt(ServiceRegistryScope registryScope) throws Exception { + Properties properties = Environment.getProperties(); + properties.put( AvailableSettings.ISOLATION, "SERIALIZABLE" ); + + ConnectionProvider provider = getConnectionProviderUnderTest( registryScope ); + + try { + ( (Configurable) provider ).configure( PropertiesHelper.map( properties ) ); + + if ( provider instanceof Startable ) { + ( (Startable) provider ).start(); + } + + Connection connection = provider.getConnection(); + assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() ); + provider.closeConnection( connection ); + } + finally { + ( (Stoppable) provider ).stop(); + } + } +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelExtension.java index 5af5096c77f2..634847d3495d 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelExtension.java @@ -46,18 +46,36 @@ public class DomainModelExtension private static final String MODEL_KEY = MetadataImplementor.class.getName(); + public static DomainModelScope requireDomainModelScope(Object testInstance, ExtensionContext context) { + var scope = findDomainModelScope( testInstance, context ); + if ( scope == null ) { + throw new RuntimeException( "Could not locate DomainModelScope : " + context.getDisplayName() ); + } + return scope; + } + + public static DomainModelScope getOrCreateDomainModelScope(Object testInstance, ExtensionContext context) { + var scope = findDomainModelScope( testInstance, context ); + if ( scope == null ) { + final ServiceRegistryScope serviceRegistryScope = ServiceRegistryExtension.findServiceRegistryScope( + testInstance, + context + ); + scope = new DomainModelScopeImpl( serviceRegistryScope, serviceRegistry -> { + return (MetadataImplementor) new MetadataSources( serviceRegistry ).buildMetadata(); + } ); + } + return scope; + } + + /** * Intended for use from external consumers. Will never create a scope, just * attempt to consume an already created and stored one */ public static DomainModelScope findDomainModelScope(Object testInstance, ExtensionContext context) { final ExtensionContext.Store store = locateExtensionStore( testInstance, context ); - final DomainModelScope existing = (DomainModelScope) store.get( MODEL_KEY ); - if ( existing != null ) { - return existing; - } - - throw new RuntimeException( "Could not locate DomainModelScope : " + context.getDisplayName() ); + return (DomainModelScope) store.get( MODEL_KEY ); } public static DomainModelScope resolveForMethodLevelSessionFactoryScope(ExtensionContext context) { @@ -147,7 +165,8 @@ private static ExtensionContext.Store locateExtensionStore(Object testInstance, } private static DomainModelScope createDomainModelScope( - Object testInstance, Optional domainModelAnnRef, + Object testInstance, + Optional domainModelAnnRef, ExtensionContext context) { final ServiceRegistryScope serviceRegistryScope = ServiceRegistryExtension.findServiceRegistryScope( testInstance, diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelParameterResolver.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelParameterResolver.java index 87976161931b..05203d1cabb2 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelParameterResolver.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelParameterResolver.java @@ -26,7 +26,7 @@ public boolean supportsParameter( public Object resolveParameter( ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { - final DomainModelScope modelScope = DomainModelExtension.findDomainModelScope( + final DomainModelScope modelScope = DomainModelExtension.requireDomainModelScope( extensionContext.getRequiredTestInstance(), extensionContext ); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java index bf59a3d181f0..ce584a3dc1f2 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java @@ -75,7 +75,7 @@ public void postProcessTestInstance(Object testInstance, ExtensionContext contex if ( sfAnnRef.isPresent() || SessionFactoryProducer.class.isAssignableFrom( context.getRequiredTestClass() ) ) { - final DomainModelScope domainModelScope = DomainModelExtension.findDomainModelScope( testInstance, context ); + final DomainModelScope domainModelScope = DomainModelExtension.getOrCreateDomainModelScope( testInstance, context ); final SessionFactoryScope created = createSessionFactoryScope( testInstance, sfAnnRef, domainModelScope, context ); locateExtensionStore( testInstance, context ).put( SESSION_FACTORY_KEY, created ); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SettingConfiguration.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SettingConfiguration.java index 9a82b7ed1383..7dd4e4866140 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SettingConfiguration.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SettingConfiguration.java @@ -7,6 +7,8 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; /** + * Allows setting multiple configuration values at once. + * * @author Steve Ebersole */ public @interface SettingConfiguration { diff --git a/local-build-plugins/src/main/groovy/local.java-module.gradle b/local-build-plugins/src/main/groovy/local.java-module.gradle index 003186fa84c2..ce507eafd58f 100644 --- a/local-build-plugins/src/main/groovy/local.java-module.gradle +++ b/local-build-plugins/src/main/groovy/local.java-module.gradle @@ -59,8 +59,7 @@ dependencies { testImplementation testLibs.junit5Engine testImplementation testLibs.junit5Params testImplementation testLibs.junit5Launcher - testImplementation testLibs.junit4 - testImplementation testLibs.junit4Engine + testImplementation testLibs.assertjCore testRuntimeOnly testLibs.log4j2