Search in sources :

Example 16 with PageRequest

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());
}
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 17 with PageRequest

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());
}
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 18 with PageRequest

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());
}
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 19 with PageRequest

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());
}
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 20 with PageRequest

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