db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r676962 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang: ConstantExpressionTest.java LangScripts.java _Suite.java constantExpression.sql
Date Tue, 15 Jul 2008 16:48:48 GMT
Author: kmarsden
Date: Tue Jul 15 09:48:48 2008
New Revision: 676962

URL: http://svn.apache.org/viewvc?rev=676962&view=rev
Log:
DERBY-3750 Convert "org.apache.derbyTesting.functionTests.tests.lang.constant Expression.sql"
to junit

Contributed by Junjie Peng


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstantExpressionTest.java
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/constantExpression.sql
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.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/ConstantExpressionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstantExpressionTest.java?rev=676962&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstantExpressionTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstantExpressionTest.java
Tue Jul 15 09:48:48 2008
@@ -0,0 +1,155 @@
+/**
+ * Derby - Class org.apache.derbyTesting.functionTests.tests.lang.ConstantExpressionTest
+ * 
+ * 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.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Test;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Test case for constantExpression.sql, which provides tests
+ * for constant expression evaluation.
+ */
+public class ConstantExpressionTest extends BaseJDBCTestCase {
+
+    /**
+     * Constructor. 
+     */
+    public ConstantExpressionTest(String name) throws SQLException {
+        super(name);
+    }
+
+    public static Test suite(){    
+        return TestConfiguration.defaultSuite(
+                ConstantExpressionTest.class);
+    }
+
+    /**
+     * Create the table t1 with 3 rows, and two procedures.
+     * @throws SQLException 
+     *      if SQLException is thrown.
+     * @see junit.framework.TestCase#setUp()
+     */
+    public void setUp() throws SQLException{
+        String sql = "create table t1(c1 int)";
+        Statement st = createStatement();
+        st.executeUpdate(sql);
+
+        sql = "insert into t1 values 1, 2, 3";
+        assertEquals("Fail to insert into table", 3, st.executeUpdate(sql));
+
+        st.close();
+    }
+
+    /** 
+     * Drop table t1 and close two procedures.
+     * @throws Exception 
+     *      if Exception is thrown.
+     * @see org.apache.derbyTesting.junit.BaseJDBCTestCase#tearDown()
+     */
+    public void tearDown() throws Exception {
+        dropTable("t1");
+        super.tearDown();
+    }
+
+    /**
+     * Test false constant expressions.
+     * @throws SQLException
+     *      if SQLException is thrown.
+     */
+    public void testFalseConstantExpressions() throws SQLException{
+        String[] falseCases = {
+                "1 <> 1", "1 = 1 and 1 = 0", "1 = (2 + 3 - 2)",
+                "(case when 1 = 1 then 0 else 1 end) = 1",
+                "1 in (2, 3, 4)", "1 between 2 and 3",
+        };
+
+        Statement st = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+                ResultSet.CONCUR_READ_ONLY);
+        ResultSet rs;
+        String sql;
+        for(int i = 0; i < falseCases.length; i++){
+            sql = "select * from t1 where " + falseCases[i];
+            rs = st.executeQuery(sql);
+            JDBC.assertEmpty(rs);
+        }
+
+        st.close();
+
+        sql = "select * from t1 where ? = 1";
+        PreparedStatement ps1 = prepareStatement(sql);
+        ps1.setInt(1, 0);
+        rs = ps1.executeQuery();
+        JDBC.assertEmpty(rs);
+        ps1.close();
+
+        sql = "select * from t1 where cast(? as int) = 1";
+        PreparedStatement ps2 = prepareStatement(sql);
+        ps2.setInt(1, 0);
+        rs = ps2.executeQuery();
+        JDBC.assertEmpty(rs);
+        ps2.close();
+    }
+
+    /**
+     * Test true constant expressions.
+     * @throws SQLException
+     */
+    public void testTrueConstantExpressions() throws SQLException{
+        String[] trueCases = {
+                "1 = 1", "1 = 0 or 1 = 1", "1 + 2 = (2 + 3 - 2)",
+                "(case when 1 = 1 then 1 else 0 end) = 1",
+                "1 in (2, 3, 4, 4, 3, 2, 1)", "1 + 1 between 0 and 3",
+        };
+        String[][] content = {
+                { "1", }, { "2", }, { "3", }, 
+        };
+
+        Statement st = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+                ResultSet.CONCUR_READ_ONLY);
+        ResultSet rs;
+        String sql;
+        for(int i = 0; i < trueCases.length; i++){
+            sql = "select * from t1 where " + trueCases[i];
+            rs = st.executeQuery(sql);
+            JDBC.assertFullResultSet(rs, content);
+        }
+
+        st.close();
+
+        sql = "select * from t1 where ? = 1";
+        PreparedStatement ps1 = prepareStatement(sql);
+        ps1.setInt(1, 1);
+        rs = ps1.executeQuery();
+        JDBC.assertFullResultSet(rs, content);
+        ps1.close();
+
+        sql = "select * from t1 where cast(? as int) = 1";
+        PreparedStatement ps2 = prepareStatement(sql);
+        ps2.setInt(1, 1);
+        rs = ps2.executeQuery();
+        JDBC.assertFullResultSet(rs, content);
+        ps2.close();
+    }
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java?rev=676962&r1=676961&r2=676962&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LangScripts.java
Tue Jul 15 09:48:48 2008
@@ -66,7 +66,6 @@
         "aggregate",        
         "cast",
         "comparisons",
-        "constantExpression",
         "delete",
         "derived",
         "depend",

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=676962&r1=676961&r2=676962&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 Jul 15 09:48:48 2008
@@ -171,6 +171,7 @@
         suite.addTest(MixedCaseExpressionTest.suite());
         suite.addTest(MiscErrorsTest.suite());
         suite.addTest(ArithmeticTest.suite());
+        suite.addTest(ConstantExpressionTest.suite());
         
         return suite;
 	}



Mime
View raw message