@Test
  public void testAuthZFailureLlapCachePurge() throws Exception {
    // using different code blocks so that jdbc variables are not accidentally re-used
    // between the actions. Different connection/statement object should be used for each action.
    {
      Connection hs2Conn = getConnection("user1");
      boolean caughtException = false;
      Statement stmt = hs2Conn.createStatement();
      try {
        stmt.execute("llap cache -purge");
      } catch (SQLException e) {
        caughtException = true;
        String msg = "Error while processing statement: Permission denied: Principal [name=user1, type=USER] does " +
          "not have following privileges for operation LLAP_CACHE_PURGE [[ADMIN PRIVILEGE] on Object " +
          "[type=COMMAND_PARAMS, name=[llap, cache, -purge]], [ADMIN PRIVILEGE] on Object " +
          "[type=SERVICE_NAME, name=localhost]]";
        assertTrue(e.getMessage().contains(msg));
      } finally {
        stmt.close();
        hs2Conn.close();
      }
      assertTrue("Exception expected ", caughtException);
    }
  }
Test SQL standard authorization with jdbc/hiveserver2
itests/hive-unit/src/test/java/org/apache/hive/jdbc/authorization/TestJdbcWithSQLAuthorization.java