Skip to content

Commit 0bb11da

Browse files
committed
spring-projects#282 - Add a few more tests for 'PartTreeR2dbcQuery'
1 parent cf32380 commit 0bb11da

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

Diff for: src/main/java/org/springframework/data/r2dbc/repository/query/ConditionFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public Condition createCondition(Part part) {
149149
return Conditions.isEqual(lhs, rhs).not();
150150
}
151151
default:
152-
throw new UnsupportedOperationException("Creating conditions for type " + type + " is unsupported");
152+
throw new IllegalArgumentException("Unsupported keyword " + type);
153153
}
154154

155155
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.springframework.data.r2dbc.repository.query;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertNull;
6+
7+
/**
8+
* @author Roman Chigvintsev
9+
*/
10+
public class LikeEscaperTest {
11+
@Test
12+
public void ignoresNulls() {
13+
assertNull(LikeEscaper.DEFAULT.escape(null));
14+
}
15+
}

Diff for: src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryIntegrationTests.java

+37
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,19 @@ public void createsQueryToFindAllEntitiesByIntegerAttributeWithDescendingOrderin
376376
assertThat(bindableQuery.get()).isEqualTo(expectedSql);
377377
}
378378

379+
@Test
380+
public void createsQueryToFindAllEntitiesByIntegerAttributeWithAscendingOrderingByStringAttribute()
381+
throws Exception {
382+
R2dbcQueryMethod queryMethod = getQueryMethod("findAllByAgeOrderByLastNameAsc", Integer.class);
383+
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, databaseClient, r2dbcConverter,
384+
dataAccessStrategy);
385+
RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[]{"oh"});
386+
BindableQuery bindableQuery = r2dbcQuery.createQuery(accessor);
387+
String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE
388+
+ " WHERE " + TABLE + ".age = ? ORDER BY last_name ASC";
389+
assertThat(bindableQuery.get()).isEqualTo(expectedSql);
390+
}
391+
379392
@Test
380393
public void createsQueryToFindAllEntitiesByStringAttributeNot() throws Exception {
381394
R2dbcQueryMethod queryMethod = getQueryMethod("findAllByLastNameNot", String.class);
@@ -477,6 +490,26 @@ public void throwsExceptionWhenSimplePropertyPredicateHasIterableParameter() thr
477490
r2dbcQuery.createQuery(getAccessor(queryMethod, new Object[]{Collections.singleton(1L)}));
478491
}
479492

493+
@Test
494+
public void throwsExceptionWhenConditionKeywordIsUnsupported() throws Exception {
495+
thrown.expect(IllegalArgumentException.class);
496+
thrown.expectMessage("Unsupported keyword IS_EMPTY");
497+
R2dbcQueryMethod queryMethod = getQueryMethod("findAllByIdIsEmpty");
498+
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, databaseClient, r2dbcConverter,
499+
dataAccessStrategy);
500+
r2dbcQuery.createQuery(getAccessor(queryMethod, new Object[0]));
501+
}
502+
503+
@Test
504+
public void throwsExceptionWhenInvalidNumberOfParameterIsGiven() throws Exception {
505+
thrown.expect(IllegalArgumentException.class);
506+
thrown.expectMessage("Invalid number of parameters given!");
507+
R2dbcQueryMethod queryMethod = getQueryMethod("findAllByFirstName", String.class);
508+
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, databaseClient, r2dbcConverter,
509+
dataAccessStrategy);
510+
r2dbcQuery.createQuery(getAccessor(queryMethod, new Object[0]));
511+
}
512+
480513
private R2dbcQueryMethod getQueryMethod(String methodName, Class<?>... parameterTypes) throws Exception {
481514
Method method = UserRepository.class.getMethod(methodName, parameterTypes);
482515
return new R2dbcQueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class),
@@ -526,6 +559,8 @@ private interface UserRepository extends Repository<User, Long> {
526559

527560
Flux<User> findAllByFirstNameNotContaining(String notContaining);
528561

562+
Flux<User> findAllByAgeOrderByLastNameAsc(Integer age);
563+
529564
Flux<User> findAllByAgeOrderByLastNameDesc(Integer age);
530565

531566
Flux<User> findAllByLastNameNot(String lastName);
@@ -545,6 +580,8 @@ private interface UserRepository extends Repository<User, Long> {
545580
Flux<User> findAllByIdIn(Long id);
546581

547582
Flux<User> findAllById(Collection<Long> ids);
583+
584+
Flux<User> findAllByIdIsEmpty();
548585
}
549586

550587
@Table("users")

0 commit comments

Comments
 (0)