From add6fc84c86d2e1b2c790cd1bddf10da4ba67032 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Thu, 15 Oct 2015 18:07:27 +0100 Subject: [PATCH] HHH-10197 - Add test --- .../hibernate/test/schemaupdate/Group.java | 63 ++++++++++++ ...leNameWithForeignKeysSchemaUpdateTest.java | 95 +++++++++++++++++++ .../org/hibernate/test/schemaupdate/User.java | 53 +++++++++++ .../test/schemaupdate/UserGroup.hbm.xml | 50 ++++++++++ 4 files changed, 261 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/schemaupdate/Group.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/schemaupdate/QuotedTableNameWithForeignKeysSchemaUpdateTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/schemaupdate/User.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/schemaupdate/UserGroup.hbm.xml diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/Group.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/Group.java new file mode 100644 index 0000000000..b9dcc51d41 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/Group.java @@ -0,0 +1,63 @@ +/* + * 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.schemaupdate; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +/** + * @author Andrea Boriero + */ +public class Group implements Serializable { + + private String org; + private String name; + private String description; + + private Set users = new HashSet(); + + public Group(String name, String org) { + this.org = org; + this.name = name; + } + + public Group() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOrg() { + return org; + } + + public void setOrg(String org) { + this.org = org; + } + + public Set getUsers() { + return users; + } + + public void setUsers(Set users) { + this.users = users; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/QuotedTableNameWithForeignKeysSchemaUpdateTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/QuotedTableNameWithForeignKeysSchemaUpdateTest.java new file mode 100644 index 0000000000..5c8b643c29 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/QuotedTableNameWithForeignKeysSchemaUpdateTest.java @@ -0,0 +1,95 @@ +/* + * 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.schemaupdate; + +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.hbm2ddl.SchemaUpdate; +import org.hibernate.tool.hbm2ddl.Target; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +/** + * @author Andrea Boriero + */ +@TestForIssue(jiraKey = "HHH-10197") +public class QuotedTableNameWithForeignKeysSchemaUpdateTest extends BaseUnitTestCase { + + @Before + public void setUp() { + StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); + try { + + final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) + .addResource( "org/hibernate/test/schemaupdate/UserGroup.hbm.xml" ) + .buildMetadata(); + metadata.validate(); + new SchemaUpdate( metadata ).execute( Target.EXPORT ); + + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } + + @Test + public void testUpdateExistingSchema() { + StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); + try { + + final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) + .addResource( "org/hibernate/test/schemaupdate/UserGroup.hbm.xml" ) + .buildMetadata(); + new SchemaUpdate( metadata ).execute( Target.EXPORT ); + + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } + + @Test + public void testGeneratingUpdateScript() { + StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); + try { + + final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) + .addResource( "org/hibernate/test/schemaupdate/UserGroup.hbm.xml" ) + .buildMetadata(); + new SchemaUpdate( metadata ).execute( true, false ); + + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } + + @After + public void tearDown() { + StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); + try { + + final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) + .addResource( "org/hibernate/test/schemaupdate/UserGroup.hbm.xml" ) + .buildMetadata(); + SchemaExport schemaExport = new SchemaExport( ssr, metadata ); + schemaExport.drop( true, true ); + + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/User.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/User.java new file mode 100644 index 0000000000..0dda1392a1 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/User.java @@ -0,0 +1,53 @@ +/* + * 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.schemaupdate; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +/** + * @author Andrea Boriero + */ +public class User implements Serializable { + + private String org; + private String name; + private Set groups = new HashSet(); + + public User(String name, String org) { + this.org = org; + this.name = name; + } + + public User() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOrg() { + return org; + } + + public void setOrg(String org) { + this.org = org; + } + + public Set getGroups() { + return groups; + } + + public void setGroups(Set groups) { + this.groups = groups; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/UserGroup.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/UserGroup.hbm.xml new file mode 100644 index 0000000000..5971c8dadf --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/UserGroup.hbm.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + org + + + + + + + + + + + + + + + + + + org + + + + + \ No newline at end of file