JDBCCertRecordStoreConnection implements CertRecordStoreConnection { @Override public List<X509CertRecord> updateUnrefreshedCertificatesNotificationTimestamp(String lastNotifiedServer, long lastNotifiedTime, String provider) { final String caller = "updateUnrefreshedCertificatesNotificationTimestamp"; int affectedRows; try (PreparedStatement ps = con.prepareStatement(SQL_UPDATE_UNREFRESHED_X509_RECORDS_NOTIFICATION_TIMESTAMP)) { ps.setTimestamp(1, new java.sql.Timestamp(lastNotifiedTime)); ps.setString(2, lastNotifiedServer); ps.setString(3, provider); affectedRows = executeUpdate(ps, caller); } catch (SQLException ex) { throw sqlError(ex, caller); } if (affectedRows > 0) { return getNotifyUnrefreshedCertificates(lastNotifiedServer, lastNotifiedTime); } return new ArrayList<>(); } JDBCCertRecordStoreConnection(Connection con); @Override void setOperationTimeout(int queryTimeout); @Override void close(); @Override X509CertRecord getX509CertRecord(String provider, String instanceId, String service); @Override boolean updateX509CertRecord(X509CertRecord certRecord); @Override boolean insertX509CertRecord(X509CertRecord certRecord); @Override boolean deleteX509CertRecord(String provider, String instanceId, String service); @Override int deleteExpiredX509CertRecords(int expiryTimeMins); @Override List<X509CertRecord> updateUnrefreshedCertificatesNotificationTimestamp(String lastNotifiedServer,
                                                                      long lastNotifiedTime,
                                                                      String provider); static final String DB_COLUMN_INSTANCE_ID; static final String DB_COLUMN_INSTANCE_PROVIDER; static final String DB_COLUMN_SERVICE; static final String DB_COLUMN_CURRENT_IP; static final String DB_COLUMN_CURRENT_SERIAL; static final String DB_COLUMN_CURRENT_TIME; static final String DB_COLUMN_PREV_IP; static final String DB_COLUMN_PREV_SERIAL; static final String DB_COLUMN_PREV_TIME; static final String DB_COLUMN_CLIENT_CERT; static final String DB_COLUMN_LAST_NOTIFIED_TIME; static final String DB_COLUMN_LAST_NOTIFIED_SERVER; static final String DB_COLUMN_EXPIRY_TIME; static final String DB_COLUMN_HOSTNAME; }
@Test public void testUpdateUnrefreshedCertificatesNotificationTimestamp() throws Exception { JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn); Mockito.when(mockPrepStmt.executeUpdate()) .thenReturn(3) .thenReturn(0); long currentTime = System.currentTimeMillis(); Timestamp ts = new Timestamp(currentTime); Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_TIME)) .thenReturn(ts) .thenReturn(ts) .thenReturn(ts); Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_SERVER)) .thenReturn("server0") .thenReturn("server1") .thenReturn("server2"); Mockito.when(mockResultSet.next()) .thenReturn(true) .thenReturn(true) .thenReturn(true) .thenReturn(false); Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_SERVICE)).thenReturn(null); Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_HOSTNAME)).thenReturn(null); Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_INSTANCE_ID)).thenReturn(null); Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_EXPIRY_TIME)).thenReturn(ts); Mockito.when(mockResultSet.getBoolean(JDBCCertRecordStoreConnection.DB_COLUMN_CLIENT_CERT)).thenReturn(false); Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_CURRENT_TIME)).thenReturn(ts); Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_PREV_TIME)).thenReturn(ts); List<X509CertRecord> unrefreshedCertificateRecords = jdbcConn.updateUnrefreshedCertificatesNotificationTimestamp("localhost", currentTime, "provider"); assertNotNull(unrefreshedCertificateRecords); assertEquals(unrefreshedCertificateRecords.size(), 3); for (int i = 0; i < unrefreshedCertificateRecords.size(); ++i) { assertEquals(unrefreshedCertificateRecords.get(i).getLastNotifiedServer(), "server" + i); assertEquals(unrefreshedCertificateRecords.get(i).getLastNotifiedTime(), new Date(currentTime)); } jdbcConn.close(); }