Verify custom finders can handle PageRequest as method parameter.
Spring Data Commons patched handling subclasses of special parameter types through spring-projects/spring-data-commons#2626. This commit adds test cases ensuring things work properly with Spring Data JPA. See #2013.
This commit is contained in:
@@ -1709,6 +1709,32 @@ public class UserRepositoryTests {
|
||||
assertThat(users).hasSize(0);
|
||||
}
|
||||
|
||||
@Test // GH-2013
|
||||
void findByCollectionWithPageable() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
Page<User> userPage = repository.findByAgeIn(List.of(28, 35), (Pageable) PageRequest.of(0, 2));
|
||||
|
||||
assertThat(userPage).hasSize(2);
|
||||
assertThat(userPage.getTotalElements()).isEqualTo(2);
|
||||
assertThat(userPage.getTotalPages()).isEqualTo(1);
|
||||
assertThat(userPage.getContent()).containsExactlyInAnyOrder(firstUser, secondUser);
|
||||
}
|
||||
|
||||
@Test // GH-2013
|
||||
void findByCollectionWithPageRequest() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
Page<User> userPage = repository.findByAgeIn(List.of(28, 35), (PageRequest) PageRequest.of(0, 2));
|
||||
|
||||
assertThat(userPage).hasSize(2);
|
||||
assertThat(userPage.getTotalElements()).isEqualTo(2);
|
||||
assertThat(userPage.getTotalPages()).isEqualTo(1);
|
||||
assertThat(userPage.getContent()).containsExactlyInAnyOrder(firstUser, secondUser);
|
||||
}
|
||||
|
||||
@Test // DATAJPA-606
|
||||
void findByEmptyArrayOfIntegers() {
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.sample;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.QueryHint;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -23,10 +26,8 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.QueryHint;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -52,6 +53,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Jeff Sheets
|
||||
* @author Andrey Kovalev
|
||||
* @author JyotirmoyVS
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public interface UserRepository
|
||||
extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User>, UserRepositoryCustom {
|
||||
@@ -504,6 +506,12 @@ public interface UserRepository
|
||||
// DATAJPA-606
|
||||
List<User> findByAgeIn(Collection<Integer> ages);
|
||||
|
||||
// GH-2013
|
||||
Page<User> findByAgeIn(Collection<Integer> ages, Pageable pageable);
|
||||
|
||||
// GH-2013
|
||||
Page<User> findByAgeIn(Collection<Integer> ages, PageRequest pageable);
|
||||
|
||||
// DATAJPA-606
|
||||
List<User> queryByAgeIn(Integer[] ages);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user