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 km...@apache.org on 2008/05/02 23:03:09 UTC

svn commit: r652911 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: master/ suites/ tests/jdbcapi/

Author: kmarsden
Date: Fri May  2 14:03:09 2008
New Revision: 652911

URL: http://svn.apache.org/viewvc?rev=652911&view=rev
Log:
DERBY-3587  Convert jdbcapi/testRelative.java to JUnit

Contributed by Suran Jayathilaka (suranjay at gmail dot com)

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/RelativeTest.java   (with props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/testRelative.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/testRelative.java
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
    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/suites/DerbyNet.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude?rev=652911&r1=652910&r2=652911&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude Fri May  2 14:03:09 2008
@@ -1,9 +1,7 @@
-# excluding jdbcapi/testRelative.java because this is a new test contributed by Shreyas Kaushik and needs to be debugged with JCC  in order to get it running with network server
 # excluding jdbcapi/SetQueryTimeoutTest.java because neither the JCC driver nor the ClientDriver support setQueryTimeout() yet.
 # excluding jdbcapi/rsgetXXXcolumnNames.java as it fails incorrectly, according to JDBC spec. Forwarding test case to JCC team.
 # excluding largedata/LobLimits.java to run with the network server because currently lobs are materialized and this test tests for 2G lobs.
 # 			see DERBY-326 and DERBY-550 issues
-jdbcapi/testRelative.java
 jdbcapi/rsgetXXXcolumnNames.java
 jdbcapi/SetQueryTimeoutTest.java
 # excluding jdbcapi/derbyStress.java - jcc runs out of memory with this test

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall?rev=652911&r1=652910&r2=652911&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall Fri May  2 14:03:09 2008
@@ -1,3 +1,2 @@
 jdbcapi/derbyStress.java
-jdbcapi/testRelative.java
 jdbcapi/SURTest_ij.sql

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?rev=652911&r1=652910&r2=652911&view=diff
==============================================================================
--- 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 May  2 14:03:09 2008
@@ -54,19 +54,9 @@
             "maxfieldsize",
             //"LOBTest", TODO: investigate failure/convert
             "SetQueryTimeoutTest",
-            // "testRelative", TODO: passes embedded, fails client - investigate failure/convert
             "rsgetXXXcolumnNames",
             
     };
-
-    /**
-     * Tests that only run in embedded.
-     */
-    private static final String[] JDBCAPI_TESTS_EMEBDDED=
-    {
-        // Tests that pass on embedded but fail on client
-        "testRelative",
-    };
     
     private JDBCHarnessJavaTest(String name) {
         super(name);
@@ -80,7 +70,6 @@
     {
         TestSuite suite = new TestSuite("jdbcapi: old harness java tests");
         suite.addTest(baseSuite("embedded", JDBCAPI_TESTS_BOTH));
-        suite.addTest(baseSuite("embedded", JDBCAPI_TESTS_EMEBDDED));
         suite.addTest(TestConfiguration.clientServerDecorator(
                 baseSuite("clientserver", JDBCAPI_TESTS_BOTH)));
         return suite;

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/RelativeTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/RelativeTest.java?rev=652911&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/RelativeTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/RelativeTest.java Fri May  2 14:03:09 2008
@@ -0,0 +1,178 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.RelativeTest
+
+   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.*;
+
+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.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.junit.Utilities;
+
+/**
+ * Tests relative scrolling of a resultset. This is the JUnit conversion of
+ * jdbcapi/testRelative test.
+ */
+public class RelativeTest extends BaseJDBCTestCase {
+
+	public RelativeTest(String name) {
+		super(name);
+	}
+
+	/**
+	 * Test relative scrolling of ResultSet with concurrency set to
+	 * CONCUR_READ_ONLY.
+	 */
+	public void testScrolling_CONCUR_READ_ONLY() throws SQLException {
+		int concurrency = ResultSet.CONCUR_READ_ONLY;
+		Statement stmt1 = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+				concurrency);
+		ResultSet rs = stmt1.executeQuery("select * from testRelative");
+
+		rs.next(); // First Record
+		assertEquals("work1", rs.getString("name"));
+		rs.relative(2);
+		assertEquals("work3", rs.getString("name"));
+		assertEquals(false, rs.isFirst());
+		assertEquals(false, rs.isLast());
+		assertEquals(false, rs.isAfterLast());
+		rs.relative(-2);
+		assertEquals("work1", rs.getString("name"));
+
+		rs.relative(10);
+		try {
+			/*
+			 * Attempting to move beyond the first/last row in the result set
+			 * positions the cursor before/after the the first/last row.
+			 * Therefore, attempting to get value will throw an exception.
+			 */
+			rs.getString("name");
+		} catch (SQLException sqle) {
+			/**
+			 * sets the expected sql state for the expected exceptions,
+			 * according to return value of usingDerbyNetClient().
+			 */
+			String NO_CURRENT_ROW_SQL_STATE = "";
+			if (usingDerbyNetClient()) {
+				NO_CURRENT_ROW_SQL_STATE = "XJ121";
+			} else {
+				NO_CURRENT_ROW_SQL_STATE = "24000";
+			}
+			assertSQLState(NO_CURRENT_ROW_SQL_STATE, sqle);
+		}
+	}
+
+	/**
+	 * Test relative scrolling of ResultSet with concurrency set to
+	 * CONCUR_UPDATABLE.
+	 */
+	public void testScrolling_CONCUR_UPDATABLE() throws SQLException {
+		int concurrency = ResultSet.CONCUR_UPDATABLE;
+		Statement stmt1 = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+				concurrency);
+		ResultSet rs = stmt1.executeQuery("select * from testRelative");
+
+		rs.next(); // First Record
+		assertEquals("work1", rs.getString("name"));
+		rs.relative(2);
+		assertEquals("work3", rs.getString("name"));
+		assertEquals(false, rs.isFirst());
+		assertEquals(false, rs.isLast());
+		assertEquals(false, rs.isAfterLast());
+		rs.relative(-2);
+		assertEquals("work1", rs.getString("name"));
+
+		rs.relative(10);
+		try {
+			/*
+			 * Attempting to move beyond the first/last row in the result set
+			 * positions the cursor before/after the the first/last row.
+			 * Therefore, attempting to get value now will throw an exception.
+			 */
+			rs.getString("name");
+		} catch (SQLException sqle) {
+			/**
+			 * sets the expected sql state for the expected exceptions,
+			 * according to return value of usingDerbyNetClient().
+			 */
+			String NO_CURRENT_ROW_SQL_STATE = "";
+			if (usingDerbyNetClient()) {
+				NO_CURRENT_ROW_SQL_STATE = "XJ121";
+			} else {
+				NO_CURRENT_ROW_SQL_STATE = "24000";
+			}
+			assertSQLState(NO_CURRENT_ROW_SQL_STATE, sqle);
+		}
+	}
+
+	/**
+	 * Runs the test fixtures in embedded and client.
+	 * 
+	 * @return test suite
+	 */
+	public static Test suite() {
+		TestSuite suite = new TestSuite("RelativeTest");
+		suite.addTest(baseSuite("RelativeTest:embedded"));
+		suite.addTest(TestConfiguration
+				.clientServerDecorator(baseSuite("RelativeTest:client")));
+		return suite;
+	}
+
+	/**
+	 * Base suite of tests that will run in both embedded and client.
+	 * 
+	 * @param name
+	 *            Name for the suite.
+	 */
+	private static Test baseSuite(String name) {
+		TestSuite suite = new TestSuite(name);
+		suite.addTestSuite(RelativeTest.class);
+		return new CleanDatabaseTestSetup(DatabasePropertyTestSetup
+				.setLockTimeouts(suite, 2, 4)) {
+
+			/**
+			 * Creates the tables used in the test cases.
+			 * 
+			 * @exception SQLException
+			 *                if a database error occurs
+			 */
+			protected void decorateSQL(Statement stmt) throws SQLException {
+				stmt.execute("create table testRelative("
+						+ "name varchar(10), i int)");
+
+				stmt.execute("insert into testRelative values ("
+						+ "'work1', NULL)");
+				stmt.execute("insert into testRelative values ("
+						+ "'work2', NULL)");
+				stmt.execute("insert into testRelative values ("
+						+ "'work3', NULL)");
+				stmt.execute("insert into testRelative values ("
+						+ "'work4', NULL)");
+			}
+		};
+	}
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/RelativeTest.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?rev=652911&r1=652910&r2=652911&view=diff
==============================================================================
--- 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 May  2 14:03:09 2008
@@ -84,7 +84,8 @@
         suite.addTest(DMDBugsTest.suite());
         suite.addTest(DataSourceTest.suite());
         suite.addTest(SavepointJdbc30Test.suite());
-
+        suite.addTest(RelativeTest.suite());
+        
         // Old harness .java tests that run using the HarnessJavaTest
         // adapter and continue to use a single master file.
         suite.addTest(JDBCHarnessJavaTest.suite());