Search in sources :

Example 41 with PageRequest

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

Example 42 with PageRequest

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

Example 43 with PageRequest

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

Example 44 with PageRequest

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

Example 45 with PageRequest

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