Restrict enum tests on column checks based on dialect support

This commit is contained in:
Marco Belladelli 2024-06-25 13:22:51 +02:00 committed by Steve Ebersole
parent 5a111c8fbb
commit 921d59ee8b
3 changed files with 13 additions and 2 deletions

View File

@ -15,7 +15,10 @@
import org.hibernate.orm.test.mapping.enumeratedvalue.EnumeratedValueTests;
import org.hibernate.type.SqlTypes;
import org.hibernate.testing.orm.junit.DialectFeatureCheck;
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;
@ -79,15 +82,16 @@ void testNulls(SessionFactoryScope scope) {
} );
}
@DomainModel(annotatedClasses = EnumeratedValueTests.Person.class)
@DomainModel(annotatedClasses = Person.class)
@SessionFactory(useCollectingStatementInspector = true)
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsColumnCheck.class )
@Test
void verifyCheckConstraints(SessionFactoryScope scope) {
scope.inTransaction( (session) -> session.doWork( (connection) -> {
try (PreparedStatement statement = connection.prepareStatement( "insert into persons (id, gender) values (?, ?)" ) ) {
statement.setInt( 1, 100 );
// this would work without check constraints or with check constraints based solely on EnumType#STRING
statement.setString( 2, "MALE" );
statement.setString( 2, "A" );
statement.executeUpdate();
fail( "Expecting a failure" );
}

View File

@ -15,7 +15,9 @@
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.type.SqlTypes;
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;
@ -86,6 +88,7 @@ void testNulls(SessionFactoryScope scope) {
@DomainModel(annotatedClasses = Person.class)
@SessionFactory
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsColumnCheck.class )
@Test
void verifyCheckConstraints(SessionFactoryScope scope) {
scope.inTransaction( (session) -> session.doWork( (connection) -> {
@ -103,6 +106,7 @@ void verifyCheckConstraints(SessionFactoryScope scope) {
@DomainModel(annotatedClasses = Person.class)
@SessionFactory
@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "Sybase (at least jTDS driver) truncates the value so the constraint is not violated" )
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsColumnCheck.class )
@Test
void verifyCheckConstraints2(SessionFactoryScope scope) {
scope.inTransaction( (session) -> session.doWork( (connection) -> {

View File

@ -12,7 +12,9 @@
import java.sql.Statement;
import org.hibernate.testing.jdbc.SQLStatementInspector;
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;
@ -85,6 +87,7 @@ void testNulls(SessionFactoryScope scope) {
@DomainModel(annotatedClasses = Person.class)
@SessionFactory(useCollectingStatementInspector = true)
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsColumnCheck.class )
@Test
void verifyCheckConstraints(SessionFactoryScope scope) {
scope.inTransaction( (session) -> session.doWork( (connection) -> {