001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.ResultSetMetaDataTest
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, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021: package org.apache.derbyTesting.functionTests.tests.jdbc4;
022:
023: import junit.framework.*;
024:
025: import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
026: import org.apache.derbyTesting.junit.BaseJDBCTestCase;
027:
028: import java.sql.*;
029: import javax.sql.*;
030:
031: public class ResultSetMetaDataTest extends BaseJDBCTestCase {
032: //classes that will be used for the test
033:
034: private PreparedStatement ps = null;
035: private ResultSet rs = null;
036: //The ResultSetMetaData object that will be used throughout the test
037: private ResultSetMetaData rsmd = null;
038:
039: /**
040: *
041: * Create a test with the given name.
042: *
043: * @param name name of the test.
044: *
045: */
046: public ResultSetMetaDataTest(String name) {
047: super (name);
048: }
049:
050: /**
051: * Create a default DataSource
052: */
053: protected void setUp() throws SQLException {
054: ps = prepareStatement("select count(*) from sys.systables");
055: rs = ps.executeQuery();
056: rsmd = rs.getMetaData();
057: }
058:
059: /**
060: *
061: * Initialize the ds to null once the tests that need to be run have been
062: * run
063: */
064: protected void tearDown() throws Exception {
065: if (rs != null && !rs.isClosed())
066: rs.close();
067: if (ps != null && !ps.isClosed())
068: ps.close();
069:
070: super .tearDown();
071:
072: }
073:
074: public void testIsWrapperForResultSetMetaData() throws SQLException {
075: assertTrue(rsmd.isWrapperFor(ResultSetMetaData.class));
076: }
077:
078: public void testUnwrapResultSetMetaData() throws SQLException {
079: ResultSetMetaData rsmd2 = rsmd.unwrap(ResultSetMetaData.class);
080: assertSame("Unwrap returned wrong object.", rsmd, rsmd2);
081: }
082:
083: public void testIsWrapperForResultSet() throws SQLException {
084: assertFalse(rsmd.isWrapperFor(ResultSet.class));
085: }
086:
087: public void testUnwrapResultSet() {
088: try {
089: ResultSet rs = rsmd.unwrap(ResultSet.class);
090: fail("Unwrap didn't fail.");
091: } catch (SQLException e) {
092: assertSQLState("XJ128", e);
093: }
094: }
095:
096: /**
097: * Return suite with all tests of the class.
098: */
099: public static Test suite() {
100: return (new TestSuite(ResultSetMetaDataTest.class,
101: "ResultSetMetaDataTest suite"));
102: }
103: }
|