use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PoolCuratorTest method testCorrectPagingWhenPageRequestOutOfBounds.
@Test
public void testCorrectPagingWhenPageRequestOutOfBounds() {
for (int i = 0; i < 5; i++) {
Pool pool = TestUtil.createPool(owner, product);
pool.setStartDate(TestUtil.createDate(2011, 1, 2));
pool.setEndDate(TestUtil.createDate(2011, 3, 2));
poolCurator.create(pool);
}
PageRequest req = new PageRequest();
req.setPage(5);
req.setPerPage(10);
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(5), page.getMaxRecords());
assertEquals(0, page.getPageData().size());
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PoolCuratorTest method availablePoolsCanBeFilteredByProductPoolAttribute.
@Test
public void availablePoolsCanBeFilteredByProductPoolAttribute() throws Exception {
Date activeDate = TestUtil.createDate(2000, 3, 2);
Pool pool1 = createPool(owner, product, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
poolCurator.create(pool1);
Product product2 = TestUtil.createProduct();
product2.setAttribute(Product.Attributes.CORES, "8");
product2 = this.createProduct(product2, owner);
Pool pool2 = createPool(owner, product2, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
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("cores", "8");
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 testCorrectPagingWhenResultsEmpty.
@Test
public void testCorrectPagingWhenResultsEmpty() {
for (int i = 0; i < 5; 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);
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(0), page.getMaxRecords());
assertEquals(0, page.getPageData().size());
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class PoolCuratorTest method availablePoolsCanBeFilteredByBothPoolAndProductPoolAttribute.
@Test
public void availablePoolsCanBeFilteredByBothPoolAndProductPoolAttribute() throws Exception {
Date activeDate = TestUtil.createDate(2000, 3, 2);
Pool pool1 = createPool(owner, product, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
poolCurator.create(pool1);
Product product2 = TestUtil.createProduct();
product2.setAttribute(Product.Attributes.CORES, "4");
product2 = this.createProduct(product2, owner);
Pool pool2 = createPool(owner, product2, 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");
filters.addAttributeFilter("cores", "4");
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 CuratorPaginationTest method testTakeSubList.
@Test
public void testTakeSubList() {
PageRequest req = new PageRequest();
req.setPage(1);
req.setPerPage(10);
List<Owner> ownerList = createOwners(20);
List<Owner> results = ownerCurator.takeSubList(req, ownerList);
assertEquals(10, results.size());
}
Aggregations