You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2007/07/03 19:27:15 UTC

svn commit: r552922 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/lang/GrantRevokeTest.java junit/BaseJDBCTestCase.java

Author: djd
Date: Tue Jul  3 10:27:09 2007
New Revision: 552922

URL: http://svn.apache.org/viewvc?view=rev&rev=552922
Log:
Cleanup GrantRevokeTest test
 do not use runSQLCommands and check for thrown exceptions as exceptions are not thrown by the method.
 add some fail() asserts in try catch blocks to ensure that the priviledge was not granted.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GrantRevokeTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java

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?view=diff&rev=552922&r1=552921&r2=552922
==============================================================================
--- 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 Tue Jul  3 10:27:09 2007
@@ -22,6 +22,7 @@
 package org.apache.derbyTesting.functionTests.tests.lang;
 
 import java.io.UnsupportedEncodingException;
+import java.sql.CallableStatement;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
@@ -466,7 +467,7 @@
         assertFunctionPrivilege(false, users[4], "S1", "F1", false);
         
         // clean up
-        revoke("execute", "function s1", "t1", users[2]);
+        revoke("execute", "function s1", "f1", users[2]);
         assertFunctionPrivilege(false, users[2], "s1", "F1", false);
     }
     
@@ -586,18 +587,10 @@
     	} catch (SQLException e) {
             	assertSQLState("42X01", e);
     	}
+        
+        assertCompileError("42X01", "grant select on schema t1 to " + users[1]);
 
-    	try {
-            runSQLCommands("grant select on schema t1 to " + users[1]);
-    	} catch (SQLException e) {
-            	assertSQLState("42X01", e);
-    	}
-    	
-    	try {
-            runSQLCommands("grant select on decimal t1 to " + users[1]);
-    	} catch (SQLException e) {
-            	assertSQLState("42X01", e);
-    	} 
+        assertCompileError("42X01",  "grant select on decimal t1 to " + users[1]);
     }
 
     public void testGrantOnNonexistantColumn() throws Exception {
@@ -673,52 +666,34 @@
     }
     
     public void testGrantExecuteOnTable() throws Exception {
-    	try {
-            runSQLCommands("grant execute on table s1.t1 to " + users[1]);
-    	} catch (SQLException e) {
-        	assertSQLState("42X01", e);
-        }
-    }
+        assertCompileError("42X01",
+                "grant execute on table s1.t1 to " + users[1]);
+     }
     
     public void testGrantSelectOnRoutine() throws Exception {
-    	try {
-            runSQLCommands("grant select on function s1.f1 to " + users[1]);
-    	} catch (SQLException e) {
-        	assertSQLState("42X01", e);
-        }
-    	
-    	try {
-            runSQLCommands("grant select on procedure s1.p1 to " + users[1]);
-    	} catch (SQLException e) {
-        	assertSQLState("42X01", e);
-        }
-    }
+        assertCompileError("42X01",
+                "grant select on function s1.f1 to " + users[1]);
+   	
+        assertCompileError("42X01",
+                "grant select on procedure s1.p1 to " + users[1]);
+   }
     
     public void testGrantExecuteWithRestrict() throws Exception {
     	// restrict invalid in grant statement
-    	try {
-            runSQLCommands("grant execute on function s1.f1 to " + users[1] + " restrict");
-    	} catch (SQLException e) {
-        	assertSQLState("42X01", e);
-        }
+        assertCompileError("42X01",
+                "grant execute on function s1.f1 to " + users[1] + " restrict");
     }
     
     public void testGrantRevokeWithoutRestrict() throws Exception {
     	// restrict invalid in grant statement
-    	try {
-            runSQLCommands("revoke execute on function s1.f1 from " + users[0]);
-    	} catch (SQLException e) {
-        	assertSQLState("42X01", e);
-        }
+        assertCompileError("42X01",
+               "revoke execute on function s1.f1 from " + users[0]);
     }
     
     public void testGrantRevokeSelectWithRestrict() throws Exception {
     	// restrict invalid in grant statement
-    	try {
-            runSQLCommands("revoke select on s1.t1 from " + users[0] + " restrict");
-    	} catch (SQLException e) {
-        	assertSQLState("42X01", e);
-        }
+        assertCompileError("42X01",
+    	     "revoke select on s1.t1 from " + users[0] + " restrict");
     }
     
     public void testGrantDeleteWithColumnList() throws Exception {
@@ -897,11 +872,10 @@
 		//add restrict to revoke execute... 
 		if (perm.equalsIgnoreCase("execute"))
 			command.append(" restrict");
-		try {
-			runSQLCommands(command.toString());
-		} catch (UnsupportedEncodingException e) {
-			fail(e.getMessage());
-		}
+        
+        Statement s = createStatement();
+        s.executeUpdate(command.toString());
+        s.close();
 	}
 
     /**
@@ -1008,10 +982,10 @@
     	Statement s = c.createStatement();
     	try {
     	    boolean b = s.execute("select " + columnListAsString(columns) + " from " + schema + "." + table);
-    	    if (hasPrivilege)
-    	    {
-    	        assertEquals(true, b);
-    	    }
+            
+            if (!hasPrivilege)
+                fail("expected no SELECT permission on table");
+
     	} catch (SQLException e) {
     		if (!hasPrivilege) {
     			assertSQLState("42502", e);
@@ -1040,10 +1014,9 @@
     	Statement s = c.createStatement();
     	try {
     	    boolean b = s.execute("delete from " + schema + "." + table);
-    	    if (hasPrivilege)
-    	    {
-    	        // b is false if no rows updated.
-    	    }
+            if (!hasPrivilege)
+                fail("expected no DELETE permission on table");
+
     	} catch (SQLException e) {
     		if (!hasPrivilege) {
     			assertSQLState("42500", e);
@@ -1090,10 +1063,9 @@
             rs.close();
             command.append(")");
     	    int i = s.executeUpdate(command.toString());
-    	    if (hasPrivilege)
-    	    {
-    	        assertEquals(1, i);
-    	    }
+            //if (!hasPrivilege)
+            //    fail("expected no INSERT permission on table");
+
     	} catch (SQLException e) {
     		if (!hasPrivilege) {
     			assertSQLState("42502", e);
@@ -1156,6 +1128,9 @@
         	    	// update count should equal select count
         	        assertEquals(columnCount, actualCount);
         	    }
+                //if (!hasPrivilege)
+                //    fail("expected no UPDATE permission on table");
+
     		} catch (SQLException e) {
         		if (!hasPrivilege) {
         			assertSQLState("42502", e);
@@ -1241,6 +1216,9 @@
     	    {
     	        assertEquals(0, i); 
     	    }
+            if (!hasPrivilege)
+                fail("expected no TRIGGER permission on table");
+
     	} catch (SQLException e) {
     		if (!hasPrivilege) {
     			assertSQLState("42500", e);
@@ -1278,6 +1256,9 @@
 		try {
 		    ps = c.prepareStatement(functioncall);
 		    rs = ps.executeQuery();
+            if (!hasPrivilege)
+                fail("expected no EXECUTE permission on function");
+
 		} catch (SQLException e) {
 			if (!hasPrivilege){
 				if (forProcedure) 
@@ -1309,11 +1290,14 @@
         
         String procedurecall = "call " + schema + "." + procedure + "()";
         
-		PreparedStatement ps = c.prepareStatement(procedurecall);
+		CallableStatement ps = c.prepareCall(procedurecall);
 		ResultSet rs = null;
 		try {
 			ps.execute();
 			rs = ps.getResultSet();
+            if (!hasPrivilege)
+                fail("expected no EXECUTE permission on procedure");
+
 		} catch (SQLException e) {
 			if (!hasPrivilege)
 				assertSQLState("42504", e);
@@ -1327,6 +1311,7 @@
 		{
 				rs.close();
 		}
+        c.close();
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?view=diff&rev=552922&r1=552921&r2=552922
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Tue Jul  3 10:27:09 2007
@@ -382,9 +382,14 @@
     }
     
     /**
-     * Run a set of SQL commands from a String discarding the output.
+     * Run a set of SQL commands from a String discarding the output,
+     * intended for setup code, not testing (assert) code.
      * Commands are separated by a semi-colon. Connection used
-     * is this objects default connection.
+     * is this objects default connection. Note that assertions
+     * are not performed by this method. Code may assert the number
+     * of failures returned, typically as zero. Exceptions
+     * thrown by statements are not thrown through this method.
+     * For single statements a Statement object should be used directly.
      * @param sqlCommands
      * @return Number of errors executing the script.
      * @throws UnsupportedEncodingException