Search in sources :

Example 16 with ResourceException

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

the class ZMSUtils method error.

public static RuntimeException error(int code, String msg, String caller) {
    LOG.error("Error: {} code: {} message: {}", caller, code, msg);
    // emit our metrics if configured. the method will automatically
    // return from the caller if caller is null
    emitMonmetricError(code, caller);
    return new ResourceException(code, new ResourceError().code(code).message(msg));
}
Also used : ResourceError(com.yahoo.athenz.zms.ResourceError) ResourceException(com.yahoo.athenz.zms.ResourceException)

Example 17 with ResourceException

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

the class ResourceExceptionTest method testCodeOnly.

@Test
public void testCodeOnly() {
    ResourceException exc = new ResourceException(400);
    assertEquals(exc.getData().toString(), "{code: 400, message: \"Bad Request\"}");
}
Also used : ResourceException(com.yahoo.athenz.zms.ResourceException) Test(org.testng.annotations.Test)

Example 18 with ResourceException

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

the class JDBCConnectionTest method testUpdatePolicyInvalidName.

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

Example 19 with ResourceException

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

the class JDBCConnectionTest method testInsertPolicyInvalidName.

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

Example 20 with ResourceException

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

the class JDBCConnectionTest method testDeleteQuotaInvalidDomain.

@Test
public void testDeleteQuotaInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(false);
    try {
        jdbcConn.deleteQuota("athenz");
        fail();
    } catch (ResourceException ex) {
        assertEquals(404, ex.getCode());
    }
    jdbcConn.close();
}
Also used : 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