Search in sources :

Example 46 with PageRequest

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

the class PoolCuratorTest method testAttributeFilterLogic.

/**
 * When filtering pools by product/pool attributes, filters specified with
 * the same attribute name are ORed, and different attributes are ANDed.
 *
 * For example applying the following filters:
 *
 * A1:foo, A1:bar, A2:biz
 *
 * will result in matches on the values of:
 * (A1 == foo OR A1 == bar) AND A2 == biz
 *
 * Another important note is that product attributes are
 * ORed with Pool attributes for each attribute specified.
 */
@Test
public void testAttributeFilterLogic() {
    Product product1 = TestUtil.createProduct();
    product1.setAttribute("A", "foo");
    product1.setAttribute("B", "bar");
    product1 = this.createProduct(product1, owner);
    Product product2 = TestUtil.createProduct();
    product2.setAttribute("A", "foo");
    product2.setAttribute("B", "zoo");
    product2 = this.createProduct(product2, owner);
    Product product3 = TestUtil.createProduct();
    product3.setAttribute("A", "biz");
    product3.setAttribute("B", "zoo");
    product3 = this.createProduct(product3, owner);
    Date activeDate = TestUtil.createDate(2000, 3, 2);
    Pool pool1 = createPool(owner, product1, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
    poolCurator.create(pool1);
    Pool pool2 = createPool(owner, product2, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
    poolCurator.create(pool2);
    Pool pool3 = createPool(owner, product3, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
    poolCurator.create(pool3);
    PageRequest req = new PageRequest();
    req.setPage(1);
    req.setPerPage(10);
    req.setOrder(PageRequest.Order.ASCENDING);
    req.setSortBy("id");
    PoolFilterBuilder filters = new PoolFilterBuilder();
    filters.addAttributeFilter("A", "foo");
    filters.addAttributeFilter("A", "biz");
    filters.addAttributeFilter("B", "zoo");
    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(2, results.size());
    Pool[] expected = new Pool[] { pool2, pool3 };
    assertTrue(results.containsAll(Arrays.asList(expected)));
}
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 47 with PageRequest

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

the class PoolCuratorTest method availablePoolsCanBeFilteredByPoolId.

@Test
public void availablePoolsCanBeFilteredByPoolId() 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));
    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.addIdFilter(pool2.getId());
    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());
    filters = new PoolFilterBuilder();
    filters.addIdFilter(pool1.getId());
    filters.addIdFilter(pool2.getId());
    page = poolCurator.listAvailableEntitlementPools(null, owner.getId(), (Collection<String>) null, null, activeDate, filters, req, false, false, false, null);
    results = page.getPageData();
    assertEquals(2, results.size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Collection(java.util.Collection) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Example 48 with PageRequest

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

the class PoolCuratorTest method requiresHostIsCaseInsensitive.

@Test
public void requiresHostIsCaseInsensitive() {
    Product product1 = TestUtil.createProduct();
    String gid = "AAABBB";
    Consumer hostConsumer = createConsumer(owner);
    Consumer guestConsumer = createConsumer(owner);
    guestConsumer.setFact("virt.is_guest", "true");
    guestConsumer.setFact("virt.uuid", gid);
    hostConsumer.addGuestId(new GuestId(gid, guestConsumer));
    guestConsumer = consumerCurator.merge(guestConsumer);
    hostConsumer = consumerCurator.merge(hostConsumer);
    product1 = this.createProduct(product1, owner);
    Date activeDate = TestUtil.createDate(2000, 3, 2);
    Pool pool = createPool(owner, product1, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
    pool.setAttribute(Pool.Attributes.REQUIRES_HOST, hostConsumer.getUuid().toUpperCase());
    poolCurator.create(pool);
    /**
     * This pool should not be found!
     */
    Pool pool2 = createPool(owner, product1, 50L, activeDate, TestUtil.createDate(2005, 3, 2));
    pool2.setAttribute(Pool.Attributes.REQUIRES_HOST, "poolForSomeOtherHost");
    poolCurator.create(pool2);
    PageRequest req = new PageRequest();
    req.setPage(1);
    req.setPerPage(10);
    req.setOrder(PageRequest.Order.ASCENDING);
    req.setSortBy("id");
    Page<List<Pool>> page = poolCurator.listAvailableEntitlementPools(guestConsumer, owner.getId(), (Collection<String>) null, null, activeDate, null, req, false, false, false, null);
    List<Pool> results = page.getPageData();
    assertEquals(1, results.size());
    assertEquals(pool, results.get(0));
}
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 49 with PageRequest

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

the class PoolCuratorTest method attributeFilterValuesAreNotCaseSensitive.

@Test
public void attributeFilterValuesAreNotCaseSensitive() {
    Product product1 = TestUtil.createProduct();
    product1.setAttribute("A", "foo");
    product1.setAttribute("B", "bar");
    product1 = this.createProduct(product1, owner);
    Date activeDate = TestUtil.createDate(2000, 3, 2);
    Pool pool = createPool(owner, product1, 100L, activeDate, TestUtil.createDate(2005, 3, 2));
    poolCurator.create(pool);
    PageRequest req = new PageRequest();
    req.setPage(1);
    req.setPerPage(10);
    req.setOrder(PageRequest.Order.ASCENDING);
    req.setSortBy("id");
    PoolFilterBuilder filters = new PoolFilterBuilder();
    filters.addAttributeFilter("A", "FOO");
    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(pool, results.get(0));
}
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 50 with PageRequest

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

the class PoolCuratorFilterTest method setUp.

@Before
public void setUp() {
    owner = createOwner();
    ownerCurator.create(owner);
    req = new PageRequest();
    req.setPage(1);
    req.setPerPage(10);
    req.setOrder(PageRequest.Order.ASCENDING);
    req.setSortBy("id");
    searchPool = createSearchPools();
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) Before(org.junit.Before)

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