Skip to content

Commit 5049c15

Browse files
committed
HHH-9866 - Add test for issue
1 parent 5eb4c0b commit 5049c15

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) {DATE}, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.test.schemaupdate;
25+
26+
import javax.persistence.Entity;
27+
import javax.persistence.Id;
28+
import javax.persistence.ManyToMany;
29+
import javax.persistence.Table;
30+
import java.sql.SQLException;
31+
import java.util.List;
32+
import java.util.Set;
33+
34+
import org.hibernate.boot.MetadataSources;
35+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
36+
import org.hibernate.boot.spi.MetadataImplementor;
37+
import org.hibernate.cfg.Environment;
38+
import org.hibernate.dialect.MySQLDialect;
39+
import org.hibernate.service.ServiceRegistry;
40+
import org.hibernate.tool.hbm2ddl.SchemaExport;
41+
42+
import org.junit.After;
43+
import org.junit.Before;
44+
import org.junit.Test;
45+
import org.junit.runner.RunWith;
46+
47+
import org.hibernate.testing.RequiresDialect;
48+
import org.hibernate.testing.TestForIssue;
49+
import org.hibernate.testing.junit4.CustomRunner;
50+
51+
import static org.hamcrest.core.IsNot.not;
52+
import static org.junit.Assert.assertThat;
53+
54+
/**
55+
* @author Andrea Boriero
56+
*/
57+
@TestForIssue(jiraKey = "HHH-9866")
58+
@RunWith(CustomRunner.class)
59+
@RequiresDialect(MySQLDialect.class)
60+
public class SchemaExportWithGlobalQuotingEnabledTest {
61+
protected ServiceRegistry serviceRegistry;
62+
protected MetadataImplementor metadata;
63+
64+
@Test
65+
public void testSchemaExport() throws Exception {
66+
67+
SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata );
68+
schemaExport.create( true, true );
69+
70+
List<SQLException> exceptions = schemaExport.getExceptions();
71+
for ( SQLException exception : exceptions ) {
72+
assertThat( exception.getMessage(), exception.getSQLState(), not( "42000" ) );
73+
}
74+
}
75+
76+
@Before
77+
public void setUp() {
78+
serviceRegistry = new StandardServiceRegistryBuilder().applySetting(
79+
Environment.GLOBALLY_QUOTED_IDENTIFIERS,
80+
"true"
81+
).build();
82+
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
83+
.addAnnotatedClass( MyEntity.class )
84+
.addAnnotatedClass( Role.class )
85+
.buildMetadata();
86+
87+
System.out.println( "********* Starting SchemaExport for START-UP *************************" );
88+
SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata );
89+
schemaExport.create( true, true );
90+
System.out.println( "********* Completed SchemaExport for START-UP *************************" );
91+
}
92+
93+
@After
94+
public void tearDown() {
95+
System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" );
96+
SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata );
97+
schemaExport.drop( true, true );
98+
System.out.println( "********* Completed SchemaExport (drop) for TEAR-DOWN *************************" );
99+
100+
StandardServiceRegistryBuilder.destroy( serviceRegistry );
101+
serviceRegistry = null;
102+
}
103+
104+
@Entity
105+
@Table(name = "MyEntity")
106+
public static class MyEntity {
107+
private int id;
108+
private Set<Role> roles;
109+
110+
@Id
111+
public int getId() {
112+
return this.id;
113+
}
114+
115+
public void setId(final int id) {
116+
this.id = id;
117+
}
118+
119+
@ManyToMany
120+
public Set<Role> getRoles() {
121+
return roles;
122+
}
123+
124+
public void setRoles(Set<Role> roles) {
125+
this.roles = roles;
126+
}
127+
}
128+
129+
@Entity
130+
public static class Role {
131+
private Integer id;
132+
133+
@Id
134+
public Integer getId() {
135+
return id;
136+
}
137+
138+
public void setId(Integer id) {
139+
this.id = id;
140+
}
141+
}
142+
143+
}

0 commit comments

Comments
 (0)