client.grantTablePrivilege(requestorUserName, roleName2, "server", "db1", "table2", "ALL");
client.grantTablePrivilege(requestorUserName, roleName2, "server", "db2", "table3", "ALL");
client.grantTablePrivilege(requestorUserName, roleName2, "server", "db2", "table4", "ALL");
client.grantTablePrivilege(requestorUserName, roleName2, "server", "db3", "table5", "ALL");
Set<TSentryPrivilege> listPrivilegesByRoleName = client.listPrivilegesByRoleName(requestorUserName, roleName2, Lists.newArrayList(new Server("server"), new Database("db1")));
assertEquals("Privilege not assigned to role2 !!", 2, listPrivilegesByRoleName.size());
listPrivilegesByRoleName = client.listPrivilegesByRoleName(requestorUserName, roleName2, Lists.newArrayList(new Server("server"), new Database("db2"), new Table("table1")));
assertEquals("Privilege not assigned to role2 !!", 0, listPrivilegesByRoleName.size());
listPrivilegesByRoleName = client.listPrivilegesByRoleName(requestorUserName, roleName2, Lists.newArrayList(new Server("server"), new Database("db1"), new Table("table1")));
assertEquals("Privilege not assigned to role2 !!", 1, listPrivilegesByRoleName.size());
listPrivilegesByRoleName = client.listPrivilegesByRoleName(requestorUserName, roleName2, Lists.newArrayList(new Server("server"), new Database("db3")));
assertEquals("Privilege not assigned to role2 !!", 1, listPrivilegesByRoleName.size());
Set<String> listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), ActiveRoleSet.ALL, new Server("server"), new Database("db2"));
Assert.assertEquals("Privilege not correctly assigned to roles !!",
Sets.newHashSet("server=server->db=db2->table=table4->action=ALL", "server=server->db=db2->table=table3->action=ALL"),
listPrivilegesForProvider);
listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), ActiveRoleSet.ALL, new Server("server"), new Database("db3"));
Assert.assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=server->db=db3->table=table5->action=ALL"), listPrivilegesForProvider);
listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), new ActiveRoleSet(Sets.newHashSet(roleName1)), new Server("server"), new Database("db3"));
Assert.assertEquals("Privilege not correctly assigned to roles !!", Sets.newHashSet("server=+"), listPrivilegesForProvider);
listPrivilegesForProvider = client.listPrivilegesForProvider(Sets.newHashSet(group1, group2), new ActiveRoleSet(Sets.newHashSet(roleName1)), new Server("server1"));
Assert.assertEquals("Privilege not correctly assigned to roles !!", new HashSet<String>(), listPrivilegesForProvider);
}