Entitler { public int revokeUnmappedGuestEntitlements(Consumer consumer) { int total = 0; CandlepinQuery<Entitlement> unmappedGuestEntitlements = consumer != null ? entitlementCurator.findByPoolAttribute(consumer, "unmapped_guests_only", "true") : entitlementCurator.findByPoolAttribute("unmapped_guests_only", "true"); List<Entitlement> entsToDelete = new LinkedList<>(); for (Entitlement entitlement : unmappedGuestEntitlements) { if (!entitlement.isValid()) { entsToDelete.add(entitlement); ++total; } } if (!entsToDelete.isEmpty()) { for (List<Entitlement> ents : this.partition(entsToDelete)) { poolManager.revokeEntitlements(ents); } } return total; } @Inject  Entitler(PoolManager pm, ConsumerCurator cc, I18n i18n, EventFactory evtFactory,
        EventSink sink, EntitlementRulesTranslator messageTranslator,
        EntitlementCurator entitlementCurator, Configuration config,
        OwnerCurator ownerCurator, PoolCurator poolCurator,
        ProductManager productManager, ProductServiceAdapter productAdapter, ContentManager contentManager,
        ConsumerTypeCurator ctc); List<Entitlement> bindByPoolQuantity(Consumer consumer, String poolId, Integer quantity); List<Entitlement> bindByPoolQuantities(String consumeruuid,
        Map<String, Integer> poolIdAndQuantities); List<Entitlement> bindByPoolQuantities(Consumer consumer,
        Map<String, Integer> poolIdAndQuantities); void adjustEntitlementQuantity(Consumer consumer, Entitlement ent,
        Integer quantity); List<Entitlement> bindByProducts(String[] productIds,
        String consumeruuid, Date entitleDate, Collection<String> fromPools); List<Entitlement> bindByProducts(AutobindData data); @Transactional List<Entitlement> bindByProducts(AutobindData data, boolean force); List<PoolQuantity> getDryRun(Consumer consumer, Owner owner,
        String serviceLevelOverride); int revokeUnmappedGuestEntitlements(Consumer consumer); int revokeUnmappedGuestEntitlements(); void sendEvents(List<Entitlement> entitlements);  }
@Test public void testUnmappedGuestRevocation() { Pool pool1 = createValidPool("1"); Pool pool2 = createExpiredPool("2"); CandlepinQuery cqmock = mock(CandlepinQuery.class); when(cqmock.iterator()).thenReturn(entsOf(pool1, pool2).iterator()); when(entitlementCurator.findByPoolAttribute(eq("unmapped_guests_only"), eq("true"))) .thenReturn(cqmock); when(config.getInt(ConfigProperties.ENTITLER_BULK_SIZE)).thenReturn(1000); int total = entitler.revokeUnmappedGuestEntitlements(); assertEquals(1, total); verify(pm).revokeEntitlements(Collections.singletonList(entOf(pool2))); }
@Test public void unmappedGuestRevocationShouldBePartitioned() { Pool pool1 = createExpiredPool("1"); Pool pool2 = createExpiredPool("2"); CandlepinQuery cqmock = mock(CandlepinQuery.class); when(cqmock.iterator()).thenReturn(entsOf(pool1, pool2).iterator()); when(entitlementCurator.findByPoolAttribute(eq("unmapped_guests_only"), eq("true"))) .thenReturn(cqmock); when(config.getInt(ConfigProperties.ENTITLER_BULK_SIZE)).thenReturn(1); int total = entitler.revokeUnmappedGuestEntitlements(); assertEquals(2, total); verify(pm).revokeEntitlements(Collections.singletonList(entOf(pool1))); verify(pm).revokeEntitlements(Collections.singletonList(entOf(pool2))); }