@Test
public void testDropPrivilege() throws Exception{

  String roleName1 = "r1";
  String roleName2 = "r2";
  String grantor = ADMIN_USER;
  PrivilegeObject queryPrivilege = new Builder()
      .setComponent(SEARCH)
      .setAction(SearchConstants.QUERY)
      .setService(SERVICE)
      .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME), new Field(FIELD_NAME)))
      .build();
  PrivilegeObject updatePrivilege = new Builder(queryPrivilege)
      .setAction(SearchConstants.UPDATE)
      .build();
  /**
   * grant query and update privilege to role r1 and r2
   */
  sentryStore.createRole(SEARCH, roleName1, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, queryPrivilege, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, updatePrivilege, grantor);
  sentryStore.createRole(SEARCH, roleName2, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, queryPrivilege, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, updatePrivilege, grantor);
  assertEquals(Sets.newHashSet(queryPrivilege,updatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
  assertEquals(Sets.newHashSet(queryPrivilege,updatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2)));
  /**
   * drop query privilege
   */
  sentryStore.dropPrivilege(SEARCH, queryPrivilege, grantor);
  assertEquals(Sets.newHashSet(updatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
  assertEquals(Sets.newHashSet(updatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2)));
  /**
   * drop ALL privilege
   */
  PrivilegeObject allPrivilege = new Builder(queryPrivilege)
      .setAction(SearchConstants.ALL)
      .build();
  sentryStore.dropPrivilege(SEARCH, allPrivilege, grantor);
  assertEquals(Sets.newHashSet(),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
  assertEquals(Sets.newHashSet(),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2)));
  /**
   * grant query and update field scope[collection1,field1] privilege to role r1
   * drop collection scope[collection1] privilege
   * there is no privilege
   */
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, queryPrivilege, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, updatePrivilege, grantor);
  PrivilegeObject parentPrivilege = new Builder()
      .setComponent(SEARCH)
      .setAction(SearchConstants.ALL)
      .setService(SERVICE)
      .setAuthorizables(Arrays.asList(new Collection(COLLECTION_NAME)))
      .build();
  sentryStore.dropPrivilege(SEARCH, parentPrivilege, grantor);
  assertEquals(Sets.newHashSet(),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
}