use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testListModifiedDomainsException.
@Test
public void testListModifiedDomainsException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockPrepStmt.executeQuery()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.listModifiedDomains(1454358900);
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 testInsertEntityException.
@Test
public void testInsertEntityException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Entity entity = new Entity().setName("entity1").setValue(JSON.fromString("{\"value\":1}", Struct.class));
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.doReturn(5).when(mockResultSet).getInt(1);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.insertEntity("my-domain", entity);
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 testListRoleMembers.
@Test
public void testListRoleMembers() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// return domain/role 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 role id
true).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
Mockito.when(mockResultSet.getString(1)).thenReturn("zdomain.user1").thenReturn("adomain.storage").thenReturn("bdomain.user2");
Mockito.when(mockResultSet.getTimestamp(2)).thenReturn(new java.sql.Timestamp(System.currentTimeMillis() + 100)).thenReturn(new java.sql.Timestamp(System.currentTimeMillis() + 200)).thenReturn(null);
List<RoleMember> roleMembers = jdbcConn.listRoleMembers("my-domain", "role1");
// data back is sorted
assertEquals(3, roleMembers.size());
assertNotNull(roleMembers.get(0).getExpiration());
assertNull(roleMembers.get(1).getExpiration());
assertNotNull(roleMembers.get(2).getExpiration());
assertEquals("adomain.storage", roleMembers.get(0).getMemberName());
assertEquals("bdomain.user2", roleMembers.get(1).getMemberName());
assertEquals("zdomain.user1", roleMembers.get(2).getMemberName());
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetRoleMemberNo.
@Test
public void testGetRoleMemberNo() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(// domain id
true).thenReturn(// rold id
true).thenReturn(// not a member
false);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// role id
7);
Membership membership = jdbcConn.getRoleMember("my-domain", "role1", "user.user1");
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "role1");
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 7);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "user.user1");
assertEquals(membership.getMemberName(), "user.user1");
assertEquals(membership.getRoleName(), "my-domain:role.role1");
assertFalse(membership.getIsMember());
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testCountPublicKeysNoResult.
@Test
public void testCountPublicKeysNoResult() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// this one is for domain id
Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(// this one is for service id
true).thenReturn(// no result for count
false);
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(7);
assertEquals(jdbcConn.countPublicKeys("my-domain", "service1"), 0);
jdbcConn.close();
}
Aggregations