Skip to content

Commit 797b6ad

Browse files
committed
HHH-19916 - Drop JUnit 4 usage
Not converted... * org.hibernate.orm.test.type.AbstractJavaTimeTypeTest subtypes - crazy parameterization (see org.hibernate.orm.test.tm.InterceptorTransactionTest)
1 parent c7d4478 commit 797b6ad

File tree

5 files changed

+137
-228
lines changed

5 files changed

+137
-228
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/index/ComponentIndexTest.java

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,36 @@
44
*/
55
package org.hibernate.orm.test.schemaupdate.index;
66

7-
import java.util.List;
87
import jakarta.persistence.Embeddable;
98
import jakarta.persistence.Embedded;
109
import jakarta.persistence.Entity;
1110
import jakarta.persistence.Id;
12-
1311
import jakarta.persistence.Index;
1412
import jakarta.persistence.Table;
15-
import org.hibernate.boot.Metadata;
16-
import org.hibernate.boot.MetadataSources;
17-
import org.hibernate.boot.registry.StandardServiceRegistry;
18-
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
19-
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
20-
13+
import org.hibernate.testing.orm.junit.DomainModel;
14+
import org.hibernate.testing.orm.junit.DomainModelScope;
2115
import org.hibernate.testing.orm.junit.JiraKey;
22-
import org.hibernate.testing.util.ServiceRegistryUtil;
23-
import org.junit.After;
24-
import org.junit.Before;
25-
import org.junit.Test;
16+
import org.hibernate.testing.orm.junit.ServiceRegistry;
17+
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
18+
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
2621

27-
import static org.junit.Assert.assertTrue;
22+
import java.util.List;
2823

2924
/**
3025
* @author Andrea Boriero
3126
*/
27+
@SuppressWarnings("JUnitMalformedDeclaration")
3228
@JiraKey( value = "HHH-11815")
29+
@ServiceRegistry
30+
@DomainModel(annotatedClasses = ComponentIndexTest.User.class)
3331
public class ComponentIndexTest {
34-
private StandardServiceRegistry ssr;
35-
private Metadata metadata;
36-
37-
@Before
38-
public void setUp(){
39-
ssr = ServiceRegistryUtil.serviceRegistry();
40-
metadata = new MetadataSources( ssr )
41-
.addAnnotatedClass( User.class )
42-
.buildMetadata();
43-
}
4432

4533
@Test
46-
public void testTheIndexIsGenerated() {
47-
final List<String> commands = new SchemaCreatorImpl( ssr ).generateCreationCommands(
48-
metadata,
49-
false
50-
);
34+
public void testTheIndexIsGenerated(ServiceRegistryScope registryScope, DomainModelScope modelScope) {
35+
final List<String> commands = new SchemaCreatorImpl( registryScope.getRegistry() )
36+
.generateCreationCommands( modelScope.getDomainModel(), false );
5137

5238
assertThatCreateIndexCommandIsGenerated( commands );
5339
}
@@ -57,30 +43,23 @@ private void assertThatCreateIndexCommandIsGenerated(List<String> commands) {
5743
for ( String command : commands ) {
5844
if ( command.toLowerCase().contains( "create index city_index" ) ) {
5945
createIndexCommandIsGenerated = true;
46+
break;
6047
}
6148
}
62-
assertTrue(
63-
"Expected create index command not found",
64-
createIndexCommandIsGenerated
65-
);
66-
}
67-
68-
@After
69-
public void tearDown(){
70-
StandardServiceRegistryBuilder.destroy( ssr );
49+
Assertions.assertTrue( createIndexCommandIsGenerated, "Expected create index command not found" );
7150
}
7251

7352
@Entity(name = "user")
7453
@Table(indexes = @Index(name = "city_index", columnList = "city"))
75-
public class User {
54+
public static class User {
7655
@Id
7756
private Long id;
7857
@Embedded
7958
private Address address;
8059
}
8160

8261
@Embeddable
83-
public class Address {
62+
public static class Address {
8463
private String city;
8564
private String street;
8665
private String postalCode;

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/index/IndexesCreationTest.java

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,38 @@
44
*/
55
package org.hibernate.orm.test.schemaupdate.index;
66

7-
import java.util.List;
87
import jakarta.persistence.Column;
98
import jakarta.persistence.Entity;
109
import jakarta.persistence.Id;
1110
import jakarta.persistence.Index;
1211
import jakarta.persistence.Table;
13-
14-
import org.hibernate.boot.Metadata;
15-
import org.hibernate.boot.MetadataSources;
16-
import org.hibernate.boot.registry.StandardServiceRegistry;
17-
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1812
import org.hibernate.dialect.H2Dialect;
1913
import org.hibernate.dialect.MySQLDialect;
2014
import org.hibernate.dialect.PostgreSQLDialect;
21-
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
22-
23-
import org.hibernate.testing.RequiresDialect;
15+
import org.hibernate.testing.orm.junit.DomainModel;
16+
import org.hibernate.testing.orm.junit.DomainModelScope;
2417
import org.hibernate.testing.orm.junit.JiraKey;
25-
import org.hibernate.testing.junit4.BaseUnitTestCase;
26-
import org.hibernate.testing.util.ServiceRegistryUtil;
27-
import org.junit.After;
28-
import org.junit.Before;
29-
import org.junit.Test;
18+
import org.hibernate.testing.orm.junit.RequiresDialect;
19+
import org.hibernate.testing.orm.junit.ServiceRegistry;
20+
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
21+
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.Test;
3024

31-
import static org.junit.Assert.assertTrue;
25+
import java.util.List;
3226

27+
@SuppressWarnings("JUnitMalformedDeclaration")
3328
@JiraKey(value = "HHH-11913")
3429
@RequiresDialect(H2Dialect.class)
3530
@RequiresDialect(PostgreSQLDialect.class)
3631
@RequiresDialect(MySQLDialect.class)
37-
public class IndexesCreationTest extends BaseUnitTestCase {
38-
private StandardServiceRegistry ssr;
39-
private Metadata metadata;
40-
41-
@Before
42-
public void setUp() {
43-
ssr = ServiceRegistryUtil.serviceRegistry();
44-
metadata = new MetadataSources( ssr )
45-
.addAnnotatedClass( TestEntity.class )
46-
.buildMetadata();
47-
}
48-
32+
@ServiceRegistry
33+
@DomainModel(annotatedClasses = IndexesCreationTest.TestEntity.class)
34+
public class IndexesCreationTest {
4935
@Test
50-
public void testTheIndexIsGenerated() {
51-
final List<String> commands = new SchemaCreatorImpl( ssr ).generateCreationCommands(
52-
metadata,
53-
false
54-
);
36+
public void testTheIndexIsGenerated(ServiceRegistryScope registryScope, DomainModelScope modelScope) {
37+
final List<String> commands = new SchemaCreatorImpl( registryScope.getRegistry() )
38+
.generateCreationCommands( modelScope.getDomainModel(), false );
5539

5640
assertThatCreateIndexCommandIsGenerated( "CREATE INDEX FIELD_1_INDEX ON TEST_ENTITY (FIELD_1)", commands );
5741
assertThatCreateIndexCommandIsGenerated(
@@ -69,18 +53,10 @@ private void assertThatCreateIndexCommandIsGenerated(String expectedCommand, Lis
6953
for ( String command : commands ) {
7054
if ( command.toLowerCase().contains( expectedCommand.toLowerCase() ) ) {
7155
createIndexCommandIsGenerated = true;
56+
break;
7257
}
7358
}
74-
assertTrue(
75-
76-
"Expected " + expectedCommand + " command not found",
77-
createIndexCommandIsGenerated
78-
);
79-
}
80-
81-
@After
82-
public void tearDown() {
83-
StandardServiceRegistryBuilder.destroy( ssr );
59+
Assertions.assertTrue( createIndexCommandIsGenerated, "Expected " + expectedCommand + " command not found" );
8460
}
8561

8662
@Entity(name = "TestEntity")

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/inheritance/ForeignKeyNameTest.java

Lines changed: 52 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,78 @@
44
*/
55
package org.hibernate.orm.test.schemaupdate.inheritance;
66

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;
1613
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
1714
import org.hibernate.tool.schema.TargetType;
15+
import org.junit.jupiter.api.Test;
16+
import org.junit.jupiter.api.io.TempDir;
1817

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;
2321

2422
import static org.hamcrest.core.Is.is;
25-
import static org.junit.Assert.assertThat;
23+
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_AUTO;
2624

2725
/**
2826
* @author Andrea Boriero
2927
*/
30-
public class ForeignKeyNameTest extends BaseUnitTestCase {
28+
@SuppressWarnings("JUnitMalformedDeclaration")
29+
@ServiceRegistry(settings = @Setting(name = HBM2DDL_AUTO, value = "none"))
30+
public class ForeignKeyNameTest {
3131

3232
@Test
3333
@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" );
4144

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();
5048

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 );
5755

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 ) );
6458
}
6559

6660
@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" );
7466

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();
8070

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 );
8777

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 ) );
9480
}
9581
}

0 commit comments

Comments
 (0)