|
4 | 4 | */ |
5 | 5 | package org.hibernate.orm.test.sql.hand.quotedidentifiers; |
6 | 6 |
|
7 | | -import org.hibernate.Session; |
8 | 7 | import org.hibernate.dialect.Dialect; |
9 | 8 | import org.hibernate.query.NativeQuery; |
| 9 | +import org.hibernate.testing.orm.junit.DialectFeatureCheck; |
| 10 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 11 | +import org.hibernate.testing.orm.junit.RequiresDialectFeature; |
| 12 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 13 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 14 | +import org.junit.jupiter.api.AfterAll; |
| 15 | +import org.junit.jupiter.api.BeforeAll; |
| 16 | +import org.junit.jupiter.api.Test; |
10 | 17 |
|
11 | | -import org.hibernate.testing.DialectCheck; |
12 | | -import org.hibernate.testing.RequiresDialectFeature; |
13 | | -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; |
14 | | -import org.junit.Test; |
15 | 18 |
|
16 | 19 | /** |
17 | 20 | * Test of various situations with native-sql queries and quoted identifiers |
18 | 21 | * |
19 | 22 | * @author Steve Ebersole |
20 | 23 | */ |
21 | | -@RequiresDialectFeature( value = NativeSqlAndQuotedIdentifiersTest.LocalDialectCheck.class ) |
22 | | -public class NativeSqlAndQuotedIdentifiersTest extends BaseCoreFunctionalTestCase { |
| 24 | +@RequiresDialectFeature(feature = NativeSqlAndQuotedIdentifiersTest.LocalDialectCheck.class) |
| 25 | +@DomainModel( |
| 26 | + xmlMappings = "org/hibernate/orm/test/sql/hand/quotedidentifiers/Mappings.hbm.xml" |
| 27 | +) |
| 28 | +@SessionFactory |
| 29 | +public class NativeSqlAndQuotedIdentifiersTest { |
23 | 30 |
|
24 | | - @Override |
25 | | - protected String getBaseForMappings() { |
26 | | - return "org/hibernate/orm/test/"; |
27 | | - } |
28 | | - |
29 | | - @Override |
30 | | - public String[] getMappings() { |
31 | | - return new String[] { "sql/hand/quotedidentifiers/Mappings.hbm.xml" }; |
32 | | - } |
| 31 | + public static class LocalDialectCheck implements DialectFeatureCheck { |
33 | 32 |
|
34 | | - public static class LocalDialectCheck implements DialectCheck { |
35 | 33 | @Override |
36 | | - public boolean isMatch(Dialect dialect) { |
| 34 | + public boolean apply(Dialect dialect) { |
37 | 35 | return '\"' == dialect.openQuote(); |
38 | 36 | } |
39 | 37 | } |
40 | 38 |
|
41 | | - @Override |
42 | | - protected void prepareTest() throws Exception { |
43 | | - if( sessionFactory()==null)return; |
44 | | - Session session = sessionFactory().openSession(); |
45 | | - session.beginTransaction(); |
46 | | - session.persist( new Person( "me" ) ); |
47 | | - session.getTransaction().commit(); |
48 | | - session.close(); |
| 39 | + @BeforeAll |
| 40 | + protected void prepareTest(SessionFactoryScope scope) throws Exception { |
| 41 | + scope.inTransaction( |
| 42 | + session -> |
| 43 | + session.persist( new Person( "me" ) ) |
| 44 | + ); |
49 | 45 | } |
50 | 46 |
|
51 | | - @Override |
52 | | - protected void cleanupTest() throws Exception { |
53 | | - if( sessionFactory()==null)return; |
54 | | - Session session = sessionFactory().openSession(); |
55 | | - session.beginTransaction(); |
56 | | - session.createQuery( "delete Person" ).executeUpdate(); |
57 | | - session.getTransaction().commit(); |
58 | | - session.close(); |
| 47 | + @AfterAll |
| 48 | + protected void cleanupTest(SessionFactoryScope scope) throws Exception { |
| 49 | + scope.getSessionFactory().getSchemaManager().truncateMappedObjects(); |
59 | 50 | } |
60 | 51 |
|
61 | 52 | @Test |
62 | | - public void testCompleteScalarDiscovery() { |
63 | | - Session session = openSession(); |
64 | | - session.beginTransaction(); |
65 | | - session.getNamedQuery( "query-person" ).list(); |
66 | | - session.getTransaction().commit(); |
67 | | - session.close(); |
| 53 | + public void testCompleteScalarDiscovery(SessionFactoryScope scope) { |
| 54 | + scope.inTransaction( |
| 55 | + session -> |
| 56 | + session.getNamedQuery( "query-person" ).list() |
| 57 | + ); |
68 | 58 | } |
69 | 59 |
|
70 | 60 | @Test |
71 | | - public void testPartialScalarDiscovery() { |
72 | | - Session session = openSession(); |
73 | | - session.beginTransaction(); |
74 | | - NativeQuery query = session.getNamedNativeQuery( "query-person", "person-scalar" ); |
75 | | - query.list(); |
76 | | - session.getTransaction().commit(); |
77 | | - session.close(); |
| 61 | + public void testPartialScalarDiscovery(SessionFactoryScope scope) { |
| 62 | + scope.inTransaction( |
| 63 | + session -> { |
| 64 | + NativeQuery query = session.getNamedNativeQuery( "query-person", "person-scalar" ); |
| 65 | + query.list(); |
| 66 | + } |
| 67 | + ); |
78 | 68 | } |
79 | 69 |
|
80 | 70 | @Test |
81 | | - public void testBasicEntityMapping() { |
82 | | - Session session = openSession(); |
83 | | - session.beginTransaction(); |
84 | | - NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-basic" ); |
85 | | - query.list(); |
86 | | - session.getTransaction().commit(); |
87 | | - session.close(); |
| 71 | + public void testBasicEntityMapping(SessionFactoryScope scope) { |
| 72 | + scope.inTransaction( |
| 73 | + session -> { |
| 74 | + NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-basic" ); |
| 75 | + query.list(); |
| 76 | + } |
| 77 | + ); |
88 | 78 | } |
89 | 79 |
|
90 | 80 | @Test |
91 | | - public void testExpandedEntityMapping() { |
92 | | - Session session = openSession(); |
93 | | - session.beginTransaction(); |
94 | | - NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-expanded" ); |
95 | | - query.list(); |
96 | | - session.getTransaction().commit(); |
97 | | - session.close(); |
| 81 | + public void testExpandedEntityMapping(SessionFactoryScope scope) { |
| 82 | + scope.inTransaction( |
| 83 | + session -> { |
| 84 | + NativeQuery query = session.getNamedNativeQuery( "query-person", "person-entity-expanded" ); |
| 85 | + query.list(); |
| 86 | + } |
| 87 | + ); |
98 | 88 | } |
99 | 89 | } |
0 commit comments