Search in sources :

Example 21 with PageRequest

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);
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) ArrayList(java.util.ArrayList) List(java.util.List) Criteria(org.hibernate.Criteria) Test(org.junit.Test)

Example 22 with PageRequest

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);
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 23 with PageRequest

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());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Test(org.junit.Test)

Example 24 with PageRequest

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);
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 25 with PageRequest

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());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Test(org.junit.Test)

Aggregations

PageRequest (org.candlepin.common.paging.PageRequest)62 Test (org.junit.Test)54 List (java.util.List)35 ArrayList (java.util.ArrayList)32 LinkedList (java.util.LinkedList)26 Date (java.util.Date)14 Page (org.candlepin.common.paging.Page)13 Pool (org.candlepin.model.Pool)9 PoolFilterBuilder (org.candlepin.model.PoolFilterBuilder)7 Consumer (org.candlepin.model.Consumer)6 Owner (org.candlepin.model.Owner)5 EntitlementDTO (org.candlepin.dto.api.v1.EntitlementDTO)4 Entitlement (org.candlepin.model.Entitlement)4 Product (org.candlepin.model.Product)4 Transactional (com.google.inject.persist.Transactional)3 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)3 EntitlementFilterBuilder (org.candlepin.model.EntitlementFilterBuilder)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 BadRequestException (org.candlepin.common.exceptions.BadRequestException)2