Skip to content

Commit

Permalink
HHH-9866 - Add test for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Jun 14, 2015
1 parent 5eb4c0b commit 5049c15
Showing 1 changed file with 143 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) {DATE}, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.schemaupdate;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;

import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.CustomRunner;

import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;

/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-9866")
@RunWith(CustomRunner.class)
@RequiresDialect(MySQLDialect.class)
public class SchemaExportWithGlobalQuotingEnabledTest {
protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata;

@Test
public void testSchemaExport() throws Exception {

SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata );
schemaExport.create( true, true );

List<SQLException> exceptions = schemaExport.getExceptions();
for ( SQLException exception : exceptions ) {
assertThat( exception.getMessage(), exception.getSQLState(), not( "42000" ) );
}
}

@Before
public void setUp() {
serviceRegistry = new StandardServiceRegistryBuilder().applySetting(
Environment.GLOBALLY_QUOTED_IDENTIFIERS,
"true"
).build();
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( MyEntity.class )
.addAnnotatedClass( Role.class )
.buildMetadata();

System.out.println( "********* Starting SchemaExport for START-UP *************************" );
SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata );
schemaExport.create( true, true );
System.out.println( "********* Completed SchemaExport for START-UP *************************" );
}

@After
public void tearDown() {
System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" );
SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata );
schemaExport.drop( true, true );
System.out.println( "********* Completed SchemaExport (drop) for TEAR-DOWN *************************" );

StandardServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistry = null;
}

@Entity
@Table(name = "MyEntity")
public static class MyEntity {
private int id;
private Set<Role> roles;

@Id
public int getId() {
return this.id;
}

public void setId(final int id) {
this.id = id;
}

@ManyToMany
public Set<Role> getRoles() {
return roles;
}

public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}

@Entity
public static class Role {
private Integer id;

@Id
public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}
}

}

0 comments on commit 5049c15

Please sign in to comment.