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 rh...@apache.org on 2006/03/28 20:29:21 UTC
svn commit: r389571 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests:
suites/ tests/jdbc4/
Author: rhillegas
Date: Tue Mar 28 10:29:18 2006
New Revision: 389571
URL: http://svn.apache.org/viewcvs?rev=389571&view=rev
Log:
Commit Kristian's patch for DERBY-944: raising appropriate exceptions for RowID calls.
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/RowIdNotImplementedTest.java (with props)
Removed:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestRowId.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestRowId_app.properties
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestCallableStatementMethods.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestResultSetMethods.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall?rev=389571&r1=389570&r2=389571&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbc40.runall Tue Mar 28 10:29:18 2006
@@ -5,4 +5,5 @@
jdbc4/TestQueryObject.java
jdbc4/TestDbMetaData.java
jdbc4/TestJDBC40Exception.java
+jdbc4/RowIdNotImplementedTest.junit
jdbc4/StatementTest.junit
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/RowIdNotImplementedTest.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/RowIdNotImplementedTest.java?rev=389571&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/RowIdNotImplementedTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/RowIdNotImplementedTest.java Tue Mar 28 10:29:18 2006
@@ -0,0 +1,263 @@
+/*
+ *
+ * Derby - Class RowIdNotImplementedTest
+ *
+ * Copyright 2006 The Apache Software Foundation or its
+ * licensors, as applicable.
+ *
+ * Licensed 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.jdbc4;
+
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+import org.apache.derby.impl.jdbc.EmbedRowId;
+
+import junit.framework.*;
+
+import java.sql.*;
+
+/**
+ * Test that all methods and functionality related to RowId reflect that it
+ * has not yet been implemented.
+ * The tests are written to be run with JDK 1.6.
+ * All methods that throws SQLException, should utilize the
+ * SQLFeatureNotSupportedException-subclass. Methods unable to throw
+ * SQLException, must throw java.lang.UnsupportedOperationException.
+ * As RowId is implemented, tests demonstrating correctness of the API should
+ * be moved into the proper test classes (for instance, test updateRowId in
+ * the test class for ResultSet).
+ * The reason for specifying all tests here was mainly because there were no
+ * existing JUnit tests for the various classes implementing RowId methods.
+ */
+public class RowIdNotImplementedTest
+ extends BaseJDBCTestCase {
+
+ /** Default connection used by the tests. */
+ private Connection con = null;
+
+ /**
+ * Create test with given name.
+ *
+ * @param name name of test.
+ */
+ public RowIdNotImplementedTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Obtain default connection.
+ *
+ * @throws SQLException if obtaining connection fails.
+ */
+ public void setUp()
+ throws SQLException {
+ con = getConnection();
+ }
+
+ /**
+ * Do rollback and close on connection.
+ *
+ * @throws SQLException if rollback or close fails on connection.
+ */
+ public void tearDown()
+ throws SQLException {
+ if (con != null && !con.isClosed()) {
+ con.rollback();
+ con.close();
+ }
+ }
+
+ public void testRowIdInPreparedStatementSetRowId()
+ throws SQLException {
+ PreparedStatement pStmt =
+ con.prepareStatement("select count(*) from sys.systables");
+ try {
+ pStmt.setRowId(1, null);
+ fail("PreparedStatement.setRowId should not be implemented");
+ } catch (SQLFeatureNotSupportedException sfnse) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdInCallableStatementGetRowIdInt()
+ throws SQLException {
+ CallableStatement cStmt = getCallableStatement();
+ try {
+ cStmt.getRowId(1);
+ fail("CallableStatement.getRowId(int) should not be implemented.");
+ } catch (SQLFeatureNotSupportedException sfnse) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdInCallableStatementGetRowIdString()
+ throws SQLException {
+ CallableStatement cStmt = getCallableStatement();
+ try {
+ cStmt.getRowId("some-parameter-name");
+ fail("CallableStatement.getRowId(String) should not be " +
+ "implemented.");
+ } catch (SQLFeatureNotSupportedException sfnse) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdInCallableStatementSetRowId()
+ throws SQLException {
+ CallableStatement cStmt = getCallableStatement();
+ try {
+ cStmt.setRowId("some-parameter-name", null);
+ fail("CallableStatement.setRowId should not be implemented");
+ } catch (SQLFeatureNotSupportedException sfnse) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdInResultSetGetRowIdInt()
+ throws SQLException {
+ ResultSet rs = getResultSet();
+ try {
+ rs.getRowId(1);
+ fail("ResultSet.getRowId(int) should not be implemented");
+ } catch (SQLFeatureNotSupportedException sfnse) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdInResultSetGetRowIdString()
+ throws SQLException {
+ ResultSet rs = getResultSet();
+ try {
+ rs.getRowId("some-parameter-name");
+ fail("ResultSet.getRowId(String) should not be implemented");
+ } catch (SQLFeatureNotSupportedException sfnse) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdInResultSetUpdateRowIdInt()
+ throws SQLException {
+ ResultSet rs = getResultSet();
+ try {
+ rs.updateRowId(1, null);
+ fail("ResultSet.updateRowId(int) should not be implemented");
+ } catch (SQLFeatureNotSupportedException sfnse) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdInResultSetUpdateRowIdString()
+ throws SQLException {
+ ResultSet rs = getResultSet();
+ try {
+ rs.updateRowId("some-parameter-name", null);
+ fail("ResultSet.updateRowId(String) should not be implemented");
+ } catch (SQLFeatureNotSupportedException sfnse) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdInDatabaseMetaDataRowIdLifeTime()
+ throws SQLException {
+ DatabaseMetaData meta = con.getMetaData();
+ RowIdLifetime rowIdLifetime = meta.getRowIdLifetime();
+ assertEquals("RowIdLifetime should be ROWID_UNSUPPORTED",
+ RowIdLifetime.ROWID_UNSUPPORTED,
+ rowIdLifetime);
+ meta = null;
+ }
+
+ public void testRowIdEquals() {
+ RowId rowId = getRowId();
+ try {
+ rowId.equals(rowId);
+ fail("RowId.equals should not be implemented");
+ } catch (UnsupportedOperationException uoe) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdGetBytes() {
+ RowId rowId = getRowId();
+ try {
+ rowId.getBytes();
+ fail("RowId.getBytes should not be implemented");
+ } catch (UnsupportedOperationException uoe) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdToString() {
+ RowId rowId = getRowId();
+ try {
+ rowId.toString();
+ fail("RowId.toString should not be implemented");
+ } catch (UnsupportedOperationException uoe) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ public void testRowIdHashCode() {
+ RowId rowId = getRowId();
+ try {
+ rowId.hashCode();
+ fail("RowId.hashCode should not be implemented");
+ } catch (UnsupportedOperationException uoe) {
+ // Do nothing, we are fine.
+ }
+ }
+
+ /**
+ * Create a callable statement.
+ *
+ * @return a <code>CallableStatement</code>
+ * @throws SQLException if creation of CallableStatement fails.
+ */
+ private CallableStatement getCallableStatement()
+ throws SQLException {
+ // No need to actuall call a stored procedure.
+ return con.prepareCall("values 1");
+ }
+
+ /**
+ * Create a resultset.
+ *
+ * @return a <code>ResultSet</code>
+ * @throws SQLException if creation of ResultSet fails.
+ */
+ private ResultSet getResultSet()
+ throws SQLException {
+ // Create a very simple resultset.
+ return con.createStatement().executeQuery("values 1");
+ }
+
+ /**
+ * Create a <code>RowId</code>-object.
+ */
+ public java.sql.RowId getRowId() {
+ EmbedRowId embRowId = new EmbedRowId();
+ return (java.sql.RowId)embRowId;
+ }
+
+ /**
+ * Return test suite.
+ *
+ * @return test suite.
+ */
+ public static Test suite() {
+ return new TestSuite(RowIdNotImplementedTest.class,
+ "RowIdNotImplementedTest suite");
+ }
+
+} // End class RowIdNotImplementedTest
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/RowIdNotImplementedTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestCallableStatementMethods.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestCallableStatementMethods.java?rev=389571&r1=389570&r2=389571&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestCallableStatementMethods.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestCallableStatementMethods.java Tue Mar 28 10:29:18 2006
@@ -39,51 +39,6 @@
Connection conn=null;
CallableStatement cs=null;
- void t_getRowId1() {
- try {
- cs.getRowId(0);
- System.out.println("Not Implemented Exception not thrown");
- } catch(SQLException e) {
- if(SQLState.NOT_IMPLEMENTED.equals (e.getSQLState())) {
- System.out.println("Unexpected SQLException"+e);
- }
-
- } catch(Exception e) {
- System.out.println("Exception"+e);
- e.printStackTrace();
- }
- }
-
- void t_getRowId2() {
- try {
- cs.getRowId(null);
- System.out.println("Not Implemented Exception not thrown");
- } catch(SQLException e) {
- if(SQLState.NOT_IMPLEMENTED.equals (e.getSQLState())) {
- System.out.println("Unexpected SQLException"+e);
- }
- } catch(Exception e) {
- System.out.println("Exception"+e);
- e.printStackTrace();
- }
- }
-
- void t_setRowId() {
- try {
- cs.setRowId(null,null);
- System.out.println("Not Implemented Exception not thrown");
- } catch(SQLException e) {
-
- if(SQLState.NOT_IMPLEMENTED.equals (e.getSQLState())) {
- System.out.println("Unexpected SQLException"+e);
- }
-
- } catch(Exception e) {
- System.out.println("Exception"+e);
- e.printStackTrace();
- }
- }
-
void t_setNString() {
try {
cs.setNString(null,null);
@@ -244,9 +199,6 @@
void startCallableStatementMethodTest(Connection conn_in,CallableStatement cs_in) {
conn = conn_in;
cs = cs_in;
- t_getRowId1();
- t_getRowId2();
- t_setRowId();
t_setNString();
t_setNCharacterStream();
t_setNClob1();
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java?rev=389571&r1=389570&r2=389571&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java Tue Mar 28 10:29:18 2006
@@ -26,7 +26,6 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
-import java.sql.RowIdLifetime;
import org.apache.derby.tools.ij;
@@ -87,12 +86,6 @@
System.out.println
("FAIL: providesQueryObjectGenerator() should " +
"return false");
- }
-
- RowIdLifetime lifetime = met.getRowIdLifetime();
- if (lifetime != RowIdLifetime.ROWID_UNSUPPORTED) {
- System.out.println("FAIL: getRowIdLifetime() should return " +
- "ROWID_UNSUPPORTED, but got " + lifetime);
}
try {
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java?rev=389571&r1=389570&r2=389571&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestPreparedStatementMethods.java Tue Mar 28 10:29:18 2006
@@ -67,19 +67,6 @@
filepath = userDir + sep + ".." + sep + filepath;
}
}
- void t_setRowId() {
- try {
- ps.setRowId(0,null);
- System.out.println("UnImplemented Exception not thrown in code");
- } catch(SQLException e) {
- if(SQLState.NOT_IMPLEMENTED.equals (e.getSQLState())) {
- System.out.println("Unexpected SQLException"+e);
- }
- } catch(Exception e) {
- System.out.println("Unexpected exception thrown in method"+e);
- e.printStackTrace();
- }
- }
void t_setNString() {
try {
ps.setNString(0,null);
@@ -515,7 +502,6 @@
"sys.systables");
conn = conn_main;
ps = ps_main;
- t_setRowId();
t_setNString();
t_setNCharacterStream();
t_setNClob1();
@@ -583,7 +569,6 @@
"sys.systables");
conn = conn_main;
ps = ps_main;
- t_setRowId();
t_setNString();
t_setNCharacterStream();
t_setNClob1();
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestResultSetMethods.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestResultSetMethods.java?rev=389571&r1=389570&r2=389571&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestResultSetMethods.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestResultSetMethods.java Tue Mar 28 10:29:18 2006
@@ -63,65 +63,6 @@
}
}
- void t_getRowId1() {
- try {
- rs.getRowId(0);
- System.out.println("unImplemented Exception not thrown in code");
- } catch(SQLException e) {
- if(SQLState.NOT_IMPLEMENTED.equals (e.getSQLState())) {
- System.out.println("Unexpected SQLException"+e);
- }
-
- } catch(Exception e) {
- System.out.println("Unexpected exception caught"+e);
- e.printStackTrace();
- }
- }
- void t_getRowId2(){
- try {
- rs.getRowId(null);
- System.out.println("unImplemented Exception not thrown in code");
- } catch(SQLException e) {
- if(SQLState.NOT_IMPLEMENTED.equals (e.getSQLState())) {
- System.out.println("Unexpected SQLException"+e);
- }
-
- } catch(Exception e) {
- System.out.println("Unexpected exception caught"+e);
- e.printStackTrace();
- }
- }
-
- void t_updateRowId1() {
- try {
- rs.updateRowId(0,null);
- System.out.println("unImplemented Exception not thrown in code");
- } catch(SQLException e) {
- if(SQLState.NOT_IMPLEMENTED.equals (e.getSQLState())) {
- System.out.println("Unexpected SQLException"+e);
- }
-
- } catch(Exception e) {
- System.out.println("Unexpected exception caught"+e);
- e.printStackTrace();
- }
- }
-
- void t_updateRowId2(){
- try {
- rs.updateRowId(null,null);
- System.out.println("unImplemented Exception not thrown in code");
- } catch(SQLException e) {
- if(SQLState.NOT_IMPLEMENTED.equals (e.getSQLState())) {
- System.out.println("Unexpected SQLException"+e);
- }
-
- } catch(Exception e) {
- System.out.println("Unexpected exception caught"+e);
- e.printStackTrace();
- }
- }
-
/**
* Tests that <code>ResultSet.getHoldability()</code> has the
* correct behaviour.
@@ -525,12 +466,6 @@
conn = conn_in;
ps = ps_in;
rs = rs_in;
-
- t_getRowId1();
- t_getRowId2();
-
- t_updateRowId1();
- t_updateRowId2();
t_getHoldability();
t_isClosed();