use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class EntitlementCuratorTest method listAllByOwner.
@Test
public void listAllByOwner() {
PageRequest req = createPageRequest();
EntitlementFilterBuilder filters = new EntitlementFilterBuilder();
Page<List<Entitlement>> entitlementPages = entitlementCurator.listByOwner(owner, null, filters, req);
List<Entitlement> entitlements = entitlementPages.getPageData();
assertEquals("should return all the entitlements:", 2, entitlements.size());
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class EntitlementCuratorTest method listByOwnerWithPagingAndFiltering.
/*
* should be enough to test a single filtering criterion.
* other tests are covered in consumer tests
*/
@Test
public void listByOwnerWithPagingAndFiltering() {
PageRequest req = createPageRequest();
EntitlementFilterBuilder filters = new EntitlementFilterBuilder();
filters.addAttributeFilter("pool_attr_1", "attr1");
Page<List<Entitlement>> entitlementPages = entitlementCurator.listByOwner(owner, null, filters, req);
List<Entitlement> entitlements = entitlementPages.getPageData();
assertEquals("should match only one out of two entitlements:", 1, entitlements.size());
Pool p = entitlements.get(0).getPool();
assertTrue("Did not find ent by pool attribute 'pool_attr_1'", p.hasAttribute("pool_attr_1"));
assertEquals(p.getAttributeValue("pool_attr_1"), "attr1");
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class EntitlementCuratorTest method createPageRequest.
private PageRequest createPageRequest() {
PageRequest req = new PageRequest();
req.setPage(1);
req.setPerPage(10);
req.setOrder(PageRequest.Order.ASCENDING);
req.setSortBy("id");
return req;
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class CuratorPaginationTest method testReturnsAllResultsWhenPostFilteringByCriteria.
@Test
public void testReturnsAllResultsWhenPostFilteringByCriteria() {
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"));
/* 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.listByCriteria(criteria, pageRequest, true);
assertEquals(Integer.valueOf(4), p.getMaxRecords());
List<Owner> ownerList = p.getPageData();
assertEquals(4, ownerList.size());
assertEquals("6", ownerList.get(0).getKey());
PageRequest pageRequest2 = p.getPageRequest();
assertEquals(pageRequest, pageRequest2);
}
use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.
the class OwnerResourceTest method getAllEntitlementsForOwner.
@Test
public void getAllEntitlementsForOwner() {
PageRequest req = new PageRequest();
req.setPage(1);
req.setPerPage(10);
Owner owner = this.createOwner();
Consumer consumer = this.createConsumer(owner);
Pool pool = this.createPool(owner, this.createProduct());
Entitlement e = this.createEntitlement(owner, consumer, pool, null);
List<Entitlement> entitlements = new ArrayList<>();
entitlements.add(e);
Page<List<Entitlement>> page = new Page<>();
page.setPageData(entitlements);
OwnerResource ownerres = new OwnerResource(this.ownerCurator, this.productCurator, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, this.entitlementCurator, null, null, null, null, null, null, null, null, null, null, null, this.modelTranslator);
List<EntitlementDTO> result = ownerres.ownerEntitlements(owner.getKey(), null, null, null, req);
assertEquals(1, result.size());
assertEquals(e.getId(), result.get(0).getId());
}
Aggregations