Skip to content

Commit c7d4478

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 dc9a404 commit c7d4478

File tree

5 files changed

+180
-312
lines changed

5 files changed

+180
-312
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/idbag/IdBagSequenceTest.java

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,55 @@
44
*/
55
package org.hibernate.orm.test.schemaupdate.idbag;
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.DialectFeatureChecks;
9+
import org.hibernate.testing.orm.junit.DomainModel;
10+
import org.hibernate.testing.orm.junit.DomainModelScope;
11+
import org.hibernate.testing.orm.junit.JiraKey;
12+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
13+
import org.hibernate.testing.orm.junit.ServiceRegistry;
14+
import org.hibernate.testing.orm.junit.Setting;
1615
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
1716
import org.hibernate.tool.schema.TargetType;
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.io.TempDir;
1819

19-
import org.hibernate.testing.DialectChecks;
20-
import org.hibernate.testing.RequiresDialectFeature;
21-
import org.hibernate.testing.orm.junit.JiraKey;
22-
import org.hibernate.testing.junit4.BaseUnitTestCase;
23-
import org.hibernate.testing.util.ServiceRegistryUtil;
24-
import org.junit.Test;
20+
import java.io.File;
21+
import java.nio.file.Files;
22+
import java.util.EnumSet;
2523

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

2927
/**
3028
* @author Andrea Boriero
3129
*/
30+
@SuppressWarnings("JUnitMalformedDeclaration")
3231
@JiraKey(value = "HHH-10373")
33-
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
34-
public class IdBagSequenceTest extends BaseUnitTestCase {
32+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class)
33+
@ServiceRegistry(settings = @Setting(name = HBM2DDL_AUTO, value = "none"))
34+
@DomainModel(xmlMappings = "org/hibernate/orm/test/schemaupdate/idbag/Mappings.hbm.xml")
35+
public class IdBagSequenceTest {
3536

3637
@Test
37-
public void testIdBagSequenceGeneratorIsCreated() throws Exception {
38-
StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistryBuilder()
39-
.applySetting( Environment.HBM2DDL_AUTO, "none" )
40-
.build();
41-
try {
42-
File output = File.createTempFile( "update_script", ".sql" );
43-
output.deleteOnExit();
44-
45-
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
46-
.addResource( "org/hibernate/orm/test/schemaupdate/idbag/Mappings.hbm.xml" )
47-
.buildMetadata();
48-
metadata.orderColumns( false );
49-
metadata.validate();
50-
51-
new SchemaUpdate()
52-
.setHaltOnError( true )
53-
.setOutputFile( output.getAbsolutePath() )
54-
.setDelimiter( ";" )
55-
.setFormat( true )
56-
.execute( EnumSet.of( TargetType.SCRIPT ), metadata );
57-
58-
String fileContent = new String( Files.readAllBytes( output.toPath() ) );
59-
assertThat( fileContent.toLowerCase().contains( "create sequence seq_child_id" ), is( true ) );
60-
}
61-
finally {
62-
StandardServiceRegistryBuilder.destroy( ssr );
63-
}
38+
public void testIdBagSequenceGeneratorIsCreated(
39+
DomainModelScope modelScope,
40+
@TempDir File tmpDir) throws Exception {
41+
final var scriptFile = new File( tmpDir, "update_script.sql" );
42+
43+
final var metadata = modelScope.getDomainModel();
44+
metadata.orderColumns( false );
45+
metadata.validate();
46+
47+
new SchemaUpdate()
48+
.setHaltOnError( true )
49+
.setOutputFile( scriptFile.getAbsolutePath() )
50+
.setDelimiter( ";" )
51+
.setFormat( true )
52+
.execute( EnumSet.of( TargetType.SCRIPT ), metadata );
53+
54+
String fileContent = new String( Files.readAllBytes( scriptFile.toPath() ) );
55+
MatcherAssert.assertThat( fileContent.toLowerCase().contains( "create sequence seq_child_id" ), is( true ) );
6456
}
6557

6658
}

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/idgenerator/SequenceGenerationTest.java

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,90 +4,65 @@
44
*/
55
package org.hibernate.orm.test.schemaupdate.idgenerator;
66

7-
import java.io.File;
8-
import java.nio.file.Files;
9-
import java.util.EnumSet;
10-
import java.util.List;
11-
import java.util.regex.Matcher;
12-
import java.util.regex.Pattern;
137
import jakarta.persistence.Entity;
148
import jakarta.persistence.GeneratedValue;
159
import jakarta.persistence.GenerationType;
1610
import jakarta.persistence.Id;
1711
import jakarta.persistence.SequenceGenerator;
1812
import jakarta.persistence.Table;
19-
20-
import org.hibernate.boot.MetadataSources;
21-
import org.hibernate.boot.registry.StandardServiceRegistry;
22-
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
23-
import org.hibernate.boot.spi.MetadataImplementor;
24-
import org.hibernate.cfg.Environment;
13+
import org.hamcrest.MatcherAssert;
2514
import org.hibernate.dialect.H2Dialect;
15+
import org.hibernate.testing.orm.junit.DomainModel;
16+
import org.hibernate.testing.orm.junit.DomainModelScope;
17+
import org.hibernate.testing.orm.junit.RequiresDialect;
18+
import org.hibernate.testing.orm.junit.ServiceRegistry;
19+
import org.hibernate.testing.orm.junit.Setting;
2620
import org.hibernate.tool.hbm2ddl.SchemaExport;
2721
import org.hibernate.tool.schema.TargetType;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.io.TempDir;
2824

29-
import org.hibernate.testing.RequiresDialect;
30-
import org.hibernate.testing.junit4.BaseUnitTestCase;
31-
import org.hibernate.testing.util.ServiceRegistryUtil;
32-
import org.junit.After;
33-
import org.junit.Before;
34-
import org.junit.Test;
25+
import java.io.File;
26+
import java.nio.file.Files;
27+
import java.util.EnumSet;
28+
import java.util.List;
29+
import java.util.regex.Matcher;
30+
import java.util.regex.Pattern;
3531

3632
import static org.hamcrest.core.Is.is;
37-
import static org.junit.Assert.assertThat;
33+
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_AUTO;
3834

3935
/**
4036
* @author Andrea Boriero
4137
*/
38+
@SuppressWarnings("JUnitMalformedDeclaration")
4239
@RequiresDialect(H2Dialect.class)
43-
public class SequenceGenerationTest extends BaseUnitTestCase {
44-
private StandardServiceRegistry ssr;
45-
private File output;
46-
private MetadataImplementor metadata;
40+
@ServiceRegistry(settings = @Setting(name = HBM2DDL_AUTO, value = "none"))
41+
@DomainModel(annotatedClasses = SequenceGenerationTest.TestEntity.class)
42+
public class SequenceGenerationTest {
43+
@Test
44+
public void testSequenceIsGenerated(
45+
DomainModelScope modelScope,
46+
@TempDir File tmpDir) throws Exception {
47+
final var scriptFile = new File( tmpDir, "update_script.sql" );
4748

48-
@Before
49-
public void setUp() throws Exception {
50-
ssr = ServiceRegistryUtil.serviceRegistryBuilder()
51-
.applySetting( Environment.HBM2DDL_AUTO, "none" )
52-
.build();
53-
output = File.createTempFile( "update_script", ".sql" );
54-
output.deleteOnExit();
55-
metadata = (MetadataImplementor) new MetadataSources( ssr )
56-
.addAnnotatedClass( TestEntity.class )
57-
.buildMetadata();
49+
final var metadata = modelScope.getDomainModel();
5850
metadata.orderColumns( false );
5951
metadata.validate();
60-
}
6152

62-
@Test
63-
public void testSequenceIsGenerated() throws Exception {
6453
new SchemaExport()
65-
.setOutputFile( output.getAbsolutePath() )
66-
.create( EnumSet.of( TargetType.SCRIPT, TargetType.DATABASE ), metadata );
54+
.setOutputFile( scriptFile.getAbsolutePath() )
55+
.create( EnumSet.of( TargetType.SCRIPT ), metadata );
6756

68-
List<String> commands = Files.readAllLines( output.toPath() );
57+
List<String> commands = Files.readAllLines( scriptFile.toPath() );
6958

70-
assertThat(
59+
MatcherAssert.assertThat(
7160
isCommandGenerated( commands, "create table test_entity \\(id .*, primary key \\(id\\)\\);" ),
72-
is( true )
73-
);
61+
is( true ) );
7462

75-
assertThat(
63+
MatcherAssert.assertThat(
7664
isCommandGenerated( commands, "create sequence sequence_generator start with 5 increment by 3;" ),
77-
is( true )
78-
);
79-
}
80-
81-
@After
82-
public void tearDown() {
83-
try {
84-
new SchemaExport()
85-
.drop( EnumSet.of( TargetType.DATABASE ), metadata );
86-
}
87-
finally {
88-
StandardServiceRegistryBuilder.destroy( ssr );
89-
}
90-
65+
is( true ) );
9166
}
9267

9368
private boolean isCommandGenerated(List<String> commands, String expectedCommnad) {

hibernate-core/src/test/java/org/hibernate/orm/test/schemaupdate/idgenerator/SequenceGeneratorsTest.java

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,66 @@
44
*/
55
package org.hibernate.orm.test.schemaupdate.idgenerator;
66

7-
import java.io.File;
8-
import java.nio.file.Files;
9-
import java.util.EnumSet;
10-
import java.util.List;
11-
import java.util.regex.Matcher;
12-
import java.util.regex.Pattern;
137
import jakarta.persistence.Entity;
148
import jakarta.persistence.GeneratedValue;
159
import jakarta.persistence.GenerationType;
1610
import jakarta.persistence.Id;
1711
import jakarta.persistence.SequenceGenerator;
1812
import jakarta.persistence.SequenceGenerators;
1913
import jakarta.persistence.Table;
20-
21-
import org.hibernate.boot.MetadataSources;
22-
import org.hibernate.boot.registry.StandardServiceRegistry;
23-
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
24-
import org.hibernate.boot.spi.MetadataImplementor;
25-
import org.hibernate.cfg.Environment;
14+
import org.hamcrest.MatcherAssert;
2615
import org.hibernate.dialect.H2Dialect;
16+
import org.hibernate.testing.orm.junit.DomainModel;
17+
import org.hibernate.testing.orm.junit.DomainModelScope;
18+
import org.hibernate.testing.orm.junit.RequiresDialect;
19+
import org.hibernate.testing.orm.junit.ServiceRegistry;
20+
import org.hibernate.testing.orm.junit.Setting;
2721
import org.hibernate.tool.hbm2ddl.SchemaExport;
2822
import org.hibernate.tool.schema.TargetType;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.api.io.TempDir;
2925

30-
import org.hibernate.testing.RequiresDialect;
31-
import org.hibernate.testing.junit4.BaseUnitTestCase;
32-
import org.hibernate.testing.util.ServiceRegistryUtil;
33-
import org.junit.After;
34-
import org.junit.Before;
35-
import org.junit.Test;
26+
import java.io.File;
27+
import java.nio.file.Files;
28+
import java.util.EnumSet;
29+
import java.util.List;
30+
import java.util.regex.Matcher;
31+
import java.util.regex.Pattern;
3632

3733
import static org.hamcrest.core.Is.is;
38-
import static org.junit.Assert.assertThat;
34+
import static org.hibernate.cfg.SchemaToolingSettings.HBM2DDL_AUTO;
3935

4036
/**
4137
* @author Andrea Boriero
4238
*/
39+
@SuppressWarnings("JUnitMalformedDeclaration")
4340
@RequiresDialect(H2Dialect.class)
44-
public class SequenceGeneratorsTest extends BaseUnitTestCase {
45-
private StandardServiceRegistry ssr;
46-
private File output;
47-
private MetadataImplementor metadata;
41+
@ServiceRegistry(settings = @Setting(name = HBM2DDL_AUTO, value = "none"))
42+
@DomainModel(annotatedClasses = SequenceGeneratorsTest.TestEntity.class)
43+
public class SequenceGeneratorsTest {
44+
@Test
45+
public void testSequenceIsGenerated(
46+
DomainModelScope modelScope,
47+
@TempDir File tmpDir) throws Exception {
48+
final var scriptFile = new File( tmpDir, "update_script.sql" );
4849

49-
@Before
50-
public void setUp() throws Exception {
51-
ssr = ServiceRegistryUtil.serviceRegistryBuilder()
52-
.applySetting( Environment.HBM2DDL_AUTO, "none" )
53-
.build();
54-
output = File.createTempFile( "update_script", ".sql" );
55-
output.deleteOnExit();
56-
metadata = (MetadataImplementor) new MetadataSources( ssr )
57-
.addAnnotatedClass( TestEntity.class )
58-
.buildMetadata();
50+
final var metadata = modelScope.getDomainModel();
5951
metadata.orderColumns( false );
6052
metadata.validate();
61-
}
6253

63-
@Test
64-
public void testSequenceIsGenerated() throws Exception {
6554
new SchemaExport()
66-
.setOutputFile( output.getAbsolutePath() )
67-
.create( EnumSet.of( TargetType.SCRIPT, TargetType.DATABASE ), metadata );
55+
.setOutputFile( scriptFile.getAbsolutePath() )
56+
.create( EnumSet.of( TargetType.SCRIPT ), metadata );
6857

69-
List<String> commands = Files.readAllLines( output.toPath() );
58+
var commands = Files.readAllLines( scriptFile.toPath() );
7059

71-
assertThat(
60+
MatcherAssert.assertThat(
7261
isCommandGenerated( commands, "CREATE TABLE TEST_ENTITY \\(ID .*, PRIMARY KEY \\(ID\\)\\);" ),
73-
is( true )
74-
);
62+
is( true ) );
7563

76-
assertThat(
64+
MatcherAssert.assertThat(
7765
isCommandGenerated( commands, "CREATE SEQUENCE SEQUENCE_GENERATOR START WITH 5 INCREMENT BY 3;" ),
78-
is( true )
79-
);
80-
}
81-
82-
@After
83-
public void tearDown() {
84-
try {
85-
new SchemaExport()
86-
.drop( EnumSet.of( TargetType.DATABASE ), metadata );
87-
}
88-
finally {
89-
StandardServiceRegistryBuilder.destroy( ssr );
90-
}
91-
66+
is( true ) );
9267
}
9368

9469
private boolean isCommandGenerated(List<String> commands, String expectedCommnad) {

0 commit comments

Comments
 (0)