Search in sources :

Example 26 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCCertRecordStoreTest method testGetConnectionException.

@Test
public void testGetConnectionException() throws SQLException {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    Mockito.doThrow(new SQLException()).when(mockDataSrc).getConnection();
    try {
        JDBCCertRecordStore store = new JDBCCertRecordStore(mockDataSrc);
        store.getConnection();
        fail();
    } catch (RuntimeException ex) {
        assertTrue(true);
    }
}
Also used : SQLException(java.sql.SQLException) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 27 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCCertRecordStoreTest method testGetConnection.

@Test
public void testGetConnection() throws SQLException {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    Connection mockConn = Mockito.mock(Connection.class);
    Mockito.doReturn(mockConn).when(mockDataSrc).getConnection();
    JDBCCertRecordStore store = new JDBCCertRecordStore(mockDataSrc);
    assertNotNull(store.getConnection());
    store.clearConnections();
}
Also used : Connection(java.sql.Connection) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 28 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCSSHRecordStoreTest method testGetConnectionException.

@Test
public void testGetConnectionException() throws SQLException {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    Mockito.doThrow(new SQLException()).when(mockDataSrc).getConnection();
    try {
        JDBCSSHRecordStore store = new JDBCSSHRecordStore(mockDataSrc);
        store.getConnection();
        fail();
    } catch (RuntimeException ex) {
        assertTrue(true);
    }
}
Also used : SQLException(java.sql.SQLException) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Test(org.testng.annotations.Test)

Example 29 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCSSHRecordStoreTest method testLog.

@Test
public void testLog() {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    JDBCSSHRecordStore store = new JDBCSSHRecordStore(mockDataSrc);
    Principal principal = SimplePrincipal.create("user", "joe", "creds");
    // make sure no exceptions are thrown when processing log request
    store.log(principal, "10.11.12.13", "athenz.api", "1234");
}
Also used : PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) Principal(com.yahoo.athenz.auth.Principal) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Test(org.testng.annotations.Test)

Example 30 with PoolableDataSource

use of com.yahoo.athenz.common.server.db.PoolableDataSource in project athenz by yahoo.

the class JDBCSSHRecordStoreTest method testEnableNotifications.

@Test
public void testEnableNotifications() {
    PoolableDataSource mockDataSrc = Mockito.mock(PoolableDataSource.class);
    JDBCSSHRecordStore store = new JDBCSSHRecordStore(mockDataSrc);
    boolean isEnabled = store.enableNotifications(null, null, null);
    assertFalse(isEnabled);
    NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
    String serverName = "testServer";
    isEnabled = store.enableNotifications(notificationManager, rolesProvider, serverName);
    // Not supported for FileCertStore even if all dependencies provided
    assertFalse(isEnabled);
}
Also used : NotificationManager(com.yahoo.athenz.common.server.notification.NotificationManager) PoolableDataSource(com.yahoo.athenz.common.server.db.PoolableDataSource) RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Aggregations

PoolableDataSource (com.yahoo.athenz.common.server.db.PoolableDataSource)30 Test (org.testng.annotations.Test)22 Connection (java.sql.Connection)11 JDBCObjectStore (com.yahoo.athenz.zms.store.impl.jdbc.JDBCObjectStore)7 SQLException (java.sql.SQLException)7 JDBCObjectStore (com.yahoo.athenz.zms.store.jdbc.JDBCObjectStore)5 Properties (java.util.Properties)4 Principal (com.yahoo.athenz.auth.Principal)2 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)2 RolesProvider (com.yahoo.athenz.common.server.db.RolesProvider)2 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)2 ResourceException (com.yahoo.athenz.zms.ResourceException)2 File (java.io.File)1 IOException (java.io.IOException)1 X509Certificate (java.security.cert.X509Certificate)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1