HHH-1122 - Add test for issue
This commit is contained in:
parent
bd42804f14
commit
6f985e2fa1
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* 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.Table;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
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.cfg.Environment;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||
import org.hibernate.tool.hbm2ddl.Target;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-1122")
|
||||
public class SchemaUpdateDelimiterTest {
|
||||
|
||||
public static final String EXPECTED_DELIMITER = ";";
|
||||
|
||||
@Test
|
||||
public void testSchemaUpdateApplyDelimiterToGeneratedSQL() throws Exception {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( Environment.HBM2DDL_AUTO, "none" )
|
||||
.build();
|
||||
try {
|
||||
File output = File.createTempFile( "update_script", ".sql" );
|
||||
output.deleteOnExit();
|
||||
|
||||
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||
.addAnnotatedClass( TestEntity.class )
|
||||
.buildMetadata();
|
||||
metadata.validate();
|
||||
|
||||
SchemaUpdate su = new SchemaUpdate( ssr, metadata );
|
||||
su.setHaltOnError( true );
|
||||
su.setOutputFile( output.getAbsolutePath() );
|
||||
su.setDelimiter( EXPECTED_DELIMITER );
|
||||
su.setFormat( true );
|
||||
su.execute( Target.SCRIPT );
|
||||
|
||||
List<String> sqlLines = Files.readAllLines( output.toPath() );
|
||||
for ( String line : sqlLines ) {
|
||||
assertThat(
|
||||
"The expected delimiter is not applied " + line,
|
||||
line.endsWith( EXPECTED_DELIMITER ),
|
||||
is( true )
|
||||
);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "test_entity")
|
||||
public static class TestEntity {
|
||||
@Id
|
||||
private String field;
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue