001: package test.org.mandarax.jdbc;
002:
003: /*
004: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: import java.sql.*;
022: import org.mandarax.jdbc.server.*;
023: import org.mandarax.kernel.Derivation;
024: import junit.framework.TestSuite;
025:
026: /**
027: * A test suite for result set meta data.
028: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
029: * @version 3.3.2 <29 December 2004>
030: * @since 3.0
031: */
032:
033: public class ResultSetMetaDataTests implements TestURLs, Constants {
034:
035: /**
036: * Launch the test suite. See TestRunner for interpretation
037: * of command line parameters.
038: * @see test.org.mandarax.testsupport.TestRunner
039: * @param args parameters
040: */
041: public static void main(String[] args) {
042: test.org.mandarax.testsupport.TestRunner.run(
043: ResultSetMetaDataTests.class, args);
044: }
045:
046: /**
047: * Get the test suite.
048: * @return a test suite
049: */
050: public static TestSuite suite() {
051:
052: TestSuite suite = new TestSuite(
053: "Test suite for SQL result set meta data");
054: /* test kb structure:
055: first_name,name,dob,weight,size
056: "Tom", "Meier", "01/01/1960", 80, 1.80;
057: ...
058: */
059: suite.addTest(new ResultSetMetaDataTestCase(
060: "select * from people") {
061: protected boolean check(ResultSetMetaData metaData)
062: throws Exception {
063: int colCount = metaData.getColumnCount();
064: return PseudoColumns.PSEUDO_COLUMNS.length + 5 == colCount;
065: }
066: });
067: suite.addTest(new ResultSetMetaDataTestCase(
068: "select * from people") {
069: protected boolean check(ResultSetMetaData metaData)
070: throws Exception {
071: String name = metaData.getColumnName(1);
072: return "first_name".equals(name);
073: }
074: });
075: suite.addTest(new ResultSetMetaDataTestCase(
076: "select * from people") {
077: protected boolean check(ResultSetMetaData metaData)
078: throws Exception {
079: String name = metaData.getColumnName(2);
080: return "name".equals(name);
081: }
082: });
083: suite.addTest(new ResultSetMetaDataTestCase(
084: "select * from people") {
085: protected boolean check(ResultSetMetaData metaData)
086: throws Exception {
087: String name = metaData.getColumnName(3);
088: return "dob".equals(name);
089: }
090: });
091: suite.addTest(new ResultSetMetaDataTestCase(
092: "select * from people") {
093: protected boolean check(ResultSetMetaData metaData)
094: throws Exception {
095: String name = metaData.getColumnName(4);
096: return "weight".equals(name);
097: }
098: });
099: suite.addTest(new ResultSetMetaDataTestCase(
100: "select * from people") {
101: protected boolean check(ResultSetMetaData metaData)
102: throws Exception {
103: String name = metaData.getColumnName(5);
104: return "size".equals(name);
105: }
106: });
107: suite.addTest(new ResultSetMetaDataTestCase(
108: "select * from people") {
109: protected boolean check(ResultSetMetaData metaData)
110: throws Exception {
111: String name = metaData.getColumnName(6);
112: return PseudoColumns.PSEUDO_COLUMNS[0].equals(name);
113: }
114: });
115: suite.addTest(new ResultSetMetaDataTestCase(
116: "select * from people") {
117: protected boolean check(ResultSetMetaData metaData)
118: throws Exception {
119: int type = metaData.getColumnType(1);
120: return type == Types.VARCHAR;
121: }
122: });
123: suite.addTest(new ResultSetMetaDataTestCase(
124: "select * from people") {
125: protected boolean check(ResultSetMetaData metaData)
126: throws Exception {
127: int type = metaData.getColumnType(2);
128: return type == Types.VARCHAR;
129: }
130: });
131: suite.addTest(new ResultSetMetaDataTestCase(
132: "select * from people") {
133: protected boolean check(ResultSetMetaData metaData)
134: throws Exception {
135: int type = metaData.getColumnType(3);
136: return type == Types.DATE;
137: }
138: });
139: suite.addTest(new ResultSetMetaDataTestCase(
140: "select * from people") {
141: protected boolean check(ResultSetMetaData metaData)
142: throws Exception {
143: int type = metaData.getColumnType(4);
144: return type == Types.INTEGER;
145: }
146: });
147: suite.addTest(new ResultSetMetaDataTestCase(
148: "select * from people") {
149: protected boolean check(ResultSetMetaData metaData)
150: throws Exception {
151: int type = metaData.getColumnType(5);
152: return type == Types.DOUBLE;
153: }
154: });
155: suite.addTest(new ResultSetMetaDataTestCase(
156: "select * from people") {
157: protected boolean check(ResultSetMetaData metaData)
158: throws Exception {
159: int type = metaData.getColumnType(6);
160: return type == Types.JAVA_OBJECT;
161: }
162: });
163: suite.addTest(new ResultSetMetaDataTestCase(
164: "select * from people") {
165: protected boolean check(ResultSetMetaData metaData)
166: throws Exception {
167: String className = metaData.getColumnClassName(1);
168: return String.class.getName().equals(className);
169: }
170: });
171: suite.addTest(new ResultSetMetaDataTestCase(
172: "select * from people") {
173: protected boolean check(ResultSetMetaData metaData)
174: throws Exception {
175: String className = metaData.getColumnClassName(2);
176: return String.class.getName().equals(className);
177: }
178: });
179: suite.addTest(new ResultSetMetaDataTestCase(
180: "select * from people") {
181: protected boolean check(ResultSetMetaData metaData)
182: throws Exception {
183: String className = metaData.getColumnClassName(3);
184: return java.sql.Date.class.getName().equals(className);
185: }
186: });
187: suite.addTest(new ResultSetMetaDataTestCase(
188: "select * from people") {
189: protected boolean check(ResultSetMetaData metaData)
190: throws Exception {
191: String className = metaData.getColumnClassName(4);
192: return Integer.class.getName().equals(className);
193: }
194: });
195: suite.addTest(new ResultSetMetaDataTestCase(
196: "select * from people") {
197: protected boolean check(ResultSetMetaData metaData)
198: throws Exception {
199: String className = metaData.getColumnClassName(5);
200: return Double.class.getName().equals(className);
201: }
202: });
203: suite.addTest(new ResultSetMetaDataTestCase(
204: "select * from people") {
205: protected boolean check(ResultSetMetaData metaData)
206: throws Exception {
207: String className = metaData.getColumnClassName(6);
208: return Derivation.class.getName().equals(className);
209: }
210: });
211: suite.addTest(new ResultSetMetaDataTestCase(
212: "select * from people") {
213: protected boolean check(ResultSetMetaData metaData)
214: throws Exception {
215: for (int i = 0; i < metaData.getColumnCount(); i++) {
216: String name = metaData.getTableName(i + 1);
217: if (!("people".equals(name)))
218: return false;
219: }
220: return true;
221: }
222: });
223: suite.addTest(new ResultSetMetaDataTestCase(
224: "select * from people") {
225: protected boolean check(ResultSetMetaData metaData)
226: throws Exception {
227: for (int i = 0; i < metaData.getColumnCount(); i++) {
228: String name = metaData.getSchemaName(i + 1);
229: if (!(DatabaseMetaDataImpl.DEFAULT_SCHEMA
230: .equals(name)))
231: return false;
232: }
233: return true;
234: }
235: });
236: suite.addTest(new ResultSetMetaDataTestCase(
237: "select * from people") {
238: protected boolean check(ResultSetMetaData metaData)
239: throws Exception {
240: for (int i = 0; i < metaData.getColumnCount(); i++) {
241: String name = metaData.getCatalogName(i + 1);
242: if (!(DatabaseMetaDataImpl.DEFAULT_CATALOG
243: .equals(name)))
244: return false;
245: }
246: return true;
247: }
248: });
249: suite.addTest(new ResultSetMetaDataTestCase(
250: "select * from people") {
251: protected boolean check(ResultSetMetaData metaData)
252: throws Exception {
253: for (int i = 0; i < metaData.getColumnCount(); i++) {
254: if (metaData.isDefinitelyWritable(i + 1))
255: return false;
256: }
257: return true;
258: }
259: });
260: suite.addTest(new ResultSetMetaDataTestCase(
261: "select * from people") {
262: protected boolean check(ResultSetMetaData metaData)
263: throws Exception {
264: for (int i = 0; i < metaData.getColumnCount(); i++) {
265: if (metaData.isWritable(i + 1))
266: return false;
267: }
268: return true;
269: }
270: });
271: suite.addTest(new ResultSetMetaDataTestCase(
272: "select * from people") {
273: protected boolean check(ResultSetMetaData metaData)
274: throws Exception {
275: for (int i = 0; i < metaData.getColumnCount(); i++) {
276: if (!metaData.isReadOnly(i + 1))
277: return false;
278: }
279: return true;
280: }
281: });
282:
283: return suite;
284: }
285:
286: }
|