41
41
import reactor .core .publisher .Mono ;
42
42
43
43
import java .lang .reflect .Method ;
44
+ import java .util .Date ;
44
45
45
46
import static org .assertj .core .api .Assertions .assertThat ;
46
47
import static org .mockito .Mockito .*;
51
52
@ RunWith (MockitoJUnitRunner .class )
52
53
public class PartTreeR2dbcQueryIntegrationTests {
53
54
private static final String TABLE = "users" ;
54
- private static final String ALL_FIELDS = TABLE + ".id, " + TABLE + ".first_name, " + TABLE + ".last_name" ;
55
+ private static final String ALL_FIELDS = TABLE + ".id, "
56
+ + TABLE + ".first_name, "
57
+ + TABLE + ".last_name, "
58
+ + TABLE + ".date_of_birth" ;
55
59
56
60
@ Mock
57
61
private ConnectionFactory connectionFactory ;
@@ -112,7 +116,7 @@ public void createsQueryWithLimitForExistsProjection() throws Exception {
112
116
113
117
@ Test
114
118
public void createsQueryToFindAllEntitiesByTwoStringAttributes () throws Exception {
115
- R2dbcQueryMethod queryMethod = getQueryMethod ("findByLastNameAndFirstName " , String .class , String .class );
119
+ R2dbcQueryMethod queryMethod = getQueryMethod ("findAllByLastNameAndFirstName " , String .class , String .class );
116
120
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
117
121
dataAccessStrategy );
118
122
BindableQuery bindableQuery = r2dbcQuery .createQuery (getAccessor (queryMethod , new Object []{"Doe" , "John" }));
@@ -123,7 +127,7 @@ public void createsQueryToFindAllEntitiesByTwoStringAttributes() throws Exceptio
123
127
124
128
@ Test
125
129
public void createsQueryToFindAllEntitiesByOneOfTwoStringAttributes () throws Exception {
126
- R2dbcQueryMethod queryMethod = getQueryMethod ("findByLastNameOrFirstName " , String .class , String .class );
130
+ R2dbcQueryMethod queryMethod = getQueryMethod ("findAllByLastNameOrFirstName " , String .class , String .class );
127
131
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
128
132
dataAccessStrategy );
129
133
BindableQuery bindableQuery = r2dbcQuery .createQuery (getAccessor (queryMethod , new Object []{"Doe" , "John" }));
@@ -132,6 +136,18 @@ public void createsQueryToFindAllEntitiesByOneOfTwoStringAttributes() throws Exc
132
136
assertThat (bindableQuery .get ()).isEqualTo (expectedSql );
133
137
}
134
138
139
+ @ Test
140
+ public void createsQueryToFindAllEntitiesByDateAttributeBetween () throws Exception {
141
+ R2dbcQueryMethod queryMethod = getQueryMethod ("findAllByDateOfBirthBetween" , Date .class , Date .class );
142
+ PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
143
+ dataAccessStrategy );
144
+ RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object []{null , new Date ()});
145
+ BindableQuery bindableQuery = r2dbcQuery .createQuery (accessor );
146
+ String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE
147
+ + " WHERE " + TABLE + ".date_of_birth >= ? AND " + TABLE + ".date_of_birth <= ?" ;
148
+ assertThat (bindableQuery .get ()).isEqualTo (expectedSql );
149
+ }
150
+
135
151
private R2dbcQueryMethod getQueryMethod (String methodName , Class <?>... parameterTypes ) throws Exception {
136
152
Method method = UserRepository .class .getMethod (methodName , parameterTypes );
137
153
return new R2dbcQueryMethod (method , new DefaultRepositoryMetadata (UserRepository .class ),
@@ -145,11 +161,13 @@ private RelationalParametersParameterAccessor getAccessor(R2dbcQueryMethod query
145
161
private interface UserRepository extends Repository <User , Long > {
146
162
Flux <User > findAllByFirstName (String firstName );
147
163
148
- Flux <User > findByLastNameAndFirstName (String lastName , String firstName );
164
+ Flux <User > findAllByLastNameAndFirstName (String lastName , String firstName );
149
165
150
- Flux <User > findByLastNameOrFirstName (String lastName , String firstName );
166
+ Flux <User > findAllByLastNameOrFirstName (String lastName , String firstName );
151
167
152
168
Mono <Boolean > existsByFirstName (String firstName );
169
+
170
+ Flux <User > findAllByDateOfBirthBetween (Date from , Date to );
153
171
}
154
172
155
173
@ Table ("users" )
@@ -159,5 +177,6 @@ private static class User {
159
177
private Long id ;
160
178
private String firstName ;
161
179
private String lastName ;
180
+ private Date dateOfBirth ;
162
181
}
163
182
}
0 commit comments