@Test
public void testRenamePrivilege() throws Exception{

  String roleName1 = "r1";
  String roleName2 = "r2";
  String grantor = ADMIN_USER;
  List<? extends Authorizable> oldAuthoriables = Arrays.asList(new Collection(COLLECTION_NAME), new Field(FIELD_NAME));
  List<? extends Authorizable> newAuthoriables = Arrays.asList(new Collection(COLLECTION_NAME), new Field(NOT_FIELD_NAME));
  PrivilegeObject oldQueryPrivilege = new Builder()
      .setComponent(SEARCH)
      .setAction(SearchConstants.QUERY)
      .setService(SERVICE)
      .setAuthorizables(oldAuthoriables)
      .build();
  PrivilegeObject oldUpdatePrivilege = new Builder(oldQueryPrivilege)
      .setAction(SearchConstants.UPDATE)
      .build();
  PrivilegeObject oldALLPrivilege = new Builder(oldQueryPrivilege)
      .setAction(SearchConstants.ALL)
      .build();
  PrivilegeObject newQueryPrivilege = new Builder()
      .setComponent(SEARCH)
      .setAction(SearchConstants.QUERY)
      .setService(SERVICE)
      .setAuthorizables(newAuthoriables)
      .build();
  PrivilegeObject newUpdatePrivilege = new Builder(newQueryPrivilege)
      .setAction(SearchConstants.UPDATE)
      .build();
  PrivilegeObject newALLPrivilege = new Builder(newQueryPrivilege)
      .setAction(SearchConstants.ALL)
      .build();
  /**
   * grant query and update privilege to role r1
   * grant all privilege to role r2
   */
  sentryStore.createRole(SEARCH, roleName1, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, oldQueryPrivilege, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName1, oldUpdatePrivilege, grantor);
  sentryStore.createRole(SEARCH, roleName2, grantor);
  sentryStore.alterRoleGrantPrivilege(SEARCH, roleName2, oldALLPrivilege, grantor);
  assertEquals(Sets.newHashSet(oldQueryPrivilege,oldUpdatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
  assertEquals(Sets.newHashSet(oldALLPrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2)));
  /**
   * rename old query privilege to new query privilege
   */
  sentryStore.renamePrivilege(SEARCH, SERVICE,
                                    oldAuthoriables,
                                    newAuthoriables,
                                    grantor);
  assertEquals(Sets.newHashSet(newQueryPrivilege,newUpdatePrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
  assertEquals(Sets.newHashSet(newALLPrivilege),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2)));
  /**
   * rename collection scope[collection=collection1] privilege to [collection=not_collection1]
   * These privileges belong to collection scope[collection=collection1] will change to
   * [collection=not_collection1]
   */
  List<? extends Authorizable> newAuthoriables1 = Arrays.asList(new Collection(NOT_COLLECTION_NAME),new Field(NOT_FIELD_NAME));
  PrivilegeObject newQueryPrivilege1 = new Builder(newQueryPrivilege)
        .setAuthorizables(newAuthoriables1)
        .build();
  PrivilegeObject newUpdatePrivilege1 = new Builder(newUpdatePrivilege)
        .setAuthorizables(newAuthoriables1)
        .build();
  PrivilegeObject newALLPrivilege1 = new Builder(newALLPrivilege)
        .setAuthorizables(newAuthoriables1)
        .build();
  sentryStore.renamePrivilege(SEARCH, SERVICE,
      Arrays.asList(new Collection(COLLECTION_NAME)),
      Arrays.asList(new Collection(NOT_COLLECTION_NAME)),
      grantor);
  assertEquals(Sets.newHashSet(newQueryPrivilege1,newUpdatePrivilege1),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName1)));
  assertEquals(Sets.newHashSet(newALLPrivilege1),
      sentryStore.getPrivilegesByRole(SEARCH, Sets.newHashSet(roleName2)));
}