|
19 | 19 | import io.r2dbc.spi.ConnectionFactoryMetadata;
|
20 | 20 | import lombok.Data;
|
21 | 21 | import org.junit.Before;
|
| 22 | +import org.junit.Rule; |
22 | 23 | import org.junit.Test;
|
| 24 | +import org.junit.rules.ExpectedException; |
23 | 25 | import org.junit.runner.RunWith;
|
24 | 26 | import org.mockito.Mock;
|
25 | 27 | import org.mockito.junit.MockitoJUnitRunner;
|
@@ -66,6 +68,9 @@ public class PartTreeR2dbcQueryIntegrationTests {
|
66 | 68 | @Mock
|
67 | 69 | private R2dbcConverter r2dbcConverter;
|
68 | 70 |
|
| 71 | + @Rule |
| 72 | + public ExpectedException thrown = ExpectedException.none(); |
| 73 | + |
69 | 74 | private RelationalMappingContext mappingContext;
|
70 | 75 | private ReactiveDataAccessStrategy dataAccessStrategy;
|
71 | 76 | private DatabaseClient databaseClient;
|
@@ -439,6 +444,39 @@ public void createsQueryToFindAllEntitiesByStringAttributeIgnoringCase() throws
|
439 | 444 | assertThat(bindableQuery.get()).isEqualTo(expectedSql);
|
440 | 445 | }
|
441 | 446 |
|
| 447 | + @Test |
| 448 | + public void throwsExceptionWhenIgnoringCaseIsImpossible() throws Exception { |
| 449 | + thrown.expect(IllegalStateException.class); |
| 450 | + thrown.expectMessage("Unable to ignore case of java.lang.Long type, " + |
| 451 | + "the property 'id' must reference a string"); |
| 452 | + R2dbcQueryMethod queryMethod = getQueryMethod("findByIdIgnoringCase", Long.class); |
| 453 | + PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, databaseClient, r2dbcConverter, |
| 454 | + dataAccessStrategy); |
| 455 | + r2dbcQuery.createQuery(getAccessor(queryMethod, new Object[]{1L})); |
| 456 | + } |
| 457 | + |
| 458 | + @Test |
| 459 | + public void throwsExceptionWhenInPredicateHasNonIterableParameter() throws Exception { |
| 460 | + thrown.expect(IllegalArgumentException.class); |
| 461 | + thrown.expectMessage("Operator IN on id requires a Collection argument, " + |
| 462 | + "found class java.lang.Long in method findAllByIdIn."); |
| 463 | + R2dbcQueryMethod queryMethod = getQueryMethod("findAllByIdIn", Long.class); |
| 464 | + PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, databaseClient, r2dbcConverter, |
| 465 | + dataAccessStrategy); |
| 466 | + r2dbcQuery.createQuery(getAccessor(queryMethod, new Object[]{1L})); |
| 467 | + } |
| 468 | + |
| 469 | + @Test |
| 470 | + public void throwsExceptionWhenSimplePropertyPredicateHasIterableParameter() throws Exception { |
| 471 | + thrown.expect(IllegalArgumentException.class); |
| 472 | + thrown.expectMessage("Operator SIMPLE_PROPERTY on id requires a scalar argument, " + |
| 473 | + "found interface java.util.Collection in method findAllById."); |
| 474 | + R2dbcQueryMethod queryMethod = getQueryMethod("findAllById", Collection.class); |
| 475 | + PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, databaseClient, r2dbcConverter, |
| 476 | + dataAccessStrategy); |
| 477 | + r2dbcQuery.createQuery(getAccessor(queryMethod, new Object[]{Collections.singleton(1L)})); |
| 478 | + } |
| 479 | + |
442 | 480 | private R2dbcQueryMethod getQueryMethod(String methodName, Class<?>... parameterTypes) throws Exception {
|
443 | 481 | Method method = UserRepository.class.getMethod(methodName, parameterTypes);
|
444 | 482 | return new R2dbcQueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class),
|
@@ -501,6 +539,12 @@ private interface UserRepository extends Repository<User, Long> {
|
501 | 539 | Flux<User> findAllByActiveFalse();
|
502 | 540 |
|
503 | 541 | Flux<User> findAllByFirstNameIgnoreCase(String firstName);
|
| 542 | + |
| 543 | + Mono<User> findByIdIgnoringCase(Long id); |
| 544 | + |
| 545 | + Flux<User> findAllByIdIn(Long id); |
| 546 | + |
| 547 | + Flux<User> findAllById(Collection<Long> ids); |
504 | 548 | }
|
505 | 549 |
|
506 | 550 | @Table("users")
|
|
0 commit comments