Skip to content

Commit 8d87806

Browse files
committed
HHH-19846 - Remove JUnit4: org.hibernate.orm.test.dialect.function
Signed-off-by: Jan Schatteman <[email protected]>
1 parent a45c2b6 commit 8d87806

File tree

3 files changed

+75
-130
lines changed

3 files changed

+75
-130
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/HANAFunctionsTest.java

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,114 +4,82 @@
44
*/
55
package org.hibernate.orm.test.dialect.function;
66

7-
import static org.junit.Assert.assertEquals;
8-
import static org.junit.Assert.assertNotNull;
9-
import static org.junit.Assert.assertNull;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertNotNull;
9+
import static org.junit.jupiter.api.Assertions.assertNull;
1010

1111
import java.math.BigDecimal;
1212

13-
import org.hibernate.Session;
14-
import org.hibernate.Transaction;
1513
import org.hibernate.dialect.HANADialect;
16-
import org.hibernate.query.Query;
17-
import org.hibernate.testing.RequiresDialect;
14+
import org.hibernate.testing.orm.junit.DomainModel;
15+
import org.hibernate.testing.orm.junit.RequiresDialect;
1816
import org.hibernate.testing.orm.junit.JiraKey;
19-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
20-
import org.junit.Test;
17+
import org.hibernate.testing.orm.junit.SessionFactory;
18+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2121

2222
@RequiresDialect(HANADialect.class)
23-
public class HANAFunctionsTest extends BaseCoreFunctionalTestCase {
24-
25-
@Override
26-
protected String getBaseForMappings() {
27-
return "org/hibernate/orm/test/";
28-
}
29-
30-
@Override
31-
public String[] getMappings() {
32-
return new String[]{ "dialect/function/Product.hbm.xml" };
33-
}
34-
35-
@Override
36-
protected void afterSessionFactoryBuilt() {
37-
Product product = new Product();
38-
product.setLength( 100 );
39-
product.setPrice( new BigDecimal( 1.298 ) );
40-
try ( Session s = openSession() ) {
41-
Transaction tx = s.beginTransaction();
42-
s.persist( product );
43-
tx.commit();
44-
}
23+
@DomainModel(xmlMappings = {"org/hibernate/orm/test/dialect/function/Product.hbm.xml"})
24+
@SessionFactory
25+
public class HANAFunctionsTest {
26+
27+
@BeforeEach
28+
public void setup(SessionFactoryScope scope) {
29+
scope.inTransaction( session -> {
30+
Product product = new Product();
31+
product.setLength( 100 );
32+
product.setPrice( new BigDecimal( "1.298" ) );
33+
session.persist( product );
34+
} );
4535
}
4636

4737
@Test
4838
@JiraKey(value = "HHH-12546")
49-
public void testLocateFunction() {
50-
try ( Session s = openSession() ) {
51-
Transaction tx = s.beginTransaction();
52-
Query<Product> q = s.createQuery( "select p from Product p where locate('.', cast(p.price as string)) > 0", Product.class );
53-
Product p = q.uniqueResult();
39+
public void testLocateFunction(SessionFactoryScope scope) {
40+
scope.inTransaction( session -> {
41+
Product p = session.createQuery( "select p from Product p where locate('.', cast(p.price as string)) > 0", Product.class ).uniqueResult();
5442
assertNotNull( p );
5543
assertEquals( 100, p.getLength() );
5644
assertEquals( BigDecimal.valueOf( 1.29 ), p.getPrice() );
57-
tx.commit();
58-
}
59-
60-
try ( Session s = openSession() ) {
61-
Transaction tx = s.beginTransaction();
62-
Query<Product> q = s.createQuery( "select p from Product p where locate('.', cast(p.price as string)) = 0", Product.class );
63-
Product p = q.uniqueResult();
45+
} );
46+
scope.inTransaction( session -> {
47+
Product p = session.createQuery( "select p from Product p where locate('.', cast(p.price as string)) = 0", Product.class ).uniqueResult();
6448
assertNull( p );
65-
tx.commit();
66-
}
49+
} );
6750

68-
try ( Session s = openSession() ) {
69-
Transaction tx = s.beginTransaction();
70-
Query<Product> q = s.createQuery( "select p from Product p where locate('.', cast(p.price as string), 3) > 0", Product.class );
71-
Product p = q.uniqueResult();
51+
scope.inTransaction( session -> {
52+
Product p = session.createQuery( "select p from Product p where locate('.', cast(p.price as string), 3) > 0", Product.class ).uniqueResult();
7253
assertNull( p );
73-
tx.commit();
74-
}
54+
} );
7555

7656
}
7757

7858
@Test
79-
public void testSubstringFunction() {
80-
try ( Session s = openSession() ) {
81-
Transaction tx = s.beginTransaction();
82-
Query<Product> q = s.createQuery( "select p from Product p where substring(cast(p.price as string), 1, 2) = '1.'", Product.class );
83-
Product p = q.uniqueResult();
59+
public void testSubstringFunction(SessionFactoryScope scope) {
60+
scope.inTransaction( session -> {
61+
Product p = session.createQuery( "select p from Product p where substring(cast(p.price as string), 1, 2) = '1.'", Product.class ).uniqueResult();
8462
assertNotNull( p );
8563
assertEquals( 100, p.getLength() );
8664
assertEquals( BigDecimal.valueOf( 1.29 ), p.getPrice() );
87-
tx.commit();
88-
}
65+
} );
8966

90-
try ( Session s = openSession() ) {
91-
Transaction tx = s.beginTransaction();
92-
Query<Product> q = s.createQuery( "select p from Product p where substring(cast(p.price as string), 1, 2) = '.1'", Product.class );
93-
Product p = q.uniqueResult();
67+
scope.inTransaction( session -> {
68+
Product p = session.createQuery( "select p from Product p where substring(cast(p.price as string), 1, 2) = '.1'", Product.class ).uniqueResult();
9469
assertNull( p );
95-
tx.commit();
96-
}
70+
} );
9771

98-
try ( Session s = openSession() ) {
99-
Transaction tx = s.beginTransaction();
100-
Query<Product> q = s.createQuery( "select p from Product p where substring(cast(p.price as string), 1) = '1.29'", Product.class );
101-
Product p = q.uniqueResult();
72+
scope.inTransaction( session -> {
73+
Product p = session.createQuery( "select p from Product p where substring(cast(p.price as string), 1) = '1.29'", Product.class ).uniqueResult();
10274
assertNotNull( p );
10375
assertEquals( 100, p.getLength() );
10476
assertEquals( BigDecimal.valueOf( 1.29 ), p.getPrice() );
105-
tx.commit();
106-
}
77+
} );
10778

108-
try ( Session s = openSession() ) {
109-
Transaction tx = s.beginTransaction();
110-
Query<Product> q = s.createQuery( "select p from Product p where substring(cast(p.price as string), 1) = '1.'", Product.class );
111-
Product p = q.uniqueResult();
79+
scope.inTransaction( session -> {
80+
Product p = session.createQuery( "select p from Product p where substring(cast(p.price as string), 1) = '1.'", Product.class ).uniqueResult();
11281
assertNull( p );
113-
tx.commit();
114-
}
82+
} );
11583
}
11684

11785
}

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/HSQLTruncFunctionTest.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,30 @@
88
import jakarta.persistence.Id;
99

1010
import org.hibernate.dialect.HSQLDialect;
11-
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
11+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
12+
import org.hibernate.testing.orm.junit.Jpa;
13+
import org.hibernate.testing.orm.junit.RequiresDialect;
14+
import org.junit.jupiter.api.Test;
1215

13-
import org.hibernate.testing.RequiresDialect;
14-
import org.junit.Test;
15-
16-
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
17-
import static org.junit.Assert.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
1817

1918
/**
2019
@author Vlad Mihalcea
2120
*/
2221
@RequiresDialect( HSQLDialect.class )
23-
public class HSQLTruncFunctionTest extends BaseEntityManagerFunctionalTestCase {
24-
25-
@Override
26-
protected Class<?>[] getAnnotatedClasses() {
27-
return new Class<?>[] {
28-
Person.class
29-
};
30-
}
22+
@Jpa(annotatedClasses = {HSQLTruncFunctionTest.Person.class})
23+
public class HSQLTruncFunctionTest {
3124

3225
@Test
33-
public void testTruncateAndTruncFunctions(){
34-
doInJPA( this::entityManagerFactory, entityManager -> {
26+
public void testTruncateAndTruncFunctions(EntityManagerFactoryScope scope){
27+
scope.inTransaction( entityManager -> {
3528
Person person = new Person();
3629
person.setId( 1L );
3730
person.setHighestScore( 99.56d );
3831
entityManager.persist( person );
3932
} );
4033

41-
doInJPA( this::entityManagerFactory, entityManager -> {
34+
scope.inTransaction( entityManager -> {
4235
Double score = entityManager.createQuery(
4336
"select truncate(p.highestScore, 1) " +
4437
"from Person p " +
@@ -49,7 +42,7 @@ public void testTruncateAndTruncFunctions(){
4942
assertEquals( 99.5d, score, 0.01 );
5043
} );
5144

52-
doInJPA( this::entityManagerFactory, entityManager -> {
45+
scope.inTransaction( entityManager -> {
5346
Double score = entityManager.createQuery(
5447
"select trunc(p.highestScore, 1) " +
5548
"from Person p " +

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/function/MySQLRoundFunctionTest.java

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,36 @@
55
package org.hibernate.orm.test.dialect.function;
66
import java.math.BigDecimal;
77

8-
import org.junit.Test;
8+
import org.hibernate.testing.orm.junit.DomainModel;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.junit.jupiter.api.Test;
912

10-
import org.hibernate.query.Query;
11-
import org.hibernate.Session;
12-
import org.hibernate.Transaction;
1313
import org.hibernate.dialect.MySQLDialect;
14-
import org.hibernate.testing.RequiresDialect;
15-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
14+
import org.hibernate.testing.orm.junit.RequiresDialect;
1615

17-
import static org.junit.Assert.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
1817

1918
/**
2019
@author Strong Liu
2120
*/
2221
@RequiresDialect( MySQLDialect.class )
23-
public class MySQLRoundFunctionTest extends BaseCoreFunctionalTestCase {
24-
25-
@Override
26-
public String[] getMappings() {
27-
return new String[]{"dialect/function/Product.hbm.xml"};
28-
}
29-
30-
@Override
31-
protected String getBaseForMappings() {
32-
return "org/hibernate/orm/test/";
33-
}
22+
@DomainModel(xmlMappings = {"org/hibernate/orm/test/dialect/function/Product.hbm.xml"})
23+
@SessionFactory
24+
public class MySQLRoundFunctionTest {
3425

3526
@Test
36-
public void testRoundFunction(){
37-
Product product = new Product();
38-
product.setLength( 100 );
39-
product.setPrice( new BigDecimal( 1.298 ) );
40-
Session s=openSession();
41-
Transaction tx=s.beginTransaction();
42-
s.persist( product );
43-
tx.commit();
44-
s.close();
45-
s=openSession();
46-
tx=s.beginTransaction();
47-
Query q=s.createQuery( "select round(p.price,1) from Product p" );
48-
Object o=q.uniqueResult();
49-
assertEquals( BigDecimal.class , o.getClass() );
50-
assertEquals( BigDecimal.valueOf( 1.3 ) , o );
51-
tx.commit();
52-
s.close();
53-
27+
public void testRoundFunction(SessionFactoryScope scope){
28+
scope.inTransaction( session -> {
29+
Product product = new Product();
30+
product.setLength( 100 );
31+
product.setPrice( new BigDecimal( 1.298 ) );
32+
session.persist( product );
33+
} );
34+
scope.inTransaction( session -> {
35+
BigDecimal bd = session.createQuery( "select round(p.price,1) from Product p", BigDecimal.class ).uniqueResult();
36+
assertEquals( BigDecimal.valueOf( 1.3 ), bd );
37+
} );
5438
}
5539

5640
}

0 commit comments

Comments
 (0)