KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  
3    Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.ResultSetMetaDataTest
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, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19  
20  */

21 package org.apache.derbyTesting.functionTests.tests.jdbc4;
22
23 import junit.framework.*;
24
25 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
26 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
27
28 import java.sql.*;
29 import javax.sql.*;
30
31
32 public class ResultSetMetaDataTest extends BaseJDBCTestCase {
33     //classes that will be used for the test
34

35     private PreparedStatement ps =null;
36     private ResultSet rs =null;
37     //The ResultSetMetaData object that will be used throughout the test
38
private ResultSetMetaData rsmd =null;
39     
40     /**
41      *
42      * Create a test with the given name.
43      *
44      * @param name name of the test.
45      *
46      */

47     public ResultSetMetaDataTest(String JavaDoc name) {
48         super(name);
49     }
50     
51     /**
52      * Create a default DataSource
53      */

54     protected void setUp() throws SQLException {
55          ps = prepareStatement("select count(*) from sys.systables");
56     rs = ps.executeQuery();
57         rsmd = rs.getMetaData();
58     }
59     
60     /**
61      *
62      * Initialize the ds to null once the tests that need to be run have been
63      * run
64      */

65     protected void tearDown() throws Exception JavaDoc {
66         if(rs != null && !rs.isClosed())
67             rs.close();
68         if(ps != null && !ps.isClosed())
69             ps.close();
70         
71         super.tearDown();
72
73     }
74
75     public void testIsWrapperForResultSetMetaData() throws SQLException {
76         assertTrue(rsmd.isWrapperFor(ResultSetMetaData.class));
77     }
78
79     public void testUnwrapResultSetMetaData() throws SQLException {
80         ResultSetMetaData rsmd2 = rsmd.unwrap(ResultSetMetaData.class);
81         assertSame("Unwrap returned wrong object.", rsmd, rsmd2);
82     }
83
84     public void testIsWrapperForResultSet() throws SQLException {
85         assertFalse(rsmd.isWrapperFor(ResultSet.class));
86     }
87
88     public void testUnwrapResultSet() {
89         try {
90             ResultSet rs = rsmd.unwrap(ResultSet.class);
91             fail("Unwrap didn't fail.");
92         } catch (SQLException e) {
93             assertSQLState("XJ128", e);
94         }
95     }
96
97     /**
98      * Return suite with all tests of the class.
99      */

100     public static Test suite() {
101         return (new TestSuite(ResultSetMetaDataTest.class,
102                               "ResultSetMetaDataTest suite"));
103     }
104 }
105
Popular Tags