EntitlementCertificateGenerator { @Transactional public void regenerateCertificatesByEntitlementIds(Iterable<String> entitlementIds, boolean lazy) { if (lazy) { this.entitlementCurator.markEntitlementsDirty(entitlementIds); } else { for (String entitlementId : entitlementIds) { Entitlement entitlement = entitlementCurator.get(entitlementId); if (entitlement == null) { log.info("Unable to load entitlement for regeneration: {}", entitlementId); continue; } this.regenerateCertificatesOf(entitlement, false); } } } @Inject  EntitlementCertificateGenerator(EntitlementCertificateCurator entitlementCertificateCurator,
        EntitlementCertServiceAdapter entCertServiceAdapter, EntitlementCurator entitlementCurator,
        PoolCurator poolCurator, EventSink eventSink, EventFactory eventFactory,
        ProductCurator productCurator, ContentAccessManager contentAccessManager,
        OwnerCurator ownerCurator); @Transactional Map<String, EntitlementCertificate> generateEntitlementCertificates(Consumer consumer,
        Map<String, Product> products, Map<String, PoolQuantity> poolQuantities,
        Map<String, Entitlement> entitlements, boolean save); @Transactional EntitlementCertificate generateEntitlementCertificate(Pool pool, Entitlement entitlement); @Transactional EntitlementCertificate generateEntitlementCertificate(Pool pool, Entitlement entitlement,
        boolean updateEntitlement); @Transactional void regenerateCertificatesOf(Entitlement entitlement, boolean lazy); @Transactional void regenerateCertificatesOf(Iterable<Entitlement> entitlements, boolean lazy); @Transactional void regenerateCertificatesByEntitlementIds(Iterable<String> entitlementIds, boolean lazy); @Transactional void regenerateCertificatesOf(Consumer consumer, boolean lazy); @Transactional void regenerateCertificatesOf(String environmentId, Collection<String> contentIds,
        boolean lazy); @Transactional void regenerateCertificatesOf(Owner owner, String productId, boolean lazy); @Transactional void regenerateCertificatesOf(Owner owner, Product product, boolean lazy); @Transactional void regenerateCertificatesOf(Collection<Owner> owners, Collection<Product> products,
        boolean lazy);  }
@Test public void testLazyRegenerationByEntitlementId() throws Exception { Owner owner = TestUtil.createOwner("test-owner", "Test Owner"); Consumer consumer = TestUtil.createConsumer(owner); Product product = TestUtil.createProduct(); Pool pool = TestUtil.createPool(owner, product); Entitlement entitlement = TestUtil.createEntitlement(owner, consumer, pool, null); entitlement.setId("lazy-ent-id"); Collection<String> entitlements = Arrays.asList(entitlement.getId()); this.ecGenerator.regenerateCertificatesByEntitlementIds(entitlements, true); verify(this.mockEntitlementCurator, times(1)).markEntitlementsDirty(eq(entitlements)); verifyZeroInteractions(this.mockEntCertAdapter); }
@Test public void testNonLazyRegenerationByEntitlementId() throws Exception { Owner owner = TestUtil.createOwner("test-owner", "Test Owner"); Consumer consumer = TestUtil.createConsumer(owner); Product product = TestUtil.createProduct(); Pool pool = TestUtil.createPool(owner, product); Entitlement entitlement = TestUtil.createEntitlement(owner, consumer, pool, null); entitlement.setId("test-ent-id"); Collection<String> entitlements = Arrays.asList(entitlement.getId()); pool.setEntitlements(new HashSet(Arrays.asList(entitlement))); HashMap<String, EntitlementCertificate> ecMap = new HashMap<>(); ecMap.put(pool.getId(), new EntitlementCertificate()); when(this.mockEntitlementCurator.get(eq(entitlement.getId()))).thenReturn(entitlement); when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), any(Map.class), any(Map.class), any(Map.class), anyBoolean())).thenReturn(ecMap); when(mockEventFactory.entitlementChanged(any(Entitlement.class))).thenReturn(mock(Event.class)); this.ecGenerator.regenerateCertificatesByEntitlementIds(entitlements, false); assertFalse(entitlement.isDirty()); verify(this.mockEntCertAdapter, times(1)).generateEntitlementCerts(any(Consumer.class), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor .capture(), eq(false)); verify(this.mockEventSink, times(1)).queueEvent(any(Event.class)); }