Search in sources :

Example 6 with PageRequest

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

the class LinkHeaderResponseFilterTest method testGetPrevPage.

@Test
public void testGetPrevPage() {
    Page<Object> p = new Page<>();
    p.setMaxRecords(55);
    PageRequest pr = new PageRequest();
    p.setPageRequest(pr);
    pr.setPerPage(10);
    pr.setPage(3);
    assertEquals(Integer.valueOf(2), interceptor.getPrevPage(p));
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Page(org.candlepin.common.paging.Page) Test(org.junit.Test)

Example 7 with PageRequest

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

the class LinkHeaderResponseFilterTest method testGetPrevPageWhenOnFirstPage.

@Test
public void testGetPrevPageWhenOnFirstPage() {
    Page<Object> p = new Page<>();
    p.setMaxRecords(55);
    PageRequest pr = new PageRequest();
    p.setPageRequest(pr);
    pr.setPerPage(10);
    pr.setPage(1);
    assertNull(interceptor.getPrevPage(p));
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Page(org.candlepin.common.paging.Page) Test(org.junit.Test)

Example 8 with PageRequest

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

the class OwnerResourceTest method getEntitlementsForNonExistantOwner.

@Test(expected = NotFoundException.class)
public void getEntitlementsForNonExistantOwner() {
    PageRequest req = new PageRequest();
    req.setPage(1);
    req.setPerPage(10);
    OwnerCurator oc = mock(OwnerCurator.class);
    ProductCurator pc = mock(ProductCurator.class);
    OwnerResource ownerres = new OwnerResource(oc, pc, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.modelTranslator);
    ownerres.ownerEntitlements("Taylor Swift", null, null, null, req);
}
Also used : OwnerCurator(org.candlepin.model.OwnerCurator) PageRequest(org.candlepin.common.paging.PageRequest) ProductCurator(org.candlepin.model.ProductCurator) Test(org.junit.Test)

Example 9 with PageRequest

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

the class PoolManagerFunctionalTest method testListConditionDevPools.

@Test
public void testListConditionDevPools() {
    Owner owner = createOwner();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Pool pool1 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    poolCurator.create(pool1);
    Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool2);
    Consumer devSystem = new Consumer("dev", "user", owner, systemType);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    Consumer nonDevSystem = new Consumer("system", "user", owner, systemType);
    nonDevSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(devSystem, null, owner.getId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(2, results.getPageData().size());
    results = poolManager.listAvailableEntitlementPools(nonDevSystem, null, owner.getId(), null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(1, results.getPageData().size());
    Pool found2 = results.getPageData().get(0);
    assertEquals(pool2, found2);
}
Also used : Owner(org.candlepin.model.Owner) PageRequest(org.candlepin.common.paging.PageRequest) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) 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) Test(org.junit.Test)

Example 10 with PageRequest

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

the class PoolManagerFunctionalTest method testListAllForConsumerExcludesErrors.

@Test
public void testListAllForConsumerExcludesErrors() {
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(parentSystem, null, 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 will 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(parentSystem, null, 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(4, 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) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pool(org.candlepin.model.Pool) 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