db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r713158 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang: GeneratedColumnsHelper.java GeneratedColumnsPermsTest.java GeneratedColumnsTest.java _Suite.java
Date Tue, 11 Nov 2008 20:48:20 GMT
Author: rhillegas
Date: Tue Nov 11 12:48:19 2008
New Revision: 713158

URL: http://svn.apache.org/viewvc?rev=713158&view=rev
Log:
DERBY-3932: Add basic tests of permissions on generated columns.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java?rev=713158&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
Tue Nov 11 12:48:19 2008
@@ -0,0 +1,293 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsHelper
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derby.iapi.util.StringUtil;
+import org.apache.derby.catalog.DefaultInfo;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+
+import org.apache.derby.catalog.types.RoutineAliasInfo;
+
+/**
+ * <p>
+ * Helper routines for testing generated columns. See DERBY-481.
+ * </p>
+ */
+public class GeneratedColumnsHelper extends BaseJDBCTestCase
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    protected static  final   String  REDUNDANT_CLAUSE = "42613";
+    protected static  final   String  ILLEGAL_AGGREGATE = "42XA1";
+    protected static  final   String  UNSTABLE_RESULTS = "42XA2";
+    protected static  final   String  CANT_OVERRIDE_GENERATION_CLAUSE = "42XA3";
+    protected static  final   String  CANT_REFERENCE_GENERATED_COLUMN = "42XA4";
+    protected static  final   String  ROUTINE_CANT_ISSUE_SQL = "42XA5";
+    protected static  final   String  BAD_FOREIGN_KEY_ACTION = "42XA6";
+    protected static  final   String  ILLEGAL_ADD_DEFAULT = "42XA7";
+    protected static  final   String  ILLEGAL_RENAME = "42XA8";
+    
+    protected static  final   String  NOT_NULL_VIOLATION = "23502";
+    protected static  final   String  CONSTRAINT_VIOLATION = "23513";
+    protected static  final   String  FOREIGN_KEY_VIOLATION = "23503";
+    protected static  final   String  ILLEGAL_DUPLICATE = "23505";
+    protected static  final   String  SYNTAX_ERROR = "42X01";
+    protected static  final   String  COLUMN_OUT_OF_SCOPE = "42X04";
+    protected static  final   String  OPERATION_FORBIDDEN = "X0Y25";
+
+    protected static  final   String  LACK_TABLE_PRIV = "42500";
+    protected static  final   String  LACK_COLUMN_PRIV = "42502";
+    protected static  final   String  LACK_EXECUTE_PRIV = "42504";
+    
+    protected static  final   String  CASCADED_COLUMN_DROP_WARNING = "01009";
+    protected static  final   String  CONSTRAINT_DROPPED_WARNING = "01500";
+    protected static  final   String  TRIGGER_DROPPED_WARNING = "01502";
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+
+    /**
+     * Create a new instance.
+     */
+
+    public GeneratedColumnsHelper(String name)
+    {
+        super(name);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // HELPER METHODS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * Run good DDL.
+     * @throws SQLException 
+     */
+    protected void    goodStatement( Connection conn, String ddl ) throws SQLException
+    {
+        PreparedStatement    ps = chattyPrepare( conn, ddl );
+
+        ps.execute();
+        ps.close();
+    }
+    
+    /**
+     * Prepare a statement and report its sql text.
+     */
+    protected PreparedStatement   chattyPrepare( Connection conn, String text )
+        throws SQLException
+    {
+        println( "Preparing statement:\n\t" + text );
+        
+        return conn.prepareStatement( text );
+    }
+
+    /**
+     * Assert that the statement text, when compiled, raises an exception
+     */
+    protected void    expectCompilationError( String sqlState, String query )
+    {
+        println( "\nExpecting " + sqlState + " when preparing:\n\t" + query );
+
+        assertCompileError( sqlState, query );
+    }
+
+    /**
+     * Assert that the statement text, when executed, raises an error.
+     */
+    protected void    expectExecutionError( Connection conn, String sqlState, String query
)
+        throws Exception
+    {
+        println( "\nExpecting " + sqlState + " when executing:\n\t"  );
+        PreparedStatement   ps = chattyPrepare( conn, query );
+
+        assertStatementError( sqlState, ps );
+    }
+
+    /**
+     * Assert that the statement text, when executed, raises a warning.
+     */
+    protected void    expectExecutionWarning( Connection conn, String sqlState, String query
)
+        throws Exception
+    {
+        expectExecutionWarnings( conn, new String[] { sqlState }, query );
+    }
+
+    /**
+     * Assert that the statement text, when executed, raises a warning.
+     */
+    protected void    expectExecutionWarnings( Connection conn, String[] sqlStates, String
query )
+        throws Exception
+    {
+        println( "\nExpecting warnings " + fill( sqlStates ).toString() + " when executing:\n\t"
 );
+        PreparedStatement   ps = chattyPrepare( conn, query );
+
+        ps.execute();
+
+        int idx = 0;
+
+        for ( SQLWarning sqlWarning = ps.getWarnings(); sqlWarning != null; sqlWarning =
sqlWarning.getNextWarning() )
+        {
+            String          actualSQLState = sqlWarning.getSQLState();
+
+            if ( idx >= sqlStates.length )
+            {
+                fail( "Got more warnings than we expected." );
+            }
+
+            String  expectedSqlState = sqlStates[ idx++ ];
+
+            assertEquals( expectedSqlState, actualSQLState );
+        }
+
+        assertEquals( idx, sqlStates.length );
+
+        ps.close();
+    }
+
+    /**
+     * <p>
+     * Assert whether a routine is expected to be DETERMINISTIC.
+     * </p>
+     */
+    public  void    assertDeterministic( Connection conn, String routineName, boolean isDeterministic
)
+        throws Exception
+    {
+        PreparedStatement   ps = conn.prepareStatement
+            (
+             "select a.aliasinfo\n" +
+             "from sys.sysaliases a\n" +
+             "where alias =  ?"
+             );
+        ps.setString( 1, routineName );
+        ResultSet               rs = ps.executeQuery();
+
+        rs.next();
+        RoutineAliasInfo    rai = (RoutineAliasInfo) rs.getObject( 1 );
+
+        assertEquals( isDeterministic, rai.isDeterministic() );
+
+        rs.close();
+        ps.close();
+    }
+
+    /**
+     * Assert that the statement returns the correct results.
+     */
+    protected void assertResults( Connection conn, String query, String[][] rows, boolean
trimResults )
+        throws Exception
+    {
+        PreparedStatement   ps = chattyPrepare( conn, query );
+        ResultSet                   rs = ps.executeQuery();
+
+        assertResults( rs, rows, trimResults );
+
+        rs.close();
+        ps.close();
+    }
+        
+    /**
+     * Assert that the ResultSet returns the desired rows.
+     */
+    protected void assertResults( ResultSet rs, String[][] rows, boolean trimResults )
+        throws Exception
+    {
+        int     rowCount = rows.length;
+
+        for ( int i = 0; i < rowCount; i++ )
+        {
+            String[]    row = rows[ i ];
+            int             columnCount = row.length;
+
+            assertTrue( rs.next() );
+
+            for ( int j = 0; j < columnCount; j++ )
+            {
+                String  expectedValue =  row[ j ];
+                String  actualValue = null;
+                int         column = j+1;
+
+                actualValue = rs.getString( column );
+                if ( rs.wasNull() ) { actualValue = null; }
+
+                if ( (actualValue != null) && trimResults ) { actualValue = actualValue.trim();
}
+                
+                assertEquals( (expectedValue == null), rs.wasNull() );
+                
+                if ( expectedValue == null )    { assertNull( actualValue ); }
+                else { assertEquals(expectedValue, actualValue); }
+            }
+        }
+
+        assertFalse( rs.next() );
+    }
+
+    /**
+     * <p>
+     * Fill an ArrayList from an array.
+     * </p>
+     */
+    protected ArrayList   fill( Object[] raw )
+    {
+        ArrayList   result = new ArrayList();
+        int             count = raw.length;
+
+        for ( int i = 0; i < count; i++ ) { result.add( raw[ i ] ); }
+
+        return result;
+    }
+    
+
+}
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java?rev=713158&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
Tue Nov 11 12:48:19 2008
@@ -0,0 +1,462 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsPermsTest
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.DriverManager;
+import java.util.ArrayList;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derby.iapi.util.StringUtil;
+import org.apache.derby.catalog.DefaultInfo;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+
+import org.apache.derby.catalog.types.RoutineAliasInfo;
+
+/**
+ * <p>
+ * Test permissions on generated columns. See DERBY-481.
+ * </p>
+ */
+public class GeneratedColumnsPermsTest extends GeneratedColumnsHelper
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private static  final   String      TEST_DBO = "TEST_DBO";
+    private static  final   String      JANET = "JANET";
+    private static  final   String[]    LEGAL_USERS = { TEST_DBO, JANET };
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+
+    /**
+     * Create a new instance.
+     */
+
+    public GeneratedColumnsPermsTest(String name)
+    {
+        super(name);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // JUnit BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+
+    /**
+     * Construct top level suite in this JUnit test
+     */
+    public static Test suite()
+    {
+        TestSuite suite = (TestSuite) TestConfiguration.embeddedSuite(GeneratedColumnsPermsTest.class);
+
+        Test        cleanTest = new CleanDatabaseTestSetup( suite );
+        Test        authenticatedTest = DatabasePropertyTestSetup.builtinAuthentication
+            ( cleanTest, LEGAL_USERS, "generatedColumnsPermissions" );
+        Test        authorizedTest = TestConfiguration.sqlAuthorizationDecorator( authenticatedTest
);
+
+        return authorizedTest;
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // TESTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Test that you need select/insert/update/delete privileges on a generated column and
not just on
+     * the columns it references.
+     * </p>
+     */
+    public  void    test_001_basicPermissions()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+        Connection  janetConnection = openUserConnection( JANET );
+
+        //
+        // Verify correct behavior when have granted only SELECT and UPDATE on the referenced
column.
+        //
+        goodStatement
+            (
+             dboConnection,
+             "create table t_bp_1( a int, b int generated always as ( -a ) )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "insert into t_bp_1( a ) values ( 1 )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant select ( a ) on t_bp_1 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant update ( a ) on t_bp_1 to public"
+             );
+        
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_TABLE_PRIV,
+             "insert into test_dbo.t_bp_1( a ) values ( 100 )"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_COLUMN_PRIV,
+             "update test_dbo.t_bp_1 set a = a+ 1"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_TABLE_PRIV,
+             "delete from test_dbo.t_bp_1 where a = 2"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_COLUMN_PRIV,
+             "select * from test_dbo.t_bp_1 order by a"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select a from test_dbo.t_bp_1 order by a",
+             new String[][]
+             {
+                 { "1", },
+             },
+             false
+             );
+        
+        //
+        // Verify correct behavior when we also grant SELECT on the generated column.
+        //
+        goodStatement
+            (
+             dboConnection,
+             "grant select ( b ) on t_bp_1 to public"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_TABLE_PRIV,
+             "insert into test_dbo.t_bp_1( a ) values ( 100 )"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_COLUMN_PRIV,
+             "update test_dbo.t_bp_1 set a = a+ 1"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_TABLE_PRIV,
+             "delete from test_dbo.t_bp_1 where a = 2"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_bp_1 order by a",
+             new String[][]
+             {
+                 { "1", "-1", },
+             },
+             false
+             );
+        
+        //
+        // Verify correct behavior when we also grant UPDATE on the generated column.
+        //
+        goodStatement
+            (
+             dboConnection,
+             "grant update ( b ) on t_bp_1 to public"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_TABLE_PRIV,
+             "insert into test_dbo.t_bp_1( a ) values ( 100 )"
+             );
+        goodStatement
+            (
+             janetConnection,
+             "update test_dbo.t_bp_1 set a = a+ 1"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_TABLE_PRIV,
+             "delete from test_dbo.t_bp_1 where a = 2"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_bp_1 order by a",
+             new String[][]
+             {
+                 { "2", "-2", },
+             },
+             false
+             );
+        
+        //
+        // Verify correct behavior when we also grant INSERT on the table.
+        //
+        goodStatement
+            (
+             dboConnection,
+             "grant insert on t_bp_1 to public"
+             );
+        goodStatement
+            (
+             janetConnection,
+             "insert into test_dbo.t_bp_1( a ) values ( 100 )"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_TABLE_PRIV,
+             "delete from test_dbo.t_bp_1 where a = 2"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_bp_1 order by a",
+             new String[][]
+             {
+                 { "2", "-2", },
+                 { "100", "-100", },
+             },
+             false
+             );
+        
+        //
+        // Verify correct behavior when we also grant DELETE on the table.
+        //
+        goodStatement
+            (
+             dboConnection,
+             "grant delete on t_bp_1 to public"
+             );
+        goodStatement
+            (
+             janetConnection,
+             "delete from test_dbo.t_bp_1 where a = 2"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_bp_1 order by a",
+             new String[][]
+             {
+                 { "100", "-100", },
+             },
+             false
+             );
+   }
+
+    /**
+     * <p>
+     * Test that you need execute privilege to run functions mentioned in
+     * generation clauses.
+     * </p>
+     */
+    public  void    test_002_functionPermissions()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+        Connection  janetConnection = openUserConnection( JANET );
+
+        //
+        // Verify correct behavior when EXECUTE privilege is not granted.
+        //
+        goodStatement
+            (
+             dboConnection,
+             "create function f_fp_minus\n" +
+             "(\n" +
+             "    a int\n" +
+             ")\n" +
+             "returns int\n" +
+             "language java\n" +
+             "deterministic\n" +
+             "parameter style java\n" +
+             "no sql\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.GeneratedColumnsTest.minus'\n"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create table t_fp_1( a int, b int generated always as ( test_dbo.f_fp_minus(
a ) ) )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant update on t_fp_1 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant insert on t_fp_1 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "grant select on t_fp_1 to public"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "insert into test_dbo.t_fp_1( a ) values ( 100 )"
+             );
+
+        goodStatement
+            (
+             janetConnection,
+             "create function f_fp_minus\n" +
+             "(\n" +
+             "    a int\n" +
+             ")\n" +
+             "returns int\n" +
+             "language java\n" +
+             "deterministic\n" +
+             "parameter style java\n" +
+             "no sql\n" +
+             "external name 'java.lang.Math.abs'\n"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_EXECUTE_PRIV,
+             "update test_dbo.t_fp_1 set a = a + 1"
+             );
+        expectExecutionError
+            (
+             janetConnection,
+             LACK_EXECUTE_PRIV,
+             "insert into test_dbo.t_fp_1( a ) values ( 200 )"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_fp_1 order by a",
+             new String[][]
+             {
+                 { "100", "-100", },
+             },
+             false
+             );
+
+        //
+        // Verify correct behavior when EXECUTE privilege is granted.
+        //
+        goodStatement
+            (
+             dboConnection,
+             "grant execute on function f_fp_minus to public"
+             );
+        goodStatement
+            (
+             janetConnection,
+             "update test_dbo.t_fp_1 set a = a + 1"
+             );
+        goodStatement
+            (
+             janetConnection,
+             "insert into test_dbo.t_fp_1( a ) values ( 200 )"
+             );
+        assertResults
+            (
+             janetConnection,
+             "select * from test_dbo.t_fp_1 order by a",
+             new String[][]
+             {
+                 { "101", "-101", },
+                 { "200", "-200", },
+             },
+             false
+             );
+    }
+    
+    /**
+     * <p>
+     * Test ddl that can only be issued when authorization is turned on.
+     * </p>
+     */
+    public  void    test_003_ddl()
+        throws Exception
+    {
+        Connection  conn = getConnection();
+
+        //
+        // Verify that current_role is not allowed in generation clauses.
+        //
+        expectCompilationError
+            (
+             UNSTABLE_RESULTS,
+             "create table t_ddl_1( a int, b varchar( 128 ) generated always as ( current_role
) )"
+             );
+    }
+    
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // MINIONS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsPermsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=713158&r1=713157&r2=713158&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Tue Nov 11 12:48:19 2008
@@ -48,7 +48,7 @@
  * Test generated columns. See DERBY-481.
  * </p>
  */
-public class GeneratedColumnsTest extends BaseJDBCTestCase
+public class GeneratedColumnsTest extends GeneratedColumnsHelper
 {
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -56,27 +56,6 @@
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
-    private static  final   String  REDUNDANT_CLAUSE = "42613";
-    private static  final   String  ILLEGAL_AGGREGATE = "42XA1";
-    private static  final   String  UNSTABLE_RESULTS = "42XA2";
-    private static  final   String  CANT_OVERRIDE_GENERATION_CLAUSE = "42XA3";
-    private static  final   String  CANT_REFERENCE_GENERATED_COLUMN = "42XA4";
-    private static  final   String  ROUTINE_CANT_ISSUE_SQL = "42XA5";
-    private static  final   String  BAD_FOREIGN_KEY_ACTION = "42XA6";
-    private static  final   String  ILLEGAL_ADD_DEFAULT = "42XA7";
-    private static  final   String  ILLEGAL_RENAME = "42XA8";
-    private static  final   String  NOT_NULL_VIOLATION = "23502";
-    private static  final   String  CONSTRAINT_VIOLATION = "23513";
-    private static  final   String  FOREIGN_KEY_VIOLATION = "23503";
-    private static  final   String  ILLEGAL_DUPLICATE = "23505";
-    private static  final   String  SYNTAX_ERROR = "42X01";
-    private static  final   String  COLUMN_OUT_OF_SCOPE = "42X04";
-    private static  final   String  OPERATION_FORBIDDEN = "X0Y25";
-
-    private static  final   String  CASCADED_COLUMN_DROP_WARNING = "01009";
-    private static  final   String  CONSTRAINT_DROPPED_WARNING = "01500";
-    private static  final   String  TRIGGER_DROPPED_WARNING = "01502";
-    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // STATE
@@ -3357,90 +3336,22 @@
     ///////////////////////////////////////////////////////////////////////////////////
 
 
-    /**
-     * Run good DDL.
-     * @throws SQLException 
-     */
-    private void    goodStatement( Connection conn, String ddl ) throws SQLException
-    {
-        PreparedStatement    ps = chattyPrepare( conn, ddl );
-
-        ps.execute();
-        ps.close();
-    }
-    
-    /**
-     * Prepare a statement and report its sql text.
-     */
-    private PreparedStatement   chattyPrepare( Connection conn, String text )
-        throws SQLException
-    {
-        println( "Preparing statement:\n\t" + text );
-        
-        return conn.prepareStatement( text );
-    }
-
-    /**
-     * Assert that the statement text, when compiled, raises an exception
-     */
-    private void    expectCompilationError( String sqlState, String query )
-    {
-        println( "\nExpecting " + sqlState + " when preparing:\n\t" + query );
-
-        assertCompileError( sqlState, query );
-    }
-
-    /**
-     * Assert that the statement text, when executed, raises an error.
-     */
-    private void    expectExecutionError( Connection conn, String sqlState, String query
)
-        throws Exception
-    {
-        println( "\nExpecting " + sqlState + " when executing:\n\t"  );
-        PreparedStatement   ps = chattyPrepare( conn, query );
-
-        assertStatementError( sqlState, ps );
-    }
-
-    /**
-     * Assert that the statement text, when executed, raises a warning.
-     */
-    private void    expectExecutionWarning( Connection conn, String sqlState, String query
)
-        throws Exception
-    {
-        expectExecutionWarnings( conn, new String[] { sqlState }, query );
-    }
-
-    /**
-     * Assert that the statement text, when executed, raises a warning.
-     */
-    private void    expectExecutionWarnings( Connection conn, String[] sqlStates, String
query )
+    // read the counter of the number of times that the minus function has been
+    // called
+    private int readMinusCounter( Connection conn )
         throws Exception
     {
-        println( "\nExpecting warnings " + fill( sqlStates ).toString() + " when executing:\n\t"
 );
-        PreparedStatement   ps = chattyPrepare( conn, query );
-
-        ps.execute();
-
-        int idx = 0;
-
-        for ( SQLWarning sqlWarning = ps.getWarnings(); sqlWarning != null; sqlWarning =
sqlWarning.getNextWarning() )
-        {
-            String          actualSQLState = sqlWarning.getSQLState();
-
-            if ( idx >= sqlStates.length )
-            {
-                fail( "Got more warnings than we expected." );
-            }
-
-            String  expectedSqlState = sqlStates[ idx++ ];
+        PreparedStatement   ps = chattyPrepare( conn, "values ( f_readMinusCounter() )" );
+        ResultSet                   rs = ps.executeQuery();
 
-            assertEquals( expectedSqlState, actualSQLState );
-        }
+        rs.next();
 
-        assertEquals( idx, sqlStates.length );
+        int     result = rs.getInt( 1 );
 
+        rs.close();
         ps.close();
+
+        return result;
     }
 
     /**
@@ -3468,101 +3379,6 @@
         ps.close();
     }
 
-    /**
-     * <p>
-     * Assert whether a routine is expected to be DETERMINISTIC.
-     * </p>
-     */
-    public  void    assertDeterministic( Connection conn, String routineName, boolean isDeterministic
)
-        throws Exception
-    {
-        PreparedStatement   ps = conn.prepareStatement
-            (
-             "select a.aliasinfo\n" +
-             "from sys.sysaliases a\n" +
-             "where alias =  ?"
-             );
-        ps.setString( 1, routineName );
-        ResultSet               rs = ps.executeQuery();
-
-        rs.next();
-        RoutineAliasInfo    rai = (RoutineAliasInfo) rs.getObject( 1 );
-
-        assertEquals( isDeterministic, rai.isDeterministic() );
-
-        rs.close();
-        ps.close();
-    }
-
-    /**
-     * Assert that the statement returns the correct results.
-     */
-    private void assertResults( Connection conn, String query, String[][] rows, boolean trimResults
)
-        throws Exception
-    {
-        PreparedStatement   ps = chattyPrepare( conn, query );
-        ResultSet                   rs = ps.executeQuery();
-
-        assertResults( rs, rows, trimResults );
-
-        rs.close();
-        ps.close();
-    }
-        
-    /**
-     * Assert that the ResultSet returns the desired rows.
-     */
-    private void assertResults( ResultSet rs, String[][] rows, boolean trimResults )
-        throws Exception
-    {
-        int     rowCount = rows.length;
-
-        for ( int i = 0; i < rowCount; i++ )
-        {
-            String[]    row = rows[ i ];
-            int             columnCount = row.length;
-
-            assertTrue( rs.next() );
-
-            for ( int j = 0; j < columnCount; j++ )
-            {
-                String  expectedValue =  row[ j ];
-                String  actualValue = null;
-                int         column = j+1;
-
-                actualValue = rs.getString( column );
-                if ( rs.wasNull() ) { actualValue = null; }
-
-                if ( (actualValue != null) && trimResults ) { actualValue = actualValue.trim();
}
-                
-                assertEquals( (expectedValue == null), rs.wasNull() );
-                
-                if ( expectedValue == null )    { assertNull( actualValue ); }
-                else { assertEquals(expectedValue, actualValue); }
-            }
-        }
-
-        assertFalse( rs.next() );
-    }
-
-    // read the counter of the number of times that the minus function has been
-    // called
-    private int readMinusCounter( Connection conn )
-        throws Exception
-    {
-        PreparedStatement   ps = chattyPrepare( conn, "values ( f_readMinusCounter() )" );
-        ResultSet                   rs = ps.executeQuery();
-
-        rs.next();
-
-        int     result = rs.getInt( 1 );
-
-        rs.close();
-        ps.close();
-
-        return result;
-    }
-
     
     /**
      * <p>
@@ -3585,21 +3401,6 @@
     
     /**
      * <p>
-     * Fill an ArrayList from an array.
-     * </p>
-     */
-    private ArrayList   fill( Object[] raw )
-    {
-        ArrayList   result = new ArrayList();
-        int             count = raw.length;
-
-        for ( int i = 0; i < count; i++ ) { result.add( raw[ i ] ); }
-
-        return result;
-    }
-    
-    /**
-     * <p>
      * Returns the column default for a column.
      * </p>
      */

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?rev=713158&r1=713157&r2=713158&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Tue Nov 11 12:48:19 2008
@@ -178,6 +178,7 @@
         suite.addTest(OptimizerOverridesTest.suite());
         suite.addTest(PrecedenceTest.suite());
         suite.addTest(GeneratedColumnsTest.suite());
+        suite.addTest(GeneratedColumnsPermsTest.suite());
 
         return suite;
 	}



Mime
View raw message