Search in sources :

Example 66 with JDBCConnection

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

the class JDBCConnectionTest method testDeletePrincipalSubDomainException.

@Test
public void testDeletePrincipalSubDomainException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockPrepStmt.executeUpdate()).thenReturn(1).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.deletePrincipal("user.jake", true);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.INTERNAL_SERVER_ERROR);
    }
    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 67 with JDBCConnection

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

the class JDBCConnectionTest method testListRoles.

@Test
public void testListRoles() 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("zrole").thenReturn("arole").thenReturn("brole");
    List<String> roles = jdbcConn.listRoles("my-domain");
    // data back is sorted
    assertEquals(3, roles.size());
    assertEquals("arole", roles.get(0));
    assertEquals("brole", roles.get(1));
    assertEquals("zrole", roles.get(2));
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 68 with JDBCConnection

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

the class JDBCConnectionTest method testUpdateDomainModTimestampFailure.

@Test
public void testUpdateDomainModTimestampFailure() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.doReturn(0).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.updateDomainModTimestamp("my-domain");
    assertFalse(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 69 with JDBCConnection

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

the class JDBCConnectionTest method testCountPoliciesInvalidDomain.

@Test
public void testCountPoliciesInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
    false);
    try {
        jdbcConn.countPolicies("my-domain");
    } 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 70 with JDBCConnection

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

the class JDBCConnectionTest method testInsertServiceHostInvalidService.

@Test
public void testInsertServiceHostInvalidService() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
    5);
    Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
    true).thenReturn(// this one is for service id
    false);
    try {
        jdbcConn.insertServiceHost("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)

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