use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateRoleInvalidRoleDomain.
@Test
public void testUpdateRoleInvalidRoleDomain() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Role role = new Role().setName("my-domain2:role.role1");
try {
jdbcConn.updateRole("my-domain", role);
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 testCountEntitiesException.
@Test
public void testCountEntitiesException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// return domain id
Mockito.doReturn(5).when(mockResultSet).getInt(1);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true);
Mockito.when(mockPrepStmt.executeQuery()).thenReturn(mockResultSet).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.countEntities("my-domain");
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 testListRoleAuditLogs.
@Test
public void testListRoleAuditLogs() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.next()).thenReturn(// domain id success
true).thenReturn(// role id success
true).thenReturn(// 2 log entries
true).thenReturn(true).thenReturn(false);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// role id
7);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACTION)).thenReturn("ADD").thenReturn("DELETE");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_MEMBER)).thenReturn("user.member1").thenReturn("user.member2");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ADMIN)).thenReturn("user.admin1").thenReturn("user.admin2");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_AUDIT_REF)).thenReturn("").thenReturn("audit-ref");
Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_CREATED);
List<RoleAuditLog> logs = jdbcConn.listRoleAuditLogs("my-domain", "role1");
assertNotNull(logs);
assertEquals(2, logs.size());
assertEquals("ADD", logs.get(0).getAction());
assertEquals("user.admin1", logs.get(0).getAdmin());
assertEquals("user.member1", logs.get(0).getMember());
assertNull(logs.get(0).getAuditRef());
assertEquals("DELETE", logs.get(1).getAction());
assertEquals("user.admin2", logs.get(1).getAdmin());
assertEquals("user.member2", logs.get(1).getMember());
assertEquals("audit-ref", logs.get(1).getAuditRef());
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateDomainNullFields.
@Test
public void testUpdateDomainNullFields() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Domain domain = new Domain().setName("my-domain").setEnabled(true).setAuditEnabled(false);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.updateDomain(domain);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "");
Mockito.verify(mockPrepStmt, times(1)).setBoolean(4, true);
Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, false);
Mockito.verify(mockPrepStmt, times(1)).setString(6, "");
Mockito.verify(mockPrepStmt, times(1)).setInt(7, 0);
Mockito.verify(mockPrepStmt, times(1)).setString(8, "");
Mockito.verify(mockPrepStmt, times(1)).setString(9, "my-domain");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testAddRoleAssertionsEmptyList.
@Test
public void testAddRoleAssertionsEmptyList() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
List<Assertion> principalAssertions = new ArrayList<>();
jdbcConn.addRoleAssertions(principalAssertions, null, null);
assertEquals(0, principalAssertions.size());
jdbcConn.addRoleAssertions(principalAssertions, new ArrayList<Assertion>(), null);
assertEquals(0, principalAssertions.size());
jdbcConn.close();
}
Aggregations