use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testPrepareRolePrinciaplsStatementWithPrincipal.
@Test
public void testPrepareRolePrinciaplsStatementWithPrincipal() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
jdbcConn.prepareRolePrincipalsStatement("user.user1", "user", false);
Mockito.verify(mockPrepStmt, times(1)).setString(Matchers.eq(1), Matchers.eq("user.user1"));
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection 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.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testDeleteAssertionException.
@Test
public void testDeleteAssertionException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// policy id
7);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for policy id
true);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.deleteAssertion("my-domain", "policy1", (long) 101);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testListPublicKeys.
@Test
public void testListPublicKeys() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// return domain/service id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(7);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
true).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_KEY_ID)).thenReturn("zms1.zone1").thenReturn("zms2.zone1").thenReturn("zms3.zone1");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_KEY_VALUE)).thenReturn("Value1").thenReturn("Value2").thenReturn("Value3");
List<PublicKeyEntry> publicKeys = jdbcConn.listPublicKeys("my-domain", "service1");
// data back is sorted
assertEquals(3, publicKeys.size());
assertEquals("zms1.zone1", publicKeys.get(0).getId());
assertEquals("Value1", publicKeys.get(0).getKey());
assertEquals("zms2.zone1", publicKeys.get(1).getId());
assertEquals("Value2", publicKeys.get(1).getKey());
assertEquals("zms3.zone1", publicKeys.get(2).getId());
assertEquals("Value3", publicKeys.get(2).getKey());
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetRoleId.
@Test
public void testGetRoleId() throws Exception {
// first time success from mysql, second time failure so
// we can verify we get the value from our cache
Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(false);
Mockito.doReturn(9).when(mockResultSet).getInt(1);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
assertEquals(9, jdbcConn.getRoleId(7, "role1"));
assertEquals(9, jdbcConn.getRoleId(7, "role1"));
jdbcConn.close();
}
Aggregations