|
15 | 15 | */
|
16 | 16 | package org.springframework.data.jpa.repository;
|
17 | 17 |
|
18 |
| -import static java.util.Arrays.asList; |
| 18 | +import static java.util.Arrays.*; |
19 | 19 | import static org.assertj.core.api.Assertions.assertThat;
|
20 | 20 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
21 | 21 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
22 |
| -import static org.springframework.data.domain.Example.of; |
| 22 | +import static org.springframework.data.domain.Example.*; |
23 | 23 | import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatcher;
|
24 | 24 | import static org.springframework.data.domain.ExampleMatcher.StringMatcher;
|
25 | 25 | import static org.springframework.data.domain.ExampleMatcher.matching;
|
26 |
| -import static org.springframework.data.domain.Sort.Direction.ASC; |
27 |
| -import static org.springframework.data.domain.Sort.Direction.DESC; |
| 26 | +import static org.springframework.data.domain.Sort.Direction.*; |
| 27 | +import static org.springframework.data.jpa.domain.Specification.*; |
28 | 28 | import static org.springframework.data.jpa.domain.Specification.not;
|
29 |
| -import static org.springframework.data.jpa.domain.Specification.where; |
30 | 29 | import static org.springframework.data.jpa.domain.sample.UserSpecifications.userHasAgeLess;
|
31 | 30 | import static org.springframework.data.jpa.domain.sample.UserSpecifications.userHasFirstname;
|
32 | 31 | import static org.springframework.data.jpa.domain.sample.UserSpecifications.userHasFirstnameLike;
|
|
75 | 74 | import org.springframework.data.domain.Sort.Order;
|
76 | 75 | import org.springframework.data.jpa.domain.Specification;
|
77 | 76 | import org.springframework.data.jpa.domain.sample.Address;
|
| 77 | +import org.springframework.data.jpa.domain.sample.QUser; |
78 | 78 | import org.springframework.data.jpa.domain.sample.Role;
|
79 | 79 | import org.springframework.data.jpa.domain.sample.SpecialUser;
|
80 | 80 | import org.springframework.data.jpa.domain.sample.User;
|
@@ -2444,6 +2444,47 @@ void findByFluentSpecificationWithSimplePropertyPathsDoesntLoadUnrequestedPaths(
|
2444 | 2444 | );
|
2445 | 2445 | }
|
2446 | 2446 |
|
| 2447 | + @Test // GH-2820 |
| 2448 | + void findByFluentPredicateWithProjectionAndPageRequest() { |
| 2449 | + |
| 2450 | + flushTestUsers(); |
| 2451 | + em.clear(); |
| 2452 | + |
| 2453 | + Page<User> users = repository.findBy(QUser.user.firstname.contains("v"), q -> q // |
| 2454 | + .project("firstname") // |
| 2455 | + .page(PageRequest.of(0, 10))); |
| 2456 | + |
| 2457 | + assertThat(users).extracting(User::getFirstname).containsExactlyInAnyOrder(firstUser.getFirstname(), |
| 2458 | + thirdUser.getFirstname(), fourthUser.getFirstname()); |
| 2459 | + } |
| 2460 | + |
| 2461 | + @Test // GH-2820 |
| 2462 | + void findByFluentPredicateWithProjectionAndAll() { |
| 2463 | + |
| 2464 | + flushTestUsers(); |
| 2465 | + em.clear(); |
| 2466 | + |
| 2467 | + List<User> users = repository.findBy(QUser.user.firstname.contains("v"), q -> q // |
| 2468 | + .project("firstname") // |
| 2469 | + .all()); |
| 2470 | + |
| 2471 | + assertThat(users).extracting(User::getFirstname).containsExactlyInAnyOrder(firstUser.getFirstname(), |
| 2472 | + thirdUser.getFirstname(), fourthUser.getFirstname()); |
| 2473 | + } |
| 2474 | + |
| 2475 | + @Test // GH-2820 |
| 2476 | + void findByFluentPredicateWithPageRequest() { |
| 2477 | + |
| 2478 | + flushTestUsers(); |
| 2479 | + em.clear(); |
| 2480 | + |
| 2481 | + Page<User> users = repository.findBy(QUser.user.firstname.contains("v"), q -> q // |
| 2482 | + .page(PageRequest.of(0, 10))); |
| 2483 | + |
| 2484 | + assertThat(users).extracting(User::getFirstname).containsExactlyInAnyOrder(firstUser.getFirstname(), |
| 2485 | + thirdUser.getFirstname(), fourthUser.getFirstname()); |
| 2486 | + } |
| 2487 | + |
2447 | 2488 | @Test // GH-2274
|
2448 | 2489 | void findByFluentSpecificationWithCollectionPropertyPathsDoesntLoadUnrequestedPaths() {
|
2449 | 2490 |
|
|
0 commit comments