From 5975d02e3997e49f571b0feb816271565c978fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Kuruc?= Date: Thu, 15 Aug 2024 14:21:02 +0200 Subject: [PATCH] Tests with current_timestamp requires Dialect UsesStandardCurrentTimestampFunction feature --- .../community/dialect/InformixDialect.java | 5 ++ .../ComplexValueGenerationTests.java | 13 ++--- .../DatabaseValueGenerationTest.java | 3 - .../DefaultGeneratedValueIdentityTest.java | 56 +++++++++---------- .../generated/DefaultGeneratedValueTest.java | 12 ++-- .../MultipleGeneratedValuesTests.java | 2 +- .../temporals/ProposedGeneratedTests.java | 4 +- .../orm/test/query/hql/FunctionTests.java | 2 + .../test/temporal/TimestampPropertyTest.java | 9 ++- 9 files changed, 49 insertions(+), 57 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java index b269c9206b..c094d8a3bf 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java @@ -661,6 +661,11 @@ public class InformixDialect extends Dialect { appender.appendSql( datetimeFormat( format ).result() ); } + @Override + public boolean supportsStandardCurrentTimestampFunction() { + return false; + } + public static Replacer datetimeFormat(String format) { return new Replacer( format, "'", "" ) .replace("%", "%%") diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/ComplexValueGenerationTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/ComplexValueGenerationTests.java index 24cc76a7b5..a5d5cda717 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/ComplexValueGenerationTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/ComplexValueGenerationTests.java @@ -25,15 +25,14 @@ import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.Generated; import org.hibernate.annotations.UpdateTimestamp; -import org.hibernate.dialect.MySQLDialect; -import org.hibernate.dialect.SybaseDialect; -import org.hibernate.dialect.TiDBDialect; import org.hibernate.generator.EventType; + +import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; 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.AfterEach; import org.junit.jupiter.api.Test; @@ -47,9 +46,9 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Steve Ebersole */ -@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase") -@SkipForDialect(dialectClass = MySQLDialect.class, reason = "See HHH-10196") -@SkipForDialect(dialectClass = TiDBDialect.class, reason = "See HHH-10196") + +@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class ) +@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class ) @DomainModel( annotatedClasses = ComplexValueGenerationTests.AuditedEntity.class ) @SessionFactory @SuppressWarnings("JUnitMalformedDeclaration") diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DatabaseValueGenerationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DatabaseValueGenerationTest.java index ded413fd22..1b1e6ce670 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DatabaseValueGenerationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DatabaseValueGenerationTest.java @@ -13,13 +13,11 @@ import java.util.EnumSet; import org.hibernate.annotations.ValueGenerationType; import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.SybaseDialect; import org.hibernate.generator.EventType; import org.hibernate.generator.EventTypeSets; import org.hibernate.generator.OnExecutionGenerator; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; -import org.hibernate.testing.SkipForDialect; import org.junit.Test; import jakarta.persistence.Column; @@ -32,7 +30,6 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; /** * @author Vlad Mihalcea */ -@SkipForDialect(value = SybaseDialect.class, comment = "Sybase doesn't seem to support current_timestamp") public class DatabaseValueGenerationTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueIdentityTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueIdentityTest.java index 28317e4fd2..cbdf7c4bca 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueIdentityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueIdentityTest.java @@ -8,7 +8,6 @@ package org.hibernate.orm.test.mapping.generated; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.Member; import java.sql.Time; import java.sql.Timestamp; import java.time.Instant; @@ -31,19 +30,17 @@ import org.hibernate.annotations.Generated; import org.hibernate.annotations.UpdateTimestamp; import org.hibernate.annotations.ValueGenerationType; import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.MySQLDialect; -import org.hibernate.dialect.SybaseDialect; -import org.hibernate.generator.AnnotationBasedGenerator; import org.hibernate.generator.EventType; -import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.OnExecutionGenerator; -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.DialectFeatureChecks; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -51,32 +48,24 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -@SkipForDialect(value = SybaseDialect.class, comment = "CURRENT_TIMESTAMP not supported as default value in Sybase") -@SkipForDialect(value = MySQLDialect.class, comment = "See HHH-10196") -@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) -public class DefaultGeneratedValueIdentityTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { TheEntity.class }; - } - - @Override - protected boolean isCleanupTestDataUsingBulkDelete() { - return true; - } +@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsIdentityColumns.class) +@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class ) +@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class ) +@DomainModel( annotatedClasses = DefaultGeneratedValueIdentityTest.TheEntity.class ) +@SessionFactory +@SuppressWarnings("JUnitMalformedDeclaration") +public class DefaultGeneratedValueIdentityTest { @Test - @TestForIssue( jiraKey = "HHH-12671" ) - public void testGenerationWithIdentityInsert() { + @JiraKey( "HHH-12671" ) + public void testGenerationWithIdentityInsert(SessionFactoryScope scope) { final TheEntity theEntity = new TheEntity(); - doInHibernate( this::sessionFactory, session -> { + scope.inTransaction( (session) -> { assertNull( theEntity.createdDate ); assertNull( theEntity.alwaysDate ); assertNull( theEntity.vmCreatedDate ); @@ -121,7 +110,7 @@ public class DefaultGeneratedValueIdentityTest extends BaseCoreFunctionalTestCas assertNotNull( theEntity.alwaysDate ); assertEquals( "Bob", theEntity.name ); - doInHibernate( this::sessionFactory, session -> { + scope.inTransaction( (session) -> { TheEntity _theEntity = session.get( TheEntity.class, theEntity.id ); assertNotNull( _theEntity.createdDate ); assertNotNull( _theEntity.alwaysDate ); @@ -145,8 +134,13 @@ public class DefaultGeneratedValueIdentityTest extends BaseCoreFunctionalTestCas } ); } + @AfterEach + public void dropTestData(SessionFactoryScope scope) { + scope.inTransaction( (s) -> s.createQuery( "delete TheEntity" ).executeUpdate() ); + } + @Entity( name = "TheEntity" ) - private static class TheEntity { + public static class TheEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueTest.java index e35328def7..c87d00f421 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueTest.java @@ -25,21 +25,20 @@ import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.Generated; import org.hibernate.annotations.UpdateTimestamp; -import org.hibernate.dialect.MySQLDialect; -import org.hibernate.dialect.SybaseDialect; -import org.hibernate.dialect.TiDBDialect; import org.hibernate.generator.EventType; import org.hibernate.generator.internal.CurrentTimestampGeneration; import org.hibernate.orm.test.annotations.MutableClock; import org.hibernate.orm.test.annotations.MutableClockSettingProvider; + +import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; 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.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -60,9 +59,8 @@ import static org.junit.Assert.assertTrue; * @author Steve Ebersole * @author Gunnar Morling */ -@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase" ) -@SkipForDialect( dialectClass = MySQLDialect.class, reason = "See HHH-10196" ) -@SkipForDialect( dialectClass = TiDBDialect.class, reason = "See HHH-10196" ) +@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class ) +@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class ) @ServiceRegistry(settingProviders = @SettingProvider(settingName = CurrentTimestampGeneration.CLOCK_SETTING_NAME, provider = MutableClockSettingProvider.class)) @DomainModel( annotatedClasses = DefaultGeneratedValueTest.TheEntity.class ) @SessionFactory diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java index f0f3932bf8..12c3f59e80 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; @DomainModel( annotatedClasses = MultipleGeneratedValuesTests.GeneratedInstantEntity.class ) @SessionFactory @RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp") -@SkipForDialect( dialectClass = SybaseASEDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported in insert/update in Sybase ASE. Also see https://groups.google.com/g/comp.databases.sybase/c/j-RxPnF3img" ) +@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class ) @SkipForDialect( dialectClass = SQLServerDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP has millisecond precision" ) public class MultipleGeneratedValuesTests { @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/ProposedGeneratedTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/ProposedGeneratedTests.java index 15c12fdd18..280fe2b37f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/ProposedGeneratedTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/ProposedGeneratedTests.java @@ -9,7 +9,6 @@ package org.hibernate.orm.test.mapping.generated.temporals; import java.time.Instant; import org.hibernate.HibernateError; -import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.generator.EventType; import org.hibernate.testing.orm.junit.DialectFeatureChecks; @@ -17,7 +16,6 @@ import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; 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 jakarta.persistence.Entity; @@ -34,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; @DomainModel( annotatedClasses = ProposedGeneratedTests.GeneratedInstantEntity.class ) @SessionFactory @RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp") -@SkipForDialect( dialectClass = SybaseASEDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported in insert/update in Sybase ASE. Also see https://groups.google.com/g/comp.databases.sybase/c/j-RxPnF3img" ) +@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class ) public class ProposedGeneratedTests { @Test public void test(SessionFactoryScope scope) throws InterruptedException { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java index 02c0c724f2..51f22a6a53 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java @@ -9,6 +9,7 @@ package org.hibernate.orm.test.query.hql; import org.hamcrest.Matchers; import org.hibernate.QueryException; import org.hibernate.community.dialect.AltibaseDialect; +import org.hibernate.community.dialect.InformixDialect; import org.hibernate.dialect.CockroachDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.community.dialect.DerbyDialect; @@ -568,6 +569,7 @@ public class FunctionTests { @Test @SkipForDialect(dialectClass = DerbyDialect.class, reason = "Derby doesn't support any form of date truncation") + @SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix doesn't support any form of date truncation") public void testDateTruncFunction(SessionFactoryScope scope) { scope.inTransaction( session -> { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/temporal/TimestampPropertyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/temporal/TimestampPropertyTest.java index 5f6845efb7..f16c9b55c2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/temporal/TimestampPropertyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/temporal/TimestampPropertyTest.java @@ -12,15 +12,14 @@ import java.util.Date; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.Generated; -import org.hibernate.dialect.MySQLDialect; -import org.hibernate.dialect.SybaseDialect; import org.hibernate.query.Query; import org.hibernate.type.StandardBasicTypes; +import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; 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 jakarta.persistence.GeneratedValue; @@ -43,8 +42,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * @author Gail Badner */ @SuppressWarnings("JUnitMalformedDeclaration") -@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in MySQL") -@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase") +@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp") +@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class ) @DomainModel( annotatedClasses = TimestampPropertyTest.Entity.class )