use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.
the class JDBCConnectionTest method testListResourceAccessNotRegisteredRolePrincipals.
@Test
public void testListResourceAccessNotRegisteredRolePrincipals() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// no role principals
Mockito.when(mockResultSet.next()).thenReturn(false);
try {
jdbcConn.listResourceAccess("user.user1", "update", "user");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.NOT_FOUND, ex.getCode());
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ResourceException 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();
}
use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.
the class JDBCConnectionTest method testListPrincipalRolesInvalidPrincipal.
@Test
public void testListPrincipalRolesInvalidPrincipal() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockPrepStmt.executeQuery()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.listPrincipalRoles("user.joe");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ResourceException 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();
}
use of com.yahoo.athenz.zms.ResourceException in project athenz by yahoo.
the class JDBCConnectionTest method testInsertRoleMemberNewPrincipalFailure.
@Test
public void testInsertRoleMemberNewPrincipalFailure() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// role id
7).thenReturn(// principal domain id
8).thenReturn(// principal id
9);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for role id
true).thenReturn(// this one is for valid principal domain
true).thenReturn(// principal does not exist
false);
// principal add returns 0
Mockito.doReturn(0).when(mockPrepStmt).executeUpdate();
try {
jdbcConn.insertRoleMember("my-domain", "role1", new RoleMember().setMemberName("user.user1"), "user.admin", "audit-ref");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 500);
}
jdbcConn.close();
}
Aggregations