Search in sources :

Example 26 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testDeleteServiceHostInvalidDomain.

@Test
public void testDeleteServiceHostInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
    false);
    try {
        jdbcConn.deleteServiceHost("my-domain", "service1", "host1");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 27 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testGetAwsDomains.

@Test
public void testGetAwsDomains() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_NAME)).thenReturn("dom1").thenReturn("dom2").thenReturn("dom3");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACCOUNT)).thenReturn("101").thenReturn("102").thenReturn("103");
    Map<String, String> awsDomains = jdbcConn.getAwsDomains("getAwsDomains");
    assertEquals(3, awsDomains.size());
    assertEquals("101", awsDomains.get("dom1"));
    assertEquals("102", awsDomains.get("dom2"));
    assertEquals("103", awsDomains.get("dom3"));
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 28 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testSqlError.

@Test
public void testSqlError() throws SQLException {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    SQLException ex = new SQLException("sql-reason", "08S01", 9999);
    ResourceException rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.CONFLICT, rEx.getCode());
    ex = new SQLException("sql-reason", "40001", 9999);
    rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.CONFLICT, rEx.getCode());
    ex = new SQLException("sql-reason", "sql-state", 1290);
    rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.GONE, rEx.getCode());
    ex = new SQLException("sql-reason", "sql-state", 1062);
    rEx = (ResourceException) jdbcConn.sqlError(ex, "sqlError");
    assertEquals(ResourceException.BAD_REQUEST, rEx.getCode());
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 29 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testGetEntityDomainNotFound.

@Test
public void testGetEntityDomainNotFound() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(false);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    try {
        jdbcConn.getEntity("my-domain", "entity1");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 30 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testListPolicies.

@Test
public void testListPolicies() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    // return domain id
    Mockito.doReturn(5).when(mockResultSet).getInt(1);
    Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
    true).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    Mockito.when(mockResultSet.getString(1)).thenReturn("zpolicy").thenReturn("apolicy").thenReturn("bpolicy");
    List<String> policies = jdbcConn.listPolicies("my-domain", null);
    // data back is sorted
    assertEquals(3, policies.size());
    assertEquals("apolicy", policies.get(0));
    assertEquals("bpolicy", policies.get(1));
    assertEquals("zpolicy", policies.get(2));
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Aggregations

JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)307 Test (org.testng.annotations.Test)307 ResourceException (com.yahoo.athenz.zms.ResourceException)131 SQLException (java.sql.SQLException)125 Assertion (com.yahoo.athenz.zms.Assertion)16 PrincipalRole (com.yahoo.athenz.zms.PrincipalRole)15 Role (com.yahoo.athenz.zms.Role)14 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)11 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)11 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)11 Domain (com.yahoo.athenz.zms.Domain)10 Entity (com.yahoo.athenz.zms.Entity)8 Quota (com.yahoo.athenz.zms.Quota)8 Policy (com.yahoo.athenz.zms.Policy)7 ResourceAccessList (com.yahoo.athenz.zms.ResourceAccessList)7 ArrayList (java.util.ArrayList)7 RoleMember (com.yahoo.athenz.zms.RoleMember)6 Struct (com.yahoo.rdl.Struct)6 Timestamp (com.yahoo.rdl.Timestamp)6 DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)5