@Test
public void testGrantRevokePrivilegeWithShortOption() throws Exception {

  runTestAsSubject(new TestOperation() {
    @Override
    public void runTestAsSubject() throws Exception {
      // create the role for test
      client.createRole(requestorName, TEST_ROLE_NAME_1);
      client.createRole(requestorName, TEST_ROLE_NAME_2);
      // test: grant privilege to role with -gpr
      String[] args = { "-gpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->action=*",
          "-conf", confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->db=db1->action=select", "-conf", confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->db=db1->table=tbl1->action=insert", "-conf",
          confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->db=db1->table=tbl1->column=col1->action=insert", "-conf",
          confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true",
          "-conf", confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      // for the uri privilege, the action will be awalys *
      args = new String[] { "-gpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->uri=hdfs://path/testuri", "-conf", confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      // test the list privilege with -lp
      args = new String[] { "-lp", "-r", TEST_ROLE_NAME_1, "-conf", confPath.getAbsolutePath() };
      SentryShellHive sentryShell = new SentryShellHive();
      Set<String> privilegeStrs = getShellResultWithOSRedirect(sentryShell, args, true);
      // validate the result for -lp
      assertEquals("Incorrect number of privileges", 6, privilegeStrs.size());
      assertTrue(privilegeStrs.contains("server=server1->action=*"));
      assertTrue(privilegeStrs.contains("server=server1->db=db1->action=select"));
      assertTrue(privilegeStrs.contains("server=server1->db=db1->table=tbl1->action=insert"));
      assertTrue(privilegeStrs
          .contains("server=server1->db=db1->table=tbl1->column=col1->action=insert"));
      assertTrue(privilegeStrs
          .contains("server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true"));
      // for the uri privilege, the action will be awalys *
      assertTrue(privilegeStrs.contains("server=server1->uri=hdfs://path/testuri->action=*"));
      // test: revoke privilege from role with -rpr
      args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->db=db1->table=tbl1->column=col1->action=insert", "-conf",
          confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      Set<TSentryPrivilege> privileges = client.listAllPrivilegesByRoleName(requestorName,
          TEST_ROLE_NAME_1);
      assertEquals("Incorrect number of privileges", 5, privileges.size());
      args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->db=db1->table=tbl1->column=col2->action=insert->grantoption=true",
          "-conf", confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1);
      assertEquals("Incorrect number of privileges", 4, privileges.size());
      args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->uri=hdfs://path/testuri", "-conf", confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1);
      assertEquals("Incorrect number of privileges", 3, privileges.size());
      args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->db=db1->table=tbl1->action=insert", "-conf",
          confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1);
      assertEquals("Incorrect number of privileges", 2, privileges.size());
      args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p",
          "server=server1->db=db1->action=select", "-conf", confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1);
      assertEquals("Incorrect number of privileges", 1, privileges.size());
      args = new String[] { "-rpr", "-r", TEST_ROLE_NAME_1, "-p", "server=server1->action=*",
          "-conf",
          confPath.getAbsolutePath() };
      SentryShellHive.main(args);
      privileges = client.listAllPrivilegesByRoleName(requestorName, TEST_ROLE_NAME_1);
      assertEquals("Incorrect number of privileges", 0, privileges.size());
      // clear the test data
      client.dropRole(requestorName, TEST_ROLE_NAME_1);
      client.dropRole(requestorName, TEST_ROLE_NAME_2);
    }
  });
}