Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...c/test/java/org/hibernate/orm/test/schemaupdate/SpannerSchemaCreationColumnTypesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* 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.orm.test.schemaupdate; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.EnumSet; | ||
import java.util.Locale; | ||
|
||
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.AvailableSettings; | ||
import org.hibernate.dialect.SpannerDialect; | ||
import org.hibernate.tool.hbm2ddl.SchemaExport; | ||
import org.hibernate.tool.schema.TargetType; | ||
|
||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.orm.junit.BaseUnitTest; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@BaseUnitTest | ||
@TestForIssue(jiraKey = "HHH-15573") | ||
public class SpannerSchemaCreationColumnTypesTest { | ||
private File output; | ||
private StandardServiceRegistry ssr; | ||
private MetadataImplementor metadata; | ||
|
||
@BeforeEach | ||
public void setUp() throws IOException { | ||
output = File.createTempFile( "create_script", ".sql" ); | ||
output.deleteOnExit(); | ||
ssr = new StandardServiceRegistryBuilder() | ||
.applySetting( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, "true" ) | ||
.applySetting( AvailableSettings.DIALECT, SpannerDialect.class ) | ||
.build(); | ||
|
||
final MetadataSources metadataSources = new MetadataSources( ssr ); | ||
metadataSources.addAnnotatedClass( TestEntity.class ); | ||
|
||
metadata = (MetadataImplementor) metadataSources.buildMetadata(); | ||
metadata.validate(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
StandardServiceRegistryBuilder.destroy( ssr ); | ||
} | ||
|
||
@Test | ||
public void testSchemaCreation() throws Exception { | ||
new SchemaExport().setHaltOnError( true ) | ||
.setOutputFile( output.getAbsolutePath() ) | ||
.setFormat( false ) | ||
.create( EnumSet.of( TargetType.SCRIPT ), metadata ); | ||
|
||
final String fileContent = new String( Files.readAllBytes( output.toPath() ) ); | ||
|
||
assertThat(fileContent.toLowerCase( Locale.ROOT )).contains( "create table test_entity_table" ); | ||
assertThat(fileContent.toLowerCase( Locale.ROOT )).contains( "id int64 not null" ); | ||
assertThat(fileContent.toLowerCase( Locale.ROOT )).contains( "name_column string(255)" ); | ||
} | ||
|
||
@Entity(name = "TestEntity") | ||
@Table(name = "TEST_ENTITY_TABLE") | ||
public static class TestEntity { | ||
|
||
@Id | ||
@Column(name = "ID") | ||
public Integer id; | ||
|
||
@Column(name = "NAME_COLUMN") | ||
public String name; | ||
} | ||
} |