55 */
66package org .hibernate .reactive ;
77
8- import java .util .ArrayList ;
9- import java .util .Arrays ;
108import java .util .Collection ;
119import java .util .List ;
12-
10+ import java . util . Objects ;
1311
1412import org .hibernate .annotations .SQLSelect ;
1513import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
2220import org .junit .jupiter .api .extension .RegisterExtension ;
2321
2422import io .vertx .junit5 .VertxTestContext ;
25- import jakarta .persistence .ElementCollection ;
2623import jakarta .persistence .Entity ;
27- import jakarta .persistence .FetchType ;
2824import jakarta .persistence .Id ;
2925
3026import static org .assertj .core .api .Assertions .assertThat ;
27+ import static org .hibernate .reactive .SQLSelectTest .Person .SELECT_QUERY ;
3128import static org .hibernate .reactive .containers .DatabaseConfiguration .DBType .POSTGRESQL ;
3229import static org .hibernate .reactive .testing .DBSelectionExtension .runOnlyFor ;
33- import static org .junit .jupiter .api .Assertions .assertNotNull ;
3430
3531public class SQLSelectTest extends BaseReactiveTest {
3632 @ RegisterExtension // We use native queries, which may be different for other DBs
3733 public DBSelectionExtension dbSelection = runOnlyFor ( POSTGRESQL );
3834
3935 private SqlStatementTracker sqlTracker ;
36+
4037 private Person thePerson ;
41- public static String SQL = "xxxxx" ;
4238
4339 @ Override
4440 protected Collection <Class <?>> annotatedEntities () {
@@ -63,33 +59,31 @@ protected void addServices(StandardServiceRegistryBuilder builder) {
6359
6460 @ BeforeEach
6561 public void populateDb (VertxTestContext context ) {
66- List <String > phones = Arrays .asList ( "999-999-9999" , "111-111-1111" , "123-456-7890" );
6762 thePerson = new Person ();
6863 thePerson .id = 724200 ;
6964 thePerson .name = "Claude" ;
70- thePerson .phones = phones ;
7165
72- test ( context , getMutinySessionFactory ().withTransaction ( ( s , t ) -> s .persist ( thePerson ) ) );
66+ test ( context , getMutinySessionFactory ().withTransaction ( s -> s .persist ( thePerson ) ) );
7367 }
7468
7569 @ Test
7670 public void findEntity (VertxTestContext context ) {
7771 test ( context , openSession ()
7872 .thenCompose ( session -> session .find ( Person .class , thePerson .getId () ) )
7973 .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+ );
8280 } )
8381 );
8482 }
8583
86- private static void assertPhones (Person person , String ... expectedPhones ) {
87- assertNotNull ( person );
88- assertThat ( person .getPhones () ).containsExactlyInAnyOrder ( expectedPhones );
89- }
9084
9185 @ Entity (name = "Person" )
92- @ SQLSelect (sql = Person . SELECT_QUERY )
86+ @ SQLSelect (sql = SELECT_QUERY )
9387 static class Person {
9488 // Query containing simple where check to distinguish from a possible generated query
9589 public static final String SELECT_QUERY = "SELECT id, name FROM person WHERE id = ? and 'hreact' = 'hreact'" ;
@@ -99,9 +93,6 @@ static class Person {
9993
10094 private String name ;
10195
102- @ ElementCollection (fetch = FetchType .EAGER )
103- private List <String > phones = new ArrayList <>();
104-
10596 public int getId () {
10697 return id ;
10798 }
@@ -118,8 +109,21 @@ public void setName(String name) {
118109 this .name = name ;
119110 }
120111
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 );
123127 }
124128 }
125129}
0 commit comments