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());
}
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());
}
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);
}
}
}
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());
}
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;
}
Aggregations