KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > jdbc4 > RowIdNotImplementedTest


1 /*
2  *
3  * Derby - Class RowIdNotImplementedTest
4  *
5  * Licensed to the Apache Software Foundation (ASF) under one or more
6  * contributor license agreements. See the NOTICE file distributed with
7  * this work for additional information regarding copyright ownership.
8  * The ASF licenses this file to you under the Apache License, Version 2.0
9  * (the "License"); you may not use this file except in compliance with
10  * the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */

20
21 package org.apache.derbyTesting.functionTests.tests.jdbc4;
22
23 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
24
25 import junit.framework.*;
26
27 import java.sql.*;
28
29 /**
30  * Test that all methods and functionality related to RowId reflect that it
31  * has not yet been implemented.
32  * The tests are written to be run with JDK 1.6.
33  * All methods that throws SQLException, should utilize the
34  * SQLFeatureNotSupportedException-subclass. Methods unable to throw
35  * SQLException, must throw java.lang.UnsupportedOperationException.
36  * As RowId is implemented, tests demonstrating correctness of the API should
37  * be moved into the proper test classes (for instance, test updateRowId in
38  * the test class for ResultSet).
39  * The reason for specifying all tests here was mainly because there were no
40  * existing JUnit tests for the various classes implementing RowId methods.
41  */

42 public class RowIdNotImplementedTest
43     extends BaseJDBCTestCase {
44
45     /**
46      * Create test with given name.
47      *
48      * @param name name of test.
49      */

50     public RowIdNotImplementedTest(String JavaDoc name) {
51         super(name);
52     }
53     
54
55     public void testRowIdInPreparedStatementSetRowId()
56         throws SQLException {
57         PreparedStatement pStmt =
58             prepareStatement("select count(*) from sys.systables");
59         try {
60             pStmt.setRowId(1, null);
61             fail("PreparedStatement.setRowId should not be implemented");
62         } catch (SQLFeatureNotSupportedException sfnse) {
63             // Do nothing, we are fine.
64
}
65     }
66     
67     public void testRowIdInCallableStatementGetRowIdInt()
68         throws SQLException {
69         CallableStatement cStmt = getCallableStatement();
70         try {
71             cStmt.getRowId(1);
72             fail("CallableStatement.getRowId(int) should not be implemented.");
73         } catch (SQLFeatureNotSupportedException sfnse) {
74             // Do nothing, we are fine.
75
}
76     }
77
78     public void testRowIdInCallableStatementGetRowIdString()
79         throws SQLException {
80         CallableStatement cStmt = getCallableStatement();
81         try {
82             cStmt.getRowId("some-parameter-name");
83             fail("CallableStatement.getRowId(String) should not be " +
84                  "implemented.");
85         } catch (SQLFeatureNotSupportedException sfnse) {
86             // Do nothing, we are fine.
87
}
88     }
89
90     public void testRowIdInCallableStatementSetRowId()
91         throws SQLException {
92         CallableStatement cStmt = getCallableStatement();
93         try {
94             cStmt.setRowId("some-parameter-name", null);
95             fail("CallableStatement.setRowId should not be implemented");
96         } catch (SQLFeatureNotSupportedException sfnse) {
97             // Do nothing, we are fine.
98
}
99     }
100
101     public void testRowIdInResultSetGetRowIdInt()
102         throws SQLException {
103         ResultSet rs = getResultSet();
104         try {
105             rs.getRowId(1);
106             fail("ResultSet.getRowId(int) should not be implemented");
107         } catch (SQLFeatureNotSupportedException sfnse) {
108             // Do nothing, we are fine.
109
}
110     }
111     
112     public void testRowIdInResultSetGetRowIdString()
113         throws SQLException {
114         ResultSet rs = getResultSet();
115         try {
116             rs.getRowId("some-parameter-name");
117             fail("ResultSet.getRowId(String) should not be implemented");
118         } catch (SQLFeatureNotSupportedException sfnse) {
119             // Do nothing, we are fine.
120
}
121     }
122
123     public void testRowIdInResultSetUpdateRowIdInt()
124         throws SQLException {
125         ResultSet rs = getResultSet();
126         try {
127             rs.updateRowId(1, null);
128             fail("ResultSet.updateRowId(int) should not be implemented");
129         } catch (SQLFeatureNotSupportedException sfnse) {
130             // Do nothing, we are fine.
131
}
132     }
133
134     public void testRowIdInResultSetUpdateRowIdString()
135         throws SQLException {
136         ResultSet rs = getResultSet();
137         try {
138             rs.updateRowId("some-parameter-name", null);
139             fail("ResultSet.updateRowId(String) should not be implemented");
140         } catch (SQLFeatureNotSupportedException sfnse) {
141             // Do nothing, we are fine.
142
}
143     }
144
145     public void testRowIdInDatabaseMetaDataRowIdLifeTime()
146         throws SQLException {
147         DatabaseMetaData meta = getConnection().getMetaData();
148         RowIdLifetime rowIdLifetime = meta.getRowIdLifetime();
149         assertEquals("RowIdLifetime should be ROWID_UNSUPPORTED",
150             RowIdLifetime.ROWID_UNSUPPORTED,
151             rowIdLifetime);
152         meta = null;
153     }
154
155     /**
156      * Create a callable statement.
157      *
158      * @return a <code>CallableStatement</code>
159      * @throws SQLException if creation of CallableStatement fails.
160      */

161     private CallableStatement getCallableStatement()
162         throws SQLException {
163         // No need to actuall call a stored procedure.
164
return prepareCall("values 1");
165     }
166
167     /**
168      * Create a resultset.
169      *
170      * @return a <code>ResultSet</code>
171      * @throws SQLException if creation of ResultSet fails.
172      */

173     private ResultSet getResultSet()
174         throws SQLException {
175         // Create a very simple resultset.
176
return createStatement().executeQuery("values 1");
177     }
178     
179     /**
180      * Return test suite.
181      *
182      * @return test suite.
183      */

184     public static Test suite() {
185         return new TestSuite(RowIdNotImplementedTest.class,
186                              "RowIdNotImplementedTest suite");
187     }
188     
189 } // End class RowIdNotImplementedTest
190
Popular Tags