Search in sources :

Example 11 with ResourceException

use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.

the class JDBCConnectionTest method testListRoleAuditLogsException.

@Test
public void testListRoleAuditLogsException() throws SQLException {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(// domain id success
    true).thenReturn(// role id success
    true);
    Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
    5).thenReturn(// role id
    7);
    Mockito.when(mockPrepStmt.executeQuery()).thenReturn(mockResultSet).thenReturn(mockResultSet).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.listRoleAuditLogs("my-domain", "role1");
        fail();
    } catch (ResourceException ex) {
        assertEquals(500, ex.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 12 with ResourceException

use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.

the class JDBCConnectionTest method testListPrincipalsException.

@Test
public void testListPrincipalsException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockPrepStmt.executeQuery()).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.listPrincipals("user");
        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 13 with ResourceException

use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.

the class JDBCConnectionTest method testVerifyDomainProductIdUniquenessFail.

@Test
public void testVerifyDomainProductIdUniquenessFail() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(false);
    Mockito.doReturn("iaas.athenz.ci").when(mockResultSet).getString(1);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    try {
        jdbcConn.verifyDomainProductIdUniqueness("iaas.athenz", Integer.valueOf(1001), "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
        assertTrue(ex.getMessage().contains("iaas.athenz.ci"));
    }
    jdbcConn.close();
}
Also used : ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 14 with ResourceException

use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.

the class JDBCConnectionTest method testGetRoleException.

@Test
public void testGetRoleException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockPrepStmt.executeQuery()).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.getRole("my-domain", "role1");
        fail();
    } catch (ResourceException ex) {
        assertEquals(500, ex.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 15 with ResourceException

use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.

the class JDBCConnectionTest method testUpdateQuotaInvalidDomain.

@Test
public void testUpdateQuotaInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Quota quota = new Quota().setName("athenz").setAssertion(10).setEntity(11).setPolicy(12).setPublicKey(13).setRole(14).setRoleMember(15).setService(16).setServiceHost(17).setSubdomain(18);
    Mockito.when(mockResultSet.next()).thenReturn(false);
    try {
        jdbcConn.updateQuota("athenz", quota);
        fail();
    } catch (ResourceException ex) {
        assertEquals(404, ex.getCode());
    }
    jdbcConn.close();
}
Also used : Quota(com.yahoo.athenz.zms.Quota) ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Aggregations

ResourceException (com.yahoo.athenz.zms.ResourceException)23 Test (org.testng.annotations.Test)22 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)19 SQLException (java.sql.SQLException)8 Policy (com.yahoo.athenz.zms.Policy)2 Quota (com.yahoo.athenz.zms.Quota)2 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)2 ResourceError (com.yahoo.athenz.zms.ResourceError)1 RoleMember (com.yahoo.athenz.zms.RoleMember)1