50
50
*/
51
51
@ RunWith (MockitoJUnitRunner .class )
52
52
public class PartTreeR2dbcQueryIntegrationTests {
53
+ private static final String TABLE = "users" ;
54
+ private static final String ALL_FIELDS = TABLE + ".id, " + TABLE + ".first_name, " + TABLE + ".last_name" ;
55
+
53
56
@ Mock
54
57
private ConnectionFactory connectionFactory ;
55
58
@ Mock
@@ -82,9 +85,9 @@ public void createsQueryToFindAllEntitiesByStringAttribute() throws Exception {
82
85
R2dbcQueryMethod queryMethod = getQueryMethod ("findAllByFirstName" , String .class );
83
86
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
84
87
dataAccessStrategy );
85
- BindableQuery bindableQuery = r2dbcQuery .createQuery (getAccessor (queryMethod , new Object []{"Matthews " }));
86
- assertThat ( bindableQuery . get ())
87
- . isEqualTo ( "SELECT users.id, users.first_name FROM users WHERE users.first_name = ?" );
88
+ BindableQuery bindableQuery = r2dbcQuery .createQuery (getAccessor (queryMethod , new Object []{"John " }));
89
+ String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE + " WHERE " + TABLE + ".first_name = ?" ;
90
+ assertThat ( bindableQuery . get ()). isEqualTo ( expectedSql );
88
91
}
89
92
90
93
@ Test
@@ -93,18 +96,29 @@ public void createsQueryWithIsNullCondition() throws Exception {
93
96
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
94
97
dataAccessStrategy );
95
98
BindableQuery bindableQuery = r2dbcQuery .createQuery ((getAccessor (queryMethod , new Object []{null })));
96
- assertThat ( bindableQuery . get ())
97
- . isEqualTo ( "SELECT users.id, users.first_name FROM users WHERE users.first_name IS NULL" );
99
+ String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE + " WHERE " + TABLE + ".first_name IS NULL" ;
100
+ assertThat ( bindableQuery . get ()). isEqualTo ( expectedSql );
98
101
}
99
102
100
103
@ Test
101
104
public void createsQueryWithLimitForExistsProjection () throws Exception {
102
105
R2dbcQueryMethod queryMethod = getQueryMethod ("existsByFirstName" , String .class );
103
106
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
104
107
dataAccessStrategy );
105
- BindableQuery query = r2dbcQuery .createQuery ((getAccessor (queryMethod , new Object []{"Matthews" })));
106
- assertThat (query .get ())
107
- .isEqualTo ("SELECT users.id FROM users WHERE users.first_name = ? LIMIT 1" );
108
+ BindableQuery query = r2dbcQuery .createQuery ((getAccessor (queryMethod , new Object []{"John" })));
109
+ String expectedSql = "SELECT " + TABLE + ".id FROM " + TABLE + " WHERE " + TABLE + ".first_name = ? LIMIT 1" ;
110
+ assertThat (query .get ()).isEqualTo (expectedSql );
111
+ }
112
+
113
+ @ Test
114
+ public void createsQueryToFindAllEntitiesByTwoStringAttributes () throws Exception {
115
+ R2dbcQueryMethod queryMethod = getQueryMethod ("findByLastNameAndFirstName" , String .class , String .class );
116
+ PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
117
+ dataAccessStrategy );
118
+ BindableQuery bindableQuery = r2dbcQuery .createQuery (getAccessor (queryMethod , new Object []{"Doe" , "John" }));
119
+ String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE
120
+ + " WHERE " + TABLE + ".last_name = ? AND " + TABLE + ".first_name = ?" ;
121
+ assertThat (bindableQuery .get ()).isEqualTo (expectedSql );
108
122
}
109
123
110
124
private R2dbcQueryMethod getQueryMethod (String methodName , Class <?>... parameterTypes ) throws Exception {
@@ -120,6 +134,8 @@ private RelationalParametersParameterAccessor getAccessor(R2dbcQueryMethod query
120
134
private interface UserRepository extends Repository <User , Long > {
121
135
Flux <User > findAllByFirstName (String firstName );
122
136
137
+ Flux <User > findByLastNameAndFirstName (String lastName , String firstName );
138
+
123
139
Mono <Boolean > existsByFirstName (String firstName );
124
140
}
125
141
@@ -129,5 +145,6 @@ private static class User {
129
145
@ Id
130
146
private Long id ;
131
147
private String firstName ;
148
+ private String lastName ;
132
149
}
133
150
}
0 commit comments