|
4 | 4 | */ |
5 | 5 | package org.hibernate.orm.test.dialect.function; |
6 | 6 |
|
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; |
10 | 10 |
|
11 | 11 | import java.math.BigDecimal; |
12 | 12 |
|
13 | | -import org.hibernate.Session; |
14 | | -import org.hibernate.Transaction; |
15 | 13 | 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; |
18 | 16 | 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; |
21 | 21 |
|
22 | 22 | @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 | + } ); |
45 | 35 | } |
46 | 36 |
|
47 | 37 | @Test |
48 | 38 | @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(); |
54 | 42 | assertNotNull( p ); |
55 | 43 | assertEquals( 100, p.getLength() ); |
56 | 44 | 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(); |
64 | 48 | assertNull( p ); |
65 | | - tx.commit(); |
66 | | - } |
| 49 | + } ); |
67 | 50 |
|
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(); |
72 | 53 | assertNull( p ); |
73 | | - tx.commit(); |
74 | | - } |
| 54 | + } ); |
75 | 55 |
|
76 | 56 | } |
77 | 57 |
|
78 | 58 | @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(); |
84 | 62 | assertNotNull( p ); |
85 | 63 | assertEquals( 100, p.getLength() ); |
86 | 64 | assertEquals( BigDecimal.valueOf( 1.29 ), p.getPrice() ); |
87 | | - tx.commit(); |
88 | | - } |
| 65 | + } ); |
89 | 66 |
|
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(); |
94 | 69 | assertNull( p ); |
95 | | - tx.commit(); |
96 | | - } |
| 70 | + } ); |
97 | 71 |
|
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(); |
102 | 74 | assertNotNull( p ); |
103 | 75 | assertEquals( 100, p.getLength() ); |
104 | 76 | assertEquals( BigDecimal.valueOf( 1.29 ), p.getPrice() ); |
105 | | - tx.commit(); |
106 | | - } |
| 77 | + } ); |
107 | 78 |
|
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(); |
112 | 81 | assertNull( p ); |
113 | | - tx.commit(); |
114 | | - } |
| 82 | + } ); |
115 | 83 | } |
116 | 84 |
|
117 | 85 | } |
0 commit comments