EntitlementCurator extends AbstractHibernateCurator<Entitlement> { public List<Entitlement> listByConsumer(Consumer consumer) { return listByConsumer(consumer, new EntitlementFilterBuilder()); } @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 listByConsumerExpired() { List<Entitlement> ents = entitlementCurator.listByConsumer(consumer); assertEquals(2, ents.size(), "Setup should add 2 entitlements:"); Product product = TestUtil.createProduct(); productCurator.create(product); Pool pool = createPool(owner, product, 1L, createDate(2000, 1, 1), createDate(2000, 2, 2)); poolCurator.create(pool); for (int i = 0; i < 2; i++) { EntitlementCertificate cert = createEntitlementCertificate("key", "certificate"); Entitlement ent = createEntitlement(owner, consumer, pool, cert); entitlementCurator.create(ent); } ents = entitlementCurator.listByConsumer(consumer); assertEquals(2, ents.size(), "adding expired entitlements should not change results:"); }
@Test public void listByConsumerFilteringByProductAttribute() { EntitlementFilterBuilder filters = new EntitlementFilterBuilder(); filters.addAttributeFilter(Product.Attributes.VARIANT, "Starter Pack"); List<Entitlement> ents = entitlementCurator.listByConsumer(consumer, filters); assertEquals(1, ents.size(), "should match only one out of two entitlements:"); Product p = ents.get(0).getPool().getProduct(); assertTrue(p.hasAttribute(Product.Attributes.VARIANT), "Did not find ent by product attribute 'variant'"); assertEquals("Starter Pack", p.getAttributeValue(Product.Attributes.VARIANT)); }
@Test public void listByConsumerFilterByMatches() { EntitlementFilterBuilder filters = new EntitlementFilterBuilder(); filters.addMatchesFilter(testProduct.getName()); List<Entitlement> ents = entitlementCurator.listByConsumer(consumer, filters); assertEquals(1, ents.size(), "should match only one out of two entitlements:"); assertEquals(ents.get(0).getPool().getName(), testProduct.getName()); }
@Test public void listByConsumersFilteringByPoolAttribute() { EntitlementFilterBuilder filters = new EntitlementFilterBuilder(); filters.addAttributeFilter("pool_attr_1", "attr1"); List<Entitlement> ents = entitlementCurator.listByConsumer(consumer, filters); assertEquals(1, ents.size(), "should match only one out of two entitlements:"); Pool p = ents.get(0).getPool(); assertTrue(p.hasAttribute("pool_attr_1"), "Did not find ent by pool attribute 'pool_attr_1'"); assertEquals(p.getAttributeValue("pool_attr_1"), "attr1"); }