JDBCCertRecordStoreConnection implements CertRecordStoreConnection { @Override public X509CertRecord getX509CertRecord(String provider, String instanceId, String service) { final String caller = "getX509CertRecord"; X509CertRecord certRecord = null; try (PreparedStatement ps = con.prepareStatement(SQL_GET_X509_RECORD)) { ps.setString(1, provider); ps.setString(2, instanceId); ps.setString(3, service); try (ResultSet rs = executeQuery(ps, caller)) { if (rs.next()) { certRecord = setRecordFromResultSet(rs); } } } catch (SQLException ex) { throw sqlError(ex, caller); } return certRecord; } 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 testGetX509CertRecord() throws Exception { Date now = new Date(); Timestamp tstamp = new Timestamp(now.getTime()); Mockito.when(mockResultSet.next()).thenReturn(true); mockNonNullableColumns(now); Mockito.doReturn(tstamp).when(mockResultSet).getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_TIME); Mockito.doReturn("last-notified-server").when(mockResultSet).getString(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_SERVER); Mockito.doReturn(tstamp).when(mockResultSet).getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_EXPIRY_TIME); Mockito.doReturn("hostname").when(mockResultSet).getString(JDBCCertRecordStoreConnection.DB_COLUMN_HOSTNAME); JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn); X509CertRecord certRecord = jdbcConn.getX509CertRecord("ostk", "instance-id", "cn"); assertNonNullableColumns(now, certRecord); assertEquals(certRecord.getLastNotifiedTime(), now); assertEquals(certRecord.getLastNotifiedServer(), "last-notified-server"); assertEquals(certRecord.getExpiryTime(), now); assertEquals(certRecord.getHostName(), "hostname"); jdbcConn.close(); }