PoolCurator extends AbstractHibernateCurator<Pool> { @SuppressWarnings("unchecked") @Transactional public List<Pool> listAvailableEntitlementPools(Consumer c, Owner o, String productId, Date activeOn) { String ownerId = (o == null) ? null : o.getId(); return listAvailableEntitlementPools(c, ownerId, (productId != null ? Arrays.asList(productId) : (Collection<String>) null), null, activeOn, new PoolFilterBuilder(), null, false, false, false, null).getPageData(); } @Inject  PoolCurator(ConsumerCurator consumerCurator, ConsumerTypeCurator consumerTypeCurator); @Transactional CandlepinQuery<Pool> listByOwner(Owner owner); @Transactional CandlepinQuery<Pool> listByOwner(Owner owner, Date activeOn); @Transactional CandlepinQuery<Pool> listByOwnerAndType(Owner owner, PoolType type); CandlepinQuery<Pool> listBySourceEntitlement(Entitlement e); Set<Pool> listBySourceEntitlements(Iterable<Entitlement> ents); @Transactional List<Pool> listByConsumer(Consumer c); @Transactional List<Pool> listByOwnerAndProduct(Owner owner, String productId); List<Pool> listExpiredPools(); @Transactional @SuppressWarnings("checkstyle:indentation") List<Pool> listExpiredPools(int blockSize); @SuppressWarnings("unchecked") @Transactional List<Pool> listAvailableEntitlementPools(Consumer c, Owner o, String productId, Date activeOn); @SuppressWarnings("unchecked") @Transactional List<Pool> listAvailableEntitlementPools(Consumer c, Owner o, Collection<String> productIds,
        Date activeOn); @SuppressWarnings("unchecked") @Transactional List<Pool> listAvailableEntitlementPools(Consumer c, String ownerId, Collection<String> productIds,
        Date activeOn); @Transactional List<Pool> listByFilter(PoolFilterBuilder filters); @Transactional Page<List<Pool>> listAvailableEntitlementPools(Consumer c, String ownerId, String productId,
        String subscriptionId, Date activeOn, PoolFilterBuilder filters,
        PageRequest pageRequest, boolean postFilter, boolean addFuture, boolean onlyFuture, Date after); @Transactional Page<List<Pool>> listAvailableEntitlementPools(Consumer c, Owner o, String productId,
        String subscriptionId, Date activeOn, PoolFilterBuilder filters,
        PageRequest pageRequest, boolean postFilter, boolean addFuture, boolean onlyFuture, Date after); @Transactional List<String> listEntitledConsumerUuids(String poolId); @Transactional @SuppressWarnings({"unchecked", "checkstyle:indentation", "checkstyle:methodlength"}) // TODO: Remove the methodlength suppression once this method is cleaned up Page<List<Pool>> listAvailableEntitlementPools(Consumer consumer, String ownerId,
        Collection<String> productIds, String subscriptionId, Date activeOn, PoolFilterBuilder filters,
        PageRequest pageRequest, boolean postFilter, boolean addFuture, boolean onlyFuture, Date after); @SuppressWarnings("unchecked") @Transactional boolean hasActiveEntitlementPools(String ownerId, Date date); @Transactional List<Pool> listPoolsRestrictedToUser(String username); @SuppressWarnings("unchecked") List<Entitlement> retrieveOrderedEntitlementsOf(Collection<Pool> existingPools); @SuppressWarnings("unchecked") List<String> retrieveOrderedEntitlementIdsOf(Collection<Pool> pools); void deactivatePool(Pool pool); @Transactional @SuppressWarnings("unchecked") List<Entitlement> entitlementsIn(Pool entitlementPool); @SuppressWarnings("unchecked") List<Pool> getBySubscriptionId(Owner owner, String subId); @SuppressWarnings("unchecked") List<Pool> getBySubscriptionIds(Owner owner, Collection<String> subIds); @SuppressWarnings("unchecked") List<Pool> getBySubscriptionIds(String ownerId, Collection<String> subIds); @SuppressWarnings("unchecked") List<Pool> getOversubscribedBySubscriptionIds(String ownerId, Map<String, Entitlement> subIdMap); @Transactional Pool replicate(Pool pool); @SuppressWarnings("checkstyle:indentation") int getNoOfDependentEntitlements(String entitlementId); @SuppressWarnings("unchecked") List<EntitlementCertificate> retrieveEntCertsOfPoolsWithSourceEntitlement(String entId); Filter disableConsumerFilter(); List<ActivationKey> getActivationKeysForPool(Pool p); Set<String> retrieveServiceLevelsForOwner(Owner owner, boolean exempt); Set<String> retrieveServiceLevelsForOwner(String ownerId, boolean exempt); @Transactional void delete(Pool entity); void batchDelete(Collection<Pool> pools, Collection<String> alreadyDeletedPools); @SuppressWarnings("checkstyle:indentation") List<Pool> getSubPoolForStackIds(Consumer consumer, Collection stackIds); @SuppressWarnings("unchecked") List<Pool> getOwnerSubPoolsForStackId(Owner owner, String stackId); @SuppressWarnings("unchecked") List<Pool> getPoolsFromBadSubs(Owner owner, Collection<String> expectedSubIds); @SuppressWarnings("unchecked") Set<String> getDerivedPoolIdsForPools(Iterable<String> poolIds); @SuppressWarnings("unchecked") Collection<String> getEntitlementIdsForPools(Collection<String> poolIds); @SuppressWarnings("unchecked") Collection<String> getPoolIdsForSourceEntitlements(Collection<String> entIds); @SuppressWarnings("unchecked") Collection<String> getPoolIdsForEntitlements(Collection<String> entIds); @SuppressWarnings("unchecked") CandlepinQuery<Pool> getPoolsBySubscriptionId(String subId); @SuppressWarnings("unchecked") CandlepinQuery<Pool> getPoolsBySubscriptionIds(Collection<String> subIds); @SuppressWarnings("unchecked") List<Pool> getOwnersFloatingPools(Owner owner); CandlepinQuery<Pool> getMasterPools(); CandlepinQuery<Pool> getMasterPoolsForOwner(Owner owner); CandlepinQuery<Pool> getMasterPoolsForOwnerExcludingSubs(Owner owner,
        Collection<String> excludedSubIds); @SuppressWarnings("unchecked") Set<String> getAllKnownProductIds(); @SuppressWarnings("unchecked") Set<String> getAllKnownProductIdsForOwner(Owner owner); @SuppressWarnings("checkstyle:indentation") Pool findDevPool(Consumer consumer); boolean exists(Pool pool); void calculateConsumedForOwnersPools(Owner owner); void calculateExportedForOwnersPools(Owner owner); void markCertificatesDirtyForPoolsWithProducts(Owner owner, Collection<String> productIds); Boolean provides(Pool pool, String providedProductId); Boolean providesDerived(Pool pool, String derivedProvidedProductId); Map<String, Set<String>> getProvidedProductIds(Collection<Pool> pools); Map<String, Set<String>> getProvidedProductIdsByPoolIds(Collection<String> poolIds); Map<String, Set<String>> getDerivedProvidedProductIds(Collection<Pool> pools); Map<String, Set<String>> getDerivedProvidedProductIdsByPoolIds(Collection<String> poolIds); @Transactional void removeCdn(Cdn cdn); void clearPoolSourceEntitlementRefs(Iterable<String> poolIds); Set<String> getExistingPoolIdsByIds(Iterable<String> poolIds); Map<String, Set<String>> getConsumerStackDerivedPoolIdMap(Iterable<String> stackIds); Set<String> getUnentitledStackDerivedPoolIds(Iterable<String> entitlementIds); static final int EXPIRED_POOL_BLOCK_SIZE; }
@Test public void testPoolNotYetActive() { Pool pool = createPool(owner, product, 100L, TestUtil.createDate(2050, 3, 2), TestUtil.createDate(2055, 3, 2)); poolCurator.create(pool); List<Pool> results = poolCurator.listAvailableEntitlementPools( consumer, consumer.getOwnerId(), null, TestUtil.createDate(2450, 3, 2)); assertEquals(0, results.size()); }
@Test public void testPoolExpired() { Owner owner = this.createOwner(); Product product = this.createProduct(owner); Consumer consumer = this.createMockConsumer(owner, false); consumer.setFact("cpu_cores", "4"); consumer = consumerCurator.merge(consumer); Pool pool = createPool(owner, product, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2005, 3, 2)); poolCurator.create(pool); List<Pool> results = poolCurator.listAvailableEntitlementPools( consumer, consumer.getOwnerId(), null, TestUtil.createDate(2005, 3, 3)); assertEquals(0, results.size()); results = poolCurator.listAvailableEntitlementPools( consumer, consumer.getOwnerId(), null, null); assertEquals(1, results.size()); }
@Test public void testAvailablePoolsDoesNotIncludeUeberPool() throws Exception { Owner owner = this.createOwner(); Product product = this.createProduct(owner); Consumer consumer = this.createMockConsumer(owner, false); consumer.setFact("cpu_cores", "4"); consumer = consumerCurator.merge(consumer); Pool pool = createPool(owner, product, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2005, 3, 2)); poolCurator.create(pool); ueberCertGenerator.generate(owner.getKey(), new NoAuthPrincipal()); List<Pool> results = poolCurator.listAvailableEntitlementPools( consumer, consumer.getOwnerId(), null, null); assertEquals(1, results.size()); }
@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()); }
@Test public void availablePoolsCanBeFilteredByPoolAttribute() 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)); 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"); 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()); }
@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()); }
@Test public void availablePoolsCanNotBeFilteredByOverriddenAttribute() throws Exception { Date activeDate = TestUtil.createDate(2000, 3, 2); Product product = TestUtil.createProduct(); product.setAttribute(Pool.Attributes.VIRT_ONLY, "true"); createProduct(product, owner); 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)); pool2.setAttribute(Product.Attributes.VIRT_ONLY, "false"); poolCurator.create(pool2); PoolFilterBuilder filters = new PoolFilterBuilder(); filters.addAttributeFilter("virt_only", "true"); Page<List<Pool>> page = poolCurator.listAvailableEntitlementPools( null, owner.getId(), (Collection<String>) null, null, activeDate, filters, null, false, false, false, null); List<Pool> results = page.getPageData(); assertEquals(1, results.size()); assertEquals(pool1, results.get(0)); }
@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()); }
@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()); }
@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)); }
@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); 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)); }
@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))); }
@Test public void testListByActiveOnIncludesSameStartDay() { Date activeOn = TestUtil.createDate(2011, 2, 2); Pool pool = TestUtil.createPool(owner, product); pool.setStartDate(activeOn); poolCurator.create(pool); assertEquals(1, poolCurator.listAvailableEntitlementPools(null, owner, (Collection<String>) null, activeOn).size()); }
@Test public void testListByActiveOnIncludesSameEndDay() { Date activeOn = TestUtil.createDate(2011, 2, 2); Pool pool = TestUtil.createPool(owner, product); pool.setEndDate(activeOn); poolCurator.create(pool); assertEquals(1, poolCurator.listAvailableEntitlementPools(null, owner, (Collection<String>) null, activeOn).size()); }
@Test public void testListByActiveOnInTheMiddle() { Date activeOn = TestUtil.createDate(2011, 2, 2); Pool pool = TestUtil.createPool(owner, product); pool.setStartDate(TestUtil.createDate(2011, 1, 2)); pool.setEndDate(TestUtil.createDate(2011, 3, 2)); poolCurator.create(pool); assertEquals(1, poolCurator.listAvailableEntitlementPools(null, owner, (Collection<String>) null, activeOn).size()); }
@Test public void testCorrectPagingWhenItemsAreFilteredByProductId() { for (int i = 0; i < 50; i++) { Pool pool = TestUtil.createPool(owner, product); pool.setStartDate(TestUtil.createDate(2011, 1, 2)); pool.setEndDate(TestUtil.createDate(2011, 3, 2)); poolCurator.create(pool); } for (int i = 0; i < 50; 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); req.setOrder(PageRequest.Order.ASCENDING); req.setSortBy("id"); 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(50), page.getMaxRecords()); List<Pool> pools = page.getPageData(); assertEquals(10, pools.size()); assertEquals(req, page.getPageRequest()); for (int i = 0; i < pools.size(); i++) { if (i < pools.size() - 1) { assertTrue(pools.get(i).getId().compareTo(pools.get(i + 1).getId()) < 1); } } }
@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()); }
@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()); }
@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()); }
@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()); }
@Test public void testGetPoolsOrderedByProductNameAscending() { Owner owner1 = this.createOwner(); this.ownerCurator.create(owner1); Pool p1 = TestUtil.createPool(owner1, this.generateProduct(owner1, "p1", "xyz")); p1.setSourceSubscription(new SourceSubscription("subscriptionId-phil", "master")); Pool p2 = TestUtil.createPool(owner1, this.generateProduct(owner1, "p2", "abc")); p2.setSourceSubscription(new SourceSubscription("subscriptionId-ned", "master1")); Pool p3 = TestUtil.createPool(owner1, this.generateProduct(owner1, "p3", "lmn")); p3.setSourceSubscription(new SourceSubscription("subscriptionId-ned1", "master11")); this.poolCurator.create(p3); this.poolCurator.create(p1); this.poolCurator.create(p2); PageRequest req = new PageRequest(); req.setOrder(PageRequest.Order.ASCENDING); req.setSortBy("Product.name"); Date activeOn = TestUtil.createDate(2019, 2, 2); Page<List<Pool>> page = poolManager.listAvailableEntitlementPools(null, null, owner1.getId(), null, null, activeOn, false, null, req, false, false, null); List<Pool> pools = page.getPageData(); List<Pool> results = new ArrayList<>(); results.add(p2); results.add(p3); results.add(p1); assertEquals(results, pools); }
@Test public void testGetPoolsOrderedByProductNameDescending() { Owner owner1 = this.createOwner(); this.ownerCurator.create(owner1); Pool p1 = TestUtil.createPool(owner1, this.generateProduct(owner1, "p1", "xyz")); p1.setSourceSubscription(new SourceSubscription("subscriptionId-phil", "master")); Pool p2 = TestUtil.createPool(owner1, this.generateProduct(owner1, "p2", "abc")); p2.setSourceSubscription(new SourceSubscription("subscriptionId-ned", "master1")); Pool p3 = TestUtil.createPool(owner1, this.generateProduct(owner1, "p3", "lmn")); p3.setSourceSubscription(new SourceSubscription("subscriptionId-ned1", "master11")); this.poolCurator.create(p3); this.poolCurator.create(p1); this.poolCurator.create(p2); PageRequest req1 = new PageRequest(); req1.setSortBy("Product.name"); req1.setOrder(PageRequest.Order.DESCENDING); Date activeOn1 = TestUtil.createDate(2019, 2, 2); Page<List<Pool>> page1 = poolManager.listAvailableEntitlementPools(null, null, owner1.getId(), null, null, activeOn1, false, null, req1, false, false, null); List<Pool> pools1 = page1.getPageData(); List<Pool> results1 = new ArrayList<>(); results1.add(p1); results1.add(p3); results1.add(p2); assertEquals(results1, pools1); }
@Test public void testGetPoolBySubscriptionId() { Owner owner1 = this.createOwner(); this.ownerCurator.create(owner1); Pool p1 = TestUtil.createPool(owner1, this.generateProduct(owner1, "p1", "p1")); p1.setSourceSubscription(new SourceSubscription("subscriptionId-phil", "master")); Pool p2 = TestUtil.createPool(owner1, this.generateProduct(owner1, "p2", "p2")); p2.setSourceSubscription(new SourceSubscription("subscriptionId-ned", "master")); this.poolCurator.create(p1); this.poolCurator.create(p2); Page<List<Pool>> result = this.poolCurator.listAvailableEntitlementPools(null, owner1.getId(), (Collection<String>) null, "subscriptionId-phil", new Date(), null, null, false, false, false, null); assertEquals("subscriptionId-phil", result.getPageData().get(0).getSubscriptionId()); }