@Test
public void testGrantPrivilegeWithAllPrivilegeExist() throws Exception {

  String roleName = "r1";
  /**
   * grantor is admin, there is no need to check grant option
   */
  String grantor = ADMIN_USER;
  PrivilegeObject allPrivilege = new Builder()
      .setComponent(SEARCH)
      .setAction(SearchConstants.ALL)
      .setService(SERVICE)
      .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME)))
      .build();
  sentryStore.createRole(SEARCH, roleName, grantor);
  /**
   * grant all privilege to role r1
   */
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, allPrivilege, grantor);
  /**
   * check role r1 truly has the privilege been granted
   */
  assertEquals(Sets.newHashSet(allPrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName)));
  PrivilegeObject queryPrivilege = new Builder(allPrivilege)
      .setAction(SearchConstants.QUERY)
      .build();
  /**
   * grant query privilege to role r1
   */
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName, queryPrivilege, grantor);
  /**
   * all privilege has been existed, the query privilege will not persistent
   */
  assertEquals(Sets.newHashSet(allPrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName)));
}