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)));
}
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());
}
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));
}
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));
}
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();
}
Aggregations