use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class CuratorPaginationTest method testPagingWithCriteria.
@Test
public void testPagingWithCriteria() {
PageRequest pageRequest = new PageRequest();
pageRequest.setSortBy("key");
pageRequest.setOrder(PageRequest.Order.ASCENDING);
pageRequest.setPage(1);
pageRequest.setPerPage(2);
Criteria criteria = session.createCriteria(Owner.class).add(Restrictions.gt("key", "5"));
Page<List<Owner>> p = ownerCurator.listByCriteria(criteria, pageRequest);
assertEquals(Integer.valueOf(4), p.getMaxRecords());
List<Owner> ownerList = p.getPageData();
assertEquals(2, ownerList.size());
assertEquals("6", ownerList.get(0).getKey());
PageRequest pageRequest2 = p.getPageRequest();
assertEquals(pageRequest, pageRequest2);
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class CuratorPaginationTest method testReturnsAllResultsWhenPostFiltering.
@Test
public void testReturnsAllResultsWhenPostFiltering() {
PageRequest pageRequest = new PageRequest();
pageRequest.setSortBy("key");
pageRequest.setOrder(PageRequest.Order.ASCENDING);
pageRequest.setPage(1);
pageRequest.setPerPage(2);
/* Since we are telling listByCriteria that we are doing post-filtering
* it should return us all results, but ordered and sorted by what we
* provide
*/
Page<List<Owner>> p = ownerCurator.listAll(pageRequest, true);
assertEquals(Integer.valueOf(10), p.getMaxRecords());
List<Owner> ownerList = p.getPageData();
assertEquals(10, ownerList.size());
assertEquals("0", ownerList.get(0).getKey());
PageRequest pageRequest2 = p.getPageRequest();
assertEquals(pageRequest, pageRequest2);
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class CuratorPaginationTest method testTakeSubListWhenRequestOutOfBounds.
@Test
public void testTakeSubListWhenRequestOutOfBounds() {
PageRequest req = new PageRequest();
req.setPage(5);
req.setPerPage(10);
List<Owner> ownerList = createOwners(10);
List<Owner> results = ownerCurator.takeSubList(req, ownerList);
assertEquals(0, results.size());
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class CuratorPaginationTest method testPaging.
@Test
public void testPaging() {
PageRequest pageRequest = new PageRequest();
pageRequest.setSortBy("key");
pageRequest.setOrder(PageRequest.Order.ASCENDING);
pageRequest.setPage(3);
pageRequest.setPerPage(2);
Page<List<Owner>> p = ownerCurator.listAll(pageRequest);
assertEquals(Integer.valueOf(10), p.getMaxRecords());
List<Owner> ownerList = p.getPageData();
assertEquals(2, ownerList.size());
// Page 1 is (0, 1); page 2 is (2, 3); page 3 is (4, 5)
assertEquals("4", ownerList.get(0).getKey());
assertEquals("5", ownerList.get(1).getKey());
PageRequest pageRequest2 = p.getPageRequest();
assertEquals(pageRequest, pageRequest2);
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class CuratorPaginationTest method testTakeSubListWhenResultsTooSmall.
@Test
public void testTakeSubListWhenResultsTooSmall() {
PageRequest req = new PageRequest();
req.setPage(1);
req.setPerPage(10);
List<Owner> ownerList = createOwners(2);
List<Owner> results = ownerCurator.takeSubList(req, ownerList);
assertEquals(2, results.size());
}
Aggregations