diff --git a/hibernate-core/src/test/java/org/hibernate/test/idgen/userdefined/UserDefinedGeneratorsTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/idgen/userdefined/UserDefinedGeneratorsTests.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/idgen/userdefined/UserDefinedGeneratorsTests.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/idgen/userdefined/UserDefinedGeneratorsTests.java index e84c5681bf..f875d210f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/idgen/userdefined/UserDefinedGeneratorsTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/idgen/userdefined/UserDefinedGeneratorsTests.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.idgen.userdefined; +package org.hibernate.orm.test.idgen.userdefined; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; @@ -40,15 +40,18 @@ import org.hibernate.resource.beans.container.spi.ContainedBean; import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.BaseUnitTest; + +import org.junit.jupiter.api.Test; + import org.mockito.Mockito; /** * @author Yanming Zhou */ @TestForIssue(jiraKey = "HHH-14688") -public class UserDefinedGeneratorsTests extends BaseUnitTestCase { +@BaseUnitTest +public class UserDefinedGeneratorsTests { @Test public void testCreateGeneratorsByBeanContainer() { @@ -104,7 +107,7 @@ public class UserDefinedGeneratorsTests extends BaseUnitTestCase { public static class Entity1 { @Id @GeneratedValue( generator = "test" ) - @GenericGenerator( name = "test", strategy = "org.hibernate.test.idgen.userdefined.UserDefinedGeneratorsTests$TestIdentifierGenerator" ) + @GenericGenerator( name = "test", strategy = "org.hibernate.orm.test.idgen.userdefined.UserDefinedGeneratorsTests$TestIdentifierGenerator" ) private Integer id; } @@ -113,7 +116,7 @@ public class UserDefinedGeneratorsTests extends BaseUnitTestCase { public static class Entity2 { @Id @GeneratedValue( generator = "test" ) - @GenericGenerator( name = "test", strategy = "org.hibernate.test.idgen.userdefined.UserDefinedGeneratorsTests$TestIdentifierGenerator" ) + @GenericGenerator( name = "test", strategy = "org.hibernate.orm.test.idgen.userdefined.UserDefinedGeneratorsTests$TestIdentifierGenerator" ) private Integer id; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/AssociatedDataPoint.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/AssociatedDataPoint.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/quote/AssociatedDataPoint.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/AssociatedDataPoint.java index 58fe8d2a8b..04ab7c211e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/AssociatedDataPoint.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/AssociatedDataPoint.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import java.util.List; diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/ColumnDefinitionQuotingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/ColumnDefinitionQuotingTest.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/quote/ColumnDefinitionQuotingTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/ColumnDefinitionQuotingTest.java index 43e9c78d50..ca386793e7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/ColumnDefinitionQuotingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/ColumnDefinitionQuotingTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import java.util.Iterator; import javax.persistence.Column; @@ -23,15 +23,17 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.mapping.PersistentClass; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.BaseUnitTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Steve Ebersole */ -public class ColumnDefinitionQuotingTest extends BaseUnitTestCase { +@BaseUnitTest +public class ColumnDefinitionQuotingTest { + @Test @TestForIssue( jiraKey = "HHH-9491" ) public void testExplicitQuoting() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/DataPoint.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/DataPoint.hbm.xml similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/quote/DataPoint.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/DataPoint.hbm.xml index a368ca20db..3ef22085a9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/DataPoint.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/DataPoint.hbm.xml @@ -10,9 +10,9 @@ SYSTEM "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" > - + - org.hibernate.test.quote.DataPoint$DataPointEnum + org.hibernate.orm.test.quote.DataPoint$DataPointEnum diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/DataPoint.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/DataPoint.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/quote/DataPoint.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/DataPoint.java index e4e453e4b1..ab79827bb9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/DataPoint.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/DataPoint.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import java.util.List; diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/House.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/House.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/quote/House.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/House.java index 230b9da33b..273c5c031e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/House.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/House.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/Person.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/Person.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/quote/Person.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/Person.java index daa773f944..1995d02989 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/Person.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/Person.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/Phone.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/Phone.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/quote/Phone.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/Phone.java index 07a843c63e..88f9d631c5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/Phone.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/Phone.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/quote/QuoteGlobalTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/QuoteGlobalTest.java new file mode 100644 index 0000000000..65cd948c6d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/QuoteGlobalTest.java @@ -0,0 +1,115 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.orm.test.quote; + +import java.util.Iterator; + +import org.hibernate.Transaction; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.Table; +import org.hibernate.mapping.UniqueKey; + +import org.hibernate.testing.TestForIssue; +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.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +/** + * @author Emmanuel Bernard + * @author Brett Meyer + */ +@DomainModel( + annotatedClasses = { + User.class, + Role.class, + Phone.class, + Person.class, + House.class + }, + xmlMappings = "org/hibernate/orm/test/quote/DataPoint.hbm.xml" +) +@SessionFactory +@ServiceRegistry( + settings = @Setting(name = AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, value = "true") +) +public class QuoteGlobalTest { + + @Test + @TestForIssue(jiraKey = "HHH-7890") + public void testQuotedUniqueConstraint(SessionFactoryScope scope) { + Iterator itr = scope.getMetadataImplementor().getEntityBinding( Person.class.getName() ) + .getTable().getUniqueKeyIterator(); + while ( itr.hasNext() ) { + UniqueKey uk = itr.next(); + assertEquals( 1, uk.getColumns().size() ); + assertEquals( "name", uk.getColumn( 0 ).getName() ); + return; + } + fail( "GLOBALLY_QUOTED_IDENTIFIERS caused the unique key creation to fail." ); + } + + @Test + public void testQuoteManytoMany(SessionFactoryScope scope) { + scope.inSession( + session -> { + try { + Transaction tx = session.beginTransaction(); + User u = new User(); + session.persist( u ); + Role r = new Role(); + session.persist( r ); + u.getRoles().add( r ); + session.flush(); + session.clear(); + u = session.get( User.class, u.getId() ); + assertEquals( 1, u.getRoles().size() ); + tx.rollback(); + String role = User.class.getName() + ".roles"; + assertEquals( + "User_Role", + scope.getMetadataImplementor() + .getCollectionBinding( role ) + .getCollectionTable() + .getName() + ); + } + finally { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + } + } + ); + } + + @Test + @TestForIssue(jiraKey = "HHH-8520") + public void testHbmQuoting(SessionFactoryScope scope) { + final MetadataImplementor metadataImplementor = scope.getMetadataImplementor(); + doTestHbmQuoting( DataPoint.class, metadataImplementor ); + doTestHbmQuoting( AssociatedDataPoint.class, metadataImplementor ); + } + + private void doTestHbmQuoting(Class clazz, MetadataImplementor metadataImplementor) { + Table table = metadataImplementor.getEntityBinding( clazz.getName() ).getTable(); + assertTrue( table.isQuoted() ); + Iterator itr = table.getColumnIterator(); + while ( itr.hasNext() ) { + Column column = (Column) itr.next(); + assertTrue( column.isQuoted() ); + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/QuoteTest.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/test/quote/QuoteTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/QuoteTest.java index 60878de45c..f529e74af8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/QuoteTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import java.util.HashSet; import java.util.Set; @@ -21,7 +21,6 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import org.hibernate.Session; -import org.hibernate.Transaction; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/Role.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/Role.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/quote/Role.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/Role.java index 6191b9d8be..6bfbbb23f1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/Role.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/Role.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/TableGeneratorQuotingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/TableGeneratorQuotingTest.java similarity index 87% rename from hibernate-core/src/test/java/org/hibernate/test/quote/TableGeneratorQuotingTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/TableGeneratorQuotingTest.java index 418deaddc5..7c83fb6ff8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/TableGeneratorQuotingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/TableGeneratorQuotingTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -20,6 +20,7 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator; +import org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl; import org.hibernate.tool.hbm2ddl.SchemaValidator; import org.hibernate.tool.schema.internal.SchemaCreatorImpl; import org.hibernate.tool.schema.internal.SchemaDropperImpl; @@ -27,28 +28,29 @@ import org.hibernate.tool.schema.internal.exec.GenerationTarget; import org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.orm.test.util.DdlTransactionIsolatorTestingImpl; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.hibernate.testing.orm.junit.BaseUnitTest; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.fail; -import static org.junit.Assert.fail; /** * @author Steve Ebersole */ -public class TableGeneratorQuotingTest extends BaseUnitTestCase { +@BaseUnitTest +public class TableGeneratorQuotingTest { private StandardServiceRegistry serviceRegistry; - @Before + @BeforeEach public void setUp() { serviceRegistry = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, "true" ) .build(); } - @After + @AfterEach public void tearDown() { if ( serviceRegistry != null ) { StandardServiceRegistryBuilder.destroy( serviceRegistry ); @@ -58,7 +60,8 @@ public class TableGeneratorQuotingTest extends BaseUnitTestCase { @Test @TestForIssue(jiraKey = "HHH-7927") public void testTableGeneratorQuoting() { - final Metadata metadata = new MetadataSources( serviceRegistry ).addAnnotatedClass( TestEntity.class ).buildMetadata(); + final Metadata metadata = new MetadataSources( serviceRegistry ).addAnnotatedClass( TestEntity.class ) + .buildMetadata(); final ConnectionProvider connectionProvider = serviceRegistry.getService( ConnectionProvider.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/User.java b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/User.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/test/quote/User.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/quote/User.java index 52d446061b..0066f2f8c6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/User.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/quote/User.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.quote; +package org.hibernate.orm.test.quote; import java.io.Serializable; import java.util.HashSet; diff --git a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/Entity.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/Entity.hbm.xml similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/test/typeoverride/Entity.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/Entity.hbm.xml index 4af9b4c159..f10fd59ff6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/Entity.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/Entity.hbm.xml @@ -9,7 +9,7 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/Entity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/Entity.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/typeoverride/Entity.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/Entity.java index b9663106b0..4e26c6eb6c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/Entity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/Entity.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.typeoverride; +package org.hibernate.orm.test.typeoverride; /** * @author Gail Badner diff --git a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/H2DialectOverridePrefixedVarcharSqlTypeDesc.java b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/H2DialectOverridePrefixedVarcharSqlTypeDesc.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/typeoverride/H2DialectOverridePrefixedVarcharSqlTypeDesc.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/H2DialectOverridePrefixedVarcharSqlTypeDesc.java index 7bf6dab841..bb6a55d638 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/H2DialectOverridePrefixedVarcharSqlTypeDesc.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/H2DialectOverridePrefixedVarcharSqlTypeDesc.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.typeoverride; +package org.hibernate.orm.test.typeoverride; import org.hibernate.dialect.H2Dialect; import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/H2DialectOverrideVarcharSqlCode.java b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/H2DialectOverrideVarcharSqlCode.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/typeoverride/H2DialectOverrideVarcharSqlCode.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/H2DialectOverrideVarcharSqlCode.java index 91d9d608d6..99d31cc2ae 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/H2DialectOverrideVarcharSqlCode.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/H2DialectOverrideVarcharSqlCode.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.typeoverride; +package org.hibernate.orm.test.typeoverride; import java.sql.Types; diff --git a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/StoredPrefixedStringType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/StoredPrefixedStringType.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/test/typeoverride/StoredPrefixedStringType.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/StoredPrefixedStringType.java index 7ae8823ee6..dc1acb5225 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/StoredPrefixedStringType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/StoredPrefixedStringType.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.typeoverride; +package org.hibernate.orm.test.typeoverride; import java.sql.CallableStatement; import java.sql.PreparedStatement; diff --git a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/TypeOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/TypeOverrideTest.java similarity index 52% rename from hibernate-core/src/test/java/org/hibernate/test/typeoverride/TypeOverrideTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/TypeOverrideTest.java index dd98ed31dd..279829225c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/typeoverride/TypeOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/typeoverride/TypeOverrideTest.java @@ -4,33 +4,44 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.typeoverride; +package org.hibernate.orm.test.typeoverride; + +import org.hibernate.boot.MetadataBuilder; +import org.hibernate.dialect.AbstractHANADialect; +import org.hibernate.dialect.CockroachDialect; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.PostgreSQL81Dialect; +import org.hibernate.dialect.PostgreSQLDialect; +import org.hibernate.dialect.SybaseDialect; +import org.hibernate.type.descriptor.jdbc.BlobTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.IntegerTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.VarbinaryTypeDescriptor; +import org.hibernate.type.descriptor.jdbc.VarcharTypeDescriptor; + +import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest; +import org.hibernate.testing.orm.junit.SkipForDialect; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; -import org.hibernate.Session; -import org.hibernate.cfg.Configuration; -import org.hibernate.dialect.*; -import org.hibernate.testing.SkipForDialect; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.type.descriptor.jdbc.*; -import org.junit.Test; - /** * @author Gail Badner */ -public class TypeOverrideTest extends BaseCoreFunctionalTestCase { +public class TypeOverrideTest extends BaseSessionFactoryFunctionalTest { + @Override - public String[] getMappings() { - return new String[] { "typeoverride/Entity.hbm.xml" }; + protected String[] getOrmXmlFiles() { + return new String[] { "org/hibernate/orm/test/typeoverride/Entity.hbm.xml" }; } @Override - public void configure(Configuration cfg) { - cfg.registerTypeOverride( StoredPrefixedStringType.INSTANCE ); + protected void applyMetadataBuilder(MetadataBuilder metadataBuilder) { + metadataBuilder.applyBasicType( StoredPrefixedStringType.INSTANCE ); } @Test @@ -39,19 +50,19 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase { assertSame( IntegerTypeDescriptor.INSTANCE, remapSqlTypeDescriptor( IntegerTypeDescriptor.INSTANCE ) ); // A few dialects explicitly override BlobTypeDescriptor.DEFAULT - if ( CockroachDialect.class.isInstance( getDialect() )) { + if ( CockroachDialect.class.isInstance( getDialect() ) ) { assertSame( VarbinaryTypeDescriptor.INSTANCE, getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT ) ); } - else if ( PostgreSQL81Dialect.class.isInstance( getDialect() ) || PostgreSQLDialect.class.isInstance( getDialect() ) ) { + else if ( PostgreSQL81Dialect.class.isInstance( getDialect() ) || PostgreSQLDialect.class.isInstance( getDialect() ) ) { assertSame( BlobTypeDescriptor.BLOB_BINDING, getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT ) ); } - else if (SybaseDialect.class.isInstance( getDialect() )) { + else if ( SybaseDialect.class.isInstance( getDialect() ) ) { assertSame( BlobTypeDescriptor.PRIMITIVE_ARRAY_BINDING, getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT ) @@ -60,7 +71,8 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase { else if ( AbstractHANADialect.class.isInstance( getDialect() ) ) { assertSame( ( (AbstractHANADialect) getDialect() ).getBlobTypeDescriptor(), - getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT ) ); + getDialect().remapSqlTypeDescriptor( BlobTypeDescriptor.DEFAULT ) + ); } else { assertSame( @@ -86,7 +98,10 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase { public void testDialectWithNonStandardSqlTypeDescriptor() { assertNotSame( VarcharTypeDescriptor.INSTANCE, StoredPrefixedStringType.INSTANCE.getJdbcTypeDescriptor() ); final Dialect dialect = new H2DialectOverridePrefixedVarcharSqlTypeDesc(); - final JdbcTypeDescriptor remapped = remapSqlTypeDescriptor( dialect, StoredPrefixedStringType.PREFIXED_VARCHAR_TYPE_DESCRIPTOR ); + final JdbcTypeDescriptor remapped = remapSqlTypeDescriptor( + dialect, + StoredPrefixedStringType.PREFIXED_VARCHAR_TYPE_DESCRIPTOR + ); assertSame( VarcharTypeDescriptor.INSTANCE, remapped ); } @@ -98,48 +113,53 @@ public class TypeOverrideTest extends BaseCoreFunctionalTestCase { return dialect.remapSqlTypeDescriptor( jdbcTypeDescriptor ); } - @Test - public void testInsert() { - Session s = openSession(); - s.getTransaction().begin(); - Entity e = new Entity( "name" ); - s.save( e ); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.getTransaction().begin(); - e = ( Entity ) s.get( Entity.class, e.getId() ); - assertFalse( e.getName().startsWith( StoredPrefixedStringType.PREFIX ) ); - assertEquals( "name", e.getName() ); - s.delete( e ); - s.getTransaction().commit(); - s.close(); + @AfterEach + public void tearDown() { + inTransaction( + session -> + session.createQuery( "delete from Entity" ).executeUpdate() + ); } @Test - @SkipForDialect( value = SybaseASE15Dialect.class, jiraKey = "HHH-6426") + public void testInsert() { + Entity e = new Entity( "name" ); + inTransaction( + session -> + session.save( e ) + ); + + inTransaction( + session -> { + Entity entity = session.get( Entity.class, e.getId() ); + assertFalse( entity.getName().startsWith( StoredPrefixedStringType.PREFIX ) ); + assertEquals( "name", entity.getName() ); + session.delete( entity ); + } + ); + } + + @Test + @SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "HHH-6426") public void testRegisteredFunction() { - Session s = openSession(); - s.getTransaction().begin(); Entity e = new Entity( "name " ); - s.save( e ); - s.getTransaction().commit(); - s.close(); + inTransaction( + session -> + session.save( e ) + ); - s = openSession(); - s.getTransaction().begin(); - e = ( Entity ) s.get( Entity.class, e.getId() ); - assertFalse( e.getName().startsWith( StoredPrefixedStringType.PREFIX ) ); - assertEquals( "name ", e.getName() ); - s.getTransaction().commit(); - s.close(); + inTransaction( + session -> { + Entity entity = session.get( Entity.class, e.getId() ); + assertFalse( entity.getName().startsWith( StoredPrefixedStringType.PREFIX ) ); + assertEquals( "name ", entity.getName() ); + } + ); - s = openSession(); - s.getTransaction().begin(); - s.delete( e ); - s.getTransaction().commit(); - s.close(); + inTransaction( + session -> + session.delete( e ) + ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteGlobalTest.java b/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteGlobalTest.java deleted file mode 100644 index e770de56b7..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteGlobalTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.quote; - -import java.util.Iterator; -import java.util.Map; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.Table; -import org.hibernate.mapping.UniqueKey; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * @author Emmanuel Bernard - * @author Brett Meyer - */ -public class QuoteGlobalTest extends BaseNonConfigCoreFunctionalTestCase { - - @Test - @TestForIssue(jiraKey = "HHH-7890") - public void testQuotedUniqueConstraint() { - Iterator itr = metadata().getEntityBinding( Person.class.getName() ) - .getTable().getUniqueKeyIterator(); - while ( itr.hasNext() ) { - UniqueKey uk = itr.next(); - assertEquals( uk.getColumns().size(), 1 ); - assertEquals( uk.getColumn( 0 ).getName(), "name"); - return; - } - fail( "GLOBALLY_QUOTED_IDENTIFIERS caused the unique key creation to fail." ); - } - - @Test - public void testQuoteManytoMany() { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - User u = new User(); - s.persist( u ); - Role r = new Role(); - s.persist( r ); - u.getRoles().add( r ); - s.flush(); - s.clear(); - u = (User) s.get( User.class, u.getId() ); - assertEquals( 1, u.getRoles().size() ); - tx.rollback(); - String role = User.class.getName() + ".roles"; - assertEquals( "User_Role", metadata().getCollectionBinding( role ).getCollectionTable().getName() ); - s.close(); - } - - @Test - @TestForIssue(jiraKey = "HHH-8520") - public void testHbmQuoting() { - doTestHbmQuoting( DataPoint.class ); - doTestHbmQuoting( AssociatedDataPoint.class ); - } - - private void doTestHbmQuoting(Class clazz) { - Table table = metadata().getEntityBinding( clazz.getName() ).getTable(); - assertTrue( table.isQuoted() ); - Iterator itr = table.getColumnIterator(); - while(itr.hasNext()) { - Column column = (Column) itr.next(); - assertTrue( column.isQuoted() ); - } - } - - @Override - protected void addSettings(Map settings) { - settings.put( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, "true" ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - User.class, - Role.class, - Phone.class, - Person.class, - House.class - }; - } - - @Override - protected String[] getMappings() { - return new String[] { "quote/DataPoint.hbm.xml" }; - } - -}