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 dy...@apache.org on 2007/12/04 20:41:37 UTC
svn commit: r601058 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests:
master/ suites/ tests/jdbcapi/
Author: dyre
Date: Tue Dec 4 11:41:36 2007
New Revision: 601058
URL: http://svn.apache.org/viewvc?rev=601058&view=rev
Log:
DERBY-3203: Convert jdbcapi/statementJdbc20.java to JUnit
Patch file: DERBY-3203v2.diff
Patch contributed by Ramin Moazeni
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java (with props)
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc20.out
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
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
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/statementJdbc20.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc20.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc20.out?rev=601058&r1=601057&r2=601058&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc20.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc20.out Tue Dec 4 11:41:36 2007
@@ -1,19 +0,0 @@
-Test statementJdbc20 starting
-Fetch Size 25
-Fetch Direction 1001
-1 2 3.1
-Result Set Fetch Size 25
-Result Set Fetch Direction 1001
-PASS -- expected exception
-SQLSTATE(XJ061): java.sql.SQLException: The 'setFetchDirection()' method is only allowed on scroll cursors.
-Result Set Fetch Size 250
-Result Set Fetch Direction 1001
-PASS -- expected exception
-SQLSTATE(XJ062): java.sql.SQLException: Invalid parameter value '100' for ResultSet.setFetchSize(int rows).
-PASS -- expected exception
-SQLSTATE(XJ061): java.sql.SQLException: The 'setFetchDirection()' method is only allowed on scroll cursors.
-PASS -- expected exception
-SQLSTATE(X0Y78): java.sql.SQLException: Statement.executeQuery() cannot be called with a statement that returns a row count.
-PASS -- expected exception
-SQLSTATE(X0Y79): java.sql.SQLException: Statement.executeUpdate() cannot be called with a statement that returns a ResultSet.
-Test statementJdbc20 finished
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=601058&r1=601057&r2=601058&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 Tue Dec 4 11:41:36 2007
@@ -1,6 +1,5 @@
# excluding resultsetStream.java because this test uses java.io.FileInputStream throughout the test
# excluding TestErrorStreamTarget.java since it's not relevant for clients
-# excluding statementJdbc20.java because this tests fetch_reverse throughout the test
# 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.
@@ -8,7 +7,6 @@
# 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/resultsetStream.java
-jdbcapi/statementJdbc20.java
jdbcapi/testRelative.java
jdbcapi/rsgetXXXcolumnNames.java
jdbcapi/SetQueryTimeoutTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude?rev=601058&r1=601057&r2=601058&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNetClient.exclude Tue Dec 4 11:41:36 2007
@@ -1,10 +1,7 @@
# excluding TestErrorStreamTarget.java since it's not relevant for clients
-# excluding statementJdbc20.java because this tests fetch_reverse throughout the test
-# regardless of framework
# 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/statementJdbc20.java
largedata/LobLimits.java
#
# This test brings the network server up and down by itself
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=601058&r1=601057&r2=601058&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 Tue Dec 4 11:41:36 2007
@@ -47,7 +47,6 @@
{
// from old jdbc20.runall
"connectionJdbc20",
- // "statementJdbc20", runs in embedded only
"resultsetJdbc20",
// from old jdbcapi.runall
@@ -71,9 +70,6 @@
*/
private static final String[] JDBCAPI_TESTS_EMEBDDED=
{
- // excluded from derby client in old harness
- "statementJdbc20",
-
// Tests that run ok in embedded but have a different client master file.
"savepointJdbc30_JSR169",
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java?rev=601058&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java Tue Dec 4 11:41:36 2007
@@ -0,0 +1,259 @@
+/*
+
+Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.StatementJdbc20Test
+
+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.ResultSet;
+import java.sql.Statement;
+import java.sql.SQLException;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test of additional methods in JDBC2.0 methods in statement and
+ * resultset classes.
+ * This test converts the old jdbcapi/statementJdbc20.java test
+ * to JUnit.
+ */
+public class StatementJdbc20Test extends BaseJDBCTestCase {
+
+ /**
+ * Create a test with the given name.
+ *
+ * @param name name of the test.
+ */
+ public StatementJdbc20Test(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("StatementJdbc20Test");
+ suite.addTest(baseSuite("StatementJdbc20Test:embedded"));
+ suite.addTest(
+ TestConfiguration.clientServerDecorator(
+ baseSuite("StatementJdbc20Test:client")));
+
+ return suite;
+ }
+
+ private static Test baseSuite(String name) {
+ TestSuite suite = new TestSuite(name);
+
+ suite.addTestSuite(StatementJdbc20Test.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 {
+
+ Connection conn = getConnection();
+
+ /**
+ * Creates the table used in the test cases.
+ *
+ */
+ stmt.execute("create table tab1 (i int, s smallint, r real)");
+ stmt.executeUpdate("insert into tab1 values(1, 2, 3.1)");
+ }
+ };
+ }
+
+ /**
+ * Testing wrong values for setFetchSize
+ * and setFetchDirection.
+ *
+ * @exception SQLException if error occurs
+ */
+ public void testWrongVaues() throws SQLException {
+
+ Statement stmt = createStatement();
+
+ stmt.setFetchSize(25);
+ stmt.setFetchDirection(ResultSet.FETCH_REVERSE);
+ stmt.setEscapeProcessing(true);
+
+ //Error testing : set wrong values ..
+ try {
+ stmt.setFetchSize(-1000);
+ fail("setFetchSize(-1000) expected to fail");
+ } catch(SQLException e) {
+ assertSQLState("XJ065", e);
+ }
+
+ try {
+ stmt.setFetchDirection(-1000);
+ fail("setFetchDirection(-1000) expected to fail");
+ } catch(SQLException e){
+ assertSQLState("XJ064", e);
+ }
+
+ assertEquals(stmt.getFetchSize(), 25);
+ assertEquals(stmt.getFetchDirection(), ResultSet.FETCH_REVERSE);
+
+ stmt.close();
+ }
+ /**
+ * Tests reading data from database
+ *
+ * @exception SQLException if error occurs
+ */
+ public void testReadingData() throws SQLException {
+
+ Statement stmt = createStatement();
+ ResultSet rs;
+
+ // read the data just for the heck of it
+ rs = stmt.executeQuery("select * from tab1");
+ while (rs.next()) {
+ assertEquals(rs.getInt(1), 1);
+ assertEquals(rs.getShort(2), 2);
+ assertEquals(rs.getDouble(3), 3.1, 0.01);
+ }
+
+ rs.close();
+ stmt.close();
+ }
+ /**
+ * Tests values local to result set and get them back
+ *
+ * @exception SQLException if error occurs
+ */
+ public void testLocalValuesOfResultSet() throws SQLException {
+
+ Statement stmt = createStatement();
+ ResultSet rs;
+
+ stmt.setFetchSize(25);
+ stmt.setFetchDirection(ResultSet.FETCH_REVERSE);
+ stmt.setEscapeProcessing(true);
+
+ rs = stmt.executeQuery("select * from tab1");
+ // Get the constatnts for a result set
+ assertEquals(rs.getFetchSize(), 25);
+ assertEquals(rs.getFetchDirection(), ResultSet.FETCH_REVERSE);
+
+ // change values local to result set and get them back
+ rs.setFetchSize(250);
+ try{
+ rs.setFetchDirection(ResultSet.FETCH_FORWARD);
+ }catch(SQLException e){
+
+ if (usingEmbedded())
+ assertSQLState("XJ061", e);
+ else
+ assertSQLState("XJ125", e);
+ }
+
+ assertEquals(rs.getFetchSize(), 250);
+ assertEquals(rs.getFetchDirection(), ResultSet.FETCH_REVERSE);
+
+ // exception conditions
+ stmt.setMaxRows(10);
+ try{
+ rs.setFetchSize(100);
+ } catch(SQLException e){
+ assertSQLState("XJ062", e);
+ }
+
+ //Error testing : set wrong values ..
+ try{
+ rs.setFetchSize(-2000);
+ fail("setFetchSize(-2000) expected to fail");
+ } catch(SQLException e){
+ assertSQLState("XJ062", e);
+ }
+
+ try{
+ rs.setFetchDirection(-2000);
+ } catch(SQLException e){
+
+ if (usingEmbedded())
+ assertSQLState("XJ061", e);
+ else
+ assertSQLState("XJ125", e);
+ }
+
+ // set the fetch size values to zero .. to ensure
+ // error condtions are correct !
+
+ rs.setFetchSize(0);
+ stmt.setFetchSize(0);
+
+ rs.close();
+ }
+ /**
+ * Tests creating tables with executeQuery which is
+ * not allowed on statements that return a row count
+ *
+ * @exception SQLException
+ * if error occurs
+ */
+ public void testCreateTableWithExecuteQuery() throws SQLException {
+
+ Statement stmt = createStatement();
+ ResultSet rs;
+
+ //RESOLVE - uncomment tests in 3.5
+ // executeQuery() not allowed on statements
+ // that return a row count
+ try {
+ stmt.executeQuery("create table trash(c1 int)");
+ } catch (SQLException e) {
+ if (usingEmbedded())
+ assertSQLState("X0Y78", e);
+ else
+ assertSQLState("XJ207", e);
+ }
+
+ // verify that table was not created
+ try {
+ rs = stmt.executeQuery("select * from trash");
+ System.out.println("select from trash expected to fail");
+ } catch (SQLException e) {
+ assertSQLState("42X05", e);
+ }
+
+ // executeUpdate() not allowed on statements
+ // that return a ResultSet
+ try {
+ stmt.executeUpdate("values 1");
+ } catch (SQLException e) {
+ assertSQLState("X0Y79", e);
+ }
+
+ stmt.close();
+ commit();
+ }
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.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=601058&r1=601057&r2=601058&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 Tue Dec 4 11:41:36 2007
@@ -78,6 +78,7 @@
suite.addTest(NullSQLTextTest.suite());
suite.addTest(PrepStmtNullTest.suite());
suite.addTest(StatementJdbc30Test.suite());
+ suite.addTest(StatementJdbc20Test.suite());
suite.addTest(ClobTest.suite());
suite.addTest(BlobUpdatableStreamTest.suite());
suite.addTest(AIjdbcTest.suite());
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/statementJdbc20.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/statementJdbc20.java?rev=601058&r1=601057&r2=601058&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/statementJdbc20.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/statementJdbc20.java Tue Dec 4 11:41:36 2007
@@ -1,215 +0,0 @@
-/*
-
- Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.statementJdbc20
-
- 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.DriverManager;
-import java.sql.ResultSetMetaData;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import org.apache.derby.tools.ij;
-import org.apache.derby.tools.JDBCDisplayUtil;
-import org.apache.derbyTesting.junit.BaseJDBCTestCase;
-import org.apache.derbyTesting.junit.JDBC;
-
-/**
- * Test of additional methods in JDBC2.0 methods in statement and
- * resultset classes.
- *
- */
-
-public class statementJdbc20 {
-
- public static void main(String[] args) {
- Connection con;
- ResultSet rs;
- Statement stmt;
-
- System.out.println("Test statementJdbc20 starting");
-
- try
- {
- // use the ij utility to read the property file and
- // make the initial connection.
- ij.getPropertyArg(args);
- con = ij.startJBMS();
-
-
- stmt = con.createStatement();
-
- //create a table, insert a row, do a select from the table,
- stmt.execute("create table tab1 (i int, s smallint, r real)");
- stmt.executeUpdate("insert into tab1 values(1, 2, 3.1)");
-
- // set all the peformance hint parameters
- stmt.setFetchSize(25);
- stmt.setFetchDirection(ResultSet.FETCH_REVERSE);
- stmt.setEscapeProcessing(true);
-
- //Error testing : set wrong values ..
- try{
- stmt.setFetchSize(-1000);
- System.out.println("setFetchSize(-1000) expected to fail");
- }
- catch(SQLException e){
- BaseJDBCTestCase.assertSQLState("XJ065", e);
- }
-
- try{
- stmt.setFetchDirection(-1000);
- System.out.println("setFetchDirection(-1000) expected to fail");
- }
- catch(SQLException e){
- BaseJDBCTestCase.assertSQLState("XJ064", e);
- }
-
-
- System.out.println("Fetch Size " + stmt.getFetchSize());
- System.out.println("Fetch Direction " + stmt.getFetchDirection());
-
- // read the data just for the heck of it
- rs = stmt.executeQuery("select * from tab1");
- while (rs.next())
- {
- System.out.println(rs.getInt(1) + " " + rs.getShort(2) +
- " " + rs.getFloat(3));
- }
-
- // Get the constatnts for a result set
- System.out.println("Result Set Fetch Size " + rs.getFetchSize());
- System.out.println("Result Set Fetch Direction " + rs.getFetchDirection());
-
- // change values local to result set and get them back
- rs.setFetchSize(250);
- try{
- rs.setFetchDirection(ResultSet.FETCH_FORWARD);
- }catch(SQLException e){
- dumpExpectedSQLExceptions(e);
- }
-
- System.out.println("Result Set Fetch Size " + rs.getFetchSize());
- System.out.println("Result Set Fetch Direction " + rs.getFetchDirection());
-
- // exception conditions
- stmt.setMaxRows(10);
- try{
- rs.setFetchSize(100);
- }
- catch(SQLException e){
- dumpExpectedSQLExceptions(e);
- }
-
- //Error testing : set wrong values ..
- try{
- rs.setFetchSize(-2000);
- System.out.println("setFetchSize(-2000) expected to fail");
- }
- catch(SQLException e){
- BaseJDBCTestCase.assertSQLState("XJ062", e);
- }
-
- try{
- rs.setFetchDirection(-2000);
- }
- catch(SQLException e){
- dumpExpectedSQLExceptions(e);
- }
-
- // set the fetch size values to zero .. to ensure
- // error condtions are correct !
-
- rs.setFetchSize(0);
- stmt.setFetchSize(0);
-
- rs.close();
-
- //RESOLVE - uncomment tests in 3.5
- // executeQuery() not allowed on statements
- // that return a row count
- try
- {
- stmt.executeQuery("create table trash(c1 int)");
- }
- catch (SQLException e)
- {
- dumpExpectedSQLExceptions(e);
- }
-
- // verify that table was not created
- try
- {
- rs = stmt.executeQuery("select * from trash");
- System.out.println("select from trash expected to fail");
- }
- catch (SQLException e)
- {
- BaseJDBCTestCase.assertSQLState("42X05", e);
- }
-
- // executeUpdate() not allowed on statements
- // that return a ResultSet
- try
- {
- stmt.executeUpdate("values 1");
- }
- catch (SQLException e)
- {
- dumpExpectedSQLExceptions(e);
- }
-
- stmt.close();
- con.commit();
- con.close();
-
- }
- catch (SQLException e) {
- dumpSQLExceptions(e);
- e.printStackTrace();
- }
- catch (Throwable e) {
- System.out.println("FAIL -- unexpected exception: "+e);
- e.printStackTrace();
- }
-
- System.out.println("Test statementJdbc20 finished");
- }
-
- static private void dumpSQLExceptions (SQLException se) {
- System.out.println("FAIL -- unexpected exception");
- while (se != null) {
- System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
- se = se.getNextException();
- }
- }
-
- static private void dumpExpectedSQLExceptions (SQLException se) {
- System.out.println("PASS -- expected exception");
- while (se != null) {
- System.out.println("SQLSTATE("+se.getSQLState()+"): "+se);
- se = se.getNextException();
- }
- }
-
-}