use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testInsertX509Record.
@Test
public void testInsertX509Record() throws Exception {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
Date now = new Date();
X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
certRecord.setLastNotifiedTime(now);
certRecord.setLastNotifiedServer("last-notified-server");
certRecord.setExpiryTime(now);
certRecord.setHostName("hostname");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertX509CertRecord(certRecord);
assertTrue(requestSuccess);
verifyInsertNonNullableColumns(now);
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(11, new java.sql.Timestamp(now.getTime()));
Mockito.verify(mockPrepStmt, times(1)).setString(12, "hostname");
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testInsertX509RecordNullableColumns.
@Test
public void testInsertX509RecordNullableColumns() throws Exception {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
Date now = new Date();
X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
certRecord.setLastNotifiedTime(null);
certRecord.setLastNotifiedServer(null);
certRecord.setExpiryTime(null);
certRecord.setHostName(null);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertX509CertRecord(certRecord);
assertTrue(requestSuccess);
verifyInsertNonNullableColumns(now);
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(11, null);
Mockito.verify(mockPrepStmt, times(1)).setString(12, null);
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testInsertX509RecordAlreadyExists.
@Test
public void testInsertX509RecordAlreadyExists() throws Exception {
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
Date now = new Date();
X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
certRecord.setLastNotifiedTime(now);
certRecord.setLastNotifiedServer("last-notified-server");
certRecord.setExpiryTime(now);
certRecord.setHostName("hostname");
Mockito.doThrow(new SQLException("entry already exits", "state", 1062)).doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertX509CertRecord(certRecord);
assertTrue(requestSuccess);
// we should have all operation done once for insert and one for update
Mockito.verify(mockPrepStmt, times(1)).setString(1, "ostk");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "instance-id");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "cn");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "current-serial");
Mockito.verify(mockPrepStmt, times(1)).setString(6, "current-ip");
Mockito.verify(mockPrepStmt, times(1)).setString(7, "prev-serial");
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(8, new java.sql.Timestamp(now.getTime()));
Mockito.verify(mockPrepStmt, times(1)).setString(9, "prev-ip");
Mockito.verify(mockPrepStmt, times(1)).setBoolean(10, false);
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(11, new java.sql.Timestamp(now.getTime()));
Mockito.verify(mockPrepStmt, times(1)).setString(12, "hostname");
Mockito.verify(mockPrepStmt, times(1)).setString(1, "current-serial");
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(2, new java.sql.Timestamp(now.getTime()));
Mockito.verify(mockPrepStmt, times(1)).setString(3, "current-ip");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "prev-serial");
Mockito.verify(mockPrepStmt, times(1)).setString(6, "prev-ip");
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(7, new java.sql.Timestamp(now.getTime()));
Mockito.verify(mockPrepStmt, times(1)).setString(8, "hostname");
Mockito.verify(mockPrepStmt, times(1)).setBoolean(9, false);
Mockito.verify(mockPrepStmt, times(1)).setString(10, "ostk");
Mockito.verify(mockPrepStmt, times(1)).setString(11, "instance-id");
Mockito.verify(mockPrepStmt, times(1)).setString(12, "cn");
// common between insert/update so count is 2 times
Mockito.verify(mockPrepStmt, times(2)).setTimestamp(5, new java.sql.Timestamp(now.getTime()));
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method testGetX509CertRecordNullableColumns.
@Test
public void testGetX509CertRecordNullableColumns() throws Exception {
Date now = new Date();
Mockito.when(mockResultSet.next()).thenReturn(true);
mockNonNullableColumns(now);
Mockito.doReturn(null).when(mockResultSet).getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_TIME);
Mockito.doReturn(null).when(mockResultSet).getString(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_SERVER);
Mockito.doReturn(null).when(mockResultSet).getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_EXPIRY_TIME);
Mockito.doReturn(null).when(mockResultSet).getString(JDBCCertRecordStoreConnection.DB_COLUMN_HOSTNAME);
JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
X509CertRecord certRecord = jdbcConn.getX509CertRecord("ostk", "instance-id", "cn");
assertNonNullableColumns(now, certRecord);
assertNull(certRecord.getLastNotifiedTime());
assertNull(certRecord.getLastNotifiedServer());
assertNull(certRecord.getExpiryTime());
assertNull(certRecord.getHostName());
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class JDBCCertRecordStoreConnectionTest method getRecordWithNonNullableColumns.
private X509CertRecord getRecordWithNonNullableColumns(Date now) {
X509CertRecord certRecord = new X509CertRecord();
certRecord.setService("cn");
certRecord.setProvider("ostk");
certRecord.setInstanceId("instance-id");
certRecord.setCurrentIP("current-ip");
certRecord.setCurrentSerial("current-serial");
certRecord.setCurrentTime(now);
certRecord.setPrevIP("prev-ip");
certRecord.setPrevSerial("prev-serial");
certRecord.setPrevTime(now);
certRecord.setClientCert(false);
return certRecord;
}
Aggregations