You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by pr...@apache.org on 2014/06/13 08:52:18 UTC

[2/2] git commit: SENTRY-293: Create a new mvn cluster test profile for provider db tests (Sravya Tirukkovalur via Prasad Mujumdar)

SENTRY-293: Create a new mvn cluster test profile for provider db tests (Sravya Tirukkovalur via Prasad Mujumdar)


Project: http://git-wip-us.apache.org/repos/asf/incubator-sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-sentry/commit/c5393407
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/c5393407
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/c5393407

Branch: refs/heads/master
Commit: c53934070c07d337118c53eb0b19d6675202d26f
Parents: b087172
Author: Prasad Mujumdar <pr...@cloudera.com>
Authored: Thu Jun 12 23:51:51 2014 -0700
Committer: Prasad Mujumdar <pr...@cloudera.com>
Committed: Thu Jun 12 23:51:51 2014 -0700

----------------------------------------------------------------------
 .../apache/sentry/provider/file/PolicyFile.java |   6 +
 sentry-tests/sentry-tests-hive/pom.xml          |  63 ++++++
 .../e2e/dbprovider/PolicyProviderForTest.java   | 157 ---------------
 .../e2e/dbprovider/TestDatabaseProvider.java    |  97 +++++++++-
 .../tests/e2e/dbprovider/TestDbCrossDbOps.java  |  11 +-
 .../tests/e2e/dbprovider/TestDbEndToEnd.java    |  15 +-
 .../TestDbExportImportPrivileges.java           |   9 +-
 .../TestDbMetadataObjectRetrieval.java          |  10 +-
 .../dbprovider/TestDbMetadataPermissions.java   |  10 +-
 .../dbprovider/TestDbMovingToProduction.java    |  10 +-
 .../dbprovider/TestDbPrivilegeAtTransform.java  |  10 +-
 .../TestDbPrivilegesAtDatabaseScope.java        |  10 +-
 .../TestDbPrivilegesAtFunctionScope.java        |  10 +-
 .../TestDbPrivilegesAtTableScope.java           |  10 +-
 .../TestDbRuntimeMetadataRetrieval.java         |  10 +-
 .../tests/e2e/dbprovider/TestDbSandboxOps.java  |  11 +-
 .../e2e/dbprovider/TestDbUriPermissions.java    |  10 +-
 .../e2e/dbprovider/TestDbUserManagement.java    |  31 ---
 .../AbstractTestWithStaticConfiguration.java    | 194 ++++++++++++++++---
 .../sentry/tests/e2e/hive/TestConfigTool.java   |   8 -
 .../sentry/tests/e2e/hive/TestCrossDbOps.java   |  15 +-
 .../sentry/tests/e2e/hive/TestEndToEnd.java     |   9 -
 .../e2e/hive/TestExportImportPrivileges.java    |  15 +-
 .../e2e/hive/TestMetadataObjectRetrieval.java   |  15 +-
 .../tests/e2e/hive/TestMetadataPermissions.java |  16 +-
 .../tests/e2e/hive/TestMovingToProduction.java  |  23 +--
 .../tests/e2e/hive/TestPerDBConfiguration.java  |   6 +-
 .../e2e/hive/TestPerDatabasePolicyFile.java     |  10 +-
 .../e2e/hive/TestPrivilegeAtTransform.java      |  12 +-
 .../e2e/hive/TestPrivilegesAtDatabaseScope.java |  16 +-
 .../e2e/hive/TestPrivilegesAtFunctionScope.java |  15 +-
 .../e2e/hive/TestPrivilegesAtTableScope.java    |  16 +-
 .../e2e/hive/TestRuntimeMetadataRetrieval.java  |  17 +-
 .../sentry/tests/e2e/hive/TestSandboxOps.java   |  14 +-
 .../tests/e2e/hive/TestUriPermissions.java      |  21 +-
 .../tests/e2e/hive/TestUserManagement.java      |  35 ++--
 .../sentry/tests/e2e/hive/fs/ClusterDFS.java    |   1 +
 .../e2e/hive/hiveserver/HiveServerFactory.java  |   1 +
 .../hive/hiveserver/UnmanagedHiveServer.java    |   1 +
 ...actMetastoreTestWithStaticConfiguration.java |   3 -
 .../e2e/metastore/TestMetaStoreWithPigHCat.java |   7 +-
 .../e2e/metastore/TestMetastoreEndToEnd.java    |   7 +-
 .../src/test/resources/core-site.xml            |  33 ----
 43 files changed, 501 insertions(+), 499 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
----------------------------------------------------------------------
diff --git a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
index ceeb653..f479ac7 100644
--- a/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
+++ b/sentry-provider/sentry-provider-file/src/main/java/org/apache/sentry/provider/file/PolicyFile.java
@@ -61,6 +61,12 @@ public class PolicyFile {
   protected final Multimap<String, String> rolesToPermissions = ArrayListMultimap
       .create();
 
+  public Multimap<String, String> getGroupsToRoles() {
+    return groupsToRoles;
+  }
+  public Multimap<String, String> getRolesToPermissions() {
+    return rolesToPermissions;
+  }
   public PolicyFile addRolesToGroup(String groupName, String... roleNames)
       throws Exception {
     return addRolesToGroup(groupName, false, roleNames);

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/pom.xml
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/pom.xml b/sentry-tests/sentry-tests-hive/pom.xml
index cd95252..96ff006 100644
--- a/sentry-tests/sentry-tests-hive/pom.xml
+++ b/sentry-tests/sentry-tests-hive/pom.xml
@@ -449,5 +449,68 @@ limitations under the License.
       </plugins>
      </build>
    </profile>
+   <profile>
+     <id>cluster-hadoop-provider-db</id>
+     <build>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-enforcer-plugin</artifactId>
+          <version>1.0</version>
+          <executions>
+            <execution>
+              <id>enforce-property</id>
+              <goals>
+                <goal>enforce</goal>
+              </goals>
+              <configuration>
+                <rules>
+                  <requireProperty>
+                    <property>HADOOP_CONF_DIR</property>
+                    <message>HADOOP_CONF_DIR env. variable has to be set</message>
+                  </requireProperty>
+                  <requireProperty>
+                    <property>HIVE_CONF_DIR</property>
+                    <message>HIVE_CONF_DIR env. variable has to be set</message>
+                  </requireProperty>
+                </rules>
+                <fail>true</fail>
+              </configuration>
+            </execution>
+          </executions>
+        </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <systemPropertyVariables>
+            <buildDirectory>${project.build.directory}</buildDirectory>
+          </systemPropertyVariables>
+        <additionalClasspathElements>
+          <additionalClasspathElement>${HIVE_CONF_DIR}</additionalClasspathElement>
+          <additionalClasspathElement>${HADOOP_CONF_DIR}</additionalClasspathElement>
+        </additionalClasspathElements>
+        <includes>
+          <include>**/TestDbCrossDbOps.java</include>
+          <include>**/TestDbEndToEnd.java</include>
+          <include>**/TestDbMetadataObjectRetrieval.java</include>
+          <include>**/TestDbMetadataPermissions.java</include>
+          <include>**/TestDbMovingToProduction.java</include>
+          <include>**/TestDbPerDatabasePolicyFile.java</include>
+          <include>**/TestDbPrivilegeAtTransform.java</include>
+          <include>**/TestDbPrivilegesAtDatabaseScope.java</include>
+          <include>**/TestDbPrivilegesAtTableScope.java</include>
+          <include>**/TestDbSandboxOps.java</include>
+          <include>**/TestDbExportImportPrivileges.java</include>
+          <include>**/TestDbUriPermissions.java</include>
+          <include>**/TestDbRuntimeMetadataRetrieval.java</include>
+          <include>**/TestDbPrivilegesAtFunctionScope.java</include>
+        </includes>
+        <argLine>-Dsentry.e2etest.hiveServer2Type=UnmanagedHiveServer2 -Dsentry.e2etest.DFSType=ClusterDFS -Dsentry.e2etest.external.sentry=true</argLine>
+       </configuration>
+      </plugin>
+      </plugins>
+     </build>
+   </profile>
   </profiles>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/PolicyProviderForTest.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/PolicyProviderForTest.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/PolicyProviderForTest.java
deleted file mode 100644
index 47ce66d..0000000
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/PolicyProviderForTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sentry.tests.e2e.dbprovider;
-
-import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_SPLITTER;
-import static org.apache.sentry.provider.common.ProviderConstants.PRIVILEGE_PREFIX;
-import static org.apache.sentry.provider.common.ProviderConstants.ROLE_SPLITTER;
-import static org.apache.sentry.tests.e2e.hive.StaticUserGroup.ADMIN1;
-import static org.apache.sentry.tests.e2e.hive.StaticUserGroup.ADMINGROUP;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.apache.sentry.SentryUserException;
-import org.apache.sentry.core.model.db.AccessConstants;
-import org.apache.sentry.core.model.db.DBModelAction;
-import org.apache.sentry.core.model.db.DBModelAuthorizable;
-import org.apache.sentry.core.model.db.DBModelAuthorizable.AuthorizableType;
-import org.apache.sentry.policy.db.DBModelAuthorizables;
-import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient;
-import org.apache.sentry.provider.db.service.thrift.TSentryRole;
-import org.apache.sentry.provider.file.PolicyFile;
-import org.apache.tools.ant.util.StringUtils;
-import org.mortbay.log.Log;
-
-import com.google.common.collect.Sets;
-
-public class PolicyProviderForTest extends PolicyFile {
-  protected static final Set<String> ADMIN_GROUP_SET = Sets
-      .newHashSet(ADMINGROUP);
-  private static SentryPolicyServiceClient sentryClient;
-
-  protected SentryPolicyServiceClient getSentryClient() {
-    return sentryClient;
-  }
-
-  public static void setSentryClient(
-      SentryPolicyServiceClient newSentryClient) {
-    sentryClient = newSentryClient;
-  }
-
-  public static void clearSentryClient() {
-    sentryClient = null;
-  }
-
-  public static PolicyProviderForTest setAdminOnServer1(String admin)
-      throws Exception {
-    PolicyProviderForTest policyFile = new PolicyProviderForTest();
-    policyFile.addRolesToGroup(admin, "admin_role")
-        .addPermissionsToRole("admin_role", "server=server1");
-    return policyFile;
-  }
-
-  public void write(File file) throws Exception {
-    super.write(file);
-    if (!usingSentryService()) {
-      return;
-    }
-
-    // remove existing metadata
-    for (TSentryRole tRole : sentryClient.listRoles(ADMIN1)) {
-      sentryClient.dropRole(ADMIN1, tRole.getRoleName());
-    }
-
-    // create roles and add privileges
-    for (Entry<String, Collection<String>> roleEntry : rolesToPermissions
-        .asMap().entrySet()) {
-      sentryClient.createRole(ADMIN1, roleEntry.getKey());
-      for (String privilege : roleEntry.getValue()) {
-        addPrivilege(roleEntry.getKey(), privilege);
-      }
-    }
-
-    // grant roles to groups
-    for (Entry<String, Collection<String>> groupEntry : groupsToRoles.asMap()
-        .entrySet()) {
-      for (String roleNames : groupEntry.getValue()) {
-        for (String roleName : roleNames.split(",")) {
-          try {
-            sentryClient
-                .grantRoleToGroup(ADMIN1, groupEntry.getKey(), roleName);
-          } catch (SentryUserException e) {
-            Log.warn("Error granting role " + roleName + " to group "
-                + groupEntry.getKey());
-          }
-        }
-      }
-    }
-  }
-
-  private void addPrivilege(String roleName, String privileges) throws Exception {
-    String serverName = null, dbName = null, tableName = null, uriPath = null;
-    String action = AccessConstants.ALL;
-    for (String privilege : ROLE_SPLITTER.split(privileges)) {
-      for(String section : AUTHORIZABLE_SPLITTER.split(privilege)) {
-        // action is not an authorizeable
-        if(!section.toLowerCase().startsWith(PRIVILEGE_PREFIX)) {
-          DBModelAuthorizable dbAuthorizable = DBModelAuthorizables.from(section);
-          if(dbAuthorizable == null) {
-            throw new IOException("Unknow Auth type " + section);
-          }
-
-          if (AuthorizableType.Server.equals(dbAuthorizable.getAuthzType())) {
-            serverName = dbAuthorizable.getName();
-          } else if (AuthorizableType.Db.equals(dbAuthorizable.getAuthzType())) {
-            dbName = dbAuthorizable.getName();
-          } else if (AuthorizableType.Table.equals(dbAuthorizable.getAuthzType())) {
-            tableName = dbAuthorizable.getName();
-          } else if (AuthorizableType.URI.equals(dbAuthorizable.getAuthzType())) {
-            uriPath = dbAuthorizable.getName();
-          } else {
-            throw new IOException("Unsupported auth type " + dbAuthorizable.getName()
-                + " : " + dbAuthorizable.getTypeName());
-          }
-        } else {
-          action = DBModelAction.valueOf(
-              StringUtils.removePrefix(section, PRIVILEGE_PREFIX).toUpperCase())
-              .toString();
-        }
-      }
-
-      if (tableName != null) {
-        sentryClient.grantTablePrivilege(ADMIN1, roleName, serverName, dbName,
-            tableName, action);
-      } else if (dbName != null) {
-        sentryClient.grantDatabasePrivilege(ADMIN1, roleName, serverName, dbName);
-      } else if (uriPath != null) {
-        sentryClient.grantURIPrivilege(ADMIN1, roleName, serverName, uriPath);
-      } else if (serverName != null) {
-        sentryClient.grantServerPrivilege(ADMIN1, roleName, serverName);
-        ;
-      }
-    }
-
-  }
-
-  private boolean usingSentryService() {
-    return sentryClient != null;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
index 44f41be..6187692 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDatabaseProvider.java
@@ -20,8 +20,10 @@ package org.apache.sentry.tests.e2e.dbprovider;
 import org.apache.sentry.provider.db.SentryAccessDeniedException;
 import org.apache.sentry.provider.db.SentryAlreadyExistsException;
 import org.apache.sentry.provider.db.SentryNoSuchObjectException;
+import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import static org.hamcrest.Matchers.equalToIgnoringCase;
 import static org.hamcrest.Matchers.is;
+import org.junit.After;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
@@ -30,24 +32,52 @@ import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 
-public class TestDatabaseProvider extends AbstractTestWithDbProvider {
+public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
 
-  @Before
-  public void setup() throws Exception {
-    createContext();
+  @BeforeClass
+  public static void setupTestStaticConfiguration() throws Exception{
+    useSentryService = true;
+    AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
   }
 
   /**
    * This test is only used for manual testing of beeline with Sentry Service
    * @throws Exception
    */
+  @Override
+  @After
+  public void clearDB() throws Exception {
+    Connection connection;
+    Statement statement;
+    connection = context.createConnection(ADMIN1);
+    statement = context.createStatement(connection);
+    ResultSet resultSet;
+    resultSet = statement.executeQuery("SHOW roles");
+    List<String> roles = new ArrayList<String>();
+    while ( resultSet.next()) {
+      roles.add(resultSet.getString(1));
+    }
+    for(String role:roles) {
+      statement.execute("DROP Role " + role);
+    }
+
+    statement.close();
+    connection.close();
+    if (context != null) {
+      context.close();
+    }
+  }
+
   @Ignore
   @Test
   public void beelineTest() throws Exception{
@@ -90,7 +120,16 @@ public class TestDatabaseProvider extends AbstractTestWithDbProvider {
   /**
    * Grant/Revoke privilege - Positive cases
    * @throws Exception
-   */
+    1.1. All on server
+    1.2. All on database
+    1.3. All on URI
+    1.4. All on table
+    1.5. Insert on table
+    1.6. Select on table
+    1.7. Partial privileges on table
+    1.7.1. Grant all, revoke insert leads to select on table
+    1.7.2. Grant all, revoke select leads to select on table
+     */
   @Test
   public void testGrantRevokePrivileges() throws Exception {
     Connection connection;
@@ -274,7 +313,6 @@ public class TestDatabaseProvider extends AbstractTestWithDbProvider {
       assertThat(resultSet.getString(10), equalToIgnoringCase(ADMIN1));//grantor
 
     }
-
     statement.close();
     connection.close();
   }
@@ -306,6 +344,22 @@ public class TestDatabaseProvider extends AbstractTestWithDbProvider {
   /**
    * Corner cases
    * @throws Exception
+    7.1. Drop role which doesn't exist, throws SentryNoSuchObjectException
+    7.2. Create role which already exists, throws SentryAlreadyExitsException
+    7.3. Drop role when privileges mapping exists and create role with same name, old
+    mappings should not exist
+    7.4. Grant role, when role doesn't exist, throws SentryNoSuchObjectException
+    7.5. Grant role when mapping exists, silently allows
+    7.6. Grant multiple roles to a group
+    7.7. Revoke role after role has been dropped, SentryNoSuchObjectException
+    7.8. Revoke role from a group when mapping doesn't exist, silently allows
+    7.9. Grant privilege to a role, privilege already exists, silently allows
+    7.10. Grant privilege to a role, mapping already exists, silently allows
+    7.11. Multiple privileges to a role
+    7.12. Revoke privilege when privilege doesn't exist, silently allows
+    7.13. Revoke privilege, when role doesn't exist, SentryNoSuchObjectException
+    7.14. Revoke privilege when mapping doesn't exist, silently allows
+    7.15. Drop role should remove role-group mapping
    */
   @Test
   public void testCornerCases() throws Exception {
@@ -409,10 +463,20 @@ public class TestDatabaseProvider extends AbstractTestWithDbProvider {
     statement.execute("REVOKE ALL on TABLE tab1 from Role role1");
     resultSet = statement.executeQuery("SHOW GRANT ROLE role1");
     assertResultSize(resultSet, 1);
+    statement.execute("DROP role role2");
+
+    //Drop role should remove role-group mapping
+    //state: role1 -> grant all on server
+    statement.execute("GRANT ROLE role1 to GROUP " + USERGROUP1);
+    statement.execute("DROP ROLE role1");
+    resultSet = statement.executeQuery("SHOW ROLE GRANT GROUP " + USERGROUP1);
+    assertResultSize(resultSet, 0);
   }
   /**
    * SHOW ROLES
    * @throws Exception
+   3.1. When there are no roles, returns empty list
+   3.2. When there are roles, returns correct list with correct schema.
    */
   @Test
   public void testShowRoles() throws Exception {
@@ -441,13 +505,17 @@ public class TestDatabaseProvider extends AbstractTestWithDbProvider {
   /**
    * SHOW ROLE GRANT GROUP groupName
    * @throws Exception
+   4.1. When there are no roles and group, throws SentryNoSuchObjectException
+   4.2. When there are roles, returns correct list with correct schema.
    */
   @Test
   public void testShowRolesByGroup() throws Exception {
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    context.assertSentryException(statement,"SHOW ROLE GRANT GROUP " + ADMINGROUP,
-        SentryNoSuchObjectException.class.getSimpleName());
+    //This is non deterministic as we are now using same sentry service across the tests
+    // and orphan groups are not cleaned up.
+    //context.assertSentryException(statement,"SHOW ROLE GRANT GROUP " + ADMINGROUP,
+    //    SentryNoSuchObjectException.class.getSimpleName());
     statement.execute("CREATE ROLE role1");
     statement.execute("CREATE ROLE role2");
     statement.execute("CREATE ROLE role3");
@@ -474,7 +542,18 @@ public class TestDatabaseProvider extends AbstractTestWithDbProvider {
   /**
    * SHOW GRANT ROLE roleName
    * @throws Exception
-   */
+    5.1. When there are no privileges granted to a role, returns an empty list
+    5.2. When there are privileges, returns correct list with correct schema.
+    5.3. Given privileges on table, show grant on table should return table privilege.
+    5.4. Privileges on database
+    5.4.1. Show grant on database should return correct priv
+    5.4.2. Show grant on table should return correct priv
+    5.5. Privileges on server
+    5.5.1. Show grant on database should return correct priv
+    5.5.2. Show grant on table should return correct priv
+    5.5.3. Show grant on server should return correct priv (sql not supported yet in hive)
+    5.6. Show grant on uri (sql not supported yet in hive)
+  */
   @Test
   public void testShowPrivilegesByRole() throws Exception {
     Connection connection = context.createConnection(ADMIN1);

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossDbOps.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossDbOps.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossDbOps.java
index 6411e2b..719dddf 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossDbOps.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbCrossDbOps.java
@@ -19,18 +19,23 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestCrossDbOps;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 /* Tests privileges at table scope with cross database access */
 
 public class TestDbCrossDbOps extends TestCrossDbOps {
 
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception{
-    policy_on_hdfs = true;
+    //policy_on_hdfs = true;
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbEndToEnd.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbEndToEnd.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbEndToEnd.java
index 634dd52..46d9332 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbEndToEnd.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbEndToEnd.java
@@ -18,6 +18,7 @@
 package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.provider.db.SentryAccessDeniedException;
+import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -29,24 +30,32 @@ import java.sql.Statement;
 
 import org.apache.sentry.provider.file.PolicyFile;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.io.Resources;
 
-public class TestDbEndToEnd extends AbstractTestWithDbProvider {
+public class TestDbEndToEnd extends AbstractTestWithStaticConfiguration {
   private final String SINGLE_TYPE_DATA_FILE_NAME = "kv1.dat";
   private File dataFile;
   private PolicyFile policyFile;
 
+  @BeforeClass
+  public static void setupTestStaticConfiguration() throws Exception{
+    useSentryService = true;
+    AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
+  }
+
+  @Override
   @Before
   public void setup() throws Exception {
-    createContext();
+    super.setupAdmin();
+    super.setup();
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
     policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
-    setupAdmin(context);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbExportImportPrivileges.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbExportImportPrivileges.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbExportImportPrivileges.java
index 78677ba..3d67ab7 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbExportImportPrivileges.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbExportImportPrivileges.java
@@ -19,15 +19,20 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestExportImportPrivileges;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbExportImportPrivileges extends TestExportImportPrivileges {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataObjectRetrieval.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataObjectRetrieval.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataObjectRetrieval.java
index 2701e55..53c7d0b 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataObjectRetrieval.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataObjectRetrieval.java
@@ -19,15 +19,21 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestMetadataObjectRetrieval;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbMetadataObjectRetrieval extends TestMetadataObjectRetrieval {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataPermissions.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataPermissions.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataPermissions.java
index e311e51..97b0e06 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataPermissions.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMetadataPermissions.java
@@ -19,15 +19,21 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestMetadataPermissions;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbMetadataPermissions extends TestMetadataPermissions {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMovingToProduction.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMovingToProduction.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMovingToProduction.java
index 4b44e63..cd27a4f 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMovingToProduction.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbMovingToProduction.java
@@ -18,15 +18,21 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestMovingToProduction;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbMovingToProduction extends TestMovingToProduction {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeAtTransform.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeAtTransform.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeAtTransform.java
index 2cbf0a7..1bb82ed 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeAtTransform.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeAtTransform.java
@@ -19,14 +19,20 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestPrivilegeAtTransform;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbPrivilegeAtTransform extends TestPrivilegeAtTransform {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtDatabaseScope.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtDatabaseScope.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtDatabaseScope.java
index 7ea8166..e1cda29 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtDatabaseScope.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtDatabaseScope.java
@@ -19,16 +19,22 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestPrivilegesAtDatabaseScope;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbPrivilegesAtDatabaseScope extends
     TestPrivilegesAtDatabaseScope {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtFunctionScope.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtFunctionScope.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtFunctionScope.java
index e12b072..cebad98 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtFunctionScope.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtFunctionScope.java
@@ -18,16 +18,22 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestPrivilegesAtFunctionScope;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbPrivilegesAtFunctionScope extends
     TestPrivilegesAtFunctionScope {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtTableScope.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtTableScope.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtTableScope.java
index db17012..7c861d3 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtTableScope.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegesAtTableScope.java
@@ -19,15 +19,21 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestPrivilegesAtTableScope;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbPrivilegesAtTableScope extends TestPrivilegesAtTableScope {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbRuntimeMetadataRetrieval.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbRuntimeMetadataRetrieval.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbRuntimeMetadataRetrieval.java
index 302492a..5324656 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbRuntimeMetadataRetrieval.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbRuntimeMetadataRetrieval.java
@@ -18,16 +18,22 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestRuntimeMetadataRetrieval;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbRuntimeMetadataRetrieval extends
     TestRuntimeMetadataRetrieval {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbSandboxOps.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbSandboxOps.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbSandboxOps.java
index f822785..e21dfe3 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbSandboxOps.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbSandboxOps.java
@@ -20,17 +20,24 @@ import static org.junit.Assert.assertTrue;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestSandboxOps;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 
 public class TestDbSandboxOps extends TestSandboxOps {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
+
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 
   @Ignore

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUriPermissions.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUriPermissions.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUriPermissions.java
index f52fb67..43a310f 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUriPermissions.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUriPermissions.java
@@ -18,14 +18,20 @@ package org.apache.sentry.tests.e2e.dbprovider;
 
 import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
 import org.apache.sentry.tests.e2e.hive.TestUriPermissions;
+import org.junit.Before;
 import org.junit.BeforeClass;
 
 public class TestDbUriPermissions extends TestUriPermissions {
+  @Override
+  @Before
+  public void setup() throws Exception {
+    super.setupAdmin();
+    super.setup();
+  }
   @BeforeClass
   public static void setupTestStaticConfiguration() throws Exception {
     useSentryService = true;
     AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
+
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUserManagement.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUserManagement.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUserManagement.java
deleted file mode 100644
index e24137d..0000000
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbUserManagement.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sentry.tests.e2e.dbprovider;
-
-import org.apache.sentry.tests.e2e.hive.AbstractTestWithStaticConfiguration;
-import org.junit.BeforeClass;
-
-public class TestDbUserManagement {
-  @BeforeClass
-  public static void setupTestStaticConfiguration() throws Exception {
-    // useSentryService = true;
-    AbstractTestWithStaticConfiguration.setupTestStaticConfiguration();
-    PolicyProviderForTest.setSentryClient(AbstractTestWithStaticConfiguration
-        .getSentryClient());
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java
index 952b021..fd969a6 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/AbstractTestWithStaticConfiguration.java
@@ -17,9 +17,14 @@
 package org.apache.sentry.tests.e2e.hive;
 
 import java.io.File;
+import java.io.IOException;
 import java.sql.Connection;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeoutException;
 
@@ -30,19 +35,24 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
 import org.apache.sentry.binding.hive.SentryHiveAuthorizationTaskFactoryImpl;
+import org.apache.sentry.core.model.db.DBModelAction;
+import org.apache.sentry.core.model.db.DBModelAuthorizable;
+import org.apache.sentry.policy.db.DBModelAuthorizables;
+import static org.apache.sentry.provider.common.ProviderConstants.AUTHORIZABLE_SPLITTER;
+import static org.apache.sentry.provider.common.ProviderConstants.PRIVILEGE_PREFIX;
+import static org.apache.sentry.provider.common.ProviderConstants.ROLE_SPLITTER;
 import org.apache.sentry.provider.db.SimpleDBProviderBackend;
-import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient;
 import org.apache.sentry.provider.file.PolicyFile;
 import org.apache.sentry.service.thrift.SentryService;
-import org.apache.sentry.service.thrift.SentryServiceClientFactory;
 import org.apache.sentry.service.thrift.SentryServiceFactory;
 import org.apache.sentry.service.thrift.ServiceConstants.ClientConfig;
 import org.apache.sentry.service.thrift.ServiceConstants.ServerConfig;
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
 import org.apache.sentry.tests.e2e.hive.fs.DFS;
 import org.apache.sentry.tests.e2e.hive.fs.DFSFactory;
 import org.apache.sentry.tests.e2e.hive.hiveserver.HiveServer;
 import org.apache.sentry.tests.e2e.hive.hiveserver.HiveServerFactory;
+import org.apache.tools.ant.util.StringUtils;
+import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -60,9 +70,8 @@ public abstract class AbstractTestWithStaticConfiguration {
       ALL_DB2 = "server=server1->db=db_2",
       SELECT_DB1_TBL1 = "server=server1->db=db_1->table=tb_1->action=select",
       SELECT_DB1_TBL2 = "server=server1->db=db_1->table=tb_2->action=select",
-      SELECT_DB1_NONTABLE = "server=server1->db=db_1->table=this table does not exist->action=select",
+      SELECT_DB1_NONTABLE = "server=server1->db=db_1->table=blahblah->action=select",
       INSERT_DB1_TBL1 = "server=server1->db=db_1->table=tb_1->action=insert",
-      INSERT_DB1_TBL2 = "server=server1->db=db_1->table=tb_2->action=insert",
       SELECT_DB2_TBL2 = "server=server1->db=db_2->table=tb_2->action=select",
       INSERT_DB2_TBL1 = "server=server1->db=db_2->table=tb_1->action=insert",
       SELECT_DB1_VIEW1 = "server=server1->db=db_1->table=view_1->action=select",
@@ -87,9 +96,10 @@ public abstract class AbstractTestWithStaticConfiguration {
       VIEW1 = "view_1",
       VIEW2 = "view_2",
       VIEW3 = "view_3",
-      INDEX1 = "index_1",
-      INDEX2 = "index_2";
+      INDEX1 = "index_1";
+
   protected static final String SERVER_HOST = "localhost";
+  private static final String EXTERNAL_SENTRY_SERVICE = "sentry.e2etest.external.sentry";
 
   protected static boolean policy_on_hdfs = false;
   protected static boolean useSentryService = false;
@@ -106,13 +116,11 @@ public abstract class AbstractTestWithStaticConfiguration {
   protected static Map<String, String> properties;
   protected static SentryService sentryServer;
   protected static Configuration sentryConf;
-  protected static SentryPolicyServiceClient sentryClient;
-  protected Context context;
+  protected static Context context;
 
-  public Context createContext() throws Exception {
+  public static void createContext() throws Exception {
     context = new Context(hiveServer, fileSystem,
         baseDir, confDir, dataDir, policyFileLocation);
-    return context;
   }
   protected void dropDb(String user, String...dbs) throws Exception {
     Connection connection = context.createConnection(user);
@@ -179,7 +187,8 @@ public abstract class AbstractTestWithStaticConfiguration {
     fileSystem = dfs.getFileSystem();
 
     String policyURI;
-    PolicyFile policyFile = PolicyFile.setAdminOnServer1(ADMIN1);
+    PolicyFile policyFile = PolicyFile.setAdminOnServer1(ADMIN1)
+        .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     policyFile.write(policyFileLocation);
     if (policy_on_hdfs) {
       String dfsUri = fileSystem.getDefaultUri(fileSystem.getConf()).toString();
@@ -190,25 +199,109 @@ public abstract class AbstractTestWithStaticConfiguration {
     } else {
       policyURI = policyFileLocation.getPath();
     }
-
-    if (useSentryService) {
+    boolean startSentry = new Boolean(System.getProperty(EXTERNAL_SENTRY_SERVICE, "false"));
+    if (useSentryService && (!startSentry)) {
       setupSentryService();
     }
 
     hiveServer = HiveServerFactory.create(properties, baseDir, confDir, logDir, policyURI, fileSystem);
     hiveServer.start();
+    createContext();
   }
+
   protected void writePolicyFile(PolicyFile policyFile) throws Exception{
 
     policyFile.write(context.getPolicyFile());
     if(policy_on_hdfs) {
       dfs.writePolicyFile(context.getPolicyFile());
+    } else if(useSentryService) {
+      grantPermissions(policyFile);
+    }
+  }
+
+  private void grantPermissions(PolicyFile policyFile) throws Exception{
+    Connection connection = context.createConnection(ADMIN1);
+    Statement statement = context.createStatement(connection);
+
+    // remove existing metadata
+    ResultSet resultSet = statement.executeQuery("SHOW ROLES");
+    while( resultSet.next()) {
+      Statement statement1 = context.createStatement(connection);
+      if(!resultSet.getString(1).equalsIgnoreCase("admin_role")) {
+        statement1.execute("DROP ROLE " + resultSet.getString(1));
+      }
+    }
+
+    // create roles and add privileges
+    for (Map.Entry<String, Collection<String>> roleEntry : policyFile.getRolesToPermissions()
+        .asMap().entrySet()) {
+      if(!roleEntry.getKey().equalsIgnoreCase("admin_role")){
+        statement.execute("CREATE ROLE " + roleEntry.getKey());
+        for (String privilege : roleEntry.getValue()) {
+          addPrivilege(roleEntry.getKey(), privilege, statement);
+        }
+      }
+    }
+    // grant roles to groups
+    for (Map.Entry<String, Collection<String>> groupEntry : policyFile.getGroupsToRoles().asMap()
+        .entrySet()) {
+      for (String roleNames : groupEntry.getValue()) {
+        for (String roleName : roleNames.split(",")) {
+            statement.execute("GRANT ROLE " + roleName + " TO GROUP " + groupEntry.getKey());
+        }
+      }
+    }
+  }
+  private void addPrivilege(String roleName, String privileges, Statement statement)
+      throws IOException, SQLException{
+    String serverName = null, dbName = null, tableName = null, uriPath = null;
+    String action = "ALL";//AccessConstants.ALL;
+    for (String privilege : ROLE_SPLITTER.split(privileges)) {
+      for(String section : AUTHORIZABLE_SPLITTER.split(privilege)) {
+        // action is not an authorizeable
+        if(!section.toLowerCase().startsWith(PRIVILEGE_PREFIX)) {
+          DBModelAuthorizable dbAuthorizable = DBModelAuthorizables.from(section);
+          if(dbAuthorizable == null) {
+            throw new IOException("Unknown Auth type " + section);
+          }
+
+          if (DBModelAuthorizable.AuthorizableType.Server.equals(dbAuthorizable.getAuthzType())) {
+            serverName = dbAuthorizable.getName();
+          } else if (DBModelAuthorizable.AuthorizableType.Db.equals(dbAuthorizable.getAuthzType())) {
+            dbName = dbAuthorizable.getName();
+          } else if (DBModelAuthorizable.AuthorizableType.Table.equals(dbAuthorizable.getAuthzType())) {
+            tableName = dbAuthorizable.getName();
+          } else if (DBModelAuthorizable.AuthorizableType.URI.equals(dbAuthorizable.getAuthzType())) {
+            uriPath = dbAuthorizable.getName();
+          } else {
+            throw new IOException("Unsupported auth type " + dbAuthorizable.getName()
+                + " : " + dbAuthorizable.getTypeName());
+          }
+        } else {
+          action = DBModelAction.valueOf(
+              StringUtils.removePrefix(section, PRIVILEGE_PREFIX).toUpperCase())
+              .toString();
+        }
+      }
+
+      if (tableName != null) {
+        statement.execute("CREATE DATABASE IF NOT EXISTS " + dbName);
+        statement.execute("USE " + dbName);
+        statement.execute("GRANT " + action + " ON TABLE " + tableName + " TO ROLE " + roleName);
+      } else if (dbName != null) {
+        statement.execute("GRANT " + action + " ON DATABASE " + dbName + " TO ROLE " + roleName);
+      } else if (uriPath != null) {
+        statement.execute("GRANT " + action + " ON URI '" + uriPath + "' TO ROLE " + roleName);//ALL?
+      } else if (serverName != null) {
+        statement.execute("GRANT ALL ON SERVER " + serverName + " TO ROLE " + roleName);
+        ;
+      }
     }
   }
 
   private static void setupSentryService() throws Exception {
+
     sentryConf = new Configuration(false);
-    PolicyFile policyFile = new PolicyFile();
 
     properties.put(HiveServerFactory.AUTHZ_PROVIDER_BACKEND,
         SimpleDBProviderBackend.class.getName());
@@ -259,6 +352,62 @@ public abstract class AbstractTestWithStaticConfiguration {
     dfs.createBaseDir();
   }
 
+  @After
+  public void clearDB() throws Exception {
+    Connection connection;
+    Statement statement;
+    connection = context.createConnection(ADMIN1);
+    statement = context.createStatement(connection);
+    ResultSet resultSet;
+
+    resultSet = statement.executeQuery("SHOW DATABASES");
+    while (resultSet.next()) {
+      if(! resultSet.getString(1).equalsIgnoreCase("default")) {
+        Statement statement2 = connection.createStatement();
+        statement2.execute("DROP DATABASE " + resultSet.getString(1) + " CASCADE");
+      }
+    }
+    statement.execute("USE default");
+    resultSet = statement.executeQuery("SHOW tables");
+    while(resultSet.next()) {
+      Statement statement2 = context.createStatement(connection);
+      statement2.execute("DROP table " + resultSet.getString(1));
+      statement2.close();
+    }
+
+    if(useSentryService) {
+      resultSet = statement.executeQuery("SHOW roles");
+      List<String> roles = new ArrayList<String>();
+      while ( resultSet.next()) {
+        roles.add(resultSet.getString(1));
+      }
+      for(String role:roles) {
+        statement.execute("DROP Role " + role);
+      }
+    }
+    statement.close();
+    connection.close();
+
+  }
+
+  protected void setupAdmin() throws Exception {
+
+    if(useSentryService) {
+    Connection connection = context.createConnection(ADMIN1);
+      Statement statement = connection.createStatement();
+      try {
+        statement.execute("CREATE ROLE admin_role");
+      } catch ( Exception e) {
+        //It is ok if admin_role already exists
+      }
+      statement.execute("GRANT ALL ON SERVER "
+          + HiveServerFactory.DEFAULT_AUTHZ_SERVER_NAME + " TO ROLE admin_role");
+      statement.execute("GRANT ROLE admin_role TO GROUP " + ADMINGROUP);
+      statement.close();
+      connection.close();
+    }
+  }
+
   @AfterClass
   public static void tearDownTestStaticConfiguration() throws Exception {
     if(hiveServer != null) {
@@ -267,13 +416,9 @@ public abstract class AbstractTestWithStaticConfiguration {
     }
 
     if (sentryServer != null) {
-      if (sentryClient != null) {
-        sentryClient.close();
-      }
-      sentryClient = null;
       sentryServer.stop();
       sentryServer = null;
-      PolicyProviderForTest.clearSentryClient();
+      sentryServer = null;
     }
 
     if(baseDir != null) {
@@ -289,13 +434,8 @@ public abstract class AbstractTestWithStaticConfiguration {
         LOGGER.info("Exception shutting down dfs", e);
       }
     }
-  }
-
-  public static SentryPolicyServiceClient getSentryClient() throws Exception {
-    if (sentryServer == null) {
-      throw new IllegalAccessException("Sentry service not initialized");
+    if (context != null) {
+      context.close();
     }
-    SentryServiceClientFactory factory = new SentryServiceClientFactory();
-    return factory.create(sentryServer.getConf());
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestConfigTool.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestConfigTool.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestConfigTool.java
index bb7bec2..c186a42 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestConfigTool.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestConfigTool.java
@@ -46,7 +46,6 @@ public class TestConfigTool extends AbstractTestWithStaticConfiguration {
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
     policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
     configTool = new SentryConfigTool();
     String hiveServer2 = System.getProperty("sentry.e2etest.hiveServer2Type",
@@ -64,13 +63,6 @@ public class TestConfigTool extends AbstractTestWithStaticConfiguration {
 
   }
 
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
-  }
-
   /**
    * Verify errors/warnings from malformed policy file
    * @throws Exception

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java
index 84e3b19..8552cc0 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestCrossDbOps.java
@@ -17,6 +17,7 @@
 
 package org.apache.sentry.tests.e2e.hive;
 
+import org.apache.sentry.provider.file.PolicyFile;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -32,8 +33,6 @@ import java.util.List;
 
 import junit.framework.Assert;
 
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -44,7 +43,7 @@ import com.google.common.io.Resources;
 
 public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
   private File dataFile;
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
   private String loadData;
 
   @BeforeClass
@@ -55,25 +54,17 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
     File dataDir = context.getDataDir();
     // copy data file to test dir
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
     loadData = "server=server1->uri=file://" + dataFile.getPath();
 
   }
 
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
-  }
-
   /*
    * Admin creates DB_1, DB2, tables (tab_1 ) and (tab_2, tab_3) in DB_1 and
    * DB_2 respectively. User user1 has select on DB_1.tab_1, insert on

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestEndToEnd.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestEndToEnd.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestEndToEnd.java
index 6c87c65..0901b67 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestEndToEnd.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestEndToEnd.java
@@ -23,7 +23,6 @@ import java.sql.Connection;
 import java.sql.Statement;
 
 import org.apache.sentry.provider.file.PolicyFile;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -37,7 +36,6 @@ public class TestEndToEnd extends AbstractTestWithStaticConfiguration {
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
@@ -46,13 +44,6 @@ public class TestEndToEnd extends AbstractTestWithStaticConfiguration {
 
   }
 
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
-  }
-
   /**
    * Steps:
    * 1. admin create a new experimental database

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestExportImportPrivileges.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestExportImportPrivileges.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestExportImportPrivileges.java
index 411a8e9..b6c985e 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestExportImportPrivileges.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestExportImportPrivileges.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sentry.tests.e2e.hive;
 
+import org.apache.sentry.provider.file.PolicyFile;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -24,8 +25,6 @@ import java.sql.Connection;
 import java.sql.Statement;
 
 import org.apache.hadoop.hive.conf.HiveConf;
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -33,23 +32,15 @@ import com.google.common.io.Resources;
 
 public class TestExportImportPrivileges extends AbstractTestWithStaticConfiguration {
   private File dataFile;
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataObjectRetrieval.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataObjectRetrieval.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataObjectRetrieval.java
index b10c0c2..e4d2333 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataObjectRetrieval.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataObjectRetrieval.java
@@ -17,6 +17,7 @@
 
 package org.apache.sentry.tests.e2e.hive;
 
+import org.apache.sentry.provider.file.PolicyFile;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -26,34 +27,24 @@ import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
 
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
 import com.google.common.io.Resources;
 
 public class TestMetadataObjectRetrieval extends AbstractTestWithStaticConfiguration {
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
   private File dataFile;
 
   @Before
   public void setup() throws Exception {
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
-    context = createContext();
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
   }
 
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
-  }
-
   /**
    * Method called to run positive tests:
    *  describe table

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataPermissions.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataPermissions.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataPermissions.java
index e0642e7..1e217a3 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataPermissions.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMetadataPermissions.java
@@ -21,20 +21,17 @@ import java.sql.Statement;
 
 import junit.framework.Assert;
 
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
+import org.apache.sentry.provider.file.PolicyFile;
 import org.junit.Before;
 import org.junit.Test;
 
 
 public class TestMetadataPermissions extends AbstractTestWithStaticConfiguration {
-  private Context context;
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
 
     policyFile
         .addRolesToGroup(USERGROUP1, "db1_all", "db2_all")
@@ -57,13 +54,6 @@ public class TestMetadataPermissions extends AbstractTestWithStaticConfiguration
     }
   }
 
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
-  }
-
   /**
    * Ensure that a user with no privileges on a database cannot
    * query that databases metadata.

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMovingToProduction.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMovingToProduction.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMovingToProduction.java
index 0889615..67cbd32 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMovingToProduction.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestMovingToProduction.java
@@ -17,6 +17,7 @@
 
 package org.apache.sentry.tests.e2e.hive;
 
+import org.apache.sentry.provider.file.PolicyFile;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -26,8 +27,6 @@ import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
 
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -35,24 +34,16 @@ import com.google.common.io.Resources;
 
 public class TestMovingToProduction extends AbstractTestWithStaticConfiguration {
   private final String SINGLE_TYPE_DATA_FILE_NAME = "kv1.dat";
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
 
 
   @Before
   public void setUp() throws Exception {
-    context = createContext();
     File dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
   }
 
   /**
@@ -74,7 +65,7 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
   @Test
   public void testMovingTable1() throws Exception {
     policyFile
-        .addRolesToGroup(USERGROUP1, "all_db1", "load_data", "select_proddb_tbl1", "insert_proddb_tbl1")
+        .addRolesToGroup(USERGROUP1, "all_db1", "load_data")
         .addPermissionsToRole("load_data", "server=server1->uri=file://" + dataDir.getPath())
         .addPermissionsToRole("all_db1", "server=server1->db=db_1")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
@@ -107,6 +98,7 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
         + "' INTO TABLE " + tableName1);
 
     policyFile
+        .addRolesToGroup(USERGROUP1, "insert_proddb_tbl1")
         .addPermissionsToRole("insert_proddb_tbl1", "server=server1->db=proddb->table=tb_1->action=insert");
     writePolicyFile(policyFile);
     statement.execute("USE " + dbName2);
@@ -116,6 +108,7 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
 
     // b
     policyFile
+        .addRolesToGroup(USERGROUP1, "select_proddb_tbl1")
         .addPermissionsToRole("select_proddb_tbl1", "server=server1->db=proddb->table=tb_1->action=select");
     writePolicyFile(policyFile);
 
@@ -156,7 +149,7 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
   @Test
   public void testMovingTable2() throws Exception {
     policyFile
-        .addRolesToGroup(USERGROUP1, "all_db1", "load_data", "select_proddb_tbl1", "insert_proddb_tbl1")
+        .addRolesToGroup(USERGROUP1, "all_db1", "load_data")
         .addPermissionsToRole("all_db1", "server=server1->db=db_1")
         .addPermissionsToRole("load_data", "server=server1->uri=file://" + dataDir.getPath())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
@@ -187,6 +180,7 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
         + "' INTO TABLE " + dbName1 + "." + tableName1);
 
     policyFile
+        .addRolesToGroup(USERGROUP1, "insert_proddb_tbl1")
         .addPermissionsToRole("insert_proddb_tbl1", "server=server1->db=proddb->table=tb_1->action=insert");
     writePolicyFile(policyFile);
 
@@ -196,6 +190,7 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
 
     // b
     policyFile
+        .addRolesToGroup(USERGROUP1, "select_proddb_tbl1")
         .addPermissionsToRole("select_proddb_tbl1", "server=server1->db=proddb->table=tb_1->action=select");
     writePolicyFile(policyFile);
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java
index f782613..10f5dc8 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDBConfiguration.java
@@ -41,14 +41,12 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
   private static final String MULTI_TYPE_DATA_FILE_NAME = "emp.dat";
   private static final String DB2_POLICY_FILE = "db2-policy-file.ini";
 
-  private Context context;
   private File dataFile;
   private PolicyFile policyFile;
   private static String prefix;
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
     policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
 
     File dataDir = context.getDataDir();
@@ -73,9 +71,7 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
   public void teardown() throws Exception {
     // one test turns this on so let's disable it in the teardown method
     System.setProperty(SimpleDBPolicyEngine.ACCESS_ALLOW_URI_PER_DB_POLICYFILE, "false");
-    if (context != null) {
-      context.close();
-    }
+    clearDB();
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDatabasePolicyFile.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDatabasePolicyFile.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDatabasePolicyFile.java
index 85c83af..b31446c 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDatabasePolicyFile.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPerDatabasePolicyFile.java
@@ -19,7 +19,6 @@ package org.apache.sentry.tests.e2e.hive;
 
 import com.google.common.io.Resources;
 import org.apache.sentry.provider.file.PolicyFile;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -37,7 +36,7 @@ public class TestPerDatabasePolicyFile extends AbstractTestWithStaticConfigurati
   @Before
   public void setup() throws Exception {
     policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
-    context = createContext();
+    writePolicyFile(policyFile);
     dataDir = context.getDataDir();
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
@@ -45,13 +44,6 @@ public class TestPerDatabasePolicyFile extends AbstractTestWithStaticConfigurati
     to.close();
   }
 
-  @After
-  public void teardown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
-  }
-
   private void createSampleDbTable(Statement statement, String db, String table)
       throws Exception {
     statement.execute("DROP DATABASE IF EXISTS " + db + " CASCADE");

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegeAtTransform.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegeAtTransform.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegeAtTransform.java
index bc20213..1267e6b 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegeAtTransform.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegeAtTransform.java
@@ -25,8 +25,6 @@ import java.sql.Connection;
 import java.sql.Statement;
 
 import org.apache.sentry.provider.file.PolicyFile;
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -41,20 +39,12 @@ public class TestPrivilegeAtTransform extends AbstractTestWithStaticConfiguratio
   @Override
   @Before
   public void setup() throws Exception {
-    context = createContext();
     dataDir = context.getDataDir();
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtDatabaseScope.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtDatabaseScope.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtDatabaseScope.java
index 029d8d5..ff73c0a 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtDatabaseScope.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtDatabaseScope.java
@@ -17,6 +17,7 @@
 
 package org.apache.sentry.tests.e2e.hive;
 
+import org.apache.sentry.provider.file.PolicyFile;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
@@ -31,8 +32,6 @@ import java.util.Map;
 
 import junit.framework.Assert;
 
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -43,8 +42,7 @@ import com.google.common.io.Resources;
 
 public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfiguration {
 
-  private Context context;
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
 
   Map <String, String >testProperties;
   private static final String SINGLE_TYPE_DATA_FILE_NAME = "kv1.dat";
@@ -54,15 +52,7 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
   public void setup() throws Exception {
     testProperties = new HashMap<String, String>();
 
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
-    context = createContext();
-  }
-
-  @After
-  public void teardown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
   }
 
   /* Admin creates database DB_1

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtFunctionScope.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtFunctionScope.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtFunctionScope.java
index 2c9924b..ccb5550 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtFunctionScope.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtFunctionScope.java
@@ -17,6 +17,7 @@ printf_test_3 * Licensed to the Apache Software Foundation (ASF) under one or mo
 
 package org.apache.sentry.tests.e2e.hive;
 
+import org.apache.sentry.provider.file.PolicyFile;
 import static org.junit.Assert.assertFalse;
 
 import java.io.File;
@@ -26,8 +27,6 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
 
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -37,27 +36,19 @@ public class TestPrivilegesAtFunctionScope extends AbstractTestWithStaticConfigu
   private final String SINGLE_TYPE_DATA_FILE_NAME = "kv1.dat";
   private File dataDir;
   private File dataFile;
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
     dataDir = context.getDataDir();
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
 
   }
 
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
-  }
-
   /**
    * admin should be able to create/drop temp functions
    * user with db level access should be able to create/drop temp functions

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtTableScope.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtTableScope.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtTableScope.java
index 6b493c4..2fece0a 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtTableScope.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPrivilegesAtTableScope.java
@@ -17,6 +17,7 @@
 
 package org.apache.sentry.tests.e2e.hive;
 
+import org.apache.sentry.provider.file.PolicyFile;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -30,8 +31,6 @@ import java.sql.Statement;
 
 import junit.framework.Assert;
 
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -42,23 +41,14 @@ import com.google.common.io.Resources;
 
 public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfiguration {
 
-  private Context context;
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
 
   private final String SINGLE_TYPE_DATA_FILE_NAME = "kv1.dat";
   private final String MULTI_TYPE_DATA_FILE_NAME = "emp.dat";
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
-  }
-
-  @After
-  public void teardown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
   }
 
   /*

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/c5393407/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestRuntimeMetadataRetrieval.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestRuntimeMetadataRetrieval.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestRuntimeMetadataRetrieval.java
index ddb1c8b..dac0b92 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestRuntimeMetadataRetrieval.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestRuntimeMetadataRetrieval.java
@@ -26,8 +26,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.sentry.tests.e2e.dbprovider.PolicyProviderForTest;
-import org.junit.After;
+import org.apache.sentry.provider.file.PolicyFile;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -40,28 +39,19 @@ import com.google.common.io.Resources;
  * statements are validaed via a runtime fetch hook
  */
 public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfiguration {
-  private Context context;
-  private PolicyProviderForTest policyFile;
+  private PolicyFile policyFile;
   private final String SINGLE_TYPE_DATA_FILE_NAME = "kv1.dat";
   private File dataDir;
   private File dataFile;
 
   @Before
   public void setup() throws Exception {
-    context = createContext();
     dataDir = context.getDataDir();
     dataFile = new File(dataDir, SINGLE_TYPE_DATA_FILE_NAME);
     FileOutputStream to = new FileOutputStream(dataFile);
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
-    policyFile = PolicyProviderForTest.setAdminOnServer1(ADMINGROUP);
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    if (context != null) {
-      context.close();
-    }
+    policyFile = PolicyFile.setAdminOnServer1(ADMINGROUP);
   }
 
   /**
@@ -249,7 +239,6 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
     String tableNames[] = {"tb_1", "tb_2", "tb_3", "tb_4"};
 
     policyFile
-        .addRolesToGroup(USERGROUP1, "db_priv")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
     Connection connection = context.createConnection(ADMIN1);