use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testRoleIndex.
@Test
public void testRoleIndex() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
assertEquals("101:role1", jdbcConn.roleIndex("101", "role1"));
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetRolePrincipals.
@Test
public void testGetRolePrincipals() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_NAME)).thenReturn("user.user1").thenReturn("user.user2").thenReturn("user.user3");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_DOMAIN_ID)).thenReturn("101").thenReturn("101").thenReturn("102");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE_NAME)).thenReturn("role1").thenReturn("role1").thenReturn("role3");
Map<String, List<String>> rolePrincipals = jdbcConn.getRolePrincipals(null, false, "user", "getRolePrincipals");
assertEquals(2, rolePrincipals.size());
List<String> principals = rolePrincipals.get("101:role1");
assertEquals(2, principals.size());
assertEquals("user.user1", principals.get(0));
assertEquals("user.user2", principals.get(1));
principals = rolePrincipals.get("102:role3");
assertEquals(1, principals.size());
assertEquals("user.user3", principals.get(0));
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testListPrincipalRolesException.
@Test
public void testListPrincipalRolesException() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockPrepStmt.executeQuery()).thenReturn(mockResultSet).thenThrow(new SQLException("failed operation", "state", 1001));
Mockito.when(mockResultSet.next()).thenReturn(// get principal id
true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// principal id
5);
try {
jdbcConn.listPrincipalRoles("user.joe");
fail();
} catch (Exception ex) {
}
// get principal id
Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.joe");
// get role list
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testInsertHostZeroAffected.
@Test
public void testInsertHostZeroAffected() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockPrepStmt.executeUpdate()).thenReturn(0);
int value = jdbcConn.insertHost("host1");
assertEquals(0, value);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateServiceModTimestampFailure.
@Test
public void testUpdateServiceModTimestampFailure() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.doReturn(0).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// service id
7);
boolean requestSuccess = jdbcConn.updateServiceIdentityModTimestamp("my-domain", "service1");
assertFalse(requestSuccess);
// get domain id
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
// get service id
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
// update service time-stamp
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 7);
jdbcConn.close();
}
Aggregations