|
4 | 4 | */ |
5 | 5 | package org.hibernate.orm.test.schemaupdate.inheritance; |
6 | 6 |
|
7 | | -import java.io.File; |
8 | | -import java.nio.file.Files; |
9 | | -import java.util.EnumSet; |
10 | | - |
11 | | -import org.hibernate.boot.MetadataSources; |
12 | | -import org.hibernate.boot.registry.StandardServiceRegistry; |
13 | | -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
14 | | -import org.hibernate.boot.spi.MetadataImplementor; |
15 | | -import org.hibernate.cfg.Environment; |
| 7 | +import org.hamcrest.MatcherAssert; |
| 8 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 9 | +import org.hibernate.testing.orm.junit.DomainModelScope; |
| 10 | +import org.hibernate.testing.orm.junit.JiraKey; |
| 11 | +import org.hibernate.testing.orm.junit.ServiceRegistry; |
| 12 | +import org.hibernate.testing.orm.junit.Setting; |
16 | 13 | import org.hibernate.tool.hbm2ddl.SchemaUpdate; |
17 | 14 | import org.hibernate.tool.schema.TargetType; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | +import org.junit.jupiter.api.io.TempDir; |
18 | 17 |
|
19 | | -import org.hibernate.testing.orm.junit.JiraKey; |
20 | | -import org.hibernate.testing.junit4.BaseUnitTestCase; |
21 | | -import org.hibernate.testing.util.ServiceRegistryUtil; |
22 | | -import org.junit.Test; |
| 18 | +import java.io.File; |
| 19 | +import java.nio.file.Files; |
| 20 | +import java.util.EnumSet; |
23 | 21 |
|
24 | 22 | import static org.hamcrest.core.Is.is; |
25 | | -import static org.junit.Assert.assertThat; |
| 23 | +import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_AUTO; |
26 | 24 |
|
27 | 25 | /** |
28 | 26 | * @author Andrea Boriero |
29 | 27 | */ |
30 | | -public class ForeignKeyNameTest extends BaseUnitTestCase { |
| 28 | +@SuppressWarnings("JUnitMalformedDeclaration") |
| 29 | +@ServiceRegistry(settings = @Setting(name = HBM2DDL_AUTO, value = "none")) |
| 30 | +public class ForeignKeyNameTest { |
31 | 31 |
|
32 | 32 | @Test |
33 | 33 | @JiraKey(value = "HHH-10169") |
34 | | - public void testJoinedSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided() throws Exception { |
35 | | - StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistryBuilder() |
36 | | - .applySetting( Environment.HBM2DDL_AUTO, "none" ) |
37 | | - .build(); |
38 | | - try { |
39 | | - File output = File.createTempFile( "update_script", ".sql" ); |
40 | | - output.deleteOnExit(); |
| 34 | + @DomainModel(xmlMappings = { |
| 35 | + "org/hibernate/orm/test/schemaupdate/inheritance/Employee.hbm.xml", |
| 36 | + "org/hibernate/orm/test/schemaupdate/inheritance/Person.hbm.xml", |
| 37 | + "org/hibernate/orm/test/schemaupdate/inheritance/Manager.hbm.xml", |
| 38 | + "org/hibernate/orm/test/schemaupdate/inheritance/Payment.hbm.xml" |
| 39 | + }) |
| 40 | + public void testJoinedSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided( |
| 41 | + DomainModelScope modelScope, |
| 42 | + @TempDir File tmpDir) throws Exception { |
| 43 | + final var scriptFile = new File( tmpDir, "update_script.sql" ); |
41 | 44 |
|
42 | | - final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) |
43 | | - .addResource( "org/hibernate/orm/test/schemaupdate/inheritance/Employee.hbm.xml" ) |
44 | | - .addResource( "org/hibernate/orm/test/schemaupdate/inheritance/Person.hbm.xml" ) |
45 | | - .addResource( "org/hibernate/orm/test/schemaupdate/inheritance/Manager.hbm.xml" ) |
46 | | - .addResource( "org/hibernate/orm/test/schemaupdate/inheritance/Payment.hbm.xml" ) |
47 | | - .buildMetadata(); |
48 | | - metadata.orderColumns( false ); |
49 | | - metadata.validate(); |
| 45 | + final var metadata = modelScope.getDomainModel(); |
| 46 | + metadata.orderColumns( false ); |
| 47 | + metadata.validate(); |
50 | 48 |
|
51 | | - new SchemaUpdate() |
52 | | - .setHaltOnError( true ) |
53 | | - .setOutputFile( output.getAbsolutePath() ) |
54 | | - .setDelimiter( ";" ) |
55 | | - .setFormat( true ) |
56 | | - .execute( EnumSet.of( TargetType.SCRIPT ), metadata ); |
| 49 | + new SchemaUpdate() |
| 50 | + .setHaltOnError( true ) |
| 51 | + .setOutputFile( scriptFile.getAbsolutePath() ) |
| 52 | + .setDelimiter( ";" ) |
| 53 | + .setFormat( true ) |
| 54 | + .execute( EnumSet.of( TargetType.SCRIPT ), metadata ); |
57 | 55 |
|
58 | | - String fileContent = new String( Files.readAllBytes( output.toPath() ) ); |
59 | | - assertThat( fileContent.toLowerCase().contains( "fk_emp_per" ), is( true ) ); |
60 | | - } |
61 | | - finally { |
62 | | - StandardServiceRegistryBuilder.destroy( ssr ); |
63 | | - } |
| 56 | + String fileContent = new String( Files.readAllBytes( scriptFile.toPath() ) ); |
| 57 | + MatcherAssert.assertThat( fileContent.toLowerCase().contains( "fk_emp_per" ), is( true ) ); |
64 | 58 | } |
65 | 59 |
|
66 | 60 | @Test |
67 | | - public void testSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided() throws Exception { |
68 | | - StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistryBuilder() |
69 | | - .applySetting( Environment.HBM2DDL_AUTO, "none" ) |
70 | | - .build(); |
71 | | - try { |
72 | | - File output = File.createTempFile( "update_script", ".sql" ); |
73 | | - output.deleteOnExit(); |
| 61 | + @DomainModel(xmlMappings = "org/hibernate/orm/test/schemaupdate/inheritance/Payment.hbm.xml") |
| 62 | + public void testSubclassForeignKeyNameIsNotAutoGeneratedWhenProvided( |
| 63 | + DomainModelScope modelScope, |
| 64 | + @TempDir File tmpDir) throws Exception { |
| 65 | + final var scriptFile = new File( tmpDir, "update_script.sql" ); |
74 | 66 |
|
75 | | - final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) |
76 | | - .addResource( "org/hibernate/orm/test/schemaupdate/inheritance/Payment.hbm.xml" ) |
77 | | - .buildMetadata(); |
78 | | - metadata.orderColumns( false ); |
79 | | - metadata.validate(); |
| 67 | + final var metadata = modelScope.getDomainModel(); |
| 68 | + metadata.orderColumns( false ); |
| 69 | + metadata.validate(); |
80 | 70 |
|
81 | | - new SchemaUpdate() |
82 | | - .setHaltOnError( true ) |
83 | | - .setOutputFile( output.getAbsolutePath() ) |
84 | | - .setDelimiter( ";" ) |
85 | | - .setFormat( true ) |
86 | | - .execute( EnumSet.of( TargetType.SCRIPT ), metadata ); |
| 71 | + new SchemaUpdate() |
| 72 | + .setHaltOnError( true ) |
| 73 | + .setOutputFile( scriptFile.getAbsolutePath() ) |
| 74 | + .setDelimiter( ";" ) |
| 75 | + .setFormat( true ) |
| 76 | + .execute( EnumSet.of( TargetType.SCRIPT ), metadata ); |
87 | 77 |
|
88 | | - String fileContent = new String( Files.readAllBytes( output.toPath() ) ); |
89 | | - assertThat( fileContent.toLowerCase().contains( "fk_cc_pay" ), is( true ) ); |
90 | | - } |
91 | | - finally { |
92 | | - StandardServiceRegistryBuilder.destroy( ssr ); |
93 | | - } |
| 78 | + String fileContent = new String( Files.readAllBytes( scriptFile.toPath() ) ); |
| 79 | + MatcherAssert.assertThat( fileContent.toLowerCase().contains( "fk_cc_pay" ), is( true ) ); |
94 | 80 | } |
95 | 81 | } |
0 commit comments