Search in sources :

Example 26 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class CuratorPaginationTest method testReturnsAllResultsWhenNotPaging.

@Test
public void testReturnsAllResultsWhenNotPaging() {
    PageRequest pageRequest = new PageRequest();
    pageRequest.setSortBy("key");
    pageRequest.setOrder(PageRequest.Order.ASCENDING);
    assertFalse(pageRequest.isPaging());
    Page<List<Owner>> p = ownerCurator.listAll(pageRequest);
    assertEquals(Integer.valueOf(10), p.getMaxRecords());
    List<Owner> ownerList = p.getPageData();
    assertEquals(10, ownerList.size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 27 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class EntitlementCuratorTest method testListByConsumerAndProductFiltered.

@Test
public void testListByConsumerAndProductFiltered() {
    PageRequest req = createPageRequest();
    Product product = TestUtil.createProduct();
    productCurator.create(product);
    Pool pool = createPool(owner, product, 1L, dateSource.currentDate(), createDate(2020, 1, 1));
    poolCurator.create(pool);
    for (int i = 0; i < 5; i++) {
        EntitlementCertificate cert = createEntitlementCertificate("key", "certificate");
        Entitlement ent = createEntitlement(owner, consumer, pool, cert);
        entitlementCurator.create(ent);
    }
    Product product2 = TestUtil.createProduct();
    productCurator.create(product2);
    Pool pool2 = createPool(owner, product2, 1L, dateSource.currentDate(), createDate(2020, 1, 1));
    poolCurator.create(pool2);
    for (int i = 0; i < 5; i++) {
        EntitlementCertificate cert = createEntitlementCertificate("key", "certificate");
        Entitlement ent = createEntitlement(owner, consumer, pool2, cert);
        entitlementCurator.create(ent);
    }
    Page<List<Entitlement>> page = entitlementCurator.listByConsumerAndProduct(consumer, product.getId(), req);
    assertEquals(Integer.valueOf(5), page.getMaxRecords());
    assertEquals(5, page.getPageData().size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 28 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class EntitlementCuratorTest method testListByConsumerAndProduct.

@Test
public void testListByConsumerAndProduct() {
    PageRequest req = createPageRequest();
    Product product = TestUtil.createProduct();
    productCurator.create(product);
    Pool pool = createPool(owner, product, 1L, dateSource.currentDate(), createDate(2020, 1, 1));
    poolCurator.create(pool);
    for (int i = 0; i < 10; i++) {
        EntitlementCertificate cert = createEntitlementCertificate("key", "certificate");
        Entitlement ent = createEntitlement(owner, consumer, pool, cert);
        entitlementCurator.create(ent);
    }
    Page<List<Entitlement>> page = entitlementCurator.listByConsumerAndProduct(consumer, product.getId(), req);
    assertEquals(Integer.valueOf(10), page.getMaxRecords());
    List<Entitlement> ents = page.getPageData();
    assertEquals(10, ents.size());
    // Make sure we have the real PageRequest, not the dummy one we send in
    // with the order and sortBy fields.
    assertEquals(req, page.getPageRequest());
    // Check that we've sorted ascending on the id
    for (int i = 0; i < ents.size(); i++) {
        if (i < ents.size() - 1) {
            assertTrue(ents.get(i).getId().compareTo(ents.get(i + 1).getId()) < 1);
        }
    }
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 29 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class EntitlementCuratorTest method listByOwnerWithPagingNoFiltering.

@Test
public void listByOwnerWithPagingNoFiltering() {
    PageRequest req = createPageRequest();
    req.setPerPage(1);
    EntitlementFilterBuilder filters = new EntitlementFilterBuilder();
    Page<List<Entitlement>> entitlementPages = entitlementCurator.listByOwner(owner, null, filters, req);
    List<Entitlement> entitlements = entitlementPages.getPageData();
    assertEquals("should return only single entitlement per page:", 1, entitlements.size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 30 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class LinkHeaderResponseFilter method getLastPage.

protected Integer getLastPage(Page<?> page) {
    PageRequest pageRequest = page.getPageRequest();
    // The last page is ceiling(maxRecords/recordsPerPage)
    int lastPage = page.getMaxRecords() / pageRequest.getPerPage();
    if (page.getMaxRecords() % pageRequest.getPerPage() != 0) {
        lastPage++;
    }
    return lastPage;
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest)

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