EntitlementCurator extends AbstractHibernateCurator<Entitlement> { @SuppressWarnings("unchecked") public CandlepinQuery<Entitlement> findByStackId(Consumer consumer, String stackId) { return findByStackIds(consumer, Arrays.asList(stackId)); } @Inject  EntitlementCurator(OwnerProductCurator ownerProductCurator, ProductCurator productCurator,
        ConsumerTypeCurator consumerTypeCurator, CandlepinQueryFactory cpQueryFactory); @Transactional Set<Entitlement> bulkUpdate(Set<Entitlement> entitlements); List<Entitlement> listByConsumer(Consumer consumer); List<Entitlement> listByConsumer(Consumer consumer, EntitlementFilterBuilder filters); List<Entitlement> listByConsumerAndPoolId(Consumer consumer, String poolId); Page<List<Entitlement>> listByConsumer(Consumer consumer, String productId,
        EntitlementFilterBuilder filters, PageRequest pageRequest); Page<List<Entitlement>> listByOwner(Owner owner, String productId,
        EntitlementFilterBuilder filters, PageRequest pageRequest); Page<List<Entitlement>> listAll(EntitlementFilterBuilder filters, PageRequest pageRequest); CandlepinQuery<Entitlement> listByOwner(Owner owner); CandlepinQuery<Entitlement> listByEnvironment(Environment environment); CandlepinQuery<Entitlement> listByEnvironment(String environmentId); CandlepinQuery<Entitlement> listByConsumerAndDate(Consumer consumer, Date activeOn); List<Entitlement> listDirty(Consumer consumer); Set<String> listEntitledProductIds(Consumer consumer, Pool pool); int markDependentEntitlementsDirty(Iterable<String> entitlementIds); Set<String> filterDistributorEntitlementIds(Iterable<String> entsIdsToFilter); @Transactional int markEntitlementsDirty(Iterable<String> entitlementIds); @Deprecated Map<Consumer, List<Entitlement>> getDistinctConsumers(List<Entitlement> entsToRevoke); @Transactional void delete(Entitlement entity); void batchDelete(Collection<Entitlement> entitlements); int batchDeleteByIds(Collection<String> entitlementIds); void unlinkEntitlements(Collection<Entitlement> entitlements); @Transactional Entitlement findByCertificateSerial(Long serial); @Transactional Entitlement replicate(Entitlement ent); @SuppressWarnings("unchecked") CandlepinQuery<Entitlement> findByStackId(Consumer consumer, String stackId); @SuppressWarnings("unchecked") CandlepinQuery<Entitlement> findByStackIds(Consumer consumer, Collection stackIds); @SuppressWarnings("unchecked") CandlepinQuery<Entitlement> findByPoolAttribute(Consumer consumer, String attributeName,
        String value); CandlepinQuery<Entitlement> findByPoolAttribute(String attributeName, String value); Entitlement findUpstreamEntitlementForStack(Consumer consumer, String stackId); Collection<String> getDependentEntitlementIdsForPools(Consumer consumer,
        Iterable<String> poolIds);  }
@Test public void findByStackIdTest() { String stackingId = "test_stack_id"; Product product = TestUtil.createProduct(); product.setAttribute(Product.Attributes.STACKING_ID, stackingId); productCurator.create(product); Pool pool = createPool(owner, product, 1L, dateSource.currentDate(), createFutureDate(1)); poolCurator.create(pool); Entitlement created = bind(consumer, pool); List<Entitlement> results = entitlementCurator.findByStackId(consumer, stackingId).list(); assertEquals(1, results.size()); assertTrue(results.contains(created)); }
@Test public void findByStackIdMultiTest() { String stackingId = "test_stack_id"; Product product = TestUtil.createProduct(); product.setAttribute(Product.Attributes.STACKING_ID, stackingId); productCurator.create(product); int ents = 5; List<Entitlement> createdEntitlements = new LinkedList<>(); for (int i = 0; i < ents; i++) { Pool pool = createPool(owner, product, 1L, dateSource.currentDate(), createFutureDate(1)); poolCurator.create(pool); createdEntitlements.add(bind(consumer, pool)); } List<Entitlement> results = entitlementCurator.findByStackId(consumer, stackingId).list(); assertEquals(ents, results.size()); assertTrue(results.containsAll(createdEntitlements) && createdEntitlements.containsAll(results)); }
@Test public void findByStackIdMultiTestWithDerived() { String stackingId = "test_stack_id"; Product product = TestUtil.createProduct(); product.setAttribute(Product.Attributes.STACKING_ID, stackingId); productCurator.create(product); Consumer otherConsumer = createConsumer(owner); otherConsumer.setEnvironment(environment); consumerCurator.create(otherConsumer); List<Entitlement> createdEntitlements = new LinkedList<>(); for (int i = 0; i < 5; i++) { Pool pool = createPool(owner, product, 1L, dateSource.currentDate(), createFutureDate(1)); if (i < 2) { pool.setSourceStack(new SourceStack(otherConsumer, "otherstackid" + i)); } else if (i < 4) { pool.setSourceEntitlement(createdEntitlements.get(0)); } poolCurator.create(pool); createdEntitlements.add(bind(consumer, pool)); } List<Entitlement> results = entitlementCurator.findByStackId(consumer, stackingId).list(); assertEquals(1, results.size()); assertEquals(createdEntitlements.get(4), results.get(0)); }