5
5
*/
6
6
package org .hibernate .reactive ;
7
7
8
- import jakarta .persistence .GeneratedValue ;
9
- import jakarta .persistence .ManyToOne ;
10
- import jakarta .persistence .OneToMany ;
11
8
import java .util .ArrayList ;
12
9
import java .util .Collection ;
13
10
import java .util .List ;
21
18
import io .vertx .junit5 .Timeout ;
22
19
import io .vertx .junit5 .VertxTestContext ;
23
20
import jakarta .persistence .Entity ;
21
+ import jakarta .persistence .GeneratedValue ;
24
22
import jakarta .persistence .Id ;
23
+ import jakarta .persistence .ManyToOne ;
24
+ import jakarta .persistence .OneToMany ;
25
25
import jakarta .persistence .Table ;
26
26
27
27
import static jakarta .persistence .CascadeType .PERSIST ;
28
28
import static jakarta .persistence .FetchType .LAZY ;
29
29
import static java .util .concurrent .TimeUnit .MINUTES ;
30
30
import static org .assertj .core .api .Assertions .assertThat ;
31
31
import static org .junit .jupiter .api .Assertions .assertEquals ;
32
- import static org .junit .jupiter .api .Assertions .assertNotNull ;
33
- import static org .junit .jupiter .api .Assertions .assertTrue ;
34
32
35
33
@ Timeout (value = 10 , timeUnit = MINUTES )
36
-
37
34
public class HQLQueryTest extends BaseReactiveTest {
38
35
39
36
Flour spelt = new Flour ( 1 , "Spelt" , "An ancient grain, is a hexaploid species of wheat." , "Wheat flour" );
@@ -82,7 +79,7 @@ public void testAutoFlushOnResultList(VertxTestContext context) {
82
79
public void testSelectScalarString (VertxTestContext context ) {
83
80
test ( context , getSessionFactory ().withSession ( s -> {
84
81
Stage .SelectionQuery <String > qr = s .createSelectionQuery ( "SELECT 'Prova' FROM Flour WHERE id = " + rye .getId (), String .class );
85
- assertNotNull ( qr );
82
+ assertThat ( qr ). isNotNull ( );
86
83
return qr .getSingleResult ();
87
84
} ).thenAccept ( found -> assertEquals ( "Prova" , found ) ) );
88
85
}
@@ -91,30 +88,33 @@ public void testSelectScalarString(VertxTestContext context) {
91
88
public void testSelectScalarCount (VertxTestContext context ) {
92
89
test ( context , getSessionFactory ().withSession ( s -> {
93
90
Stage .SelectionQuery <Long > qr = s .createSelectionQuery ( "SELECT count(*) FROM Flour" , Long .class );
94
- assertNotNull ( qr );
91
+ assertThat ( qr ). isNotNull ( );
95
92
return qr .getSingleResult ();
96
93
} ).thenAccept ( found -> assertEquals ( 3L , found ) ) );
97
94
}
98
95
99
96
@ Test
100
97
public void testSelectWithMultipleScalarValues (VertxTestContext context ) {
101
98
test ( context , getSessionFactory ().withSession ( s -> {
102
- Stage .SelectionQuery <?> qr = s .createSelectionQuery ( "SELECT 'Prova', f.id FROM Flour f WHERE f.id = " + rye .getId (), Object [].class );
103
- assertNotNull ( qr );
104
- return qr .getSingleResult ();
105
- } ).thenAccept ( found -> {
106
- assertTrue ( found instanceof Object [] );
107
- assertEquals ( "Prova" , ( (Object []) found )[0 ] );
108
- assertEquals ( rye .getId (), ( (Object []) found )[1 ] );
109
- } )
99
+ Stage .SelectionQuery <?> qr = s .createSelectionQuery (
100
+ "SELECT 'Prova', f.id FROM Flour f WHERE f.id = " + rye .getId (),
101
+ Object [].class
102
+ );
103
+ assertThat ( qr ).isNotNull ();
104
+ return qr .getSingleResult ();
105
+ } ).thenAccept ( found -> {
106
+ assertThat ( found ).isInstanceOf ( Object [].class );
107
+ assertEquals ( "Prova" , ( (Object []) found )[0 ] );
108
+ assertEquals ( rye .getId (), ( (Object []) found )[1 ] );
109
+ } )
110
110
);
111
111
}
112
112
113
113
@ Test
114
114
public void testSingleResultQueryOnId (VertxTestContext context ) {
115
115
test ( context , getSessionFactory ().withSession ( s -> {
116
116
Stage .SelectionQuery <?> qr = s .createSelectionQuery ( "FROM Flour WHERE id = 1" , Flour .class );
117
- assertNotNull ( qr );
117
+ assertThat ( qr ). isNotNull ( );
118
118
return qr .getSingleResult ();
119
119
} ).thenAccept ( flour -> assertEquals ( spelt , flour ) )
120
120
);
@@ -124,7 +124,7 @@ public void testSingleResultQueryOnId(VertxTestContext context) {
124
124
public void testSingleResultQueryOnName (VertxTestContext context ) {
125
125
test ( context , getSessionFactory ().withSession ( s -> {
126
126
Stage .SelectionQuery <?> qr = s .createSelectionQuery ( "FROM Flour WHERE name = 'Almond'" , Flour .class );
127
- assertNotNull ( qr );
127
+ assertThat ( qr ). isNotNull ( );
128
128
return qr .getSingleResult ();
129
129
} ).thenAccept ( flour -> assertEquals ( almond , flour ) )
130
130
);
@@ -135,7 +135,7 @@ public void testFromQuery(VertxTestContext context) {
135
135
test ( context , getSessionFactory ()
136
136
.withSession ( s -> {
137
137
Stage .SelectionQuery <Flour > qr = s .createSelectionQuery ( "FROM Flour ORDER BY name" , Flour .class );
138
- assertNotNull ( qr );
138
+ assertThat ( qr ). isNotNull ( );
139
139
return qr .getResultList ();
140
140
} )
141
141
.thenAccept ( results -> assertThat ( results ).containsExactly ( almond , rye , spelt ) )
0 commit comments