CertificateSerialCurator extends AbstractHibernateCurator<CertificateSerial> { @SuppressWarnings("unchecked") public CandlepinQuery<CertificateSerial> listBySerialIds(String[] ids) { if (ids == null) { return null; } Long[] lids = new Long[ids.length]; for (int i = 0; i < ids.length; i++) { lids[i] = Long.valueOf(ids[i]); } DetachedCriteria criteria = DetachedCriteria.forClass(CertificateSerial.class) .add(CPRestrictions.in("id", lids)); return this.cpQueryFactory.<CertificateSerial>buildQuery(this.currentSession(), criteria); } 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 testListBySerialIds() { CertSerialBuilder builder = new CertSerialBuilder(this.certSerialCurator); CertificateSerial serial = builder.withExpDate("03/10/2010").collected(false).revoked(false).build(); CertificateSerial serial1 = builder.withExpDate("03/10/2012").collected(true).revoked(true).build(); String[] ids = new String[2]; ids[0] = String.valueOf(serial.getSerial()); ids[1] = String.valueOf(serial1.getSerial()); List<CertificateSerial> serials = certSerialCurator.listBySerialIds(ids).list(); assertEquals(2, serials.size()); Map<BigInteger, CertificateSerial> values = new HashMap<>(); for (CertificateSerial s : serials) { values.put(s.getSerial(), s); } assertNotNull(values.get(serial.getSerial())); assertNotNull(values.get(serial1.getSerial())); }
@Test public void testListBySerialIdsReturnsNullGivenNull() { assertEquals(null, certSerialCurator.listBySerialIds(null)); }
@Test public void certSerialCreateWithManuallySetId() { Long expectedSerialNumber = Util.generateUniqueLong(); CertificateSerial serial = new CertificateSerial(expectedSerialNumber, new Date()); certSerialCurator.merge(serial); assertNotNull(serial); assertNotNull(serial.getId()); assertEquals(expectedSerialNumber, serial.getId()); CandlepinQuery<CertificateSerial> serialQuery = certSerialCurator.listBySerialIds(new String[] {serial.getId().toString()}); assertEquals(1, serialQuery.getRowCount()); }