5
5
*/
6
6
package org .hibernate .reactive ;
7
7
8
- import java .util .ArrayList ;
9
- import java .util .Arrays ;
10
8
import java .util .Collection ;
11
9
import java .util .List ;
12
-
10
+ import java . util . Objects ;
13
11
14
12
import org .hibernate .annotations .SQLSelect ;
15
13
import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
22
20
import org .junit .jupiter .api .extension .RegisterExtension ;
23
21
24
22
import io .vertx .junit5 .VertxTestContext ;
25
- import jakarta .persistence .ElementCollection ;
26
23
import jakarta .persistence .Entity ;
27
- import jakarta .persistence .FetchType ;
28
24
import jakarta .persistence .Id ;
29
25
30
26
import static org .assertj .core .api .Assertions .assertThat ;
27
+ import static org .hibernate .reactive .SQLSelectTest .Person .SELECT_QUERY ;
31
28
import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .POSTGRESQL ;
32
29
import static org .hibernate .reactive .testing .DBSelectionExtension .runOnlyFor ;
33
- import static org .junit .jupiter .api .Assertions .assertNotNull ;
34
30
35
31
public class SQLSelectTest extends BaseReactiveTest {
36
32
@ RegisterExtension // We use native queries, which may be different for other DBs
37
33
public DBSelectionExtension dbSelection = runOnlyFor ( POSTGRESQL );
38
34
39
35
private SqlStatementTracker sqlTracker ;
36
+
40
37
private Person thePerson ;
41
- public static String SQL = "xxxxx" ;
42
38
43
39
@ Override
44
40
protected Collection <Class <?>> annotatedEntities () {
@@ -63,33 +59,31 @@ protected void addServices(StandardServiceRegistryBuilder builder) {
63
59
64
60
@ BeforeEach
65
61
public void populateDb (VertxTestContext context ) {
66
- List <String > phones = Arrays .asList ( "999-999-9999" , "111-111-1111" , "123-456-7890" );
67
62
thePerson = new Person ();
68
63
thePerson .id = 724200 ;
69
64
thePerson .name = "Claude" ;
70
- thePerson .phones = phones ;
71
65
72
- test ( context , getMutinySessionFactory ().withTransaction ( ( s , t ) -> s .persist ( thePerson ) ) );
66
+ test ( context , getMutinySessionFactory ().withTransaction ( s -> s .persist ( thePerson ) ) );
73
67
}
74
68
75
69
@ Test
76
70
public void findEntity (VertxTestContext context ) {
77
71
test ( context , openSession ()
78
72
.thenCompose ( session -> session .find ( Person .class , thePerson .getId () ) )
79
73
.thenAccept ( found -> {
80
- assertPhones ( found , "999-999-9999" , "111-111-1111" , "123-456-7890" );
81
- assertThat ( sqlTracker .getLoggedQueries () ).contains ( Person .SELECT_QUERY .replace ( "?" , "$1" ) );
74
+ assertThat ( found ).isEqualTo ( thePerson );
75
+ assertThat ( sqlTracker .getLoggedQueries () )
76
+ .containsExactly (
77
+ "select version()" ,
78
+ SELECT_QUERY .replace ( "?" , "$1" )
79
+ );
82
80
} )
83
81
);
84
82
}
85
83
86
- private static void assertPhones (Person person , String ... expectedPhones ) {
87
- assertNotNull ( person );
88
- assertThat ( person .getPhones () ).containsExactlyInAnyOrder ( expectedPhones );
89
- }
90
84
91
85
@ Entity (name = "Person" )
92
- @ SQLSelect (sql = Person . SELECT_QUERY )
86
+ @ SQLSelect (sql = SELECT_QUERY )
93
87
static class Person {
94
88
// Query containing simple where check to distinguish from a possible generated query
95
89
public static final String SELECT_QUERY = "SELECT id, name FROM person WHERE id = ? and 'hreact' = 'hreact'" ;
@@ -99,9 +93,6 @@ static class Person {
99
93
100
94
private String name ;
101
95
102
- @ ElementCollection (fetch = FetchType .EAGER )
103
- private List <String > phones = new ArrayList <>();
104
-
105
96
public int getId () {
106
97
return id ;
107
98
}
@@ -118,8 +109,21 @@ public void setName(String name) {
118
109
this .name = name ;
119
110
}
120
111
121
- public List <String > getPhones () {
122
- return phones ;
112
+ @ Override
113
+ public boolean equals (Object o ) {
114
+ if ( this == o ) {
115
+ return true ;
116
+ }
117
+ if ( o == null || getClass () != o .getClass () ) {
118
+ return false ;
119
+ }
120
+ Person person = (Person ) o ;
121
+ return Objects .equals ( name , person .name );
122
+ }
123
+
124
+ @ Override
125
+ public int hashCode () {
126
+ return Objects .hash ( name );
123
127
}
124
128
}
125
129
}
0 commit comments