use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PageRequestFilterTest method testUsesDefaultOrderIfNoOrderProvided.
@Test
public void testUsesDefaultOrderIfNoOrderProvided() throws Exception {
mockReq = MockHttpRequest.create("GET", "http://localhost/candlepin/status?sort_by=id");
when(mockRequestContext.getUriInfo()).thenReturn(mockReq.getUri());
interceptor.filter(mockRequestContext);
PageRequest p = ResteasyProviderFactory.getContextData(PageRequest.class);
assertFalse(p.isPaging());
assertEquals(PageRequest.DEFAULT_ORDER, p.getOrder());
assertEquals("id", p.getSortBy());
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class LinkHeaderResponseFilterTest method testGetNextPage.
@Test
public void testGetNextPage() {
Page<Object> p = new Page<>();
p.setMaxRecords(55);
PageRequest pr = new PageRequest();
p.setPageRequest(pr);
pr.setPerPage(10);
pr.setPage(3);
assertEquals(Integer.valueOf(4), interceptor.getNextPage(p));
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class LinkHeaderResponseFilterTest method testGetLastPageWhenEvenlyDivisible.
@Test
public void testGetLastPageWhenEvenlyDivisible() {
Page<Object> p = new Page<>();
p.setMaxRecords(10);
PageRequest pr = new PageRequest();
p.setPageRequest(pr);
pr.setPerPage(10);
pr.setPage(1);
assertEquals(Integer.valueOf(1), interceptor.getLastPage(p));
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PoolCuratorTest method availablePoolsCanBeFilteredByPoolAttribute.
@Test
public void availablePoolsCanBeFilteredByPoolAttribute() throws Exception {
Date activeDate = TestUtil.createDate(2000, 3, 2);
Pool pool1 = createPool(owner, product, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
poolCurator.create(pool1);
Pool pool2 = createPool(owner, product, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
pool2.setAttribute(Product.Attributes.VIRT_ONLY, "true");
poolCurator.create(pool2);
PageRequest req = new PageRequest();
req.setPage(1);
req.setPerPage(10);
req.setOrder(PageRequest.Order.ASCENDING);
req.setSortBy("id");
PoolFilterBuilder filters = new PoolFilterBuilder();
filters.addAttributeFilter("virt_only", "true");
Page<List<Pool>> page = poolCurator.listAvailableEntitlementPools(null, owner.getId(), (Collection<String>) null, null, activeDate, filters, req, false, false, false, null);
List<Pool> results = page.getPageData();
assertEquals(1, results.size());
assertEquals(pool2.getId(), results.get(0).getId());
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PoolCuratorTest method testCorrectPagingWhenItemsAreFilteredByProductId.
@Test
public void testCorrectPagingWhenItemsAreFilteredByProductId() {
for (int i = 0; i < 50; i++) {
Pool pool = TestUtil.createPool(owner, product);
pool.setStartDate(TestUtil.createDate(2011, 1, 2));
pool.setEndDate(TestUtil.createDate(2011, 3, 2));
poolCurator.create(pool);
}
for (int i = 0; i < 50; i++) {
Product p = this.createProduct(owner);
Pool pool = TestUtil.createPool(owner, p);
pool.setStartDate(TestUtil.createDate(2011, 1, 2));
pool.setEndDate(TestUtil.createDate(2011, 3, 2));
poolCurator.create(pool);
}
PageRequest req = new PageRequest();
req.setPage(1);
req.setPerPage(10);
req.setOrder(PageRequest.Order.ASCENDING);
req.setSortBy("id");
Date activeOn = TestUtil.createDate(2011, 2, 2);
Page<List<Pool>> page = poolCurator.listAvailableEntitlementPools(null, owner, product.getId(), null, activeOn, new PoolFilterBuilder(), req, false, false, false, null);
assertEquals(Integer.valueOf(50), page.getMaxRecords());
List<Pool> pools = page.getPageData();
assertEquals(10, pools.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 < pools.size(); i++) {
if (i < pools.size() - 1) {
assertTrue(pools.get(i).getId().compareTo(pools.get(i + 1).getId()) < 1);
}
}
}
Aggregations