EntitlementCertificateGenerator { @Transactional public void regenerateCertificatesOf(Entitlement entitlement, boolean lazy) { this.regenerateCertificatesOf(Arrays.asList(entitlement), lazy); } @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 testLazyRegenerateForEntitlement() { Entitlement entitlement = new Entitlement(); this.ecGenerator.regenerateCertificatesOf(entitlement, true); assertTrue(entitlement.isDirty()); verifyZeroInteractions(this.mockEntCertAdapter); }
@Test public void testLazyRegenerateForEntitlementCollection() { List<Entitlement> entitlements = Arrays.asList( new Entitlement(), new Entitlement(), new Entitlement() ); this.ecGenerator.regenerateCertificatesOf(entitlements, true); for (Entitlement entitlement : entitlements) { assertTrue(entitlement.isDirty()); } verifyZeroInteractions(this.mockEntCertAdapter); }
@Test public void testLazyRegnerateForEnvironmentContent() { String environmentId = "env_id_1"; List<Entitlement> entitlements = this.generateEntitlements(); CandlepinQuery cqmock = mock(CandlepinQuery.class); when(cqmock.iterator()).thenReturn(entitlements.iterator()); when(this.mockEntitlementCurator.listByEnvironment(environmentId)).thenReturn(cqmock); this.ecGenerator.regenerateCertificatesOf(environmentId, Arrays.asList("c1", "c2", "c4"), true); assertTrue(entitlements.get(0).isDirty()); assertTrue(entitlements.get(1).isDirty()); assertFalse(entitlements.get(2).isDirty()); verifyZeroInteractions(this.mockEntCertAdapter); }
@Test public void testNonLazyRegnerateForEnvironmentContent() throws Exception { String environmentId = "env_id_1"; List<Entitlement> entitlements = this.generateEntitlements(); HashMap<String, EntitlementCertificate> ecMap = new HashMap<>(); for (Entitlement entitlement : entitlements) { ecMap.put(entitlement.getPool().getId(), new EntitlementCertificate()); } CandlepinQuery<Entitlement> cqmock = mock(CandlepinQuery.class); when(cqmock.iterator()).thenReturn(entitlements.iterator()); when(this.mockEntitlementCurator.listByEnvironment(environmentId)).thenReturn(cqmock); 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.regenerateCertificatesOf(environmentId, Arrays.asList("c1", "c2", "c4"), false); assertFalse(entitlements.get(0).isDirty()); assertFalse(entitlements.get(1).isDirty()); assertFalse(entitlements.get(2).isDirty()); verify(this.mockEntCertAdapter, times(2)).generateEntitlementCerts(any(Consumer.class), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor .capture(), eq(false)); verify(this.mockEventSink, times(2)).queueEvent(any(Event.class)); }
@Test public void testLazyRegenerationForProductById() 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); Set<Entitlement> entitlements = new HashSet<>(); entitlements.add(entitlement); pool.setEntitlements(entitlements); when(this.mockPoolCurator.listAvailableEntitlementPools(isNull(), eq(owner), eq(product.getId()), any(Date.class))).thenReturn(Arrays.asList(pool)); when(mockEventFactory.entitlementChanged(any(Entitlement.class))).thenReturn(mock(Event.class)); this.ecGenerator.regenerateCertificatesOf(owner, product.getId(), true); assertTrue(entitlement.isDirty()); verifyZeroInteractions(this.mockEntCertAdapter); }
@Test public void testNonLazyRegenerationForProductById() 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); Set<Entitlement> entitlements = new HashSet<>(); entitlements.add(entitlement); pool.setEntitlements(entitlements); HashMap<String, EntitlementCertificate> ecMap = new HashMap<>(); ecMap.put(pool.getId(), new EntitlementCertificate()); when(this.mockPoolCurator.listAvailableEntitlementPools(isNull(), eq(owner), eq(product.getId()), any(Date.class))).thenReturn(Arrays.asList(pool)); 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.regenerateCertificatesOf(owner, product.getId(), 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)); }
@Test public void testLazyRegenerateForConsumer() { Entitlement entitlement = new Entitlement(); Consumer consumer = new Consumer(); Owner owner = new Owner(); owner.setId("test-owner"); consumer.setOwner(owner); consumer.addEntitlement(entitlement); when(mockOwnerCurator.findOwnerById(eq("test-owner"))).thenReturn(owner); this.ecGenerator.regenerateCertificatesOf(consumer, true); assertTrue(entitlement.isDirty()); verifyZeroInteractions(this.mockEntCertAdapter); }
@Test public void testNonLazyRegenerate() throws Exception { Owner owner = TestUtil.createOwner("test-owner", "Test Owner"); Product product = TestUtil.createProduct(); Pool pool = TestUtil.createPool(owner, product); pool.setSourceSubscription(new SourceSubscription("source-sub-id", "master")); Map<String, EntitlementCertificate> entCerts = new HashMap<>(); entCerts.put(pool.getId(), new EntitlementCertificate()); when(this.mockEntCertAdapter.generateEntitlementCerts( any(Consumer.class), anyMapOf(String.class, PoolQuantity.class), anyMapOf(String.class, Entitlement.class), anyMapOf(String.class, Product.class), anyBoolean())).thenReturn(entCerts); when(mockEventFactory.entitlementChanged(any(Entitlement.class))).thenReturn(mock(Event.class)); Consumer consumer = TestUtil.createConsumer(owner); Entitlement entitlement = new Entitlement(pool, consumer, owner, 1); entitlement.setDirty(true); this.ecGenerator.regenerateCertificatesOf(entitlement, false); assertFalse(entitlement.isDirty()); verify(this.mockEntCertAdapter).generateEntitlementCerts(eq(consumer), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor .capture(), eq(false)); assertEquals(entitlement, this.entMapCaptor.getValue().get(pool.getId())); assertEquals(product, this.productMapCaptor.getValue().get(pool.getId())); verify(this.mockEventSink, times(1)).queueEvent(any(Event.class)); }