db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myrn...@apache.org
Subject svn commit: r595876 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests: jdbcapi/DatabaseMetaDataTest.java lang/GrantRevokeTest.java upgradeTests/UpgradeRun.java
Date Sat, 17 Nov 2007 00:02:41 GMT
Author: myrnavl
Date: Fri Nov 16 16:02:35 2007
New Revision: 595876

URL: http://svn.apache.org/viewvc?rev=595876&view=rev
Log:
DERBY-2242 (partial) adding tests for getColumnPrivileges and getTablePrivileges

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java?rev=595876&r1=595875&r2=595876&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DatabaseMetaDataTest.java
Fri Nov 16 16:02:35 2007
@@ -55,7 +55,7 @@
 /**
  * Test the DatabaseMetaData api.
  * <P>
- * For the methods that return a ResultSet to determine the
+ * For a number of methods that return a ResultSet to determine the
  * attributes of SQL objects (e.g. getTables) two methods
  * are provided. A non-modify and a modify one.
  * 
@@ -66,13 +66,12 @@
  * The non-modify means that the test method does not change the database
  * in order to test the return of the getXXX method is correct.
  * <BR>
- * The modify versions test
  * Work in progress.
  * TODO: Methods left to test from JDBC 3
  * 
  *  getColumnPrivileges
  *  getCrossReference
- *  getExportedKeys
+ *  getExportedKeys (note; when done, adjust comment in ODBCgetExportedKeys)
  *  getImportedKeys
  *  getIndexInfo
  *  getPrimaryKeys
@@ -82,6 +81,14 @@
  *  <P>
  *  This test is also called from the upgrade tests to test that
  *  metadata continues to work at various points in the upgrade.
+ *  
+ *  // TODO: 
+ *  convert from metadata.java test;
+ *  - implement edge case with nested connection, verified using isReadOnly()
+ *  - implement getColumns edge case (marked 'beetle 4620') with large column  
+ *    (if char or varchar size is > max integer /2 = 2147483647)
+ *  - tests for own/others Inserts/Updates/Deletes AreVisible
+ *  - insertsAreDetected, updatesAreDetected, (see deletesAreDetected)
  */
 public class DatabaseMetaDataTest extends BaseJDBCTestCase {
   
@@ -3012,4 +3019,98 @@
                 Types.INTEGER, Types.INTEGER, Types.SMALLINT, Types.SMALLINT};
         assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
     } 
+    
+    /**
+     * Test getGetColumnPrivileges; does not modify database
+     * For further testing see test lang.grantRevokeTest
+     * @throws SQLException 
+     */
+    public void testGetColumnPrivileges() throws SQLException
+    {
+        
+        String [] columnNames = {"TABLE_CAT","TABLE_SCHEM","TABLE_NAME",
+            "COLUMN_NAME","GRANTOR","GRANTEE","PRIVILEGE","IS_GRANTABLE"};
+        int [] columnTypes = {
+            Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
+            Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR};
+        // Note: the API docs seem to suggest that TABLE_SCHEM (col2) may be 
+        // null, however, that is not what we get back.
+        // For Grantee (col6), and privilege it's not so clear, as the api 
+        // doesn't specify, which means it may not be null.
+        // Modified here so test will pass.
+        // See DERBY-3212.
+        boolean [] nullability = {true,false,false,false,true,true,true,true};
+        
+        DatabaseMetaData dmd = getDMD();
+        
+        // unlike for instance getTables() and getUDTs trying to call
+        // getColumnPrivileges with all nulls gets stopped because 
+        // the spec indicates it takes a table name, not just a pattern
+        try {
+            dmd.getColumnPrivileges(null,null,null,null);
+            fail ("expected error XJ103");
+        } catch (SQLException sqle) {
+            assertSQLState("XJ103", sqle);
+        }
+        
+        ResultSet rs = dmd.getColumnPrivileges(null,null,"",null);
+        assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
+        JDBC.assertEmpty(rs);
+        
+        rs = dmd.getColumnPrivileges("","","","");
+        assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
+        JDBC.assertEmpty(rs);
+        
+        rs = dmd.getColumnPrivileges("%","%","%","%");
+        assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
+        JDBC.assertEmpty(rs);
+
+        // we didn't (can't) grant any privileges to the systabels, so no row
+        rs = dmd.getColumnPrivileges(null,"SYS","SYSTABLES","TABLEID");
+        assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
+        JDBC.assertEmpty(rs);
+        rs.close();
+    }
+
+    /**
+     * Test getGetTablePrivileges; does not modify database
+     * For further testing see test lang.grantRevokeTest
+     * @throws SQLException 
+     */
+    public void testGetTablePrivileges() throws SQLException
+    {
+        
+        String [] columnNames = {"TABLE_CAT","TABLE_SCHEM","TABLE_NAME",
+            "GRANTOR","GRANTEE","PRIVILEGE","IS_GRANTABLE"};
+        int [] columnTypes = {
+            Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
+            Types.VARCHAR,Types.VARCHAR,Types.VARCHAR};
+        // Note: the API docs seem to suggest that TABLE_SCHEM (col2) may be 
+        // null, however, that is not what we get back.
+        // For Grantee (col5), and privilege it's not so clear, as the api 
+        // doesn't specify, which means it may not be null.
+        // Modified here so test will pass.
+        // See DERBY-3212.
+        boolean [] nullability = {true,false,false,true,true,true,true};
+        
+        DatabaseMetaData dmd = getDMD();
+        
+        ResultSet rs = dmd.getTablePrivileges(null,null,null);
+        assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
+        JDBC.assertEmpty(rs);
+        
+        rs = dmd.getTablePrivileges("","","");
+        assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
+        JDBC.assertEmpty(rs);
+        
+        rs = dmd.getTablePrivileges("%","%","%");
+        assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
+        JDBC.assertEmpty(rs);
+
+        // we didn't (can't) grant any privileges to the systabels, so no row
+        rs = dmd.getTablePrivileges(null,"SYS","SYSTABLES");
+        assertMetaDataResultSet(rs, columnNames, columnTypes, nullability);
+        JDBC.assertEmpty(rs);
+        rs.close();
+    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeTest.java?rev=595876&r1=595875&r2=595876&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeTest.java
Fri Nov 16 16:02:35 2007
@@ -564,13 +564,6 @@
     }
     */
     
-    /*
-     * TODO - write more extensive tests for DatabaseMetaData.getColumnPrivileges()
-     *        and DatabaseMetaData.getTablePrivileges(). Specifically,
-     *        would be nice to have some test cases which verify grantor
-     *         and is_grantable are valid.
-     */
-    
     /* Begin standard error cases */
     
     public void testInvalidGrantAction() throws Exception {
@@ -1338,6 +1331,12 @@
     	if (columns == null) {
         	while (rs.next())
         	{
+        	// also verify that grantor and is_grantable can be obtained
+        	// Derby doesn't currently support the for grant option, the
+        	// grantor is always the object owner - in this test, TEST_DBO,
+        	// and is_grantable is always 'NO'
+          	    assertEquals(rs.getString(4),"TEST_DBO");
+          	    assertEquals(rs.getString(7),"NO");
           	    if (rs.getString(6).equals(type)) {
         	    	String privUser = rs.getString(5);
         	    	if (privUser.equals(user) || privUser.equals("PUBLIC")) {
@@ -1393,6 +1392,13 @@
     			cp = dm.getColumnPrivileges(null, schema.toUpperCase(), table.toUpperCase(), columns[i].toUpperCase());
     			found = false;
     			while (cp.next()) {
+    			// also verify that grantor and is_grantable are valid
+    			// Derby doesn't currently support for grant, so
+    			// grantor is always the object owner - in this test, 
+    			// TEST_DBO, and getColumnPrivileges casts 'NO' for 
+    			// is_grantable for supported column-related privileges
+					assertEquals("TEST_DBO", cp.getString(5));
+					assertEquals("NO", cp.getString(8));
 					if (cp.getString(7).equals(type)) {
 						String privUser = cp.getString(6);
 						if (privUser.equals(user) || privUser.equals("PUBLIC")) {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?rev=595876&r1=595875&r2=595876&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
Fri Nov 16 16:02:35 2007
@@ -377,7 +377,11 @@
             String name = m.getName();
             if (name.startsWith("test"))
             {
-                if (!(name.equals("testGetTablesModify") && oldMinor < 1))
+                if ((!(name.equals("testGetTablesModify") && oldMinor < 1)) &&
+                   // these two tests will fail with versions before 10.2.1.6
+                   // because of missing support for grant/revoke/privileges
+                   (!(name.equals("testGetTablePrivileges") && oldMinor <2)) &&
+                   (!(name.equals("testGetColumnPrivileges") && oldMinor <2)))
                     suite.addTest(new DatabaseMetaDataTest(name));
             }
         }



Mime
View raw message