@@ -307,6 +307,30 @@ public void prependsLikeOperatorParameterWithPercentSymbolForStartingWithQuery()
307
307
verify (bindSpecMock , times (1 )).bind (0 , "%hn" );
308
308
}
309
309
310
+ @ Test
311
+ public void createsQueryToFindAllEntitiesByStringAttributeContaining () throws Exception {
312
+ R2dbcQueryMethod queryMethod = getQueryMethod ("findAllByFirstNameContaining" , String .class );
313
+ PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
314
+ dataAccessStrategy );
315
+ RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object [] {"oh" });
316
+ BindableQuery bindableQuery = r2dbcQuery .createQuery (accessor );
317
+ String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE + " WHERE " + TABLE + ".first_name LIKE ?" ;
318
+ assertThat (bindableQuery .get ()).isEqualTo (expectedSql );
319
+ }
320
+
321
+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
322
+ @ Test
323
+ public void wrapsLikeOperatorParameterWithPercentSymbolsForContainingQuery () throws Exception {
324
+ R2dbcQueryMethod queryMethod = getQueryMethod ("findAllByFirstNameContaining" , String .class );
325
+ PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
326
+ dataAccessStrategy );
327
+ RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object [] {"hn" });
328
+ BindableQuery bindableQuery = r2dbcQuery .createQuery (accessor );
329
+ DatabaseClient .BindSpec bindSpecMock = mock (DatabaseClient .BindSpec .class );
330
+ bindableQuery .bind (bindSpecMock );
331
+ verify (bindSpecMock , times (1 )).bind (0 , "%hn%" );
332
+ }
333
+
310
334
private R2dbcQueryMethod getQueryMethod (String methodName , Class <?>... parameterTypes ) throws Exception {
311
335
Method method = UserRepository .class .getMethod (methodName , parameterTypes );
312
336
return new R2dbcQueryMethod (method , new DefaultRepositoryMetadata (UserRepository .class ),
@@ -351,6 +375,8 @@ private interface UserRepository extends Repository<User, Long> {
351
375
Flux <User > findAllByFirstNameStartingWith (String starting );
352
376
353
377
Flux <User > findAllByFirstNameEndingWith (String ending );
378
+
379
+ Flux <User > findAllByFirstNameContaining (String containing );
354
380
}
355
381
356
382
@ Table ("users" )
0 commit comments