use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class FileConnectionTest method testUpdateRole.
@Test
public void testUpdateRole() {
File fileDir = new File("/home/athenz/zms_store");
File quotaDir = new File("/home/athenz/zms_quota");
try (FileConnection fileconnection = new FileConnection(fileDir, quotaDir)) {
Role role = new Role();
try {
fileconnection.updateRole("domain1", role);
} catch (Exception ex) {
assertTrue(true);
}
}
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateRole.
@Test
public void testUpdateRole() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Role role = new Role().setName("my-domain:role.role1");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(// role id
4);
boolean requestSuccess = jdbcConn.updateRole("my-domain", role);
assertTrue(requestSuccess);
// get domain id
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
// get role id
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "role1");
// update role
Mockito.verify(mockPrepStmt, times(1)).setString(1, "");
Mockito.verify(mockPrepStmt, times(1)).setInt(2, 4);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class JDBCConnectionTest method testGetRole.
@Test
public void testGetRole() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.doReturn("role1").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_NAME);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_TRUST);
Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Role role = jdbcConn.getRole("my-domain", "role1");
assertNotNull(role);
assertEquals("my-domain:role.role1", role.getName());
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "role1");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateRoleInvalidRoleId.
@Test
public void testUpdateRoleInvalidRoleId() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(false);
// return domain id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5);
Role role = new Role().setName("my-domain:role.role1");
try {
jdbcConn.updateRole("my-domain", role);
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.Role in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateRoleWithTrust.
@Test
public void testUpdateRoleWithTrust() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Role role = new Role().setName("my-domain:role.role1").setTrust("trust_domain");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// role id
7);
boolean requestSuccess = jdbcConn.updateRole("my-domain", role);
assertTrue(requestSuccess);
// get domain id
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
// get role id
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "role1");
// update role
Mockito.verify(mockPrepStmt, times(1)).setString(1, "trust_domain");
Mockito.verify(mockPrepStmt, times(1)).setInt(2, 7);
jdbcConn.close();
}
Aggregations