001: /*
002: *
003: * Derby - Class RowIdNotImplementedTest
004: *
005: * Licensed to the Apache Software Foundation (ASF) under one or more
006: * contributor license agreements. See the NOTICE file distributed with
007: * this work for additional information regarding copyright ownership.
008: * The ASF licenses this file to you under the Apache License, Version 2.0
009: * (the "License"); you may not use this file except in compliance with
010: * the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
017: * either express or implied. See the License for the specific
018: * language governing permissions and limitations under the License.
019: */
020:
021: package org.apache.derbyTesting.functionTests.tests.jdbc4;
022:
023: import org.apache.derbyTesting.junit.BaseJDBCTestCase;
024:
025: import junit.framework.*;
026:
027: import java.sql.*;
028:
029: /**
030: * Test that all methods and functionality related to RowId reflect that it
031: * has not yet been implemented.
032: * The tests are written to be run with JDK 1.6.
033: * All methods that throws SQLException, should utilize the
034: * SQLFeatureNotSupportedException-subclass. Methods unable to throw
035: * SQLException, must throw java.lang.UnsupportedOperationException.
036: * As RowId is implemented, tests demonstrating correctness of the API should
037: * be moved into the proper test classes (for instance, test updateRowId in
038: * the test class for ResultSet).
039: * The reason for specifying all tests here was mainly because there were no
040: * existing JUnit tests for the various classes implementing RowId methods.
041: */
042: public class RowIdNotImplementedTest extends BaseJDBCTestCase {
043:
044: /**
045: * Create test with given name.
046: *
047: * @param name name of test.
048: */
049: public RowIdNotImplementedTest(String name) {
050: super (name);
051: }
052:
053: public void testRowIdInPreparedStatementSetRowId()
054: throws SQLException {
055: PreparedStatement pStmt = prepareStatement("select count(*) from sys.systables");
056: try {
057: pStmt.setRowId(1, null);
058: fail("PreparedStatement.setRowId should not be implemented");
059: } catch (SQLFeatureNotSupportedException sfnse) {
060: // Do nothing, we are fine.
061: }
062: }
063:
064: public void testRowIdInCallableStatementGetRowIdInt()
065: throws SQLException {
066: CallableStatement cStmt = getCallableStatement();
067: try {
068: cStmt.getRowId(1);
069: fail("CallableStatement.getRowId(int) should not be implemented.");
070: } catch (SQLFeatureNotSupportedException sfnse) {
071: // Do nothing, we are fine.
072: }
073: }
074:
075: public void testRowIdInCallableStatementGetRowIdString()
076: throws SQLException {
077: CallableStatement cStmt = getCallableStatement();
078: try {
079: cStmt.getRowId("some-parameter-name");
080: fail("CallableStatement.getRowId(String) should not be "
081: + "implemented.");
082: } catch (SQLFeatureNotSupportedException sfnse) {
083: // Do nothing, we are fine.
084: }
085: }
086:
087: public void testRowIdInCallableStatementSetRowId()
088: throws SQLException {
089: CallableStatement cStmt = getCallableStatement();
090: try {
091: cStmt.setRowId("some-parameter-name", null);
092: fail("CallableStatement.setRowId should not be implemented");
093: } catch (SQLFeatureNotSupportedException sfnse) {
094: // Do nothing, we are fine.
095: }
096: }
097:
098: public void testRowIdInResultSetGetRowIdInt() throws SQLException {
099: ResultSet rs = getResultSet();
100: try {
101: rs.getRowId(1);
102: fail("ResultSet.getRowId(int) should not be implemented");
103: } catch (SQLFeatureNotSupportedException sfnse) {
104: // Do nothing, we are fine.
105: }
106: }
107:
108: public void testRowIdInResultSetGetRowIdString()
109: throws SQLException {
110: ResultSet rs = getResultSet();
111: try {
112: rs.getRowId("some-parameter-name");
113: fail("ResultSet.getRowId(String) should not be implemented");
114: } catch (SQLFeatureNotSupportedException sfnse) {
115: // Do nothing, we are fine.
116: }
117: }
118:
119: public void testRowIdInResultSetUpdateRowIdInt()
120: throws SQLException {
121: ResultSet rs = getResultSet();
122: try {
123: rs.updateRowId(1, null);
124: fail("ResultSet.updateRowId(int) should not be implemented");
125: } catch (SQLFeatureNotSupportedException sfnse) {
126: // Do nothing, we are fine.
127: }
128: }
129:
130: public void testRowIdInResultSetUpdateRowIdString()
131: throws SQLException {
132: ResultSet rs = getResultSet();
133: try {
134: rs.updateRowId("some-parameter-name", null);
135: fail("ResultSet.updateRowId(String) should not be implemented");
136: } catch (SQLFeatureNotSupportedException sfnse) {
137: // Do nothing, we are fine.
138: }
139: }
140:
141: public void testRowIdInDatabaseMetaDataRowIdLifeTime()
142: throws SQLException {
143: DatabaseMetaData meta = getConnection().getMetaData();
144: RowIdLifetime rowIdLifetime = meta.getRowIdLifetime();
145: assertEquals("RowIdLifetime should be ROWID_UNSUPPORTED",
146: RowIdLifetime.ROWID_UNSUPPORTED, rowIdLifetime);
147: meta = null;
148: }
149:
150: /**
151: * Create a callable statement.
152: *
153: * @return a <code>CallableStatement</code>
154: * @throws SQLException if creation of CallableStatement fails.
155: */
156: private CallableStatement getCallableStatement()
157: throws SQLException {
158: // No need to actuall call a stored procedure.
159: return prepareCall("values 1");
160: }
161:
162: /**
163: * Create a resultset.
164: *
165: * @return a <code>ResultSet</code>
166: * @throws SQLException if creation of ResultSet fails.
167: */
168: private ResultSet getResultSet() throws SQLException {
169: // Create a very simple resultset.
170: return createStatement().executeQuery("values 1");
171: }
172:
173: /**
174: * Return test suite.
175: *
176: * @return test suite.
177: */
178: public static Test suite() {
179: return new TestSuite(RowIdNotImplementedTest.class,
180: "RowIdNotImplementedTest suite");
181: }
182:
183: } // End class RowIdNotImplementedTest
|