001: // jTDS JDBC Driver for Microsoft SQL Server and Sybase
002: // Copyright (C) 2004 The jTDS Project
003: //
004: // This library is free software; you can redistribute it and/or
005: // modify it under the terms of the GNU Lesser General Public
006: // License as published by the Free Software Foundation; either
007: // version 2.1 of the License, or (at your option) any later version.
008: //
009: // This library is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: // Lesser General Public License for more details.
013: //
014: // You should have received a copy of the GNU Lesser General Public
015: // License along with this library; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: //
018: package net.sourceforge.jtds.test;
019:
020: import java.sql.DatabaseMetaData;
021: import java.sql.ResultSet;
022:
023: /**
024: * Test JDBC3 extensions to <code>DatabaseMetaData</code>.
025: *
026: * @version $Id: DatabaseMetaDataJDBC3Test.java,v 1.2 2005/01/05 12:24:14 alin_sinpalean Exp $
027: */
028: public class DatabaseMetaDataJDBC3Test extends MetaDataTestCase {
029:
030: public DatabaseMetaDataJDBC3Test(String name) {
031: super (name);
032: }
033:
034: /**
035: * Test meta data functions that return boolean values.
036: */
037: public void testBooleanOptions() throws Exception {
038: DatabaseMetaData dbmd = con.getMetaData();
039: //
040: // Test JDBC 3 items
041: //
042: assertTrue("locatorsUpdateCopy", dbmd.locatorsUpdateCopy());
043: assertTrue("supportsGetGeneratedKeys", dbmd
044: .supportsGetGeneratedKeys());
045: assertTrue("supportsMultipleOpenResults", dbmd
046: .supportsMultipleOpenResults());
047: assertTrue("supportsNamedParameters", dbmd
048: .supportsNamedParameters());
049: assertFalse(
050: "supportsResultSetHoldability",
051: dbmd
052: .supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT));
053: assertFalse(
054: "supportsResultSetHoldability",
055: dbmd
056: .supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT));
057: assertTrue("supportsSavepoints", dbmd.supportsSavepoints());
058: assertTrue("supportsStatementPooling", dbmd
059: .supportsStatementPooling());
060: }
061:
062: /**
063: * Test meta data function that return integer values.
064: */
065: public void testIntOptions() throws Exception {
066: DatabaseMetaData dbmd = con.getMetaData();
067: //
068: // JDBC3 functions
069: //
070: assertTrue("getDatabaseMajorVersion", dbmd
071: .getDatabaseMajorVersion() >= 0);
072: assertTrue("getDatabaseMinorVersion", dbmd
073: .getDatabaseMinorVersion() >= 0);
074: assertEquals("getResultSetHoldability",
075: ResultSet.HOLD_CURSORS_OVER_COMMIT, dbmd
076: .getResultSetHoldability());
077: assertEquals("getSQLStateType", 1, dbmd.getSQLStateType());
078: assertEquals("getJDBCMajorVersion", 3, dbmd
079: .getJDBCMajorVersion());
080: assertEquals("getJDBCMinorVersion", 0, dbmd
081: .getJDBCMinorVersion());
082: }
083:
084: /**
085: * Test meta data functions that return result sets.
086: */
087: public void testResultSets() throws Exception {
088: DatabaseMetaData dbmd = con.getMetaData();
089: ResultSet rs;
090: //
091: // JDBC3 Methods
092: //
093: rs = dbmd.getAttributes(null, null, null, null);
094: assertTrue(checkColumnNames(rs, new String[] { "TYPE_CAT",
095: "TYPE_SCHEM", "TYPE_NAME", "ATTR_NAME", "DATA_TYPE",
096: "ATTR_TYPE_NAME", "ATTR_SIZE", "DECIMAL_DIGITS",
097: "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "ATTR_DEF",
098: "SQL_DATA_TYPE", "SQL_DATETIME_SUB",
099: "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE",
100: "SCOPE_CATALOG", "SCOPE_SCHEMA", "SCOPE_TABLE",
101: "SOURCE_DATA_TYPE" }));
102: assertFalse(rs.next());
103: rs.close();
104: //
105: rs = dbmd.getSuperTables(null, null, "%");
106: assertTrue(checkColumnNames(rs, new String[] { "TABLE_CAT",
107: "TABLE_SCHEM", "TABLE_NAME", "SUPERTABLE_NAME" }));
108: assertFalse(rs.next());
109: rs.close();
110: //
111: rs = dbmd.getSuperTypes(null, null, "%");
112: assertTrue(checkColumnNames(rs, new String[] { "TYPE_CAT",
113: "TYPE_SCHEM", "TYPE_NAME", "SUPERTYPE_CAT",
114: "SUPERTYPE_SCHEM", "SUPERTYPE_NAME" }));
115: assertFalse(rs.next());
116: rs.close();
117: }
118:
119: public static void main(String[] args) {
120: junit.textui.TestRunner.run(DatabaseMetaDataJDBC3Test.class);
121: }
122: }
|