db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r833055 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/dropTable.out suites/derbylang.runall tests/lang/DropTableTest.java tests/lang/_Suite.java tests/lang/dropTable.sql
Date Thu, 05 Nov 2009 15:00:27 GMT
Author: bpendleton
Date: Thu Nov  5 15:00:04 2009
New Revision: 833055

URL: http://svn.apache.org/viewvc?rev=833055&view=rev
Log:
DERBY-4423: Convert dropTable.sql into JUnit

This patch was contributed by Eranda Sooriyabandara (070468D at gmail dot com).

This change replaces the dropTable.sql test suite by an equivalent JUnit
test suite named DropTableTest.java. dropTable.sql is removed from the
old harness suite and DropTableTest is added to the derbylang JUnit suite.

There are no functional changes to the test cases.


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DropTableTest.java
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/dropTable.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/dropTable.sql
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall?rev=833055&r1=833054&r2=833055&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/derbylang.runall
Thu Nov  5 15:00:04 2009
@@ -9,7 +9,6 @@
 lang/db2Compatibility.sql
 lang/ddlTableLockMode.sql
 lang/desc_index.sql
-lang/dropTable.sql
 lang/emptyStatistics.sql
 lang/fk_nonSPS.sql
 lang/holdCursorIJ.sql

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DropTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DropTableTest.java?rev=833055&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DropTableTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DropTableTest.java
Thu Nov  5 15:00:04 2009
@@ -0,0 +1,334 @@
+/*
+Derby - Class org.apache.derbyTesting.functionTests.tests.lang.DropTableTest
+
+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.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLWarning;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+public final class DropTableTest extends BaseJDBCTestCase {
+
+    /**
+     * Public constructor required for running test as standalone JUnit.
+     */
+    public DropTableTest(String name)
+    {
+        super(name);
+    }
+    
+    ResultSet rs = null;
+    ResultSetMetaData rsmd;
+    SQLWarning sqlWarn = null;
+    PreparedStatement pSt;
+    CallableStatement cSt;
+    String [][] expRS;
+    String [] expColNames;
+    Statement st;
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("dropTable Test");
+        suite.addTest(TestConfiguration.defaultSuite(DropTableTest.class));
+        return suite;
+    }
+
+    public void testDropTableWithConstraints() throws Exception
+    {
+        //test table with different constraints
+        
+        st = createStatement();
+        getConnection().setAutoCommit(false);
+        
+        // test simple table - all should work
+        
+        st.executeUpdate( "create table t1 ( a int)");
+        st.executeUpdate( " drop table t1");
+        
+        // t1 shouldn't be found
+        
+        assertStatementError("42X05", st, "select * from t1");
+        
+        // test table with unique constraint - all should work
+        
+        st.executeUpdate( "create table t1 (a int not null unique)");
+        st.executeUpdate( " drop table t1");
+        
+        // t1 shouldn't be found
+        
+        assertStatementError("42X05", st, "select * from t1");
+        
+        // test table with primary constraint - all should work
+        
+        st.executeUpdate( "create table t1 ( a int not null primary key)");
+        st.executeUpdate( " drop table t1");
+        
+        // t1 shouldn't be found
+        
+        assertStatementError("42X05", st, "select * from t1");
+        
+        // test table with check constraint - all should work
+        
+        st.executeUpdate( "create table t1 ( a int check(a > 0))");
+        st.executeUpdate( " drop table t1");
+        
+        // t1 shouldn't be found
+        
+        assertStatementError("42X05", st, "select * from t1");
+        
+        // test table with index - all should work
+        
+        st.executeUpdate( "create table t1 ( a int)");
+        st.executeUpdate( " create index t1index on t1(a)");
+        st.executeUpdate( " drop table t1");
+        
+        // t1 shouldn't be found
+        
+        assertStatementError("42X05", st, "select * from t1");
+        
+        // test table with foreign key references;
+        
+        st.executeUpdate( "create table t1(a int not null primary key)");
+        st.executeUpdate(
+                " create table t2(a int constraint reft1a references t1(a))");
+        
+        // this should fail with a dependent constraint error
+        
+        assertStatementError("X0Y25", st, "drop table t1");
+        
+        // dropping dependent constraint
+        
+        st.executeUpdate( "alter table t2 drop constraint reft1a");
+        
+        // this should work since dependent constraint was dropped
+        
+        st.executeUpdate( "drop table t1");
+        
+        // t1 shouldn't be found
+        
+        assertStatementError("42X05", st, "select * from t1");
+        
+        // the following should work since no referential 
+        // constraint is left
+        
+        st.executeUpdate( "insert into t2 values(1)");
+        st.executeUpdate( " drop table t2");
+        
+        st.close();
+    }
+    public void testDropTableWithView() throws SQLException{
+        // test table with view
+        
+        st = createStatement();
+        getConnection().setAutoCommit(false);
+        
+        st.executeUpdate( "create table t1(a int, b int)");
+        st.executeUpdate( " create table t2(c int, d int)");
+        st.executeUpdate( " create view vt1a as select a from t1");
+        st.executeUpdate( " create view vt1b as select b from t1");
+        st.executeUpdate( " create view vt1t2 as select * from t1, t2");
+        st.executeUpdate( " create view vvt1a as select * from vt1a");
+        st.executeUpdate( " create view vvvt1a as select * from vvt1a");
+        
+        // this should fail with view being a dependent object
+        
+        assertStatementError("X0Y23", st, "drop table t1");
+        
+        // dropping dependent views
+        
+        st.executeUpdate( "drop view vvvt1a");
+        st.executeUpdate( " drop view vvt1a");
+        st.executeUpdate( " drop view vt1t2");
+        st.executeUpdate( " drop view vt1b");
+        st.executeUpdate( " drop view vt1a");
+        
+        // this should work after dependent views were dropped
+        
+        st.executeUpdate( "drop table t1");
+        
+        // this shouldn't find the view
+        
+        assertStatementError("42X05", st, "select * from vt1a");
+        assertStatementError("42X05", st, " select * from vt1b");
+        assertStatementError("42X05", st, " select * from vt1t2");
+        assertStatementError("42X05", st, " select * from vvt1a");
+        assertStatementError("42X05", st, " select * from vvvt1a");
+        st.executeUpdate( " drop table t2");
+        
+        st.close();
+    }
+    public void testDropTableWithPreparedStatement() throws SQLException{
+        // test table with prepared statement
+        
+        st = createStatement();
+        getConnection().setAutoCommit(false);
+        
+        st.executeUpdate( "create table t1(a int)");
+        pSt = prepareStatement( "select * from t1");
+        
+        // this should work, statement will be invalidated and 
+        // will fail when recompiled
+        
+        st.executeUpdate( "drop table t1");
+        assertStatementError("42X05", pSt);
+ 
+        st.close();
+    }
+    public void testDropTableWithTriggers() throws SQLException{
+        // test table with triggers
+        
+        st = createStatement();
+        getConnection().setAutoCommit(false);
+        
+        st.executeUpdate( "create table t1(a int)");
+        st.executeUpdate( " create table t2(a int)");
+        st.executeUpdate(
+            " create trigger t1trig after insert on t1 for each "
+            + "row insert into t2 values(1)");
+        
+        // this should work - trigger should be deleted
+        
+        st.executeUpdate( "drop table t1");
+        
+        // t1 shouldn't be found
+        
+        assertStatementError("42X05", st, "select * from t1");
+        st.executeUpdate( " drop table t2");
+        
+        // test table within the body of a trigger on another table
+        
+        st.executeUpdate( "create table t1(a int)");
+        st.executeUpdate( " create table t2(a int)");
+        st.executeUpdate(
+            " create trigger t2trig after insert on t2 for each "
+            + "row insert into t1 values(1)");
+        
+        // this should work
+        
+        st.executeUpdate( "drop table t1");
+        
+        // the following should get an error when trying to 
+        // recompile the trigger action
+        
+        assertStatementError("42X05", st, "insert into t2 values(1)");
+        st.executeUpdate( " drop table t2");
+        
+        st.close();
+    }
+    
+    public void testDropTableDropView() throws SQLException{
+        // test drop view
+        
+        st = createStatement();
+        getConnection().setAutoCommit(false);
+        
+        st.executeUpdate( "create table t1(a int)");
+        st.executeUpdate( " create view vt1 as select * from t1");
+        st.executeUpdate( " create view vvt1 as select * from vt1");
+        
+        // these should fail
+        
+        assertStatementError("X0Y23", st, "drop view vt1");
+        assertStatementError("42X01", st, " drop view vt1 restrict");
+        assertStatementError("42X01", st, " drop view vt1 cascade");
+        
+        st.close();
+    }
+    public void testDropTableIndexesDropped() throws SQLException{
+        // make sure that indexes are dropped for drop table
+        
+        st = createStatement();
+        getConnection().setAutoCommit(false);
+        
+        st.executeUpdate( "create table t2(a int not null primary key)");
+        st.executeUpdate(
+            "create table reft2(a int constraint ref1 references t2)");
+        
+        // count should be 2
+        
+        JDBC.assertSingleValueResultSet( st.executeQuery(
+            "select count(*) from (sys.sysconglomerates c), (sys.systables t) "
+            + "where t.tableid = c.tableid and "
+            + "t.tablename = 'REFT2'"), "2");
+        
+        // drop dependent referential constraint
+        
+        st.executeUpdate( "alter table reft2 drop constraint ref1");
+        
+        // should work since dependent constraint was previously 
+        // dropped
+        
+        st.executeUpdate( "drop table t2");
+        
+        // count should be 1
+        
+        JDBC.assertSingleValueResultSet( st.executeQuery(
+            "select count(*) "
+            + "from (sys.sysconglomerates c), (sys.systables t) "
+            + "where t.tableid = c.tableid and "
+            + "t.tablename = 'REFT2'"), "1");
+        
+         getConnection().rollback();
+        
+        // unsuccessful drop table should not affect open cursor 
+        // beetle 4393
+        
+        st.executeUpdate(
+            " create table T1 (i int, c varchar(255), d varchar(255))");
+        st.executeUpdate( " insert into T1(i) values(1)");
+        st.executeUpdate( " insert into T1(i) values(2)");
+        
+        Statement st1 = getConnection().createStatement();
+        st1.setCursorName("X1");
+        
+        ResultSet rs1 = st1.executeQuery( "select i from t1 for update of c"); 
+        pSt = prepareStatement("update t1 set c = CHAR(i) where current of X1");
+        
+        assertStatementError("X0X95",st,"drop table T1");
+        
+        rs1.next();      
+        
+        pSt.executeUpdate();
+        
+        rs=st.executeQuery("select * from T1");
+        expColNames=new String[]{"I","C","D"};
+        JDBC.assertColumnNames(rs, expColNames);
+        
+        expRS=new String[][]{
+            {"1","1",null},
+            {"2",null,null}
+        };
+        JDBC.assertFullResultSet(rs, expRS);
+        
+        st1.close();
+        st.close();
+        //pretend all of the above didn't happen
+        getConnection().setAutoCommit(true);
+    }
+}

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

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=833055&r1=833054&r2=833055&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
Thu Nov  5 15:00:04 2009
@@ -66,7 +66,8 @@
         suite.addTest(ColumnDefaultsTest.suite());
         suite.addTest(CompressTableTest.suite());
         suite.addTest(DatabaseClassLoadingTest.suite());
-        suite.addTest(DynamicLikeOptimizationTest.suite());
+        suite.addTest(DropTableTest.suite());
+	  suite.addTest(DynamicLikeOptimizationTest.suite());
         suite.addTest(ExistsWithSubqueriesTest.suite());
         suite.addTest(FloatTypesTest.suite());
         suite.addTest(GrantRevokeTest.suite());



Mime
View raw message