From 1fb839b8417a23766648be3c3d711d3bde47d8da Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 3 Aug 2021 10:25:25 +0200 Subject: [PATCH] Skip some tests for databases that don't support a current_timestamp function with microsecond precision --- .../generated/AbstractGeneratedPropertyTest.java | 6 ++++++ .../generated/ComplexValueGenerationTests.java | 5 +++++ .../generated/CurrentTimestampAnnotationTests.java | 4 ++++ .../generated/DefaultGeneratedValueIdentityTest.java | 4 +++- .../mapping/generated/DefaultGeneratedValueTest.java | 2 +- .../generated/GeneratedPropertyEntity.hbm.xml | 6 ++---- .../InDbGenerationsWithAnnotationsTests.java | 4 ++++ .../generated/MSSQLGeneratedPropertyEntity.hbm.xml | 4 ++-- .../TimestampGeneratedValuesWithCachingTest.java | 2 +- .../TriggerGeneratedValuesWithCachingTest.java | 6 ++++-- .../TriggerGeneratedValuesWithoutCachingTest.java | 6 +++--- .../generated/temporals/GeneratedInstantTests.java | 4 ++++ .../temporals/MultipleGeneratedValuesTests.java | 6 ++++++ .../generated/temporals/ProposedGeneratedTests.java | 6 ++++++ .../testing/orm/junit/DialectFeatureChecks.java | 12 ++++++++++++ 15 files changed, 63 insertions(+), 14 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/AbstractGeneratedPropertyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/AbstractGeneratedPropertyTest.java index 192f134838..0b654f97ee 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/AbstractGeneratedPropertyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/AbstractGeneratedPropertyTest.java @@ -22,6 +22,12 @@ import static org.junit.Assert.assertTrue; * @author Steve Ebersole */ public abstract class AbstractGeneratedPropertyTest extends BaseCoreFunctionalTestCase { + + @Override + protected String getBaseForMappings() { + return "org/hibernate/orm/test/"; + } + @Test @TestForIssue( jiraKey = "HHH-2627" ) public final void testGeneratedProperty() { 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 075d995b18..281d880b4b 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 @@ -31,11 +31,14 @@ import org.hibernate.annotations.Generated; import org.hibernate.annotations.GenerationTime; import org.hibernate.annotations.GeneratorType; import org.hibernate.annotations.UpdateTimestamp; +import org.hibernate.dialect.MySQLDialect; +import org.hibernate.dialect.SybaseDialect; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.NotImplementedYet; 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; @@ -44,6 +47,8 @@ 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") @DomainModel( annotatedClasses = ComplexValueGenerationTests.AuditedEntity.class ) @SessionFactory @NotImplementedYet( diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/CurrentTimestampAnnotationTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/CurrentTimestampAnnotationTests.java index 773a458799..f2fcf0ab71 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/CurrentTimestampAnnotationTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/CurrentTimestampAnnotationTests.java @@ -14,7 +14,9 @@ import javax.persistence.Table; import org.hibernate.annotations.CurrentTimestamp; import org.hibernate.tuple.GenerationTiming; +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.junit.jupiter.api.Test; @@ -26,6 +28,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ @DomainModel( annotatedClasses = CurrentTimestampAnnotationTests.AuditedEntity.class ) @SessionFactory +@RequiresDialectFeature(feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class, comment = "We rely on current_timestamp being the SQL function name") +@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp") public class CurrentTimestampAnnotationTests { @Test public void test(SessionFactoryScope scope) { 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 32f76ca468..c5242ffffe 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 @@ -36,8 +36,10 @@ import org.hibernate.annotations.GenerationTime; import org.hibernate.annotations.GeneratorType; import org.hibernate.annotations.UpdateTimestamp; import org.hibernate.annotations.ValueGenerationType; +import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.SybaseDialect; +import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.tuple.AnnotationValueGeneration; import org.hibernate.tuple.GenerationTiming; import org.hibernate.tuple.ValueGenerator; @@ -58,7 +60,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @SkipForDialect(value = SybaseDialect.class, comment = "CURRENT_TIMESTAMP not supported as default value in Sybase") -@SkipForDialect(value = MySQLDialect.class, comment = "See HHH-10196", strictMatching = false) +@SkipForDialect(value = MySQLDialect.class, comment = "See HHH-10196") @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) @FailureExpected( jiraKey = "", 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 1111238b6d..4e4d6052c6 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 @@ -59,7 +59,7 @@ import static org.junit.Assert.assertTrue; * @author Steve Ebersole * @author Gunnar Morling */ -@SkipForDialect( dialectClass = SybaseDialect.class, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase" ) +@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase" ) @SkipForDialect( dialectClass = MySQLDialect.class, reason = "See HHH-10196" ) @NotImplementedYet( strict = false, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/GeneratedPropertyEntity.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/GeneratedPropertyEntity.hbm.xml index 7edbe6a3c7..341e0edf5b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/GeneratedPropertyEntity.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/GeneratedPropertyEntity.hbm.xml @@ -9,7 +9,7 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + @@ -41,9 +41,7 @@ - - - + \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/InDbGenerationsWithAnnotationsTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/InDbGenerationsWithAnnotationsTests.java index 29712c32f1..27d2cc5ba9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/InDbGenerationsWithAnnotationsTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/InDbGenerationsWithAnnotationsTests.java @@ -17,7 +17,9 @@ import org.hibernate.annotations.UpdateTimestamp; import org.hibernate.annotations.CurrentTimestamp; import org.hibernate.tuple.GenerationTiming; +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.junit.jupiter.api.AfterEach; @@ -33,6 +35,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ @DomainModel( annotatedClasses = InDbGenerationsWithAnnotationsTests.AuditedEntity.class ) @SessionFactory +@RequiresDialectFeature(feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class, comment = "We rely on current_timestamp being the SQL function name") +@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp") public class InDbGenerationsWithAnnotationsTests { @Test public void testGenerations(SessionFactoryScope scope) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/MSSQLGeneratedPropertyEntity.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/MSSQLGeneratedPropertyEntity.hbm.xml index c124381381..02c423702f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/MSSQLGeneratedPropertyEntity.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/MSSQLGeneratedPropertyEntity.hbm.xml @@ -9,7 +9,7 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + @@ -18,7 +18,7 @@ - + diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TimestampGeneratedValuesWithCachingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TimestampGeneratedValuesWithCachingTest.java index e2add1b647..0736472c29 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TimestampGeneratedValuesWithCachingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TimestampGeneratedValuesWithCachingTest.java @@ -20,6 +20,6 @@ import org.hibernate.testing.RequiresDialect; ) public class TimestampGeneratedValuesWithCachingTest extends AbstractGeneratedPropertyTest { public final String[] getMappings() { - return new String[] { "generated/MSSQLGeneratedPropertyEntity.hbm.xml" }; + return new String[] { "mapping/generated/MSSQLGeneratedPropertyEntity.hbm.xml" }; } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TriggerGeneratedValuesWithCachingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TriggerGeneratedValuesWithCachingTest.java index 7b13523cf2..6b387944ee 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TriggerGeneratedValuesWithCachingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TriggerGeneratedValuesWithCachingTest.java @@ -7,6 +7,8 @@ package org.hibernate.orm.test.mapping.generated; import org.hibernate.dialect.Oracle9iDialect; +import org.hibernate.dialect.OracleDialect; + import org.hibernate.testing.RequiresDialect; /** @@ -14,9 +16,9 @@ import org.hibernate.testing.RequiresDialect; * * @author Steve Ebersole */ -@RequiresDialect( value = Oracle9iDialect.class ) +@RequiresDialect( value = OracleDialect.class ) public class TriggerGeneratedValuesWithCachingTest extends AbstractGeneratedPropertyTest { public final String[] getMappings() { - return new String[] { "generated/GeneratedPropertyEntity.hbm.xml" }; + return new String[] { "mapping/generated/GeneratedPropertyEntity.hbm.xml" }; } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TriggerGeneratedValuesWithoutCachingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TriggerGeneratedValuesWithoutCachingTest.java index d368bcdad0..573130579c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TriggerGeneratedValuesWithoutCachingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/TriggerGeneratedValuesWithoutCachingTest.java @@ -6,17 +6,17 @@ */ package org.hibernate.orm.test.mapping.generated; -import org.hibernate.dialect.Oracle9iDialect; +import org.hibernate.dialect.OracleDialect; import org.hibernate.testing.RequiresDialect; /** * @author Steve Ebersole */ -@RequiresDialect( value = Oracle9iDialect.class ) +@RequiresDialect( value = OracleDialect.class ) public class TriggerGeneratedValuesWithoutCachingTest extends AbstractGeneratedPropertyTest { public final String[] getMappings() { - return new String[] { "generated/GeneratedPropertyEntity.hbm.xml" }; + return new String[] { "mapping/generated/GeneratedPropertyEntity.hbm.xml" }; } public String getCacheConcurrencyStrategy() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedInstantTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedInstantTests.java index 872ed6fa04..b8dd087d32 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedInstantTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedInstantTests.java @@ -14,7 +14,9 @@ import javax.persistence.Table; import org.hibernate.annotations.CurrentTimestamp; import org.hibernate.tuple.GenerationTiming; +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.junit.jupiter.api.Test; @@ -26,6 +28,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ @DomainModel( annotatedClasses = GeneratedInstantTests.GeneratedInstantEntity.class ) @SessionFactory +@RequiresDialectFeature(feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class, comment = "We rely on current_timestamp being the SQL function name") +@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp") public class GeneratedInstantTests { @Test public void test(SessionFactoryScope scope) { 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 61ca233d51..50a911d92a 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 @@ -12,11 +12,15 @@ import javax.persistence.Id; import javax.persistence.Table; import org.hibernate.annotations.CurrentTimestamp; +import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.tuple.GenerationTiming; +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 static org.assertj.core.api.Assertions.assertThat; @@ -28,6 +32,8 @@ 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" ) public class MultipleGeneratedValuesTests { @Test public void test(SessionFactoryScope scope) { 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 068743f454..e95201e1ac 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 @@ -11,11 +11,15 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; +import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.tuple.GenerationTiming; +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 static org.assertj.core.api.Assertions.assertThat; @@ -27,6 +31,8 @@ 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" ) public class ProposedGeneratedTests { @Test public void test(SessionFactoryScope scope) { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java index ddd57efaf7..eb3af0d945 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java @@ -372,4 +372,16 @@ abstract public class DialectFeatureChecks { return ! dialect.doesRepeatableReadCauseReadersToBlockWriters(); } } + + public static class CurrentTimestampHasMicrosecondPrecision implements DialectFeatureCheck { + public boolean apply(Dialect dialect) { + return !dialect.currentTimestamp().contains( "6" ); + } + } + + public static class UsesStandardCurrentTimestampFunction implements DialectFeatureCheck { + public boolean apply(Dialect dialect) { + return dialect.currentTimestamp().startsWith( "current_timestamp" ); + } + } }