@Test
public void testGrantALLPrivilegeWithOtherPrivilegesExist() throws Exception {

  String roleName1 = "r1";
  String roleName2 = "r2";
  /**
   * grantor is admin, there is no need to check grant option
   */
  String grantor = ADMIN_USER;
  PrivilegeObject queryPrivilege = new Builder()
      .setComponent(SEARCH)
      .setAction(SearchConstants.QUERY)
      .setService(SERVICE)
      .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME)))
      .build();
  PrivilegeObject updatePrivilege = new Builder(queryPrivilege)
      .setAction(SearchConstants.UPDATE)
      .build();
  sentryStore.createRole(SEARCH, roleName1, grantor);
  sentryStore.createRole(SEARCH, roleName2, grantor);
  /**
   * grant query and update privilege to role r1 and role r2
   */
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, queryPrivilege, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, updatePrivilege,grantor);
  assertEquals(Sets.newHashSet(queryPrivilege, updatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, queryPrivilege, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, updatePrivilege,grantor);
  assertEquals(Sets.newHashSet(queryPrivilege, updatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2)));
  PrivilegeObject allPrivilege = new Builder(queryPrivilege)
      .setAction(SearchConstants.ALL)
      .build();
  /**
   * grant all privilege to role r1
   */
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, allPrivilege, grantor);
  /**
   * check the query and update privileges of roleName1 will be removed because of ALl privilege
   * granted
   */
  assertEquals(Sets.newHashSet(allPrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
  /**
   * check the query and update privileges of roleName2 will not affected and exist
   */
  assertEquals(Sets.newHashSet(queryPrivilege, updatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2)));
}