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/08/22 02:59:54 UTC

[1/3] SENTRY-47: Tests need to clean up the databases and tables it creates (Sravya Tirukkovalur via Prasad Mujumdar)

Repository: incubator-sentry
Updated Branches:
  refs/heads/master 49e682fdd -> b6c62f791


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 e932e8f..4eb1fdf 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
@@ -61,18 +61,17 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
    */
   @Test
   public void testShowTables1() throws Exception {
-    String dbName1 = "db_1";
     // tables visible to user1 (not access to tb_4
     String tableNames[] = {"tb_1", "tb_2", "tb_3", "tb_4"};
     List<String> tableNamesValidation = new ArrayList<String>();
 
     policyFile
         .addRolesToGroup(USERGROUP1, "tab1_priv,tab2_priv,tab3_priv")
-        .addPermissionsToRole("tab1_priv", "server=server1->db=" + dbName1 + "->table="
+        .addPermissionsToRole("tab1_priv", "server=server1->db=" + DB1 + "->table="
             + tableNames[0] + "->action=select")
-        .addPermissionsToRole("tab2_priv", "server=server1->db=" + dbName1 + "->table="
+        .addPermissionsToRole("tab2_priv", "server=server1->db=" + DB1 + "->table="
             + tableNames[1] + "->action=insert")
-        .addPermissionsToRole("tab3_priv", "server=server1->db=" + dbName1 + "->table="
+        .addPermissionsToRole("tab3_priv", "server=server1->db=" + DB1 + "->table="
             + tableNames[2] + "->action=select")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
@@ -81,24 +80,24 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
 
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("USE " + dbName1);
-    createTabs(statement, dbName1, tableNames);
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
+    createTabs(statement, DB1, tableNames);
     // Admin should see all tables
     ResultSet rs = statement.executeQuery("SHOW TABLES");
     tableNamesValidation.addAll(Arrays.asList(tableNames));
 
-    validateTables(rs, dbName1, tableNamesValidation);
+    validateTables(rs, DB1, tableNamesValidation);
     statement.close();
 
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     // User1 should see tables with any level of access
     rs = statement.executeQuery("SHOW TABLES");
     tableNamesValidation.addAll(Arrays.asList(user1TableNames));
-    validateTables(rs, dbName1, tableNamesValidation);
+    validateTables(rs, DB1, tableNamesValidation);
     statement.close();
   }
 
@@ -109,14 +108,13 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
    */
   @Test
   public void testShowTables2() throws Exception {
-    String dbName1 = "db_1";
     // tables visible to user1 (not access to tb_4
     String tableNames[] = {"tb_1", "tb_2", "tb_3", "tb_4"};
     List<String> tableNamesValidation = new ArrayList<String>();
 
     policyFile
         .addRolesToGroup(USERGROUP1, "db_priv")
-        .addPermissionsToRole("db_priv", "server=server1->db=" + dbName1)
+        .addPermissionsToRole("db_priv", "server=server1->db=" + DB1)
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
@@ -124,23 +122,23 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
 
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("USE " + dbName1);
-    createTabs(statement, dbName1, tableNames);
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
+    createTabs(statement, DB1, tableNames);
     // Admin should see all tables
     ResultSet rs = statement.executeQuery("SHOW TABLES");
     tableNamesValidation.addAll(Arrays.asList(tableNames));
-    validateTables(rs, dbName1, tableNamesValidation);
+    validateTables(rs, DB1, tableNamesValidation);
     statement.close();
 
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     // User1 should see tables with any level of access
     rs = statement.executeQuery("SHOW TABLES");
     tableNamesValidation.addAll(Arrays.asList(user1TableNames));
-    validateTables(rs, dbName1, tableNamesValidation);
+    validateTables(rs, DB1, tableNamesValidation);
     statement.close();
   }
 
@@ -151,14 +149,13 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
    */
   @Test
   public void testShowTables3() throws Exception {
-    String dbName1 = "db_1";
     // tables visible to user1 (not access to tb_4
     String tableNames[] = {"tb_1", "tb_2", "tb_3", "newtab_3"};
     List<String> tableNamesValidation = new ArrayList<String>();
 
     policyFile
         .addRolesToGroup(USERGROUP1, "tab_priv")
-        .addPermissionsToRole("tab_priv", "server=server1->db=" + dbName1 + "->table="
+        .addPermissionsToRole("tab_priv", "server=server1->db=" + DB1 + "->table="
             + tableNames[3] + "->action=insert")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
@@ -168,23 +165,23 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
 
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("USE " + dbName1);
-    createTabs(statement, dbName1, tableNames);
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
+    createTabs(statement, DB1, tableNames);
     // Admin should see all tables
     ResultSet rs = statement.executeQuery("SHOW TABLES");
     tableNamesValidation.addAll(Arrays.asList(adminTableNames));
-    validateTables(rs, dbName1, tableNamesValidation);
+    validateTables(rs, DB1, tableNamesValidation);
     statement.close();
 
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     // User1 should see tables with any level of access
     rs = statement.executeQuery("SHOW TABLES");
     tableNamesValidation.addAll(Arrays.asList(user1TableNames));
-    validateTables(rs, dbName1, tableNamesValidation);
+    validateTables(rs, DB1, tableNamesValidation);
     statement.close();
   }
 
@@ -195,13 +192,12 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
    */
   @Test
   public void testShowTables4() throws Exception {
-    String dbName1 = "db_1";
     String tableNames[] = {"tb_1", "tb_2", "tb_3", "newtab_3"};
     List<String> tableNamesValidation = new ArrayList<String>();
 
     policyFile
         .addRolesToGroup(USERGROUP1, "tab_priv")
-        .addPermissionsToRole("tab_priv", "server=server1->db=" + dbName1)
+        .addPermissionsToRole("tab_priv", "server=server1->db=" + DB1)
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
@@ -210,23 +206,23 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
 
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("USE " + dbName1);
-    createTabs(statement, dbName1, tableNames);
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
+    createTabs(statement, DB1, tableNames);
     // Admin should be able to see all tables
     ResultSet rs = statement.executeQuery("SHOW TABLES");
     tableNamesValidation.addAll(Arrays.asList(adminTableNames));
-    validateTables(rs, dbName1, tableNamesValidation);
+    validateTables(rs, DB1, tableNamesValidation);
     statement.close();
 
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     // User1 should see tables with any level of access
     rs = statement.executeQuery("SHOW TABLES");
     tableNamesValidation.addAll(Arrays.asList(user1TableNames));
-    validateTables(rs, dbName1, tableNamesValidation);
+    validateTables(rs, DB1, tableNamesValidation);
     statement.close();
   }
 
@@ -262,24 +258,22 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
   @Test
   public void testShowDatabases1() throws Exception {
     List<String> dbNamesValidation = new ArrayList<String>();
-    String[] dbNames = {"db_1", "db_2", "db_3"};
-    String[] user1DbNames = {"db_1"};
+    String[] dbNames = {DB1, DB2, DB3};
+    String[] user1DbNames = {DB1};
 
     policyFile
         .addRolesToGroup(USERGROUP1, "db1_all")
-        .addPermissionsToRole("db1_all", "server=server1->db=db_1")
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
+    createDb(ADMIN1, dbNames);
+    dbNamesValidation.addAll(Arrays.asList(dbNames));
+    dbNamesValidation.add("default");
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    // create all dbs
-    createDBs(statement, dbNames);
     ResultSet rs = statement.executeQuery("SHOW DATABASES");
-    dbNamesValidation.addAll(Arrays.asList(dbNames));
-    dbNamesValidation.add("default");
-    // admin should see all dbs
-    validateDBs(rs, dbNamesValidation);
+    validateDBs(rs, dbNamesValidation); // admin should see all dbs
     rs.close();
 
     connection = context.createConnection(USER1_1);
@@ -300,28 +294,28 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
    */
   @Test
   public void testShowDatabases2() throws Exception {
-    String[] dbNames = {"db_1", "db_2", "db_3"};
+    String[] dbNames = {DB1, DB2, DB3};
     List<String> dbNamesValidation = new ArrayList<String>();
-    String[] user1DbNames = {"db_1", "db_2"};
-
-    policyFile
-        .addRolesToGroup(USERGROUP1, "db1_tab,db2_tab")
-        .addPermissionsToRole("db1_tab", "server=server1->db=db_1->table=tb_1->action=select")
-        .addPermissionsToRole("db2_tab", "server=server1->db=db_2->table=tb_1->action=insert")
-        .setUserGroupMapping(StaticUserGroup.getStaticMapping());
-    writePolicyFile(policyFile);
+    String[] user1DbNames = {DB1, DB2};
 
     // verify by SQL
     // 1, 2
+    createDb(ADMIN1, dbNames);
+    dbNamesValidation.addAll(Arrays.asList(dbNames));
+    dbNamesValidation.add("default");
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    createDBs(statement, dbNames); // create all dbs
     ResultSet rs = statement.executeQuery("SHOW DATABASES");
-    dbNamesValidation.addAll(Arrays.asList(dbNames));
-    dbNamesValidation.add("default");
     validateDBs(rs, dbNamesValidation); // admin should see all dbs
     rs.close();
 
+    policyFile
+        .addRolesToGroup(USERGROUP1, "db1_tab,db2_tab")
+        .addPermissionsToRole("db1_tab", "server=server1->db=" + DB1 + "->table=tb_1->action=select")
+        .addPermissionsToRole("db2_tab", "server=server1->db=" + DB2 + "->table=tb_1->action=insert")
+        .setUserGroupMapping(StaticUserGroup.getStaticMapping());
+    writePolicyFile(policyFile);
+
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     rs = statement.executeQuery("SHOW DATABASES");
@@ -332,40 +326,15 @@ public class TestRuntimeMetadataRetrieval extends AbstractTestWithStaticConfigur
     rs.close();
   }
 
-  private ArrayList<String> getAllDbs(Statement stmt) throws SQLException{
-    ArrayList<String> dbs = new ArrayList<String>();
-    ResultSet res = stmt.executeQuery("SHOW DATABASES");
-    while(res.next()) {
-      String db = res.getString(1);
-      dbs.add(db);
-    }
-    return dbs;
-  }
-  private void dropDBs(Statement stmt, ArrayList<String> dbs) throws SQLException{
-    for(String db:dbs) {
-      if(!db.equalsIgnoreCase("default")) {
-        stmt.execute("DROP DATABASE IF EXISTS " + db + " CASCADE");
-      }
-    }
-  }
-
-  // create given dbs
-  private void createDBs(Statement statement, String dbNames[])
-      throws SQLException {
-    //Clean up rest of the dbs TODO:We should really be cleaning up after each test
-    dropDBs(statement, getAllDbs(statement));
-
-    for (String dbName : dbNames) {
-      statement.execute("CREATE DATABASE " + dbName);
-    }
-  }
-
   // compare the table resultset with given array of table names
   private void validateDBs(ResultSet rs, List<String> dbNames)
       throws SQLException {
     while (rs.next()) {
       String dbName = rs.getString(1);
-      Assert.assertTrue(dbName, dbNames.remove(dbName.toLowerCase()));
+      //There might be non test related dbs in the system
+      if(dbNames.contains(dbName.toLowerCase())) {
+        dbNames.remove(dbName.toLowerCase());
+      }
     }
     Assert.assertTrue(dbNames.toString(), dbNames.isEmpty());
   }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestSandboxOps.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestSandboxOps.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestSandboxOps.java
index 8710cd3..626fd40 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestSandboxOps.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestSandboxOps.java
@@ -55,8 +55,8 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
 
   private PolicyFile addTwoUsersWithAllDb() throws Exception {
     policyFile
-    .addPermissionsToRole("db1_all", "server=server1->db=db1")
-    .addPermissionsToRole("db2_all", "server=server1->db=db2")
+    .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
+    .addPermissionsToRole("db2_all", "server=server1->db=" + DB2)
     .addRolesToGroup(USERGROUP1, "db1_all", "db2_all");
     return policyFile;
   }
@@ -68,13 +68,13 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
   public void testDbPrivileges() throws Exception {
     addTwoUsersWithAllDb();
     writePolicyFile(policyFile);
-    String[] dbs = new String[] { "db1", "db2" };
+    String[] dbs = new String[] { DB1, DB2 };
     for (String dbName : dbs) {
       dropDb(ADMIN1, dbName);
       createDb(ADMIN1, dbName);
     }
     for (String user : new String[] { USER1_1, USER1_2 }) {
-      for (String dbName : new String[] { "db1", "db2" }) {
+      for (String dbName : dbs) {
         Connection userConn = context.createConnection(user);
         String tabName = user + "_tab1";
         Statement userStmt = context.createStatement(userConn);
@@ -85,7 +85,7 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
         context.assertAuthzException(userStmt, "load data local inpath '" + dataFile + "' into table " + tabName);
         assertTrue(userStmt.execute("select * from " + tabName));
         // negative users cannot create databases
-        context.assertAuthzException(userStmt, "CREATE DATABASE " + user + "_db");
+        context.assertAuthzException(userStmt, "CREATE DATABASE " + DB3);
         userStmt.close();
         userConn.close();
       }
@@ -104,13 +104,12 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
   public void testAdminDbPrivileges() throws Exception {
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
-    String dbName = "db1";
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
 
     // access the new databases
-    adminStmt.execute("use " + dbName);
+    adminStmt.execute("use " + DB1);
     String tabName = "admin_tab1";
     adminStmt.execute("create table " + tabName + "(c1 string)");
     adminStmt.execute("load data local inpath '" + dataFile.getPath() + "' into table "
@@ -119,7 +118,7 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
 
     // cleanup
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE " + dbName + " CASCADE");
+    adminStmt.execute("DROP DATABASE " + DB1 + " CASCADE");
     adminStmt.close();
     adminCon.close();
   }
@@ -133,23 +132,22 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
   @Test
   public void testNegativeUserDMLPrivileges() throws Exception {
     policyFile
-        .addPermissionsToRole("db1_tab2_all", "server=server1->db=db1->table=table_2")
+        .addPermissionsToRole("db1_tab2_all", "server=server1->db=" + DB1 + "->table=table_2")
         .addRolesToGroup(USERGROUP1, "db1_tab2_all");
     writePolicyFile(policyFile);
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
-    String dbName = "db1";
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
-    adminStmt.execute("use " + dbName);
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
+    adminStmt.execute("use " + DB1);
     adminStmt.execute("create table table_1 (id int)");
     adminStmt.execute("create table table_2 (id int)");
     adminStmt.close();
     adminCon.close();
     Connection userConn = context.createConnection(USER1_1);
     Statement userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     // user1 doesn't have select privilege on table_1, so insert/select should fail
     context.assertAuthzException(userStmt, "insert overwrite table table_2 select * from table_1");
     context.assertAuthzException(userStmt, "insert overwrite directory '" + baseDir.getPath() + "' select * from table_1");
@@ -178,17 +176,16 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
     policyFile
         .addRolesToGroup(USERGROUP1, "db1_all")
         .addRolesToGroup(USERGROUP2, "db1_tab1_select")
-        .addPermissionsToRole("db1_tab1_select", "server=server1->db=db1->table=table_1->action=select")
-        .addPermissionsToRole("db1_all", "server=server1->db=db1");
+        .addPermissionsToRole("db1_tab1_select", "server=server1->db="+ DB1 + "->table=table_1->action=select")
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1);
     writePolicyFile(policyFile);
     // create dbs
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
-    String dbName = "db1";
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
-    adminStmt.execute("use " + dbName);
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
+    adminStmt.execute("use " + DB1);
     adminStmt.execute("create table table_1 (name string)");
     adminStmt.execute("load data local inpath '" + dataFile.getPath() + "' into table table_1");
     adminStmt.execute("create table table_2 (name string)");
@@ -202,16 +199,16 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
 
     Connection userConn = context.createConnection(USER2_1);
     Statement userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
 
     context.assertAuthzException(userStmt, "alter table table_2 add columns (id int)");
-    context.assertAuthzException(userStmt, "drop database " + dbName);
+    context.assertAuthzException(userStmt, "drop database " + DB1);
     context.assertAuthzException(userStmt, "CREATE INDEX x ON TABLE table_1(name) AS 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'");
     context.assertAuthzException(userStmt, "CREATE TEMPORARY FUNCTION strip AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDFPrintf'");
     context.assertAuthzException(userStmt, "create table foo(id int)");
     context.assertAuthzException(userStmt, "create table c_tab_2 as select * from table_2"); // no select or create privilege
     context.assertAuthzException(userStmt, "create table c_tab_1 as select * from table_1"); // no create privilege
-    context.assertAuthzException(userStmt, "ALTER DATABASE " + dbName + " SET DBPROPERTIES ('foo' = 'bar')");
+    context.assertAuthzException(userStmt, "ALTER DATABASE " + DB1 + " SET DBPROPERTIES ('foo' = 'bar')");
     context.assertAuthzException(userStmt, "ALTER VIEW v1 SET TBLPROPERTIES ('foo' = 'bar')");
     context.assertAuthzException(userStmt, "DROP VIEW IF EXISTS v1");
     context.assertAuthzException(userStmt, "create table table_5 (name string)");
@@ -382,8 +379,8 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1", "load_data")
         .addRolesToGroup(USERGROUP2, "select_tb1")
-        .addPermissionsToRole("select_tb1", "server=server1->db=db_1->table=tbl_1->action=select")
-        .addPermissionsToRole("all_db1", "server=server1->db=db_1")
+        .addPermissionsToRole("select_tb1", "server=server1->db=" + DB1 + "->table=tbl_1->action=select")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
         .addPermissionsToRole("load_data", "server=server1->uri=file://" + dataFile.toString());
     writePolicyFile(policyFile);
 
@@ -441,7 +438,7 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
 
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1", "load_data")
-        .addPermissionsToRole("all_db1", "server=server1->db=db_1")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
         .addPermissionsToRole("load_data", "server=server1->uri=file://" + allowedDir.getPath() +
             ", server=server1->uri=file://" + allowedDir.getPath() +
             ", server=server1->uri=" + allowedDfsDir.toString());
@@ -505,8 +502,8 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
     policyFile
         .addRolesToGroup(USERGROUP1, "select_tbl1")
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl1", "server=server1->db=db1->table=tbl1->action=select")
-        .addDatabase("db2", dfs.getBaseDir().toUri().toString() + "/" + DB2_POLICY_FILE);
+        .addPermissionsToRole("select_tbl1", "server=server1->db=" + DB1 + "->table=tbl1->action=select")
+        .addDatabase(DB2, dfs.getBaseDir().toUri().toString() + "/" + DB2_POLICY_FILE);
     writePolicyFile(policyFile);
 
     File db2PolicyFileHandle = new File(baseDir.getPath(), DB2_POLICY_FILE);
@@ -514,7 +511,7 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
     PolicyFile db2PolicyFile = new PolicyFile();
     db2PolicyFile
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl2", "server=server1->db=db2->table=tbl2->action=select")
+        .addPermissionsToRole("select_tbl2", "server=server1->db=" + DB2 + "->table=tbl2->action=select")
         .write(db2PolicyFileHandle);
     PolicyFiles.copyFilesToDir(fileSystem, dfs.getBaseDir(), db2PolicyFileHandle);
 
@@ -522,16 +519,16 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl1");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db2");
-    statement.execute("USE db2");
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("USE " + DB2);
     statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
@@ -543,7 +540,7 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
     // test user2 can use db2
-    statement.execute("USE db2");
+    statement.execute("USE " + DB2);
     statement.execute("select * from tbl2");
 
     statement.close();
@@ -552,8 +549,9 @@ public class TestSandboxOps  extends AbstractTestWithStaticConfiguration {
     //test cleanup
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE db1 CASCADE");
-    statement.execute("DROP DATABASE db2 CASCADE");
+    statement.execute("DROP DATABASE " + DB1 + " CASCADE");
+
+    statement.execute("DROP DATABASE " + DB2 + " CASCADE");
     statement.close();
     connection.close();
   }

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestUriPermissions.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestUriPermissions.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestUriPermissions.java
index 8a857e0..c55278c 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestUriPermissions.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestUriPermissions.java
@@ -53,7 +53,6 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     to.close();
     loadData = "server=server1->uri=file://" + dataFile.getPath();
 
-    String dbName = "db1";
     String tabName = "tab1";
     Connection userConn = null;
     Statement userStmt = null;
@@ -61,8 +60,8 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     policyFile
         .addRolesToGroup(USERGROUP1, "db1_read", "db1_write", "data_read")
         .addRolesToGroup(USERGROUP2, "db1_write")
-        .addPermissionsToRole("db1_write", "server=server1->db=" + dbName + "->table=" + tabName + "->action=INSERT")
-        .addPermissionsToRole("db1_read", "server=server1->db=" + dbName + "->table=" + tabName + "->action=SELECT")
+        .addPermissionsToRole("db1_write", "server=server1->db=" + DB1 + "->table=" + tabName + "->action=INSERT")
+        .addPermissionsToRole("db1_read", "server=server1->db=" + DB1 + "->table=" + tabName + "->action=SELECT")
         .addPermissionsToRole("data_read", loadData);
     writePolicyFile(policyFile);
 
@@ -70,16 +69,16 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
-    adminStmt.execute("use " + dbName);
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
+    adminStmt.execute("use " + DB1);
     adminStmt.execute("CREATE TABLE " + tabName + "(id int)");
     context.close();
 
     // positive test, user1 has access to file being loaded
     userConn = context.createConnection(USER1_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     userStmt.execute("load data local inpath 'file://" + dataFile.getPath() +
         "' into table " + tabName);
     userStmt.execute("select * from " + tabName + " limit 1");
@@ -91,7 +90,7 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     // Negative test, user2 doesn't have access to the file being loaded
     userConn = context.createConnection(USER2_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     context.assertAuthzException(userStmt, "load data local inpath 'file://" + dataFile.getPath() +
         "' into table " + tabName);
     userStmt.close();
@@ -101,7 +100,6 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
   // Test alter partition location
   @Test
   public void testAlterPartitionLocationPrivileges() throws Exception {
-    String dbName = "db1";
     String tabName = "tab1";
     String newPartitionDir = "foo";
     String tabDir = hiveServer.getProperty(HiveServerFactory.WAREHOUSE_DIR) +
@@ -113,9 +111,9 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
-    adminStmt.execute("use " + dbName);
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
+    adminStmt.execute("use " + DB1);
     adminStmt.execute("CREATE TABLE " + tabName + " (id int) PARTITIONED BY (dt string)");
     adminCon.close();
 
@@ -123,8 +121,8 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
         .addRolesToGroup(USERGROUP1, "db1_all", "data_read")
         .addRolesToGroup(USERGROUP2, "db1_all")
         .addRolesToGroup(USERGROUP3, "db1_tab1_all", "data_read")
-        .addPermissionsToRole("db1_all", "server=server1->db=" + dbName)
-        .addPermissionsToRole("db1_tab1_all", "server=server1->db=" + dbName + "->table=" + tabName)
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
+        .addPermissionsToRole("db1_tab1_all", "server=server1->db=" + DB1 + "->table=" + tabName)
         .addPermissionsToRole("data_read", "server=server1->uri=" + tabDir);
     writePolicyFile(policyFile);
 
@@ -132,7 +130,7 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     // positive test: user1 has privilege to alter table add partition but not set location
     userConn = context.createConnection(USER1_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     userStmt.execute("ALTER TABLE " + tabName + " ADD IF NOT EXISTS PARTITION (dt = '21-Dec-2012') " +
             " LOCATION '" + tabDir + "'");
     userStmt.execute("ALTER TABLE " + tabName + " DROP PARTITION (dt = '21-Dec-2012')");
@@ -145,7 +143,7 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     // negative test: user2 doesn't have privilege to alter table add partition
     userConn = context.createConnection(USER2_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     context.assertAuthzException(userStmt,
         "ALTER TABLE " + tabName + " ADD PARTITION (dt = '22-Dec-2012') " +
           " LOCATION '" + tabDir + "/foo'");
@@ -159,7 +157,7 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     // positive test: user3 has privilege to add/drop partitions
     userConn = context.createConnection(USER3_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     userStmt.execute(
         "ALTER TABLE " + tabName + " ADD PARTITION (dt = '22-Dec-2012') " +
           " LOCATION '" + tabDir + "/foo'");
@@ -173,7 +171,6 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
   // test alter table set location
   @Test
   public void testAlterTableLocationPrivileges() throws Exception {
-    String dbName = "db1";
     String tabName = "tab1";
     String tabDir = "file://" + hiveServer.getProperty(HiveServerFactory.WAREHOUSE_DIR) + "/" + tabName;
     Connection userConn = null;
@@ -182,7 +179,7 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     policyFile
         .addRolesToGroup(USERGROUP1, "server1_all")
         .addRolesToGroup(USERGROUP2, "db1_all, data_read")
-        .addPermissionsToRole("db1_all", "server=server1->db=" + dbName)
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
         .addPermissionsToRole("data_read", "server=server1->URI=" + tabDir)
         .addPermissionsToRole("server1_all", "server=server1");
     writePolicyFile(policyFile);
@@ -191,16 +188,16 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
-    adminStmt.execute("use " + dbName);
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
+    adminStmt.execute("use " + DB1);
     adminStmt.execute("CREATE TABLE " + tabName + " (id int)  PARTITIONED BY (dt string)");
     adminCon.close();
 
     // positive test: user2 has privilege to alter table set partition
     userConn = context.createConnection(USER2_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     userStmt.execute(
         "ALTER TABLE " + tabName + " SET LOCATION '" + tabDir +  "'");
     userConn.close();
@@ -208,7 +205,7 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     // positive test: user1 has privilege to alter table set partition
     userConn = context.createConnection(USER1_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     userStmt.execute("ALTER TABLE " + tabName + " SET LOCATION '" + tabDir + "'");
     userConn.close();
   }
@@ -216,7 +213,6 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
   // Test external table
   @Test
   public void testExternalTablePrivileges() throws Exception {
-    String dbName = "db1";
     Connection userConn = null;
     Statement userStmt = null;
 
@@ -230,7 +226,7 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     policyFile
         .addRolesToGroup(USERGROUP1, "db1_all", "data_read")
         .addRolesToGroup(USERGROUP2, "db1_all")
-        .addPermissionsToRole("db1_all", "server=server1->db=" + dbName)
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
         .addPermissionsToRole("data_read", "server=server1->URI=" + dataDirPath);
     writePolicyFile(policyFile);
 
@@ -238,15 +234,15 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
     adminStmt.close();
     adminCon.close();
 
     // negative test: user2 doesn't have privilege to create external table in given path
     userConn = context.createConnection(USER2_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     context.assertAuthzException(userStmt,
         "CREATE EXTERNAL TABLE extab1(id INT) LOCATION '" + tableDir + "'");
     context.assertAuthzException(userStmt, "CREATE TABLE extab1(id INT) LOCATION '" + tableDir + "'");
@@ -256,7 +252,7 @@ public class TestUriPermissions extends AbstractTestWithStaticConfiguration {
     // positive test: user1 has privilege to create external table in given path
     userConn = context.createConnection(USER1_1);
     userStmt = context.createStatement(userConn);
-    userStmt.execute("use " + dbName);
+    userStmt.execute("use " + DB1);
     userStmt.execute("CREATE EXTERNAL TABLE extab1(id INT) LOCATION '" + tableDir + "'");
     userStmt.execute("DROP TABLE extab1");
     userStmt.execute("CREATE TABLE extab1(id INT) LOCATION '" + tableDir + "'");


[3/3] git commit: SENTRY-47: Tests need to clean up the databases and tables it creates (Sravya Tirukkovalur via Prasad Mujumdar)

Posted by pr...@apache.org.
SENTRY-47: Tests need to clean up the databases and tables it creates (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/b6c62f79
Tree: http://git-wip-us.apache.org/repos/asf/incubator-sentry/tree/b6c62f79
Diff: http://git-wip-us.apache.org/repos/asf/incubator-sentry/diff/b6c62f79

Branch: refs/heads/master
Commit: b6c62f791de852608c4d292a0a13269fef097280
Parents: 49e682f
Author: Prasad Mujumdar <pr...@cloudera.com>
Authored: Thu Aug 21 17:59:45 2014 -0700
Committer: Prasad Mujumdar <pr...@cloudera.com>
Committed: Thu Aug 21 17:59:45 2014 -0700

----------------------------------------------------------------------
 .../dbprovider/AbstractTestWithDbProvider.java  |  25 ---
 .../e2e/dbprovider/TestDatabaseProvider.java    | 158 +++++++++---------
 .../tests/e2e/dbprovider/TestDbEndToEnd.java    |  48 +++---
 .../TestDbPrivilegeCleanupOnDrop.java           |  46 +++---
 .../AbstractTestWithStaticConfiguration.java    |  16 +-
 .../sentry/tests/e2e/hive/TestCrossDbOps.java   | 116 +++++++------
 .../sentry/tests/e2e/hive/TestEndToEnd.java     |  40 +++--
 .../tests/e2e/hive/TestMetadataPermissions.java |  22 ++-
 .../tests/e2e/hive/TestMovingToProduction.java  |  76 +++++----
 .../sentry/tests/e2e/hive/TestOperations.java   | 161 +++++++++----------
 .../tests/e2e/hive/TestPerDBConfiguration.java  | 140 ++++++++--------
 .../e2e/hive/TestPerDatabasePolicyFile.java     |  12 +-
 .../e2e/hive/TestPrivilegeAtTransform.java      |  19 ++-
 .../e2e/hive/TestPrivilegesAtDatabaseScope.java |  96 +++++------
 .../e2e/hive/TestPrivilegesAtFunctionScope.java |  36 ++---
 .../e2e/hive/TestPrivilegesAtTableScope.java    |  36 ++---
 .../e2e/hive/TestRuntimeMetadataRetrieval.java  | 145 +++++++----------
 .../sentry/tests/e2e/hive/TestSandboxOps.java   |  80 +++++----
 .../tests/e2e/hive/TestUriPermissions.java      |  56 +++----
 19 files changed, 625 insertions(+), 703 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java
index 5d7428a..47e01a7 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/AbstractTestWithDbProvider.java
@@ -130,31 +130,6 @@ public abstract class AbstractTestWithDbProvider extends AbstractTestWithHiveSer
     connection.close();
   }
 
-  protected void createDb(Connection connection, String...dbs) throws Exception {
-    Statement statement = connection.createStatement();
-    for(String db : dbs) {
-      statement.execute("CREATE DATABASE " + db);
-    }
-    statement.close();
-  }
-
-  protected void createTable(Connection connection , String db, File dataFile, String...tables)
-      throws Exception {
-    Statement statement = connection.createStatement();
-    statement.execute("USE " + db);
-    for(String table : tables) {
-      statement.execute("DROP TABLE IF EXISTS " + table);
-      statement.execute("create table " + table
-          + " (under_col int comment 'the under column', value string)");
-      statement.execute("load data local inpath '" + dataFile.getPath()
-          + "' into table " + table);
-      ResultSet res = statement.executeQuery("select * from " + table);
-      Assert.assertTrue("Table should have data after load", res.next());
-      res.close();
-    }
-    statement.close();
-  }
-
   private void startSentryService() throws Exception {
     server.start();
     final long start = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 e2c39ea..8b83859 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
@@ -131,7 +131,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     Statement statement = context.createStatement(connection);
 
     // Grant only SELECT on Database
-    statement.execute("GRANT SELECT ON DATABASE db1 TO ROLE user_role");
+    statement.execute("GRANT SELECT ON DATABASE " + DB1 + " TO ROLE user_role");
     statement.execute("GRANT ALL ON URI 'file://" + dataFile.getPath() + "' TO ROLE user_role");
     statement.execute("GRANT ROLE user_role TO GROUP " + USERGROUP1);
     statement.close();
@@ -140,18 +140,18 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // SELECT is allowed
-    statement.execute("SELECT * FROM db1.t1");
-    statement.execute("SELECT * FROM db1.t2");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t2");
     try {
       // INSERT is not allowed
-      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
       assertTrue("only SELECT allowed on t1!!", false);
     } catch (Exception e) {
       // Ignore
     }
     try {
       // INSERT is not allowed
-      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t2");
+      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t2");
       assertTrue("only SELECT allowed on t2!!", false);
     } catch (Exception e) {
       // Ignore
@@ -168,7 +168,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     Statement statement = context.createStatement(connection);
 
     // Grant only INSERT on Database
-    statement.execute("GRANT INSERT ON DATABASE db1 TO ROLE user_role");
+    statement.execute("GRANT INSERT ON DATABASE " + DB1 + " TO ROLE user_role");
     statement.execute("GRANT ALL ON URI 'file://" + dataFile.getPath() + "' TO ROLE user_role");
     statement.execute("GRANT ROLE user_role TO GROUP " + USERGROUP1);
     statement.close();
@@ -177,18 +177,18 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // INSERT is allowed
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t2");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t2");
     try {
       // SELECT is not allowed
-      statement.execute("SELECT * FROM db1.t1");
+      statement.execute("SELECT * FROM " + DB1 + ".t1");
       assertTrue("only SELECT allowed on t1!!", false);
     } catch (Exception e) {
       // Ignore
     }
     try {
       // SELECT is not allowed
-      statement.execute("SELECT * FROM db1.t2");
+      statement.execute("SELECT * FROM " + DB1 + ".t2");
       assertTrue("only INSERT allowed on t2!!", false);
     } catch (Exception e) {
       // Ignore
@@ -219,9 +219,9 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     } catch (Exception e) {
       // Ignore
     }
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("DROP TABLE IF EXISTS t1");
     statement.execute("CREATE TABLE t1 (c1 string)");
     statement.execute("DROP TABLE IF EXISTS t2");
@@ -239,7 +239,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     // Revoke ALL on Db
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("REVOKE ALL ON DATABASE db1 from ROLE user_role");
+    statement.execute("REVOKE ALL ON DATABASE " + DB1 + " from ROLE user_role");
     statement.close();
     connection.close();
 
@@ -247,7 +247,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     statement = context.createStatement(connection);
     statement.execute("SELECT * FROM t1");
     try {
-      statement.execute("SELECT * FROM db1.t2");
+      statement.execute("SELECT * FROM " + DB1 + ".t2");
       assertTrue("SELECT should not be allowed after revoke on parent!!", false);
     } catch (Exception e) {
       // Ignore
@@ -290,7 +290,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
       // Ignore
     }
     try {
-      statement.execute("SELECT * FROM db1.t2");
+      statement.execute("SELECT * FROM " + DB1 + ".t2");
       assertTrue("SELECT should not be allowed after revoke on parent!!", false);
     } catch (Exception e) {
       // Ignore
@@ -325,9 +325,9 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     statement.execute("CREATE ROLE user_role");
 
     statement.execute("GRANT SELECT ON TABLE t1 TO ROLE user_role");
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("DROP TABLE IF EXISTS t2");
     statement.execute("CREATE TABLE t2 (c1 string)");
     statement.execute("GRANT ALL ON TABLE t2 TO ROLE user_role");
@@ -338,7 +338,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     statement.execute("SELECT * FROM t1");
-    statement.execute("SELECT * FROM db1.t2");
+    statement.execute("SELECT * FROM " + DB1 + ".t2");
 
     statement.close();
     connection.close();
@@ -375,9 +375,9 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     statement.execute("CREATE ROLE user_role");
     statement.execute("CREATE ROLE user_role2");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("DROP TABLE IF EXISTS t1");
     statement.execute("CREATE TABLE t1 (c1 string)");
     statement.execute("GRANT ALL ON TABLE t1 TO ROLE user_role");
@@ -393,7 +393,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("SELECT * FROM db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
     statement.close();
     connection.close();
 
@@ -407,7 +407,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     // Revoke ALL on Db
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE " + DB1);
     statement.execute("REVOKE INSERT ON TABLE t1 from ROLE user_role");
     statement.close();
     connection.close();
@@ -415,10 +415,10 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // This Should pass
-    statement.execute("SELECT * FROM db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
 
     try {
-      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
       assertTrue("INSERT Should Not be allowed since we Revoked INSERT privileges on the table !!", false);
     } catch (Exception e) {
 
@@ -430,7 +430,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     // user_role2 can still insert into table
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
     statement.close();
     connection.close();
 
@@ -475,9 +475,9 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     Statement statement = context.createStatement(connection);
     statement.execute("CREATE ROLE user_role");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("DROP TABLE IF EXISTS t1");
     statement.execute("CREATE TABLE t1 (c1 string)");
     statement.execute("GRANT ALL ON TABLE t1 TO ROLE user_role");
@@ -489,7 +489,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("SELECT * FROM db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
     statement.close();
     connection.close();
 
@@ -502,7 +502,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     // Revoke INSERT on Db
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE " + DB1);
     statement.execute("REVOKE INSERT ON TABLE t1 from ROLE user_role");
     statement.close();
     connection.close();
@@ -510,10 +510,10 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // This Should pass
-    statement.execute("SELECT * FROM db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
 
     try {
-      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
       assertTrue("INSERT Should Not be allowed since we Revoked INSERT privileges on the table !!", false);
     } catch (Exception e) {
 
@@ -557,14 +557,14 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     Statement statement = context.createStatement(connection);
     statement.execute("CREATE ROLE user_role");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
 
     statement.execute("DROP TABLE IF EXISTS t1");
     statement.execute("CREATE TABLE t1 (c1 string)");
 
-    statement.execute("GRANT ALL ON DATABASE db1 TO ROLE user_role");
+    statement.execute("GRANT ALL ON DATABASE " + DB1 + " TO ROLE user_role");
     statement.execute("GRANT ALL ON TABLE t1 TO ROLE user_role");
     statement.execute("GRANT SELECT ON TABLE t1 TO ROLE user_role");
     statement.execute("GRANT INSERT ON TABLE t1 TO ROLE user_role");
@@ -578,8 +578,8 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // Ensure everything works
-    statement.execute("SELECT * FROM db1.t1");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
@@ -589,7 +589,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE " + DB1);
     statement.execute("REVOKE ALL ON SERVER server1 from ROLE user_role");
     statement.close();
     connection.close();
@@ -598,14 +598,14 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     statement = context.createStatement(connection);
     // Ensure nothing works
     try {
-      statement.execute("SELECT * FROM db1.t1");
+      statement.execute("SELECT * FROM " + DB1 + ".t1");
       assertTrue("SELECT should not be allowed !!", false);
     } catch (SQLException se) {
       // Ignore
     }
 
     try {
-      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
       assertTrue("INSERT should not be allowed !!", false);
     } catch (SQLException se) {
       // Ignore
@@ -643,14 +643,14 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     Statement statement = context.createStatement(connection);
     statement.execute("CREATE ROLE user_role");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
 
     statement.execute("DROP TABLE IF EXISTS t1");
     statement.execute("CREATE TABLE t1 (c1 string)");
 
-    statement.execute("GRANT ALL ON DATABASE db1 TO ROLE user_role");
+    statement.execute("GRANT ALL ON DATABASE " + DB1 + " TO ROLE user_role");
     statement.execute("GRANT ALL ON TABLE t1 TO ROLE user_role");
     statement.execute("GRANT SELECT ON TABLE t1 TO ROLE user_role");
     statement.execute("GRANT INSERT ON TABLE t1 TO ROLE user_role");
@@ -668,13 +668,13 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // Ensure everything works
-    statement.execute("SELECT * FROM db1.t1");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
-    statement.execute("REVOKE ALL ON DATABASE db1 from ROLE user_role");
+    statement.execute("USE " + DB1);
+    statement.execute("REVOKE ALL ON DATABASE " + DB1 + " from ROLE user_role");
     statement.close();
     connection.close();
 
@@ -682,14 +682,14 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     statement = context.createStatement(connection);
     // Ensure nothing works
     try {
-      statement.execute("SELECT * FROM db1.t1");
+      statement.execute("SELECT * FROM " + DB1 + ".t1");
       assertTrue("SELECT should not be allowed !!", false);
     } catch (SQLException se) {
       // Ignore
     }
 
     try {
-      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
       assertTrue("INSERT should not be allowed !!", false);
     } catch (SQLException se) {
       // Ignore
@@ -725,9 +725,9 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     Statement statement = context.createStatement(connection);
     statement.execute("CREATE ROLE user_role");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
 
     statement.execute("DROP TABLE IF EXISTS t1");
     statement.execute("CREATE TABLE t1 (c1 string)");
@@ -743,8 +743,8 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // Ensure everything works
-    statement.execute("SELECT * FROM db1.t1");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
@@ -754,7 +754,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE " + DB1);
     statement.execute("REVOKE ALL ON TABLE t1 from ROLE user_role");
     statement.close();
     connection.close();
@@ -763,14 +763,14 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     statement = context.createStatement(connection);
     // Ensure nothing works
     try {
-      statement.execute("SELECT * FROM db1.t1");
+      statement.execute("SELECT * FROM " + DB1 + ".t1");
       assertTrue("SELECT should not be allowed !!", false);
     } catch (SQLException se) {
       // Ignore
     }
 
     try {
-      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
       assertTrue("INSERT should not be allowed !!", false);
     } catch (SQLException se) {
       // Ignore
@@ -806,9 +806,9 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     Statement statement = context.createStatement(connection);
     statement.execute("CREATE ROLE user_role");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
 
     statement.execute("DROP TABLE IF EXISTS t1");
     statement.execute("CREATE TABLE t1 (c1 string)");
@@ -824,8 +824,8 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // Ensure everything works
-    statement.execute("SELECT * FROM db1.t1");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
@@ -835,7 +835,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE " + DB1);
     statement.execute("REVOKE SELECT ON TABLE t1 from ROLE user_role");
     statement.close();
     connection.close();
@@ -844,14 +844,14 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     statement = context.createStatement(connection);
     // Ensure select not allowed
     try {
-      statement.execute("SELECT * FROM db1.t1");
+      statement.execute("SELECT * FROM " + DB1 + ".t1");
       assertTrue("SELECT should not be allowed !!", false);
     } catch (SQLException se) {
       // Ignore
     }
 
     // Ensure insert allowed
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
     statement.close();
     connection.close();
 
@@ -886,9 +886,9 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     Statement statement = context.createStatement(connection);
     statement.execute("CREATE ROLE user_role");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
 
     statement.execute("DROP TABLE IF EXISTS t1");
     statement.execute("CREATE TABLE t1 (c1 string)");
@@ -904,8 +904,8 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // Ensure everything works
-    statement.execute("SELECT * FROM db1.t1");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
@@ -915,7 +915,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE " + DB1);
     statement.execute("REVOKE INSERT ON TABLE t1 from ROLE user_role");
     statement.close();
     connection.close();
@@ -924,14 +924,14 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     statement = context.createStatement(connection);
     // Ensure insert not allowed
     try {
-      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE db1.t1");
+      statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".t1");
       assertTrue("INSERT should not be allowed !!", false);
     } catch (SQLException se) {
       // Ignore
     }
 
     // Ensure select allowed
-    statement.execute("SELECT * FROM db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
     statement.close();
     connection.close();
 
@@ -1512,7 +1512,7 @@ public class TestDatabaseProvider extends AbstractTestWithStaticConfiguration {
     }
 
     //On Database - negative
-    resultSet = statement.executeQuery("SHOW GRANT ROLE role1 ON DATABASE db1");
+    resultSet = statement.executeQuery("SHOW GRANT ROLE role1 ON DATABASE " + DB1);
     rowCount = 0 ;
     while (resultSet.next()) {
       rowCount++;

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 9e97b21..acb789f 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
@@ -96,8 +96,8 @@ public class TestDbEndToEnd extends AbstractTestWithStaticConfiguration {
   public void testNonDefault() throws Exception {
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("CREATE database db1");
-    statement.execute("USE db1");
+    statement.execute("CREATE database " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE t1 (c1 string)");
     statement.execute("CREATE ROLE user_role");
     statement.execute("GRANT SELECT ON TABLE t1 TO ROLE user_role");
@@ -107,7 +107,7 @@ public class TestDbEndToEnd extends AbstractTestWithStaticConfiguration {
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
 
-    statement.execute("SELECT * FROM db1.t1");
+    statement.execute("SELECT * FROM " + DB1 + ".t1");
     statement.close();
     connection.close();
   }
@@ -152,43 +152,41 @@ public class TestDbEndToEnd extends AbstractTestWithStaticConfiguration {
    * 4. user create table, load data in experimental DB
    * 5. user create view based on table in experimental DB
    * 6. admin create table (same name) in production DB
-   * 7. admin grant read@productionDB.table to group
-   *    admin grant select@productionDB.table to group
+   * 7. admin grant read@DB2.table to group
+   *    admin grant select@DB2.table to group
    * 8. user load data from experimental table to production table
    */
   @Test
   public void testEndToEnd1() throws Exception {
 
-    String dbName1 = "db_1";
-    String dbName2 = "productionDB";
     String tableName1 = "tb_1";
     String tableName2 = "tb_2";
     String viewName1 = "view_1";
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
     // 1
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
     // 2
-    statement.execute("DROP DATABASE IF EXISTS " + dbName2 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName2);
-    statement.execute("USE " + dbName2);
-    statement.execute("DROP TABLE IF EXISTS " + dbName2 + "." + tableName2);
-    statement.execute("create table " + dbName2 + "." + tableName2
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("USE " + DB2);
+    statement.execute("DROP TABLE IF EXISTS " + DB2 + "." + tableName2);
+    statement.execute("create table " + DB2 + "." + tableName2
         + " (under_col int comment 'the under column', value string)");
     statement.execute("load data local inpath '" + dataFile.getPath()
         + "' into table " + tableName2);
 
     // 3
     statement.execute("CREATE ROLE all_db1");
-    statement.execute("GRANT ALL ON DATABASE " + dbName1 + " TO ROLE all_db1");
+    statement.execute("GRANT ALL ON DATABASE " + DB1 + " TO ROLE all_db1");
 
     statement.execute("CREATE ROLE select_tb1");
     statement.execute("CREATE ROLE insert_tb1");
     statement.execute("CREATE ROLE insert_tb2");
     statement.execute("CREATE ROLE data_uri");
 
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
     statement.execute("GRANT INSERT ON TABLE " + tableName1
         + " TO ROLE insert_tb1");
     statement.execute("GRANT INSERT ON TABLE " + tableName2
@@ -196,7 +194,7 @@ public class TestDbEndToEnd extends AbstractTestWithStaticConfiguration {
     statement.execute("GRANT ALL ON URI 'file://" + dataDir.getPath()
         + "' TO ROLE data_uri");
 
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     statement.execute("GRANT SELECT ON TABLE " + tableName1
         + " TO ROLE select_tb1");
 
@@ -210,9 +208,9 @@ public class TestDbEndToEnd extends AbstractTestWithStaticConfiguration {
     // 4
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
-    statement.execute("DROP TABLE IF EXISTS " + dbName1 + "." + tableName1);
-    statement.execute("create table " + dbName1 + "." + tableName1
+    statement.execute("USE " + DB1);
+    statement.execute("DROP TABLE IF EXISTS " + DB1 + "." + tableName1);
+    statement.execute("create table " + DB1 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.execute("load data local inpath '" + dataFile.getPath()
         + "' into table " + tableName1);
@@ -225,9 +223,9 @@ public class TestDbEndToEnd extends AbstractTestWithStaticConfiguration {
     // 7
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName2);
-    statement.execute("DROP TABLE IF EXISTS " + dbName1 + "." + tableName1);
-    statement.execute("create table " + dbName1 + "." + tableName1
+    statement.execute("USE " + DB2);
+    statement.execute("DROP TABLE IF EXISTS " + DB1 + "." + tableName1);
+    statement.execute("create table " + DB1 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.close();
     connection.close();
@@ -235,10 +233,10 @@ public class TestDbEndToEnd extends AbstractTestWithStaticConfiguration {
     // 8
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
 
     statement.execute("INSERT OVERWRITE TABLE " +
-        dbName2 + "." + tableName2 + " SELECT * FROM " + dbName1
+        DB2 + "." + tableName2 + " SELECT * FROM " + DB1
         + "." + tableName1);
     statement.close();
     connection.close();

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeCleanupOnDrop.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeCleanupOnDrop.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeCleanupOnDrop.java
index a885b8f..0959d2e 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeCleanupOnDrop.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/dbprovider/TestDbPrivilegeCleanupOnDrop.java
@@ -45,8 +45,6 @@ public class TestDbPrivilegeCleanupOnDrop extends
 
   private final String SINGLE_TYPE_DATA_FILE_NAME = "kv1.dat";
 
-  private final static String dbName1 = "db_1";
-  private final static String dbName2 = "prod";
   private final static String tableName1 = "tb_1";
   private final static String tableName2 = "tb_2";
   private final static String tableName3 = "tb_3";
@@ -135,7 +133,7 @@ public class TestDbPrivilegeCleanupOnDrop extends
     setupPrivileges(statement); // setup privileges for USER1
 
     // verify privileges on the created tables
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
     verifyTablePrivilegeExist(statement,
         Lists.newArrayList("select_tbl1", "insert_tbl1", "all_tbl1"),
         tableName1);
@@ -148,7 +146,7 @@ public class TestDbPrivilegeCleanupOnDrop extends
     verifyTablePrivilegesDropped(statement);
 
     // verify privileges created for new tables
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
     verifyTablePrivilegeExist(statement,
         Lists.newArrayList("select_tbl1", "insert_tbl1", "all_tbl1"),
         tableName1 + renameTag);
@@ -172,31 +170,31 @@ public class TestDbPrivilegeCleanupOnDrop extends
     statement.execute("GRANT ROLE all_db1, read_db1, select_tbl1, insert_tbl1,"
         + " all_tbl1, all_tbl2, all_prod to GROUP " + USERGROUP1);
 
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS " + dbName2 + " CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
   }
 
   // create test DBs and Tables
   private void setupDbObjects(Statement statement) throws Exception {
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("CREATE DATABASE " + dbName2);
-    statement.execute("create table " + dbName2 + "." + tableName1
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("create table " + DB2 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
-    statement.execute("create table " + dbName2 + "." + tableName2
+    statement.execute("create table " + DB2 + "." + tableName2
         + " (under_col int comment 'the under column', value string)");
-    statement.execute("create table " + dbName1 + "." + tableName3
+    statement.execute("create table " + DB1 + "." + tableName3
         + " (under_col int comment 'the under column', value string)");
-    statement.execute("create table " + dbName1 + "." + tableName4
+    statement.execute("create table " + DB1 + "." + tableName4
         + " (under_col int comment 'the under column', value string)");
   }
 
   // Create privileges on DB and Tables
   private void setupPrivileges(Statement statement) throws Exception {
-    statement.execute("GRANT ALL ON DATABASE " + dbName1 + " TO ROLE all_db1");
-    statement.execute("GRANT SELECT ON DATABASE " + dbName1
+    statement.execute("GRANT ALL ON DATABASE " + DB1 + " TO ROLE all_db1");
+    statement.execute("GRANT SELECT ON DATABASE " + DB1
         + " TO ROLE read_db1");
-    statement.execute("GRANT ALL ON DATABASE " + dbName2 + " TO ROLE all_prod");
-    statement.execute("USE " + dbName2);
+    statement.execute("GRANT ALL ON DATABASE " + DB2 + " TO ROLE all_prod");
+    statement.execute("USE " + DB2);
     statement.execute("GRANT SELECT ON TABLE " + tableName1
         + " TO ROLE select_tbl1");
     statement.execute("GRANT INSERT ON TABLE " + tableName1
@@ -207,20 +205,20 @@ public class TestDbPrivilegeCleanupOnDrop extends
 
   // Drop test DBs and Tables
   private void dropDbObjects(Statement statement) throws Exception {
-    statement.execute("DROP TABLE " + dbName2 + "." + tableName1);
-    statement.execute("DROP TABLE " + dbName2 + "." + tableName2);
-    statement.execute("DROP DATABASE " + dbName2);
-    statement.execute("DROP DATABASE " + dbName1 + " CASCADE");
+    statement.execute("DROP TABLE " + DB2 + "." + tableName1);
+    statement.execute("DROP TABLE " + DB2 + "." + tableName2);
+    statement.execute("DROP DATABASE " + DB2);
+    statement.execute("DROP DATABASE " + DB1 + " CASCADE");
   }
 
   // rename tables
   private void renameTables(Statement statement) throws Exception {
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
     statement.execute("ALTER TABLE " + tableName1 + " RENAME TO " + tableName1
         + renameTag);
     statement.execute("ALTER TABLE " + tableName2 + " RENAME TO " + tableName2
         + renameTag);
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     statement.execute("ALTER TABLE " + tableName3 + " RENAME TO " + tableName3
         + renameTag);
     statement.execute("ALTER TABLE " + tableName4 + " RENAME TO " + tableName4
@@ -252,8 +250,8 @@ public class TestDbPrivilegeCleanupOnDrop extends
   // verify all the test privileges are dropped as we drop the objects
   private void verifyDbPrivilegesDropped(Statement statement) throws Exception {
     List<String> roles = getRoles(statement);
-    verifyPrivilegeDropped(statement, roles, dbName2, SHOW_GRANT_DB_POSITION);
-    verifyPrivilegeDropped(statement, roles, dbName1, SHOW_GRANT_DB_POSITION);
+    verifyPrivilegeDropped(statement, roles, DB2, SHOW_GRANT_DB_POSITION);
+    verifyPrivilegeDropped(statement, roles, DB1, SHOW_GRANT_DB_POSITION);
 
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 31d8172..3a7aa41 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
@@ -27,6 +27,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -59,6 +60,7 @@ 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 static org.junit.Assert.assertTrue;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.slf4j.Logger;
@@ -143,12 +145,15 @@ public abstract class AbstractTestWithStaticConfiguration {
   protected void createDb(String user, String...dbs) throws Exception {
     Connection connection = context.createConnection(user);
     Statement statement = connection.createStatement();
+    ArrayList<String> allowedDBs = new ArrayList<String>(Arrays.asList(DB1, DB2, DB3));
     for(String db : dbs) {
+      assertTrue(db + " is not part of known test dbs which will be cleaned up after the test", allowedDBs.contains(db));
       statement.execute("CREATE DATABASE " + db);
     }
     statement.close();
     connection.close();
   }
+
   protected void createTable(String user, String db, File dataFile, String...tables)
       throws Exception {
     Connection connection = context.createConnection(user);
@@ -399,15 +404,12 @@ public abstract class AbstractTestWithStaticConfiguration {
     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");
-      }
+    String [] dbs = { DB1, DB2, DB3};
+    for (String db: dbs) {
+      statement.execute("DROP DATABASE if exists " + db + " CASCADE");
     }
+    ResultSet resultSet;
     statement.execute("USE default");
     resultSet = statement.executeQuery("SHOW tables");
     while(resultSet.next()) {

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 447f4d9..2fd0cd9 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
@@ -77,9 +77,9 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     policyFile
         .addRolesToGroup(USERGROUP1, "select_tab1", "insert_tab2")
         .addRolesToGroup(USERGROUP2, "select_tab3")
-        .addPermissionsToRole("select_tab1",  "server=server1->db=db1->table=tab1->action=select")
-        .addPermissionsToRole("select_tab3", "server=server1->db=db2->table=tab3->action=select")
-        .addPermissionsToRole("insert_tab2", "server=server1->db=db2->table=tab2->action=insert")
+        .addPermissionsToRole("select_tab1",  "server=server1->db=" + DB1 + "->table=tab1->action=select")
+        .addPermissionsToRole("select_tab3", "server=server1->db=" + DB2 + "->table=tab3->action=select")
+        .addPermissionsToRole("insert_tab2", "server=server1->db=" + DB2 + "->table=tab2->action=insert")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
@@ -91,12 +91,12 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     statement.execute("DROP DATABASE IF EXISTS DB1 CASCADE");
     statement.execute("DROP DATABASE IF EXISTS DB2 CASCADE");
 
-    statement.execute("CREATE DATABASE DB1");
-    statement.execute("CREATE DATABASE DB2");
-    statement.execute("USE DB1");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB1(id int)");
     statement.executeQuery("SHOW TABLES");
-    statement.execute("USE DB2");
+    statement.execute("USE " + DB2);
     statement.execute("CREATE TABLE TAB2(id int)");
     statement.execute("CREATE TABLE TAB3(id int)");
 
@@ -106,8 +106,8 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     Statement stmt = context.createStatement(conn);
     ResultSet res = stmt.executeQuery("SHOW DATABASES");
     List<String> result = new ArrayList<String>();
-    result.add("db1");
-    result.add("db2");
+    result.add(DB1);
+    result.add(DB2);
     result.add("default");
 
     while (res.next()) {
@@ -118,7 +118,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     res.close();
 
     // test show tables
-    stmt.execute("USE DB1");
+    stmt.execute("USE " + DB1);
     res = stmt.executeQuery("SHOW TABLES");
     result.clear();
     result.add("tab1");
@@ -130,7 +130,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     assertTrue(result.toString(), result.isEmpty());
     res.close();
 
-    stmt.execute("USE DB2");
+    stmt.execute("USE " + DB2);
     res = stmt.executeQuery("SHOW TABLES");
     result.clear();
     result.add("tab2");
@@ -150,7 +150,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     stmt = context.createStatement(conn);
     res = stmt.executeQuery("SHOW DATABASES");
     result.clear();
-    result.add("db2");
+    result.add(DB2);
     result.add("default");
 
     while (res.next()) {
@@ -161,7 +161,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     res.close();
 
     // test show tables
-    stmt.execute("USE DB2");
+    stmt.execute("USE " + DB2);
     res = stmt.executeQuery("SHOW TABLES");
     result.clear();
     result.add("tab3");
@@ -174,7 +174,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     res.close();
 
     try {
-      stmt.execute("USE DB1");
+      stmt.execute("USE " + DB1);
       Assert.fail("Expected SQL exception");
     } catch (SQLException e) {
       context.verifyAuthzException(e);
@@ -193,9 +193,9 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     // edit policy file
     policyFile.addRolesToGroup(USERGROUP1, "select_tab1", "insert_tab2")
         .addRolesToGroup(USERGROUP2, "select_tab3")
-        .addPermissionsToRole("select_tab1", "server=server1->db=db1->table=tab1->action=select")
-        .addPermissionsToRole("select_tab3", "server=server1->db=db2->table=tab3->action=select")
-        .addPermissionsToRole("insert_tab2", "server=server1->db=db2->table=tab2->action=insert")
+        .addPermissionsToRole("select_tab1", "server=server1->db=" + DB1 + "->table=tab1->action=select")
+        .addPermissionsToRole("select_tab3", "server=server1->db=" + DB2 + "->table=tab3->action=select")
+        .addPermissionsToRole("insert_tab2", "server=server1->db=" + DB2 + "->table=tab2->action=insert")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
@@ -208,12 +208,12 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     statement.execute("DROP DATABASE IF EXISTS DB1 CASCADE");
     statement.execute("DROP DATABASE IF EXISTS DB2 CASCADE");
 
-    statement.execute("CREATE DATABASE DB1");
-    statement.execute("CREATE DATABASE DB2");
-    statement.execute("USE DB1");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB1(id int)");
     statement.executeQuery("SHOW TABLES");
-    statement.execute("USE DB2");
+    statement.execute("USE " + DB2);
     statement.execute("CREATE TABLE TAB2(id int)");
     statement.execute("CREATE TABLE TAB3(id int)");
 
@@ -229,8 +229,8 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     assertEquals("TABLE_SCHEM", resMeta.getColumnName(1));
     assertEquals("TABLE_CATALOG", resMeta.getColumnName(2));
 
-    result.add("db1");
-    result.add("db2");
+    result.add(DB1);
+    result.add(DB2);
     result.add("default");
 
     while (res.next()) {
@@ -241,7 +241,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     res.close();
 
     // test direct JDBC metadata API
-    res = conn.getMetaData().getTables(null, "DB1", "tab%", null);
+    res = conn.getMetaData().getTables(null, DB1, "tab%", null);
     result.add("tab1");
 
     while (res.next()) {
@@ -252,7 +252,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     res.close();
 
     // test direct JDBC metadata API
-    res = conn.getMetaData().getTables(null, "DB2", "tab%", null);
+    res = conn.getMetaData().getTables(null, DB2, "tab%", null);
     result.add("tab2");
 
     while (res.next()) {
@@ -297,7 +297,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     assertEquals("TABLE_SCHEM", resMeta.getColumnName(1));
     assertEquals("TABLE_CATALOG", resMeta.getColumnName(2));
 
-    result.add("db2");
+    result.add(DB2);
     result.add("default");
 
     while (res.next()) {
@@ -330,7 +330,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     res.close();
 
     //test show columns
-    res = conn.getMetaData().getColumns(null, "DB1", "tab%","i%" );
+    res = conn.getMetaData().getColumns(null, DB1, "tab%","i%" );
 
     while (res.next()) {
       String columnName = res.getString(4);
@@ -414,23 +414,22 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
   public void testNegativeUserPrivileges() throws Exception {
     // edit policy file
     policyFile.addRolesToGroup(USERGROUP1, "db1_tab1_insert", "db1_tab2_all")
-        .addPermissionsToRole("db1_tab2_all", "server=server1->db=db1->table=table_2")
-        .addPermissionsToRole("db1_tab1_insert", "server=server1->db=db1->table=table_1->action=insert")
+        .addPermissionsToRole("db1_tab2_all", "server=server1->db=" + DB1 + "->table=table_2")
+        .addPermissionsToRole("db1_tab1_insert", "server=server1->db=" + DB1 + "->table=table_1->action=insert")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
-    String dbName = "db1";
     adminStmt.execute("use default");
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
-    adminStmt.execute("create table " + dbName + ".table_1 (id int)");
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
+    adminStmt.execute("create table " + DB1 + ".table_1 (id int)");
     adminStmt.close();
     adminCon.close();
     Connection userConn = context.createConnection(USER1_1);
     Statement userStmt = context.createStatement(userConn);
-    context.assertAuthzException(userStmt, "select * from " + dbName + ".table_1");
+    context.assertAuthzException(userStmt, "select * from " + DB1 + ".table_1");
     userConn.close();
     userStmt.close();
   }
@@ -444,7 +443,7 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
   @Test
   public void testNegativeUserDMLPrivileges() throws Exception {
     policyFile
-        .addPermissionsToRole("db1_tab2_all", "server=server1->db=db1->table=table_2")
+        .addPermissionsToRole("db1_tab2_all", "server=server1->db=" + DB1 + "->table=table_2")
         .addRolesToGroup(USERGROUP1, "db1_tab2_all")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
@@ -490,24 +489,23 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     policyFile
         .addRolesToGroup(USERGROUP1, "db1_all")
         .addRolesToGroup(USERGROUP2, "db1_tab1_select")
-        .addPermissionsToRole("db1_all", "server=server1->db=db1")
-        .addPermissionsToRole("db1_tab1_select", "server=server1->db=db1->table=table_1->action=select")
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
+        .addPermissionsToRole("db1_tab1_select", "server=server1->db=" + DB1 + "->table=table_1->action=select")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
     // create dbs
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
-    String dbName = "db1";
     adminStmt.execute("use default");
     adminStmt.execute("drop table if exists table_def");
     adminStmt.execute("create table table_def (name string)");
     adminStmt
     .execute("load data local inpath '" + dataFile.getPath() + "' into table table_def");
 
-    adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
-    adminStmt.execute("CREATE DATABASE " + dbName);
-    adminStmt.execute("use " + dbName);
+    adminStmt.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    adminStmt.execute("CREATE DATABASE " + DB1);
+    adminStmt.execute("use " + DB1);
 
     adminStmt.execute("create table table_1 (name string)");
     adminStmt
@@ -526,28 +524,28 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     Connection userConn = context.createConnection(USER2_1);
     Statement userStmt = context.createStatement(userConn);
 
-    context.assertAuthzException(userStmt, "drop database " + dbName);
+    context.assertAuthzException(userStmt, "drop database " + DB1);
 
     // Hive currently doesn't support cross db index DDL
 
     context.assertAuthzException(userStmt, "CREATE TEMPORARY FUNCTION strip AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDFPrintf'");
-    context.assertAuthzException(userStmt, "create table  " + dbName
-        + ".c_tab_2 as select * from  " + dbName + ".table_2");
-    context.assertAuthzException(userStmt, "select * from  " + dbName + ".table_2");
-    context.assertAuthzException(userStmt, "ALTER DATABASE " + dbName
+    context.assertAuthzException(userStmt, "create table  " + DB1
+        + ".c_tab_2 as select * from  " + DB1 + ".table_2");
+    context.assertAuthzException(userStmt, "select * from  " + DB1 + ".table_2");
+    context.assertAuthzException(userStmt, "ALTER DATABASE " + DB1
         + " SET DBPROPERTIES ('foo' = 'bar')");
-    context.assertAuthzException(userStmt, "drop table " + dbName + ".table_1");
-    context.assertAuthzException(userStmt, "DROP VIEW IF EXISTS " + dbName + ".v1");
-    context.assertAuthzException(userStmt, "create table " + dbName + ".table_5 (name string)");
-    context.assertAuthzException(userStmt, "ALTER TABLE " + dbName + ".table_1  RENAME TO "
-        + dbName + ".table_99");
-    context.assertAuthzException(userStmt, "insert overwrite table " + dbName
-        + ".table_2 select * from " + dbName + ".table_1");
-    context.assertAuthzException(userStmt, "insert overwrite table " + dbName
+    context.assertAuthzException(userStmt, "drop table " + DB1 + ".table_1");
+    context.assertAuthzException(userStmt, "DROP VIEW IF EXISTS " + DB1 + ".v1");
+    context.assertAuthzException(userStmt, "create table " + DB1 + ".table_5 (name string)");
+    context.assertAuthzException(userStmt, "ALTER TABLE " + DB1 + ".table_1  RENAME TO "
+        + DB1 + ".table_99");
+    context.assertAuthzException(userStmt, "insert overwrite table " + DB1
+        + ".table_2 select * from " + DB1 + ".table_1");
+    context.assertAuthzException(userStmt, "insert overwrite table " + DB1
         + ".table_2 select * from " + "table_def");
-    context.assertAuthzException(userStmt, "ALTER TABLE " + dbName
+    context.assertAuthzException(userStmt, "ALTER TABLE " + DB1
         + ".table_part_1 ADD IF NOT EXISTS PARTITION (year = 2012)");
-    context.assertAuthzException(userStmt, "ALTER TABLE " + dbName
+    context.assertAuthzException(userStmt, "ALTER TABLE " + DB1
         + ".table_part_1 PARTITION (year = 2012) SET LOCATION '/etc'");
     userStmt.close();
     userConn.close();
@@ -638,9 +636,9 @@ public class TestCrossDbOps extends AbstractTestWithStaticConfiguration {
     // edit policy file
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1", "load_data", "select_tb2")
-        .addPermissionsToRole("all_db1", "server=server1->db=db_1")
-        .addPermissionsToRole("all_db2", "server=server1->db=db_2")
-        .addPermissionsToRole("select_tb2", "server=server1->db=db_2->table=tb_1->action=select")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
+        .addPermissionsToRole("all_db2", "server=server1->db=" + DB2)
+        .addPermissionsToRole("select_tb2", "server=server1->db=" + DB2 + "->table=tb_1->action=select")
         .addPermissionsToRole("load_data", "server=server1->URI=file://" + dataFile.getPath())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 0901b67..23577c2 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
@@ -61,22 +61,20 @@ public class TestEndToEnd extends AbstractTestWithStaticConfiguration {
     policyFile
       .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
-    String dbName1 = "db_1";
-    String dbName2 = "productionDB";
     String tableName1 = "tb_1";
     String tableName2 = "tb_2";
     String viewName1 = "view_1";
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
     // 1
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
     // 2
-    statement.execute("DROP DATABASE IF EXISTS " + dbName2 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName2);
-    statement.execute("USE " + dbName2);
-    statement.execute("DROP TABLE IF EXISTS " + dbName2 + "." + tableName2);
-    statement.execute("create table " + dbName2 + "." + tableName2
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("USE " + DB2);
+    statement.execute("DROP TABLE IF EXISTS " + DB2 + "." + tableName2);
+    statement.execute("create table " + DB2 + "." + tableName2
         + " (under_col int comment 'the under column', value string)");
     statement.execute("load data local inpath '" + dataFile.getPath()
             + "' into table " + tableName2);
@@ -86,19 +84,19 @@ public class TestEndToEnd extends AbstractTestWithStaticConfiguration {
     // 3
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1", "data_uri", "select_tb1", "insert_tb1")
-        .addPermissionsToRole("all_db1", "server=server1->db=db_1")
-        .addPermissionsToRole("select_tb1", "server=server1->db=productionDB->table=tb_1->action=select")
-        .addPermissionsToRole("insert_tb2", "server=server1->db=productionDB->table=tb_2->action=insert")
-        .addPermissionsToRole("insert_tb1", "server=server1->db=productionDB->table=tb_2->action=insert")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
+        .addPermissionsToRole("select_tb1", "server=server1->db=" + DB2 + "->table=tb_1->action=select")
+        .addPermissionsToRole("insert_tb2", "server=server1->db=" + DB2 + "->table=tb_2->action=insert")
+        .addPermissionsToRole("insert_tb1", "server=server1->db=" + DB2 + "->table=tb_2->action=insert")
         .addPermissionsToRole("data_uri", "server=server1->uri=file://" + dataDir.getPath());
     writePolicyFile(policyFile);
 
     // 4
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
-    statement.execute("DROP TABLE IF EXISTS " + dbName1 + "." + tableName1);
-    statement.execute("create table " + dbName1 + "." + tableName1
+    statement.execute("USE " + DB1);
+    statement.execute("DROP TABLE IF EXISTS " + DB1 + "." + tableName1);
+    statement.execute("create table " + DB1 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.execute("load data local inpath '" + dataFile.getPath()
             + "' into table " + tableName1);
@@ -110,9 +108,9 @@ public class TestEndToEnd extends AbstractTestWithStaticConfiguration {
     // 7
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName2);
-    statement.execute("DROP TABLE IF EXISTS " + dbName1 + "." + tableName1);
-    statement.execute("create table " + dbName1 + "." + tableName1
+    statement.execute("USE " + DB2);
+    statement.execute("DROP TABLE IF EXISTS " + DB1 + "." + tableName1);
+    statement.execute("create table " + DB1 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.close();
     connection.close();
@@ -120,9 +118,9 @@ public class TestEndToEnd extends AbstractTestWithStaticConfiguration {
     // 8
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
     statement.execute("INSERT OVERWRITE TABLE " +
-        dbName2 + "." + tableName2 + " SELECT * FROM " + dbName1
+        DB2 + "." + tableName2 + " SELECT * FROM " + DB1
         + "." + tableName1);
     statement.close();
     connection.close();

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 1e217a3..25d1f8c 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
@@ -36,14 +36,14 @@ public class TestMetadataPermissions extends AbstractTestWithStaticConfiguration
     policyFile
         .addRolesToGroup(USERGROUP1, "db1_all", "db2_all")
         .addRolesToGroup(USERGROUP2, "db1_all")
-        .addPermissionsToRole("db1_all", "server=server1->db=db1")
-        .addPermissionsToRole("db2_all", "server=server1->db=db2")
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
+        .addPermissionsToRole("db2_all", "server=server1->db=" + DB2)
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
     Connection adminCon = context.createConnection(ADMIN1);
     Statement adminStmt = context.createStatement(adminCon);
-    for (String dbName : new String[] { "db1", "db2" }) {
+    for (String dbName : new String[] { "" + DB1, DB2 }) {
       adminStmt.execute("USE default");
       adminStmt.execute("DROP DATABASE IF EXISTS " + dbName + " CASCADE");
       adminStmt.execute("CREATE DATABASE " + dbName);
@@ -60,14 +60,13 @@ public class TestMetadataPermissions extends AbstractTestWithStaticConfiguration
    */
   @Test
   public void testDescPrivilegesNegative() throws Exception {
-    String dbName = "db2";
     Connection connection = context.createConnection(USER2_1);
     Statement statement = context.createStatement(connection);
-    context.assertAuthzException(statement, "USE " + dbName);
+    context.assertAuthzException(statement, "USE " + DB2);
 //    TODO when DESCRIBE db.table is supported tests should be uncommented
 //    for (String tabName : new String[] { "tab1", "tab2" }) {
-//      context.assertAuthzException(statement, "DESCRIBE " + dbName + "." + tabName);
-//      context.assertAuthzException(statement, "DESCRIBE EXTENDED " + dbName + "." + tabName);
+//      context.assertAuthzException(statement, "DESCRIBE " + DB1 + "." + tabName);
+//      context.assertAuthzException(statement, "DESCRIBE EXTENDED " + DB1 + "." + tabName);
 //    }
     statement.close();
     connection.close();
@@ -79,11 +78,10 @@ public class TestMetadataPermissions extends AbstractTestWithStaticConfiguration
    */
   @Test
   public void testDescDbPrivilegesNegative() throws Exception {
-    String dbName = "db2";
     Connection connection = context.createConnection(USER2_1);
     Statement statement = context.createStatement(connection);
-    context.assertAuthzException(statement, "DESCRIBE DATABASE " + dbName);
-    context.assertAuthzException(statement, "DESCRIBE DATABASE EXTENDED " + dbName);
+    context.assertAuthzException(statement, "DESCRIBE DATABASE " + DB2);
+    context.assertAuthzException(statement, "DESCRIBE DATABASE EXTENDED " + DB2);
     statement.close();
     connection.close();
   }
@@ -96,7 +94,7 @@ public class TestMetadataPermissions extends AbstractTestWithStaticConfiguration
   public void testDescDbPrivilegesPositive() throws Exception {
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    for (String dbName : new String[] { "db1", "db2" }) {
+    for (String dbName : new String[] { DB1, DB2 }) {
       statement.execute("USE " + dbName);
       Assert.assertTrue(statement.executeQuery("DESCRIBE DATABASE " + dbName).next());
       Assert.assertTrue(statement.executeQuery("DESCRIBE DATABASE EXTENDED " + dbName).next());
@@ -112,7 +110,7 @@ public class TestMetadataPermissions extends AbstractTestWithStaticConfiguration
   public void testDescPrivilegesPositive() throws Exception {
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    for (String dbName : new String[] { "db1", "db2" }) {
+    for (String dbName : new String[] { DB1, DB2 }) {
       statement.execute("USE " + dbName);
       Assert.assertTrue(statement.executeQuery("DESCRIBE DATABASE " + dbName).next());
       for (String tabName : new String[] { "tab1", "tab2" }) {

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 67cbd32..c1a8d91 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
@@ -67,22 +67,20 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1", "load_data")
         .addPermissionsToRole("load_data", "server=server1->uri=file://" + dataDir.getPath())
-        .addPermissionsToRole("all_db1", "server=server1->db=db_1")
+        .addPermissionsToRole("all_db1", "server=server1->db="  + DB1)
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
-    String dbName1 = "db_1";
-    String dbName2 = "proddb";
     String tableName1 = "tb_1";
 
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS " + dbName2 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("CREATE DATABASE " + dbName2);
-    statement.execute("DROP TABLE IF EXISTS " + dbName2 + "." + tableName1);
-    statement.execute("create table " + dbName2 + "." + tableName1
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("DROP TABLE IF EXISTS " + DB2 + "." + tableName1);
+    statement.execute("create table " + DB2 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.close();
     connection.close();
@@ -90,7 +88,7 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
     // a
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     statement.execute("DROP TABLE IF EXISTS " + tableName1);
     statement.execute("create table " + tableName1
         + " (under_col int comment 'the under column', value string)");
@@ -99,17 +97,17 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
 
     policyFile
         .addRolesToGroup(USERGROUP1, "insert_proddb_tbl1")
-        .addPermissionsToRole("insert_proddb_tbl1", "server=server1->db=proddb->table=tb_1->action=insert");
+        .addPermissionsToRole("insert_proddb_tbl1", "server=server1->db="  + DB2 + "->table=tb_1->action=insert");
     writePolicyFile(policyFile);
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
     statement.execute("INSERT OVERWRITE TABLE "
-        + tableName1 + " SELECT * FROM " + dbName1
+        + tableName1 + " SELECT * FROM " + DB1
         + "." + tableName1);
 
     // b
     policyFile
         .addRolesToGroup(USERGROUP1, "select_proddb_tbl1")
-        .addPermissionsToRole("select_proddb_tbl1", "server=server1->db=proddb->table=tb_1->action=select");
+        .addPermissionsToRole("select_proddb_tbl1", "server=server1->db="  + DB2 + "->table=tb_1->action=select");
     writePolicyFile(policyFile);
 
     ResultSet resultSet = statement.executeQuery("SELECT * FROM " + tableName1 + " LIMIT 10");
@@ -123,18 +121,18 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
     // c
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    context.assertAuthzException(statement, "USE " + dbName2);
+    context.assertAuthzException(statement, "USE " + DB2);
     context.assertAuthzException(statement, "INSERT OVERWRITE TABLE "
-        + dbName2 + "." + tableName1 + " SELECT * FROM " + dbName1
+        + DB2 + "." + tableName1 + " SELECT * FROM " + DB1
         + "." + tableName1);
-    context.assertAuthzException(statement, "SELECT * FROM " + dbName2 + "." + tableName1 + " LIMIT 10");
+    context.assertAuthzException(statement, "SELECT * FROM " + DB2 + "." + tableName1 + " LIMIT 10");
     statement.close();
     connection.close();
 
     // d
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
     context.assertAuthzException(statement, "DROP TABLE " + tableName1);
     statement.close();
     connection.close();
@@ -150,22 +148,20 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
   public void testMovingTable2() throws Exception {
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1", "load_data")
-        .addPermissionsToRole("all_db1", "server=server1->db=db_1")
+        .addPermissionsToRole("all_db1", "server=server1->db="  + DB1)
         .addPermissionsToRole("load_data", "server=server1->uri=file://" + dataDir.getPath())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
-    String dbName1 = "db_1";
-    String dbName2 = "proddb";
     String tableName1 = "tb_1";
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS " + dbName2 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("CREATE DATABASE " + dbName2);
-    statement.execute("DROP TABLE IF EXISTS " + dbName2 + "." + tableName1);
-    statement.execute("create table " + dbName2 + "." + tableName1
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("DROP TABLE IF EXISTS " + DB2 + "." + tableName1);
+    statement.execute("create table " + DB2 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.close();
     connection.close();
@@ -173,50 +169,50 @@ public class TestMovingToProduction extends AbstractTestWithStaticConfiguration
     // a
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("DROP TABLE IF EXISTS " + dbName1 + "." + tableName1);
-    statement.execute("create table " + dbName1 + "." + tableName1
+    statement.execute("DROP TABLE IF EXISTS " + DB1 + "." + tableName1);
+    statement.execute("create table " + DB1 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.execute("LOAD DATA LOCAL INPATH 'file://" + dataDir.getPath()
-        + "' INTO TABLE " + dbName1 + "." + tableName1);
+        + "' INTO TABLE " + DB1 + "." + tableName1);
 
     policyFile
         .addRolesToGroup(USERGROUP1, "insert_proddb_tbl1")
-        .addPermissionsToRole("insert_proddb_tbl1", "server=server1->db=proddb->table=tb_1->action=insert");
+        .addPermissionsToRole("insert_proddb_tbl1", "server=server1->db="  + DB2 + "->table=tb_1->action=insert");
     writePolicyFile(policyFile);
 
     statement.execute("INSERT OVERWRITE TABLE "
-        + dbName2 + "." + tableName1 + " SELECT * FROM " + dbName1
+        + DB2 + "." + tableName1 + " SELECT * FROM " + DB1
         + "." + tableName1);
 
     // b
     policyFile
         .addRolesToGroup(USERGROUP1, "select_proddb_tbl1")
-        .addPermissionsToRole("select_proddb_tbl1", "server=server1->db=proddb->table=tb_1->action=select");
+        .addPermissionsToRole("select_proddb_tbl1", "server=server1->db="  + DB2 + "->table=tb_1->action=select");
     writePolicyFile(policyFile);
 
     assertTrue("user1 should be able to select data from "
-        + dbName2 + "." + dbName2 + "." + tableName1, statement.execute("SELECT * FROM "
-            + dbName2 + "." + tableName1 + " LIMIT 10"));
-    assertTrue("user1 should be able to describe table " + dbName2 + "." + tableName1,
-        statement.execute("DESCRIBE " + dbName2 + "." + tableName1));
+        + DB2 + "." + DB2 + "." + tableName1, statement.execute("SELECT * FROM "
+            + DB2 + "." + tableName1 + " LIMIT 10"));
+    assertTrue("user1 should be able to describe table " + DB2 + "." + tableName1,
+        statement.execute("DESCRIBE " + DB2 + "." + tableName1));
 
     // c
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
 
     context.assertAuthzException(statement, "INSERT OVERWRITE TABLE "
-        + dbName2 + "." + tableName1 + " SELECT * FROM " + dbName1
+        + DB2 + "." + tableName1 + " SELECT * FROM " + DB1
         + "." + tableName1);
 
     context.assertAuthzException(statement, "SELECT * FROM "
-        + dbName2 + "." + tableName1 + " LIMIT 10");
+        + DB2 + "." + tableName1 + " LIMIT 10");
     statement.close();
     connection.close();
 
     // d
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName2);
+    statement.execute("USE " + DB2);
     context.assertAuthzException(statement, "DROP TABLE " + tableName1);
     statement.close();
     connection.close();


[2/3] SENTRY-47: Tests need to clean up the databases and tables it creates (Sravya Tirukkovalur via Prasad Mujumdar)

Posted by pr...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperations.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperations.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperations.java
index 41bd083..fddb343 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperations.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestOperations.java
@@ -35,22 +35,21 @@ import com.google.common.io.Resources;
 
 public class TestOperations extends AbstractTestWithStaticConfiguration {
   private PolicyFile policyFile;
-  final String dbName = "db1";
   final String tableName = "tb1";
   final String semanticException = "SemanticException No valid privileges";
 
   static Map<String, String> privileges = new HashMap<String, String>();
   static {
     privileges.put("all_server", "server=server1->action=all");
-    privileges.put("all_db1", "server=server1->db=db1->action=all");
-    privileges.put("select_db1", "server=server1->db=db1->action=select");
-    privileges.put("insert_db1", "server=server1->db=db1->action=insert");
-    privileges.put("all_db2", "server=server1->db=db2->action=all");
-    privileges.put("all_db1_tb1", "server=server1->db=db1->table=tb1->action=all");
-    privileges.put("select_db1_tb1", "server=server1->db=db1->table=tb1->action=select");
-    privileges.put("insert_db1_tb1", "server=server1->db=db1->table=tb1->action=insert");
-    privileges.put("insert_db2_tb2", "server=server1->db=db2->table=tb2->action=insert");
-    privileges.put("select_db1_view1", "server=server1->db=db1->table=view1->action=select");
+    privileges.put("all_db1", "server=server1->db=" + DB1 + "->action=all");
+    privileges.put("select_db1", "server=server1->db=" + DB1 + "->action=select");
+    privileges.put("insert_db1", "server=server1->db=" + DB1 + "->action=insert");
+    privileges.put("all_db2", "server=server1->db=" + DB2 + "->action=all");
+    privileges.put("all_db1_tb1", "server=server1->db=" + DB1 + "->table=tb1->action=all");
+    privileges.put("select_db1_tb1", "server=server1->db=" + DB1 + "->table=tb1->action=select");
+    privileges.put("insert_db1_tb1", "server=server1->db=" + DB1 + "->table=tb1->action=insert");
+    privileges.put("insert_db2_tb2", "server=server1->db=" + DB2 + "->table=tb2->action=insert");
+    privileges.put("select_db1_view1", "server=server1->db=" + DB1 + "->table=view1->action=select");
 
   }
 
@@ -86,7 +85,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
   private void adminCreatePartition() throws Exception{
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE " + DB1);
     statement.execute("ALTER TABLE tb1 ADD IF NOT EXISTS PARTITION (b = '1') ");
     statement.close();
     connection.close();
@@ -99,7 +98,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
    */
   @Test
   public void testAllOnDatabase() throws Exception{
-    adminCreate(dbName, null);
+    adminCreate(DB1, null);
     policyFile
         .addPermissionsToRole("all_db1", privileges.get("all_db1"))
         .addRolesToGroup(USERGROUP1, "all_db1");
@@ -108,14 +107,14 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    statement.execute("CREATE TABLE db1.tb1(a int)");
-    statement.execute("ALTER DATABASE db1 SET DBPROPERTIES ('comment'='comment')");
-    statement.execute("DROP database db1 cascade");
+    statement.execute("CREATE TABLE " + DB1 + ".tb1(a int)");
+    statement.execute("ALTER DATABASE " + DB1 + " SET DBPROPERTIES ('comment'='comment')");
+    statement.execute("DROP database " + DB1 + " cascade");
     statement.close();
     connection.close();
 
     //Negative case
-    adminCreate(dbName, null);
+    adminCreate(DB1, null);
     policyFile
         .addPermissionsToRole("select_db1", privileges.get("select_db1"))
         .addRolesToGroup(USERGROUP2, "select_db1");
@@ -123,9 +122,9 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    context.assertSentrySemanticException(statement, "CREATE TABLE db1.tb1(a int)", semanticException);
-    context.assertSentrySemanticException(statement, "ALTER DATABASE db1 SET DBPROPERTIES ('comment'='comment')", semanticException);
-    context.assertSentrySemanticException(statement, "DROP database db1 cascade", semanticException);
+    context.assertSentrySemanticException(statement, "CREATE TABLE " + DB1 + ".tb1(a int)", semanticException);
+    context.assertSentrySemanticException(statement, "ALTER DATABASE " + DB1 + " SET DBPROPERTIES ('comment'='comment')", semanticException);
+    context.assertSentrySemanticException(statement, "DROP database " + DB1 + " cascade", semanticException);
     statement.close();
     connection.close();
 
@@ -135,7 +134,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
    */
   @Test
   public void testDescDB() throws Exception {
-    adminCreate(dbName, null);
+    adminCreate(DB1, null);
     policyFile
         .addPermissionsToRole("select_db1", privileges.get("select_db1"))
         .addPermissionsToRole("insert_db1", privileges.get("insert_db1"))
@@ -145,13 +144,13 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    statement.execute("describe database db1");
+    statement.execute("describe database " + DB1);
     statement.close();
     connection.close();
 
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("describe database db1");
+    statement.execute("describe database " + DB1);
     statement.close();
     connection.close();
 
@@ -162,7 +161,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     writePolicyFile(policyFile);
     connection = context.createConnection(USER3_1);
     statement = context.createStatement(connection);
-    context.assertSentrySemanticException(statement, "describe database db1", semanticException);
+    context.assertSentrySemanticException(statement, "describe database " + DB1, semanticException);
     statement.close();
     connection.close();
 
@@ -203,7 +202,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
   */
   @Test
   public void testAllOnTable() throws Exception{
-    adminCreate(dbName, tableName, true);
+    adminCreate(DB1, tableName, true);
     policyFile
         .addPermissionsToRole("all_db1_tb1", privileges.get("all_db1_tb1"))
         .addRolesToGroup(USERGROUP1, "all_db1_tb1")
@@ -216,7 +215,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     //Negative test cases
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     assertSemanticException(statement, "CREATE INDEX table01_index ON TABLE tb1 (a) AS 'COMPACT' WITH DEFERRED REBUILD");
     assertSemanticException(statement, "DROP INDEX table01_index ON tb1");
     assertSemanticException(statement, "ALTER TABLE tb1 ADD IF NOT EXISTS PARTITION (b = '1') ");
@@ -231,13 +230,13 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     //Setup
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     statement.execute("ALTER TABLE tb1 ADD IF NOT EXISTS PARTITION (b = '10') ");
 
     //Negative test cases
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     assertSemanticException(statement, "ALTER TABLE tb1 PARTITION (b = 10) RENAME TO PARTITION (b = 2)");
     assertSemanticException(statement, "ALTER TABLE tb1 PARTITION (b = 10) SET SERDEPROPERTIES ('field.delim' = ',')");
     //assertSemanticException(statement, "ALTER TABLE tb1 ARCHIVE PARTITION (b = 2)");
@@ -260,12 +259,12 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     //assertSemanticException(statement, "ALTER INDEX tb1_index ON tb1 REBUILD");
     assertSemanticException(statement, "ALTER TABLE tb1 RENAME TO tb2");
 
-    assertSemanticException(statement, "DROP TABLE db1.tb1");
+    assertSemanticException(statement, "DROP TABLE " + DB1 + ".tb1");
 
     //Positive cases
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     statement.execute("CREATE INDEX table01_index ON TABLE tb1 (a) AS 'COMPACT' WITH DEFERRED REBUILD");
     statement.execute("DROP INDEX table01_index ON tb1");
     statement.execute("ALTER TABLE tb1 ADD IF NOT EXISTS PARTITION (b = '1') ");
@@ -302,9 +301,9 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     //Drop of the new tablename works only when Hive meta store syncs the alters with the sentry privileges.
     //This is currently not set for pseudo cluster runs
     if( hiveServer2Type.equals(HiveServerFactory.HiveServer2Type.UnmanagedHiveServer2)) {
-      statement.execute("DROP TABLE db1.tb2");
+      statement.execute("DROP TABLE " + DB1 + ".tb2");
     } else {
-      statement.execute("DROP TABLE db1.tb1");
+      statement.execute("DROP TABLE " + DB1 + ".tb1");
     }
 
     statement.close();
@@ -317,7 +316,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
    */
   @Test
   public void testSelectAndInsertOnTable() throws Exception {
-    adminCreate(dbName, tableName, true);
+    adminCreate(DB1, tableName, true);
     adminCreatePartition();
     policyFile
         .addPermissionsToRole("select_db1_tb1", privileges.get("select_db1_tb1"))
@@ -327,7 +326,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     statement.execute("ANALYZE TABLE tb1 PARTITION (b='1' ) COMPUTE STATISTICS");
     statement.close();
     connection.close();
@@ -345,7 +344,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
    */
   @Test
   public void testSelectOnTable() throws Exception {
-    adminCreate(dbName, tableName, true);
+    adminCreate(DB1, tableName, true);
     adminCreatePartition();
     policyFile
         .addPermissionsToRole("select_db1_tb1", privileges.get("select_db1_tb1"))
@@ -354,7 +353,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     statement.execute("select * from tb1");
 
     statement.executeQuery("SHOW Partitions tb1");
@@ -377,7 +376,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     writePolicyFile(policyFile);
     connection = context.createConnection(USER3_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     context.assertSentrySemanticException(statement, "select * from tb1", semanticException);
 
     statement.close();
@@ -398,7 +397,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
    */
   @Test
   public void testInsertOnTable() throws Exception {
-    adminCreate(dbName, tableName, true);
+    adminCreate(DB1, tableName, true);
     adminCreatePartition();
     policyFile
         .addPermissionsToRole("insert_db1_tb1", privileges.get("insert_db1_tb1"))
@@ -407,7 +406,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     /*statement.execute("LOCK TABLE tb1 EXCLUSIVE");
     statement.execute("UNLOCK TABLE tb1");
     */
@@ -438,7 +437,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
    */
   @Test
   public void testAlterAllOnTableAndURI() throws Exception {
-    adminCreate(dbName, tableName, true);
+    adminCreate(DB1, tableName, true);
     String tabLocation = dfs.getBaseDir() + "/" + Math.random();
     policyFile
         .addPermissionsToRole("all_db1_tb1", privileges.get("all_db1_tb1"))
@@ -450,7 +449,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     statement.execute("ALTER TABLE tb1 SET LOCATION '" + tabLocation + "'");
     statement.execute("ALTER TABLE tb1 ADD IF NOT EXISTS PARTITION (b = '3') LOCATION '" + tabLocation + "/part'");
     statement.close();
@@ -464,7 +463,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(USER3_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     context.assertSentrySemanticException(statement, "ALTER TABLE tb1 SET LOCATION '" + tabLocation + "'",
         semanticException);
     context.assertSentrySemanticException(statement, "ALTER TABLE tb1 ADD IF NOT EXISTS PARTITION (b = '3') LOCATION '"
@@ -480,8 +479,8 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
    */
   @Test
   public void testCreateView() throws Exception {
-    adminCreate(dbName, tableName);
-    adminCreate("db2", null);
+    adminCreate(DB1, tableName);
+    adminCreate(DB2, null);
     policyFile
         .addPermissionsToRole("select_db1_tb1", privileges.get("select_db1_tb1"))
         .addPermissionsToRole("all_db2", privileges.get("all_db2"))
@@ -490,8 +489,8 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    statement.execute("use db2");
-    statement.execute("create view view1 as select a from db1.tb1");
+    statement.execute("use " + DB2);
+    statement.execute("create view view1 as select a from " + DB1 + ".tb1");
     statement.close();
     connection.close();
 
@@ -503,8 +502,8 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(USER3_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db2");
-    context.assertSentrySemanticException(statement, "create view view1 as select a from db1.tb1",
+    statement.execute("Use " + DB2);
+    context.assertSentrySemanticException(statement, "create view view1 as select a from " + DB1 + ".tb1",
         semanticException);
     statement.close();
     connection.close();
@@ -525,9 +524,9 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
 
-    dropDb(ADMIN1, dbName);
-    createDb(ADMIN1, dbName);
-    createTable(ADMIN1, dbName, dataFile, tableName);
+    dropDb(ADMIN1, DB1);
+    createDb(ADMIN1, DB1);
+    createTable(ADMIN1, DB1, dataFile, tableName);
     String location = dfs.getBaseDir() + "/" + Math.random();
     policyFile
         .addPermissionsToRole("all_db1", privileges.get("all_db1"))
@@ -544,7 +543,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     //Negative case
     connection = context.createConnection(USER3_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     context.assertSentrySemanticException(statement, "export table tb1 to '" + location + "'",
         semanticException);
     statement.close();
@@ -553,7 +552,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     //Positive
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     statement.execute("export table tb1 to '" + location + "'" );
     statement.close();
     connection.close();
@@ -561,7 +560,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     //Negative
     connection = context.createConnection(USER3_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     context.assertSentrySemanticException(statement, "import table tb2 from '" + location + "'",
         semanticException);
     statement.close();
@@ -570,7 +569,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     //Positive
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     statement.execute("import table tb2 from '" + location + "'");
     statement.close();
     connection.close();
@@ -588,7 +587,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
 
-    adminCreate(dbName, tableName);
+    adminCreate(DB1, tableName);
 
     policyFile
         .addPermissionsToRole("insert_db1_tb1", privileges.get("insert_db1_tb1"))
@@ -598,7 +597,7 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    statement.execute("Use db1");
+    statement.execute("Use " + DB1);
     statement.execute("load data local inpath '" + dataFile.getPath() + "' into table tb1" );
     statement.close();
     connection.close();
@@ -609,13 +608,13 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
    */
   @Test
   public void testCTAS() throws Exception {
-    adminCreate(dbName, tableName);
-    adminCreate("db2", null);
+    adminCreate(DB1, tableName);
+    adminCreate(DB2, null);
 
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("Use db1");
-    statement.execute("create view view1 as select a from db1.tb1");
+    statement.execute("Use " + DB1);
+    statement.execute("create view view1 as select a from " + DB1 + ".tb1");
     statement.close();
     connection.close();
 
@@ -629,18 +628,18 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db2");
-    statement.execute("create table tb2 as select a from db1.tb1" );
-    context.assertSentrySemanticException(statement, "create table tb3 as select a from db1.view1",
+    statement.execute("Use " + DB2);
+    statement.execute("create table tb2 as select a from " + DB1 + ".tb1" );
+    context.assertSentrySemanticException(statement, "create table tb3 as select a from " + DB1 + ".view1",
         semanticException);
     statement.close();
     connection.close();
 
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("Use db2");
-    statement.execute("create table tb3 as select a from db1.view1" );
-    context.assertSentrySemanticException(statement, "create table tb4 as select a from db1.tb1",
+    statement.execute("Use " + DB2);
+    statement.execute("create table tb3 as select a from " + DB1 + ".view1" );
+    context.assertSentrySemanticException(statement, "create table tb4 as select a from " + DB1 + ".tb1",
         semanticException);
 
     statement.close();
@@ -658,12 +657,12 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     Resources.copy(Resources.getResource(SINGLE_TYPE_DATA_FILE_NAME), to);
     to.close();
 
-    dropDb(ADMIN1, dbName);
-    dropDb(ADMIN1, "db2");
-    createDb(ADMIN1, dbName);
-    createDb(ADMIN1, "db2");
-    createTable(ADMIN1, dbName, dataFile, tableName);
-    createTable(ADMIN1, "db2", null, "tb2");
+    dropDb(ADMIN1, DB1);
+    dropDb(ADMIN1, DB2);
+    createDb(ADMIN1, DB1);
+    createDb(ADMIN1, DB2);
+    createTable(ADMIN1, DB1, dataFile, tableName);
+    createTable(ADMIN1, DB2, null, "tb2");
     String location = dfs.getBaseDir() + "/" + Math.random();
 
     policyFile
@@ -676,15 +675,15 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
 
     Connection connection = context.createConnection(USER1_1);
     Statement statement = context.createStatement(connection);
-    assertSemanticException(statement, "insert overwrite directory '" + location + "' select * from db1.tb1" );
-    statement.execute("insert overwrite table db2.tb2 select * from db1.tb1");
+    assertSemanticException(statement, "insert overwrite directory '" + location + "' select * from " + DB1 + ".tb1" );
+    statement.execute("insert overwrite table " + DB2 + ".tb2 select * from " + DB1 + ".tb1");
     statement.close();
     connection.close();
 
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("insert overwrite directory '" + location + "' select * from db1.tb1" );
-    assertSemanticException(statement,"insert overwrite table db2.tb2 select * from db1.tb1");
+    statement.execute("insert overwrite directory '" + location + "' select * from " + DB1 + ".tb1" );
+    assertSemanticException(statement,"insert overwrite table " + DB2 + ".tb2 select * from " + DB1 + ".tb1");
     statement.close();
     connection.close();
   }
@@ -695,11 +694,11 @@ public class TestOperations extends AbstractTestWithStaticConfiguration {
     Statement statement;
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("create database db1");
-    statement.execute("create table db1.tb1(a int)");
-    statement.execute("DROP table db1.tb1");
-    statement.execute("create table db1.tb1(a int)");
-    statement.execute("use db1");
+    statement.execute("create database " + DB1);
+    statement.execute("create table " + DB1 + ".tb1(a int)");
+    statement.execute("DROP table " + DB1 + ".tb1");
+    statement.execute("create table " + DB1 + ".tb1(a int)");
+    statement.execute("use " + DB1);
     statement.execute("drop table tb1");
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 10f5dc8..4452d9a 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
@@ -80,14 +80,14 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     File db2PolicyFileHandle = new File(context.getPolicyFile().getParent(), DB2_POLICY_FILE);
     db2PolicyFile
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl2", "server=server1->db=db2->table=tbl2->action=select")
+        .addPermissionsToRole("select_tbl2", "server=server1->db="  + DB2 + "->table=tbl2->action=select")
         .write(db2PolicyFileHandle);
 
     policyFile
         .addRolesToGroup(USERGROUP1, "select_tbl1")
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl1", "server=server1->db=db1->table=tbl1->action=select")
-        .addDatabase("db2", prefix + db2PolicyFileHandle.getName())
+        .addPermissionsToRole("select_tbl1", "server=server1->db=" + DB1 +"->table=tbl1->action=select")
+        .addDatabase(DB2, prefix + db2PolicyFileHandle.getName())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
         .write(context.getPolicyFile());
 
@@ -95,16 +95,16 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE "  + DB1);
+    statement.execute("USE "  + DB1);
     statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl1");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db2");
-    statement.execute("USE db2");
+    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE "  + DB2);
+    statement.execute("USE "  + DB2);
     statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
@@ -114,13 +114,13 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE "  + DB1);
     // test user1 can execute query on tbl1
     verifyCount(statement, "SELECT COUNT(*) FROM tbl1");
 
     // user1 cannot query db2.tbl2
-    context.assertAuthzException(statement, "USE db2");
-    context.assertAuthzException(statement, "SELECT COUNT(*) FROM db2.tbl2");
+    context.assertAuthzException(statement, "USE "  + DB2);
+    context.assertAuthzException(statement, "SELECT COUNT(*) FROM "  + DB2 + ".tbl2");
     statement.close();
     connection.close();
 
@@ -128,13 +128,13 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
 
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("USE db2");
+    statement.execute("USE "  + DB2);
     // test user2 can execute query on tbl2
     verifyCount(statement, "SELECT COUNT(*) FROM tbl2");
 
     // user2 cannot query db1.tbl1
-    context.assertAuthzException(statement, "SELECT COUNT(*) FROM db1.tbl1");
-    context.assertAuthzException(statement, "USE db1");
+    context.assertAuthzException(statement, "SELECT COUNT(*) FROM " + DB1 +".tbl1");
+    context.assertAuthzException(statement, "USE "  + DB1);
 
     statement.close();
     connection.close();
@@ -142,8 +142,8 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     //test cleanup
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE db1 CASCADE");
-    statement.execute("DROP DATABASE db2 CASCADE");
+    statement.execute("DROP DATABASE " + DB1 +" CASCADE");
+    statement.execute("DROP DATABASE "  + DB2 + " CASCADE");
     statement.close();
     connection.close();
   }
@@ -168,7 +168,7 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     PolicyFile db4PolicyFile = new PolicyFile();
     db2PolicyFile
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl2", "server=server1->db=db2->table=tbl2->action=select")
+        .addPermissionsToRole("select_tbl2", "server=server1->db="  + DB2 + "->table=tbl2->action=select")
         .write(db2PolicyFileHandle);
     db3PolicyFile
         .addRolesToGroup(USERGROUP3, "select_tbl3_BAD")
@@ -181,8 +181,8 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     policyFile
         .addRolesToGroup(USERGROUP1, "select_tbl1")
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl1", "server=server1->db=db1->table=tbl1->action=select")
-        .addDatabase("db2", prefix + db2PolicyFileHandle.getName())
+        .addPermissionsToRole("select_tbl1", "server=server1->db=" + DB1 +"->table=tbl1->action=select")
+        .addDatabase(DB2, prefix + db2PolicyFileHandle.getName())
         .addDatabase("db3", prefix + db3PolicyFileHandle.getName())
         .addDatabase("db4", prefix + db4PolicyFileHandle.getName())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
@@ -192,16 +192,16 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
+    statement.execute("CREATE DATABASE "  + DB1);
+    statement.execute("USE "  + DB1);
     statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl1");
 
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db2");
-    statement.execute("USE db2");
+    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE "  + DB2);
+    statement.execute("USE "  + DB2);
     statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
@@ -226,14 +226,14 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE "  + DB1);
     // test user1 can execute query on tbl1
     verifyCount(statement, "SELECT COUNT(*) FROM tbl1");
     connection.close();
 
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("USE db2");
+    statement.execute("USE "  + DB2);
     // test user1 can execute query on tbl1
     verifyCount(statement, "SELECT COUNT(*) FROM tbl2");
     connection.close();
@@ -256,8 +256,8 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     //test cleanup
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE db1 CASCADE");
-    statement.execute("DROP DATABASE db2 CASCADE");
+    statement.execute("DROP DATABASE " + DB1 +" CASCADE");
+    statement.execute("DROP DATABASE "  + DB2 + " CASCADE");
     statement.execute("DROP DATABASE db3 CASCADE");
     statement.execute("DROP DATABASE db4 CASCADE");
     statement.close();
@@ -271,16 +271,16 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     policyFile
         .addRolesToGroup(USERGROUP1, "select_tbl1")
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl1", "server=server1->db=db1->table=tbl1->action=select")
-        .addDatabase("db2", prefix + db2PolicyFileHandle.getName())
+        .addPermissionsToRole("select_tbl1", "server=server1->db=" + DB1 +"->table=tbl1->action=select")
+        .addDatabase(DB2, prefix + db2PolicyFileHandle.getName())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
         .write(context.getPolicyFile());
 
     PolicyFile db2PolicyFile = new PolicyFile();
     db2PolicyFile
         .addRolesToGroup(USERGROUP2, "select_tbl2", "data_read", "insert_tbl2")
-        .addPermissionsToRole("select_tbl2", "server=server1->db=db2->table=tbl2->action=select")
-        .addPermissionsToRole("insert_tbl2", "server=server1->db=db2->table=tbl2->action=insert")
+        .addPermissionsToRole("select_tbl2", "server=server1->db="  + DB2 + "->table=tbl2->action=select")
+        .addPermissionsToRole("insert_tbl2", "server=server1->db="  + DB2 + "->table=tbl2->action=insert")
         .addPermissionsToRole("data_read", "server=server1->URI=file://" + dataFile)
         .write(db2PolicyFileHandle);
     // ugly hack: needs to go away once this becomes a config property. Note that this property
@@ -291,16 +291,16 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE "  + DB1);
+    statement.execute("USE "  + DB1);
     statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl1");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db2");
-    statement.execute("USE db2");
+    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE "  + DB2);
+    statement.execute("USE "  + DB2);
     statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
@@ -310,20 +310,20 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE "  + DB1);
     // test user1 can execute query on tbl1
     verifyCount(statement, "SELECT COUNT(*) FROM tbl1");
 
     // user1 cannot query db2.tbl2
-    context.assertAuthzException(statement, "USE db2");
-    context.assertAuthzException(statement, "SELECT COUNT(*) FROM db2.tbl2");
+    context.assertAuthzException(statement, "USE "  + DB2);
+    context.assertAuthzException(statement, "SELECT COUNT(*) FROM "  + DB2 + ".tbl2");
     statement.close();
     connection.close();
 
     // test per-db file for db2
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("USE db2");
+    statement.execute("USE "  + DB2);
     // test user2 can execute query on tbl2
     verifyCount(statement, "SELECT COUNT(*) FROM tbl2");
 
@@ -331,12 +331,12 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE tbl2");
 
     // user2 cannot query db1.tbl1
-    context.assertAuthzException(statement, "SELECT COUNT(*) FROM db1.tbl1");
-    context.assertAuthzException(statement, "USE db1");
+    context.assertAuthzException(statement, "SELECT COUNT(*) FROM " + DB1 +".tbl1");
+    context.assertAuthzException(statement, "USE "  + DB1);
 
     // once we disable this property all queries should fail
     System.setProperty(SimpleDBPolicyEngine.ACCESS_ALLOW_URI_PER_DB_POLICYFILE, "false");
-    context.assertAuthzException(statement, "USE db2");
+    context.assertAuthzException(statement, "USE "  + DB2);
 
     // re-enable for clean
     System.setProperty(SimpleDBPolicyEngine.ACCESS_ALLOW_URI_PER_DB_POLICYFILE, "true");
@@ -347,8 +347,8 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     //test cleanup
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE db1 CASCADE");
-    statement.execute("DROP DATABASE db2 CASCADE");
+    statement.execute("DROP DATABASE " + DB1 +" CASCADE");
+    statement.execute("DROP DATABASE "  + DB2 + " CASCADE");
     statement.close();
     connection.close();
   }
@@ -361,7 +361,7 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
   public void testDefaultDb() throws Exception {
     policyFile
         .addRolesToGroup(USERGROUP1, "select_tbl1")
-        .addPermissionsToRole("select_tbl1", "server=server1->db=db1->table=tbl1->action=select")
+        .addPermissionsToRole("select_tbl1", "server=server1->db=" + DB1 +"->table=tbl1->action=select")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
         .write(context.getPolicyFile());
 
@@ -371,12 +371,12 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
 
     statement.execute("USE default");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
+    statement.execute("CREATE DATABASE "  + DB1);
+    statement.execute("USE "  + DB1);
     statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
     statement.close();
     connection.close();
 
@@ -404,8 +404,8 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     policyFile
         .addRolesToGroup(USERGROUP1, "select_tbl1")
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl1", "server=server1->db=db1->table=tbl1->action=select")
-        .addDatabase("db2", prefix + db2PolicyFileHandle.getName())
+        .addPermissionsToRole("select_tbl1", "server=server1->db=" + DB1 +"->table=tbl1->action=select")
+        .addDatabase(DB2, prefix + db2PolicyFileHandle.getName())
         .addDatabase("default", prefix + defaultPolicyFileHandle.getName())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping())
         .write(context.getPolicyFile());
@@ -413,7 +413,7 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     PolicyFile db2PolicyFile = new PolicyFile();
     db2PolicyFile
         .addRolesToGroup(USERGROUP2, "select_tbl2")
-        .addPermissionsToRole("select_tbl2", "server=server1->db=db2->table=tbl2->action=select")
+        .addPermissionsToRole("select_tbl2", "server=server1->db="  + DB2 + "->table=tbl2->action=select")
         .write(db2PolicyFileHandle);
 
     PolicyFile defaultPolicyFile = new PolicyFile();
@@ -430,15 +430,15 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     statement.execute("CREATE TABLE dtab(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
 
-    statement.execute("DROP DATABASE IF EXISTS db1 CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db1");
-    statement.execute("USE db1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 +" CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE "  + DB1);
+    statement.execute("USE "  + DB1);
     statement.execute("CREATE TABLE tbl1(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
-    statement.execute("DROP DATABASE IF EXISTS db2 CASCADE");
-    statement.execute("CREATE DATABASE db2");
-    statement.execute("USE db2");
+    statement.execute("DROP DATABASE IF EXISTS "  + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE "  + DB2);
+    statement.execute("USE "  + DB2);
     statement.execute("CREATE TABLE tbl2(B INT, A STRING) " +
                       " row format delimited fields terminated by '|'  stored as textfile");
     statement.close();
@@ -447,10 +447,10 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     // user_1 should be able to switch to default, but not the tables from default
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE db1");
+    statement.execute("USE "  + DB1);
     statement.execute("USE default");
     context.assertAuthzException(statement, "SELECT * FROM dtab");
-    statement.execute("USE db1");
+    statement.execute("USE "  + DB1);
     context.assertAuthzException(statement, "SELECT * FROM default.dtab");
 
     statement.close();
@@ -459,10 +459,10 @@ public class TestPerDBConfiguration extends AbstractTestWithStaticConfiguration
     // user_2 should be able to access default and select from default's tables
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("USE db2");
+    statement.execute("USE "  + DB2);
     statement.execute("USE default");
     statement.execute("SELECT * FROM dtab");
-    statement.execute("USE db2");
+    statement.execute("USE "  + DB2);
     statement.execute("SELECT * FROM default.dtab");
     statement.close();
     connection.close();

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 b31446c..c8712e7 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
@@ -59,7 +59,7 @@ public class TestPerDatabasePolicyFile extends AbstractTestWithStaticConfigurati
    */
   @Test
   public void testDbSpecificFileGrantsToOtherDb() throws Exception {
-    doTestDbSpecificFileGrants("server=server1->db=db1");
+    doTestDbSpecificFileGrants("server=server1->db=" + DB1);
   }
   /**
    * Ensure that db specific file cannot grant to all db
@@ -93,8 +93,8 @@ public class TestPerDatabasePolicyFile extends AbstractTestWithStaticConfigurati
     // setup db objects needed by the test
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    createSampleDbTable(statement, "db1", "tbl1");
-    createSampleDbTable(statement, "db2", "tbl1");
+    createSampleDbTable(statement, DB1, "tbl1");
+    createSampleDbTable(statement, DB2, "tbl1");
     statement.close();
     connection.close();
 
@@ -105,14 +105,14 @@ public class TestPerDatabasePolicyFile extends AbstractTestWithStaticConfigurati
     .addRolesToGroup("group1", "db1_role");
     specificPolicyFile.write(specificPolicyFileFile);
 
-    policyFile.addDatabase("db2", specificPolicyFileFile.getPath());
+    policyFile.addDatabase(DB2, specificPolicyFileFile.getPath());
     writePolicyFile(policyFile);
 
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // test user can query table
-    context.assertAuthzException(statement, "USE db1");
-    context.assertAuthzException(statement, "SELECT COUNT(a) FROM db1.tbl1");
+    context.assertAuthzException(statement, "USE " + DB1);
+    context.assertAuthzException(statement, "SELECT COUNT(a) FROM " + DB1 + ".tbl1");
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 d115cad..2d34015 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
@@ -59,25 +59,24 @@ public class TestPrivilegeAtTransform extends AbstractTestWithStaticConfiguratio
   @Test
   public void testTransform1() throws Exception {
     policyFile
-      .addPermissionsToRole("all_db1", "server=server1->db=db_1")
+      .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
       .addRolesToGroup(USERGROUP1, "all_db1")
       .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
     // verify by SQL
     // 1, 2
-    String dbName1 = "db_1";
     String tableName1 = "tb_1";
-    String query = "select TRANSFORM(a.under_col, a.value) USING 'cat' AS (tunder_col, tvalue) FROM " + dbName1 + "." + tableName1 + " a";
+    String query = "select TRANSFORM(a.under_col, a.value) USING 'cat' AS (tunder_col, tvalue) FROM " + DB1 + "." + tableName1 + " a";
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("DROP TABLE IF EXISTS " + dbName1 + "." + tableName1);
-    statement.execute("create table " + dbName1 + "." + tableName1
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("DROP TABLE IF EXISTS " + DB1 + "." + tableName1);
+    statement.execute("create table " + DB1 + "." + tableName1
         + " (under_col int, value string)");
     statement.execute("load data local inpath '" + dataFile.getPath()
-            + "' into table " + dbName1 + "." + tableName1);
+            + "' into table " + DB1 + "." + tableName1);
     assertTrue(query, statement.execute(query));
 
     statement.close();
@@ -91,8 +90,8 @@ public class TestPrivilegeAtTransform extends AbstractTestWithStaticConfiguratio
 
     // 4
     policyFile
-      .addPermissionsToRole("select_tb1", "server=server1->db=db_1->table=tb_1->action=select")
-      .addPermissionsToRole("insert_tb1", "server=server1->db=db_1->table=tb_1->action=insert")
+      .addPermissionsToRole("select_tb1", "server=server1->db=" + DB1 + "->table=tb_1->action=select")
+      .addPermissionsToRole("insert_tb1", "server=server1->db=" + DB1 + "->table=tb_1->action=insert")
       .addRolesToGroup(USERGROUP1, "select_tb1", "insert_tb1");
     writePolicyFile(policyFile);
     context.assertAuthzExecHookException(statement, query);

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 a0669cd..653b6fb 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
@@ -61,25 +61,25 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
 
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1")
-        .addPermissionsToRole("all_db1", "server=server1->db=DB_1->action=all")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1 + "->action=all")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
 
     // setup db objects needed by the test
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("create database db_1");
-    statement.execute("create table db_1.tab1(a int)");
+    statement.execute("create database " + DB1);
+    statement.execute("create table " + DB1 + ".tab1(a int)");
 
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("use db_1");
+    statement.execute("use " + DB1);
     statement.execute("select * from tab1");
 
     policyFile
-        .addPermissionsToRole("all_db1", "server=server1->db=DB_1");
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1);
     writePolicyFile(policyFile);
-    statement.execute("use db_1");
+    statement.execute("use " + DB1);
     statement.execute("select * from tab1");
   }
 
@@ -100,8 +100,8 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1", "load_data")
         .addRolesToGroup(USERGROUP2, "all_db2")
-        .addPermissionsToRole("all_db1", "server=server1->db=DB_1")
-        .addPermissionsToRole("all_db2", "server=server1->db=DB_2")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
+        .addPermissionsToRole("all_db2", "server=server1->db=" + DB2)
         .addPermissionsToRole("load_data", "server=server1->uri=file://" + dataFile.getPath())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
@@ -109,10 +109,10 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     // setup db objects needed by the test
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS DB_2 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("CREATE DATABASE DB_2");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("CREATE DATABASE " + DB2);
     statement.close();
     connection.close();
 
@@ -120,18 +120,18 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // test user can create table
-    statement.execute("CREATE TABLE DB_1.TAB_1(A STRING)");
+    statement.execute("CREATE TABLE " + DB1 + ".TAB_1(A STRING)");
     // test user can execute load
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE DB_1.TAB_1");
-    statement.execute("CREATE TABLE DB_1.TAB_2(A STRING)");
-    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE DB_1.TAB_2");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".TAB_1");
+    statement.execute("CREATE TABLE " + DB1 + ".TAB_2(A STRING)");
+    statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE " + DB1 + ".TAB_2");
 
     // test CTAS can reference UDFs
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
     statement.execute("create table table2 as select A, count(A) from TAB_1 GROUP BY A");
 
     // test user can switch db
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
     //test user can create view
     statement.execute("CREATE VIEW VIEW_1(A) AS SELECT A FROM TAB_1");
 
@@ -163,7 +163,7 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
 
     //negative test case: user can't drop another user's database
     try {
-      statement.execute("DROP DATABASE DB_2 CASCADE");
+      statement.execute("DROP DATABASE " + DB2 + " CASCADE");
       Assert.fail("Expected SQL exception");
     } catch (SQLException e) {
       context.verifyAuthzException(e);
@@ -171,14 +171,14 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
 
     //negative test case: user can't switch into another user's database
     try {
-      statement.execute("USE DB_2");
+      statement.execute("USE " + DB2);
       Assert.fail("Expected SQL exception");
     } catch (SQLException e) {
       context.verifyAuthzException(e);
     }
 
     //User can drop own database
-    statement.execute("DROP DATABASE DB_1 CASCADE");
+    statement.execute("DROP DATABASE " + DB1 + " CASCADE");
 
     statement.close();
     connection.close();
@@ -186,7 +186,7 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     //test cleanup
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE DB_2 CASCADE");
+    statement.execute("DROP DATABASE " + DB2 + " CASCADE");
     statement.close();
     connection.close();
     context.close();
@@ -209,8 +209,8 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     policyFile
         .addRolesToGroup(USERGROUP1, "all_db1", "load_data", "exttab")
         .addRolesToGroup(USERGROUP2, "all_db2")
-        .addPermissionsToRole("all_db1", "server=server1->db=DB_1")
-        .addPermissionsToRole("all_db2", "server=server1->db=DB_2")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
+        .addPermissionsToRole("all_db2", "server=server1->db=" + DB2)
         .addPermissionsToRole("exttab", "server=server1->uri=file://" + dataDir.getPath())
         .addPermissionsToRole("load_data", "server=server1->uri=file://" + dataFile.getPath())
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
@@ -219,11 +219,11 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     // setup db objects needed by the test
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("DROP DATABASE IF EXISTS DB_2 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("CREATE DATABASE DB_2");
-    statement.execute("USE DB_1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB_1(A STRING)");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE TAB_1");
     statement.execute("CREATE TABLE PART_TAB_1(A STRING) partitioned by (B INT) STORED AS TEXTFILE");
@@ -236,7 +236,7 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
     // test user can switch db
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
     // test user can execute load
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE TAB_1");
     statement.execute("CREATE TABLE TAB_2(A STRING)");
@@ -297,8 +297,8 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     //test cleanup
     connection = context.createConnection(ADMIN1);
     statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE DB_1 CASCADE");
-    statement.execute("DROP DATABASE DB_2 CASCADE");
+    statement.execute("DROP DATABASE " + DB1 + " CASCADE");
+    statement.execute("DROP DATABASE " + DB2 + " CASCADE");
     statement.close();
     connection.close();
     context.close();
@@ -319,8 +319,8 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
         .addRolesToGroup(USERGROUP1, "all_db1")
         .addRolesToGroup(USERGROUP2, "select_db2")
         .addRolesToGroup(USERGROUP3, "all_db3")
-        .addPermissionsToRole("all_db1", "server=server1->db=DB_1")
-        .addPermissionsToRole("select_db2", "server=server1->db=DB_2->table=tab_2->action=select")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
+        .addPermissionsToRole("select_db2", "server=server1->db=" + DB2 + "->table=tab_2->action=select")
         .addPermissionsToRole("all_db3", "server=server1->db=DB_3")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);
@@ -330,40 +330,40 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
     // setup db objects needed by the test
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("use DB_1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("use " + DB1);
     statement.execute("CREATE TABLE TAB_1(A STRING)");
-    statement.execute("DROP DATABASE IF EXISTS DB_2 CASCADE");
-    statement.execute("CREATE DATABASE DB_2");
-    statement.execute("use DB_1");
+    statement.execute("DROP DATABASE IF EXISTS " + DB2 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB2);
+    statement.execute("use " + DB1);
     statement.execute("CREATE TABLE TAB_2(A STRING)");
     context.close();
 
     // user1 should be able to connect db_1
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("use DB_1");
+    statement.execute("use " + DB1);
     context.close();
 
     // user2 should not be able to connect db_1
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
     try {
-      statement.execute("use DB_1");
-      assertFalse("user2 shouldn't be able switch to db_1", true);
+      statement.execute("use " + DB1);
+      assertFalse("user2 shouldn't be able switch to " + DB1, true);
     } catch (SQLException e) {
       context.verifyAuthzException(e);
     }
-    statement.execute("use DB_2");
+    statement.execute("use " + DB2);
     context.close();
 
     // user3 who is not listed in policy file should not be able to connect db_2
     connection = context.createConnection(USER3_1);
     statement = context.createStatement(connection);
     try {
-      statement.execute("use DB_2");
-      assertFalse("user3 shouldn't be able switch to db_2", true);
+      statement.execute("use " + DB2);
+      assertFalse("user3 shouldn't be able switch to " + DB2, true);
     } catch (SQLException e) {
       context.verifyAuthzException(e);
     }
@@ -383,8 +383,8 @@ public class TestPrivilegesAtDatabaseScope extends AbstractTestWithStaticConfigu
         .addRolesToGroup(USERGROUP1, "all_db1")
         .addRolesToGroup(USERGROUP2, "select_db2")
         .addRolesToGroup(USERGROUP3, "all_default")
-        .addPermissionsToRole("all_db1", "server=server1->db=DB_1")
-        .addPermissionsToRole("select_db2", "server=server1->db=DB_2->table=tab_2->action=select")
+        .addPermissionsToRole("all_db1", "server=server1->db=" + DB1)
+        .addPermissionsToRole("select_db2", "server=server1->db=" + DB2 + "->table=tab_2->action=select")
         .addPermissionsToRole("all_default", "server=server1->db=default")
         .setUserGroupMapping(StaticUserGroup.getStaticMapping());
     writePolicyFile(policyFile);

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 1e1978d..f1f64e6 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
@@ -58,7 +58,6 @@ public class TestPrivilegesAtFunctionScope extends AbstractTestWithStaticConfigu
    */
   @Test
   public void testFuncPrivileges1() throws Exception {
-    String dbName1 = "db_1";
     String tableName1 = "tb_1";
     String udfClassName = "org.apache.hadoop.hive.ql.udf.generic.GenericUDFPrintf";
     CodeSource udfSrc = Class.forName(udfClassName).getProtectionDomain().getCodeSource();
@@ -68,13 +67,13 @@ public class TestPrivilegesAtFunctionScope extends AbstractTestWithStaticConfigu
     }
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("USE " + dbName1);
-    statement.execute("create table " + dbName1 + "." + tableName1
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
+    statement.execute("create table " + DB1 + "." + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE "
-        + dbName1 + "." + tableName1);
+        + DB1 + "." + tableName1);
     statement.execute("DROP TEMPORARY FUNCTION IF EXISTS printf_test");
     statement.execute("DROP TEMPORARY FUNCTION IF EXISTS printf_test_2");
     context.close();
@@ -83,25 +82,25 @@ public class TestPrivilegesAtFunctionScope extends AbstractTestWithStaticConfigu
         .addRolesToGroup(USERGROUP1, "db1_all", "UDF_JAR")
         .addRolesToGroup(USERGROUP2, "db1_tab1", "UDF_JAR")
         .addRolesToGroup(USERGROUP3, "db1_tab1")
-        .addPermissionsToRole("db1_all", "server=server1->db=" + dbName1)
-        .addPermissionsToRole("db1_tab1", "server=server1->db=" + dbName1 + "->table=" + tableName1)
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
+        .addPermissionsToRole("db1_tab1", "server=server1->db=" + DB1 + "->table=" + tableName1)
         .addPermissionsToRole("UDF_JAR", "server=server1->uri=file://" + udfLocation);
     writePolicyFile(policyFile);
 
     // user1 should be able create/drop temp functions
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     statement.execute(
         "CREATE TEMPORARY FUNCTION printf_test AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDFPrintf'");
     statement.execute("SELECT printf_test(value) FROM " + tableName1);
     statement.execute("DROP TEMPORARY FUNCTION printf_test");
     context.close();
 
-    // user2 has select privilege on one of the tables in db2, should be able create/drop temp functions
+    // user2 has select privilege on one of the tables in db1, should be able create/drop temp functions
     connection = context.createConnection(USER2_1);
     statement = context.createStatement(connection);
-    statement.execute("USE " + dbName1);
+    statement.execute("USE " + DB1);
     statement.execute(
         "CREATE TEMPORARY FUNCTION printf_test_2 AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDFPrintf'");
     statement.execute("SELECT printf_test_2(value) FROM " + tableName1);
@@ -112,7 +111,7 @@ public class TestPrivilegesAtFunctionScope extends AbstractTestWithStaticConfigu
     connection = context.createConnection(USER3_1);
     statement = context.createStatement(connection);
     try {
-      statement.execute("USE " + dbName1);
+      statement.execute("USE " + DB1);
       statement.execute(
       "CREATE TEMPORARY FUNCTION printf_test_bad AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDFPrintf'");
       assertFalse("CREATE TEMPORARY FUNCTION should fail for user3", true);
@@ -138,27 +137,26 @@ public class TestPrivilegesAtFunctionScope extends AbstractTestWithStaticConfigu
 
   @Test
   public void testUdfWhiteList () throws Exception {
-    String dbName1 = "db1";
     String tableName1 = "tab1";
 
     policyFile
         .addRolesToGroup(USERGROUP1, "db1_all", "UDF_JAR")
         .addRolesToGroup(USERGROUP2, "db1_tab1", "UDF_JAR")
         .addRolesToGroup(USERGROUP3, "db1_tab1")
-        .addPermissionsToRole("db1_all", "server=server1->db=" + dbName1)
-        .addPermissionsToRole("db1_tab1", "server=server1->db=" + dbName1 + "->table=" + tableName1)
+        .addPermissionsToRole("db1_all", "server=server1->db=" + DB1)
+        .addPermissionsToRole("db1_tab1", "server=server1->db=" + DB1 + "->table=" + tableName1)
         .addPermissionsToRole("UDF_JAR", "server=server1->uri=file://${user.home}/.m2");
     writePolicyFile(policyFile);
 
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = connection.createStatement();
-    statement.execute("DROP DATABASE IF EXISTS " + dbName1 + " CASCADE");
-    statement.execute("CREATE DATABASE " + dbName1);
-    statement.execute("USE " + dbName1);
+    statement.execute("DROP DATABASE IF EXISTS " + DB1 + " CASCADE");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("create table " + tableName1
         + " (under_col int comment 'the under column', value string)");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath() + "' INTO TABLE "
-        + dbName1 + "." + tableName1);
+        + DB1 + "." + tableName1);
     statement.execute("SELECT rand(), concat(value, '_foo') FROM " + tableName1);
 
     context.assertAuthzException(statement,

http://git-wip-us.apache.org/repos/asf/incubator-sentry/blob/b6c62f79/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 2fece0a..45a4b7c 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
@@ -173,8 +173,8 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     Connection connection = context.createConnection(ADMIN1);
     Statement statement = context.createStatement(connection);
     statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("USE DB_1");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB_1(A STRING)");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath()
         + "' INTO TABLE TAB_1");
@@ -188,7 +188,7 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
     // test user can execute insert on table
     statement.execute("INSERT INTO TABLE TAB_1 SELECT A FROM TAB_2");
 
@@ -262,8 +262,8 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     Statement statement = context.createStatement(connection);
 
     statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("USE DB_1");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB_1(A STRING)");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath()
         + "' INTO TABLE TAB_1");
@@ -277,7 +277,7 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
     // test user can execute query on table
     ResultSet resultSet = statement.executeQuery("SELECT COUNT(A) FROM TAB_1");
     int count = 0;
@@ -350,8 +350,8 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     Statement statement = context.createStatement(connection);
 
     statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("USE DB_1");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB_1(B INT, A STRING) "
         + " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath()
@@ -367,7 +367,7 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
     // test user can execute query TAB_1 JOIN TAB_2
     ResultSet resultSet = statement
         .executeQuery("SELECT COUNT(*) FROM TAB_1 T1 JOIN TAB_2 T2 ON (T1.B = T2.B)");
@@ -428,8 +428,8 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     Statement statement = context.createStatement(connection);
 
     statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("USE DB_1");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB_1(B INT, A STRING) "
         + " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath()
@@ -445,7 +445,7 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
     // test user can execute query on TAB_2
     ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM TAB_2");
     int count = 0;
@@ -513,8 +513,8 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     Statement statement = context.createStatement(connection);
 
     statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("USE DB_1");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB_1(B INT, A STRING) "
         + " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath()
@@ -530,7 +530,7 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
     // test user can execute query on TAB_2
     ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM TAB_2");
     int count = 0;
@@ -614,8 +614,8 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     Statement statement = context.createStatement(connection);
 
     statement.execute("DROP DATABASE IF EXISTS DB_1 CASCADE");
-    statement.execute("CREATE DATABASE DB_1");
-    statement.execute("USE DB_1");
+    statement.execute("CREATE DATABASE " + DB1);
+    statement.execute("USE " + DB1);
     statement.execute("CREATE TABLE TAB_1(B INT, A STRING) "
         + " row format delimited fields terminated by '|'  stored as textfile");
     statement.execute("LOAD DATA LOCAL INPATH '" + dataFile.getPath()
@@ -631,7 +631,7 @@ public class TestPrivilegesAtTableScope extends AbstractTestWithStaticConfigurat
     // test execution
     connection = context.createConnection(USER1_1);
     statement = context.createStatement(connection);
-    statement.execute("USE DB_1");
+    statement.execute("USE " + DB1);
 
     // test user can execute query VIEW_1 JOIN TAB_1
     ResultSet resultSet = statement