Search in sources :

Example 51 with PageRequest

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());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 52 with PageRequest

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");
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 53 with PageRequest

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;
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest)

Example 54 with PageRequest

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);
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) ArrayList(java.util.ArrayList) List(java.util.List) Criteria(org.hibernate.Criteria) Test(org.junit.Test)

Example 55 with PageRequest

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());
}
Also used : Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) Page(org.candlepin.common.paging.Page) PageRequest(org.candlepin.common.paging.PageRequest) EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

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