HHH-9967 - Add test for issue

This commit is contained in:
Andrea Boriero 2015-07-27 15:57:41 +01:00
parent 3658480642
commit 09b3410db3
1 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,98 @@
/*
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.schemaupdate;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import java.sql.SQLException;
import java.util.List;
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.PostgreSQL81Dialect;
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.Is.is;
import static org.junit.Assert.assertThat;
/**
* @author Andrea Boriero
*/
@TestForIssue(jiraKey = "HHH-9866")
@RunWith(CustomRunner.class)
@RequiresDialect(PostgreSQL81Dialect.class)
public class SchemaExportWithIndexAndDefaultSchema {
protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata;
@Test
public void shouldCreateIndex() {
SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata );
schemaExport.create( true, true );
List<SQLException> exceptions = schemaExport.getExceptions();
assertThat( exceptions.size(), is( 0 ) );
}
@Before
public void setUp() {
serviceRegistry = new StandardServiceRegistryBuilder()
.applySetting( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true" )
.applySetting( Environment.DEFAULT_SCHEMA, "public" )
.build();
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( MyEntity.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", indexes = {@Index(columnList = "id", name = "user_id_hidx")})
public static class MyEntity {
private int id;
@Id
public int getId() {
return this.id;
}
public void setId(final int id) {
this.id = id;
}
}
}