db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r567126 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/prepStmtNull.out tests/jdbcapi/JDBCHarnessJavaTest.java tests/jdbcapi/PrepStmtNullTest.java tests/jdbcapi/_Suite.java tests/jdbcapi/prepStmtNull.java
Date Fri, 17 Aug 2007 20:15:59 GMT
Author: kmarsden
Date: Fri Aug 17 13:15:58 2007
New Revision: 567126

URL: http://svn.apache.org/viewvc?view=rev&rev=567126
Log:
DERBY-2981 Convert jdbcapi/prepStamtNull.java to JUnit

Contributed by Ramin Moazeni


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtNullTest.java
  (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/prepStmtNull.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/prepStmtNull.java
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCHarnessJavaTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCHarnessJavaTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCHarnessJavaTest.java?view=diff&rev=567126&r1=567125&r2=567126
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCHarnessJavaTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/JDBCHarnessJavaTest.java
Fri Aug 17 13:15:58 2007
@@ -57,7 +57,6 @@
             "maxfieldsize",
             //"LOBTest", TODO: investigate failure/convert
             "SetQueryTimeoutTest",
-            "prepStmtNull",
             // "testRelative", TODO: passes embedded, fails client - investigate failure/convert
             "rsgetXXXcolumnNames",
             

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtNullTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtNullTest.java?view=auto&rev=567126
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtNullTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/PrepStmtNullTest.java
Fri Aug 17 13:15:58 2007
@@ -0,0 +1,201 @@
+/*
+ 
+Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.PrepStmtNullTest
+ 
+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.jdbcapi;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+/**
+ * Tests setting parameters to SQL NULL
+ * This test converts the old jdbcapi/prepStmtNull.java
+ * test to JUnit.
+ */
+
+public class PrepStmtNullTest extends BaseJDBCTestCase {
+    
+    /**
+     * Create a test with the given name.
+     *
+     * @param name name of the test.
+     */
+    
+    public PrepStmtNullTest(String name) {
+        super(name);
+    }
+    
+    /**
+     * Create suite containing client and embedded tests and to run
+     * all tests in this class
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("PrepStmtNullTest");
+        suite.addTest(baseSuite("PrepStmtNullTest:embedded"));
+        suite.addTest(
+                TestConfiguration.clientServerDecorator(
+                baseSuite("PrepStmtNullTest:client")));
+        return suite;
+    }
+    
+    private static Test baseSuite(String name) {
+        TestSuite suite = new TestSuite(name);
+        
+        suite.addTestSuite(PrepStmtNullTest.class);
+        
+        return new CleanDatabaseTestSetup(suite) {
+            /**
+             * Creates the tables used in the test
+             * cases.
+             *
+             * @exception SQLException if a database error occurs
+             */
+            protected void decorateSQL(Statement stmt) throws SQLException {
+                
+                /**
+                 * Creates the table used in the test cases.
+                 *
+                 */
+                stmt.execute("create table nullTS(name varchar(10), ts timestamp)");
+                stmt.executeUpdate("create table nullBlob(name varchar(10), bval blob(16K))");
+                stmt.executeUpdate("create table ClobBlob(cval clob, bval blob(16K))");
+            }
+        };
+    }
+    
+    /**
+     * Testing a Null Timestamp
+     *
+     * @exception SQLException if error occurs
+     */
+    public void testNullTimeStamp() throws SQLException {
+        
+        Connection conn = getConnection();
+        
+        conn.setAutoCommit(false);
+        
+        PreparedStatement pStmt = prepareStatement("insert into nullTS values (?,?)");
+        
+        pStmt.setString(1,"work");
+        pStmt.setNull(2,java.sql.Types.TIMESTAMP);
+        pStmt.addBatch();
+        pStmt.setString(1,"work1");
+        pStmt.setNull(2,java.sql.Types.TIMESTAMP,"");
+        pStmt.addBatch();
+        
+        pStmt.executeBatch();
+        pStmt.close();
+        commit();
+        
+        Statement stmt1 = createStatement();
+        ResultSet rs = stmt1.executeQuery("select * from nullTS");
+        String [][]  expectedRows = new String[][] { { "work", null },
+        { "work1", null } };
+        JDBC.assertFullResultSet(rs, expectedRows);
+        commit();
+        conn.close();
+    }
+    /**
+     * Testing a Null Blob
+     *
+     * @exception SQLException if error occurs
+     */
+    public void testNullBlob() throws SQLException {
+        
+        Connection con = getConnection();
+        
+        con.setAutoCommit(false);
+        
+        PreparedStatement pStmt = con.prepareStatement("insert into nullBlob values (?,?)");
+        
+        pStmt.setString(1,"blob");
+        pStmt.setNull(2,java.sql.Types.BLOB);
+        pStmt.addBatch();
+        pStmt.setString(1,"blob1");
+        pStmt.setNull(2,java.sql.Types.BLOB,"");
+        pStmt.addBatch();
+        
+        pStmt.executeBatch();
+        pStmt.close();
+        commit();
+        
+        Statement stmt1 = con.createStatement();
+        ResultSet rs = stmt1.executeQuery("select * from nullBlob");
+        String [][]  expectedRows = new String[][] { { "blob", null },
+        { "blob1", null } };
+        JDBC.assertFullResultSet(rs, expectedRows);
+        stmt1.close();
+        commit();
+        con.close();
+    }
+    /**
+     * Test setNull() on Clob/Blob using Varchar/binary types
+     *
+     * @exception SQLException if error occurs
+     */
+    public void testNullClobBlob() throws SQLException {
+        
+        byte[] b2 = new byte[1];
+        b2[0] = (byte)64;
+        
+        PreparedStatement pStmt = prepareStatement("insert into ClobBlob values (?,?)");
+        
+        pStmt.setNull(1, Types.VARCHAR);
+        pStmt.setBytes(2, b2);
+        pStmt.execute();
+        pStmt.setNull(1, Types.VARCHAR,"");
+        pStmt.setBytes(2, b2);
+        pStmt.execute();
+        pStmt.close();
+        
+        Statement stmt1 = createStatement();
+        ResultSet rs = stmt1.executeQuery("select * from ClobBlob");
+        String [][]  expectedRows = new String[][] { { null, bytesToString(b2) },
+        { null, bytesToString(b2) } };
+        JDBC.assertFullResultSet(rs, expectedRows);
+        rs.close();
+        
+        stmt1.close();
+    }
+    /**
+     * Helper method to convert byte array to String
+     *
+     */
+    private String bytesToString(byte[] ba) {
+        if (ba == null) return null;
+        StringBuffer s = new StringBuffer();
+        for (int i = 0; i < ba.length; ++i) {
+            s.append(Integer.toHexString(ba[i] & 0x00ff));
+        }
+        return s.toString();
+    }
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java?view=diff&rev=567126&r1=567125&r2=567126
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
Fri Aug 17 13:15:58 2007
@@ -76,6 +76,7 @@
 		suite.addTest(AuthenticationTest.suite());
 		suite.addTest(DriverTest.suite());
 		suite.addTest(NullSQLTextTest.suite());
+		suite.addTest(PrepStmtNullTest.suite());
 		suite.addTest(StatementJdbc30Test.suite());
         suite.addTest(ClobTest.suite());
         suite.addTest(BlobUpdatableStreamTest.suite());



Mime
View raw message