|
15 | 15 | */
|
16 | 16 | package org.springframework.data.jpa.repository;
|
17 | 17 |
|
18 |
| -import static java.util.Arrays.asList; |
19 |
| -import static org.assertj.core.api.Assertions.assertThat; |
20 |
| -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
21 |
| -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
22 |
| -import static org.springframework.data.domain.Example.of; |
23 |
| -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatcher; |
24 |
| -import static org.springframework.data.domain.ExampleMatcher.StringMatcher; |
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; |
| 18 | +import static java.util.Arrays.*; |
| 19 | +import static org.assertj.core.api.Assertions.*; |
| 20 | +import static org.springframework.data.domain.Example.*; |
| 21 | +import static org.springframework.data.domain.ExampleMatcher.*; |
| 22 | +import static org.springframework.data.domain.Sort.Direction.*; |
| 23 | +import static org.springframework.data.jpa.domain.Specification.*; |
28 | 24 | import static org.springframework.data.jpa.domain.Specification.not;
|
29 |
| -import static org.springframework.data.jpa.domain.Specification.where; |
30 |
| -import static org.springframework.data.jpa.domain.sample.UserSpecifications.userHasAgeLess; |
31 |
| -import static org.springframework.data.jpa.domain.sample.UserSpecifications.userHasFirstname; |
32 |
| -import static org.springframework.data.jpa.domain.sample.UserSpecifications.userHasFirstnameLike; |
33 |
| -import static org.springframework.data.jpa.domain.sample.UserSpecifications.userHasLastname; |
34 |
| -import static org.springframework.data.jpa.domain.sample.UserSpecifications.userHasLastnameLikeWithSort; |
| 25 | +import static org.springframework.data.jpa.domain.sample.UserSpecifications.*; |
35 | 26 |
|
36 | 27 | import jakarta.persistence.EntityManager;
|
37 | 28 | import jakarta.persistence.PersistenceContext;
|
|
75 | 66 | import org.springframework.data.domain.Sort.Order;
|
76 | 67 | import org.springframework.data.jpa.domain.Specification;
|
77 | 68 | import org.springframework.data.jpa.domain.sample.Address;
|
| 69 | +import org.springframework.data.jpa.domain.sample.QUser; |
78 | 70 | import org.springframework.data.jpa.domain.sample.Role;
|
79 | 71 | import org.springframework.data.jpa.domain.sample.SpecialUser;
|
80 | 72 | import org.springframework.data.jpa.domain.sample.User;
|
@@ -2444,6 +2436,47 @@ void findByFluentSpecificationWithSimplePropertyPathsDoesntLoadUnrequestedPaths(
|
2444 | 2436 | );
|
2445 | 2437 | }
|
2446 | 2438 |
|
| 2439 | + @Test // GH-2820 |
| 2440 | + void findByFluentPredicateWithProjectionAndPageRequest() { |
| 2441 | + |
| 2442 | + flushTestUsers(); |
| 2443 | + em.clear(); |
| 2444 | + |
| 2445 | + Page<User> users = repository.findBy(QUser.user.firstname.contains("v"), q -> q // |
| 2446 | + .project("firstname") // |
| 2447 | + .page(PageRequest.of(0, 10))); |
| 2448 | + |
| 2449 | + assertThat(users).extracting(User::getFirstname).containsExactlyInAnyOrder(firstUser.getFirstname(), |
| 2450 | + thirdUser.getFirstname(), fourthUser.getFirstname()); |
| 2451 | + } |
| 2452 | + |
| 2453 | + @Test // GH-2820 |
| 2454 | + void findByFluentPredicateWithProjectionAndAll() { |
| 2455 | + |
| 2456 | + flushTestUsers(); |
| 2457 | + em.clear(); |
| 2458 | + |
| 2459 | + List<User> users = repository.findBy(QUser.user.firstname.contains("v"), q -> q // |
| 2460 | + .project("firstname") // |
| 2461 | + .all()); |
| 2462 | + |
| 2463 | + assertThat(users).extracting(User::getFirstname).containsExactlyInAnyOrder(firstUser.getFirstname(), |
| 2464 | + thirdUser.getFirstname(), fourthUser.getFirstname()); |
| 2465 | + } |
| 2466 | + |
| 2467 | + @Test // GH-2820 |
| 2468 | + void findByFluentPredicateWithPageRequest() { |
| 2469 | + |
| 2470 | + flushTestUsers(); |
| 2471 | + em.clear(); |
| 2472 | + |
| 2473 | + Page<User> users = repository.findBy(QUser.user.firstname.contains("v"), q -> q // |
| 2474 | + .page(PageRequest.of(0, 10))); |
| 2475 | + |
| 2476 | + assertThat(users).extracting(User::getFirstname).containsExactlyInAnyOrder(firstUser.getFirstname(), |
| 2477 | + thirdUser.getFirstname(), fourthUser.getFirstname()); |
| 2478 | + } |
| 2479 | + |
2447 | 2480 | @Test // GH-2274
|
2448 | 2481 | void findByFluentSpecificationWithCollectionPropertyPathsDoesntLoadUnrequestedPaths() {
|
2449 | 2482 |
|
|
0 commit comments