CertificateSerialCurator extends AbstractHibernateCurator<CertificateSerial> { public CandlepinQuery<Long> getExpiredRevokedCertSerials() { return this.getExpiredRevokedCertSerials(getExpiryRestriction()); } CertificateSerialCurator(); CandlepinQuery<Long> getUncollectedRevokedCertSerials(); CandlepinQuery<Long> getExpiredRevokedCertSerials(); CandlepinQuery<Long> getExpiredRevokedCertSerials(Date cutoff); @Transactional int markSerialsAsCollected(Collection<Long> serials); @Transactional int deleteSerials(Collection<Long> serials); @Transactional int deleteRevokedExpiredAndNotCollectedSerials(); @SuppressWarnings("unchecked") CandlepinQuery<CertificateSerial> listBySerialIds(String[] ids); @SuppressWarnings("unchecked") List<Long> listEntitlementSerialIds(Consumer c);  }
@Test public void testGetExpiredRevokedCertSerials() { Date now = new Date(); Date lastWeek = Util.addDaysToDt(-7); Date nextWeek = Util.addDaysToDt(7); CertSerialBuilder builder = new CertSerialBuilder(this.certSerialCurator); builder.withExpDate(lastWeek).collected(false).revoked(false).build(); builder.withExpDate(lastWeek).collected(false).revoked(true).build(); builder.withExpDate(lastWeek).collected(true).revoked(false).build(); builder.withExpDate(lastWeek).collected(true).revoked(true).build(); builder.withExpDate(now).collected(false).revoked(false).build(); builder.withExpDate(now).collected(false).revoked(true).build(); builder.withExpDate(now).collected(true).revoked(false).build(); builder.withExpDate(now).collected(true).revoked(true).build(); builder.withExpDate(nextWeek).collected(false).revoked(false).build(); builder.withExpDate(nextWeek).collected(false).revoked(true).build(); builder.withExpDate(nextWeek).collected(true).revoked(false).build(); builder.withExpDate(nextWeek).collected(true).revoked(true).build(); Date cutoff = Util.midnight(); List<Long> expected = builder .fetch((serial) -> serial != null && serial.isRevoked() && serial.getExpiration().before(cutoff)) .map((serial) -> serial.getId()) .collect(Collectors.toList()); List<Long> uncollected = this.certSerialCurator.getExpiredRevokedCertSerials().list(); assertNotNull(uncollected); assertEquals(expected.size(), uncollected.size()); assertTrue(uncollected.containsAll(expected)); }
@Test public void testGetExpiredRevokedCertSerialsWithNoMatchingSerials() { Date now = new Date(); Date lastWeek = Util.addDaysToDt(-7); Date nextWeek = Util.addDaysToDt(7); CertSerialBuilder builder = new CertSerialBuilder(this.certSerialCurator); builder.withExpDate(lastWeek).collected(false).revoked(false).build(); builder.withExpDate(lastWeek).collected(true).revoked(false).build(); builder.withExpDate(now).collected(false).revoked(false).build(); builder.withExpDate(now).collected(false).revoked(true).build(); builder.withExpDate(now).collected(true).revoked(false).build(); builder.withExpDate(now).collected(true).revoked(true).build(); builder.withExpDate(nextWeek).collected(false).revoked(false).build(); builder.withExpDate(nextWeek).collected(false).revoked(true).build(); builder.withExpDate(nextWeek).collected(true).revoked(false).build(); builder.withExpDate(nextWeek).collected(true).revoked(true).build(); List<Long> expected = builder .fetch((serial) -> serial != null && serial.isRevoked() && serial.getExpiration().before(now)) .map((serial) -> serial.getId()) .collect(Collectors.toList()); List<Long> uncollected = this.certSerialCurator.getExpiredRevokedCertSerials().list(); assertNotNull(uncollected); assertEquals(expected.size(), uncollected.size()); assertTrue(uncollected.containsAll(expected)); }
@Test public void testGetExpiredRevokedCertSerialsWithNoData() { List<Long> uncollected = this.certSerialCurator.getExpiredRevokedCertSerials().list(); assertNotNull(uncollected); assertTrue(uncollected.isEmpty()); }
@Test public void testGetExpiredRevokedCertSerialsWithSpecifiedDate() { Date now = new Date(); Date lastWeek = Util.addDaysToDt(-7); Date nextWeek = Util.addDaysToDt(7); Date cutoff = Util.addDaysToDt(1); CertSerialBuilder builder = new CertSerialBuilder(this.certSerialCurator); builder.withExpDate(lastWeek).collected(false).revoked(false).build(); builder.withExpDate(lastWeek).collected(false).revoked(true).build(); builder.withExpDate(lastWeek).collected(true).revoked(false).build(); builder.withExpDate(lastWeek).collected(true).revoked(true).build(); builder.withExpDate(now).collected(false).revoked(false).build(); builder.withExpDate(now).collected(false).revoked(true).build(); builder.withExpDate(now).collected(true).revoked(false).build(); builder.withExpDate(now).collected(true).revoked(true).build(); builder.withExpDate(nextWeek).collected(false).revoked(false).build(); builder.withExpDate(nextWeek).collected(false).revoked(true).build(); builder.withExpDate(nextWeek).collected(true).revoked(false).build(); builder.withExpDate(nextWeek).collected(true).revoked(true).build(); List<Long> expected = builder .fetch((serial) -> serial != null && serial.isRevoked() && serial.getExpiration().before(cutoff)) .map((serial) -> serial.getId()) .collect(Collectors.toList()); List<Long> uncollected = this.certSerialCurator.getExpiredRevokedCertSerials(cutoff).list(); assertNotNull(uncollected); assertEquals(expected.size(), uncollected.size()); assertTrue(uncollected.containsAll(expected)); }
@Test public void testGetExpiredRevokedCertSerialsWithNullDateThrowsException() { assertThrows(IllegalArgumentException.class, () -> this.certSerialCurator.getExpiredRevokedCertSerials(null) ); }