Search in sources :

Example 11 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testListAllForActKeyExcludesErrors.

@Test
public void testListAllForActKeyExcludesErrors() {
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    ActivationKey ak = new ActivationKey();
    Pool akpool = new Pool();
    akpool.setAttribute(Pool.Attributes.PHYSICAL_ONLY, "true");
    ak.addPool(akpool, 1L);
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(null, ak, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(4, results.getPageData().size());
    // Creating a pool with no entitlements available, which does not trigger
    // a rules error:
    Pool pool = createPool(o, p, 0L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool);
    results = poolManager.listAvailableEntitlementPools(null, ak, parentSystem.getOwnerId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    // Pool in error should not be included. Should have the same number of
    // initial pools.
    assertEquals(5, results.getPageData().size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 12 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testListForConsumerExcludesWarnings.

@Test
public void testListForConsumerExcludesWarnings() {
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(parentSystem, null, parentSystem.getOwnerId(), (String) null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(4, results.getPageData().size());
    Pool pool = createPool(o, socketLimitedProduct, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool);
    parentSystem.setFact("cpu.cpu_socket(s)", "4");
    results = poolManager.listAvailableEntitlementPools(parentSystem, null, parentSystem.getOwnerId(), (String) null, null, null, false, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    // Pool in error should not be included. Should have the same number of
    // initial pools.
    assertEquals(4, results.getPageData().size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 13 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class PoolCuratorTest method testCorrectPagingWhenLastPage.

@Test
public void testCorrectPagingWhenLastPage() {
    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(3);
    req.setPerPage(2);
    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(1, 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 14 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class PoolCuratorTest method availablePoolsCanFilterByEmptyValueAttribute.

@Test
public void availablePoolsCanFilterByEmptyValueAttribute() 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("empty-attr", "");
    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("empty-attr", "");
    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 15 with PageRequest

use of org.candlepin.common.paging.PageRequest in project candlepin by candlepin.

the class PoolCuratorTest method testCorrectPagingWhenResultsLessThanPageSize.

@Test
public void testCorrectPagingWhenResultsLessThanPageSize() {
    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(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(5), page.getMaxRecords());
    assertEquals(5, 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)

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