Search in sources :

Example 6 with ResourceException

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

the class JDBCConnectionTest method testUpdateServiceIdentityInvalidName.

@Test
public void testUpdateServiceIdentityInvalidName() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    ServiceIdentity service = new ServiceIdentity().setName("service1");
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    Mockito.when(mockResultSet.next()).thenReturn(true);
    // return domain id
    Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(// service id
    4);
    try {
        jdbcConn.updateServiceIdentity("my-domain", service);
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    jdbcConn.close();
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ResourceException(com.yahoo.athenz.zms.ResourceException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 7 with ResourceException

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

the class ResourceExceptionTest method testGetData.

@Test
public void testGetData() {
    ResourceException exc = new ResourceException(400, "Invalid domain name");
    assertEquals(exc.getData(), "Invalid domain name");
}
Also used : ResourceException(com.yahoo.athenz.zms.ResourceException) Test(org.testng.annotations.Test)

Example 8 with ResourceException

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

the class ResourceExceptionTest method testGetDataCast.

@Test
public void testGetDataCast() {
    ResourceException exc = new ResourceException(400, new Integer(5000));
    assertEquals(exc.getData(Integer.class), new Integer(5000));
}
Also used : ResourceException(com.yahoo.athenz.zms.ResourceException) Test(org.testng.annotations.Test)

Example 9 with ResourceException

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

the class JDBCConnectionTest method testDeletePrincipalDomainException.

@Test
public void testDeletePrincipalDomainException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockPrepStmt.executeUpdate()).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 10 with ResourceException

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

the class JDBCConnectionTest method testCommitException.

@Test
public void testCommitException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, false);
    assertFalse(jdbcConn.transactionCompleted);
    Mockito.verify(mockConn, times(1)).setAutoCommit(false);
    Mockito.doThrow(new SQLException("failed operation", "state", 1001)).when(mockConn).commit();
    try {
        jdbcConn.commitChanges();
        fail();
    } catch (ResourceException ex) {
        assertTrue(jdbcConn.transactionCompleted);
        Mockito.verify(mockConn, times(1)).commit();
    }
    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)

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