KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  
3    Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.ParameterMetaDataWrapperTest
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 java.sql.*;
24 import javax.sql.*;
25 import junit.framework.*;
26
27 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
28
29 /**
30  * Tests of the <code>java.sql.ParameterMetaData</code> JDBC40 API
31  */

32 public class ParameterMetaDataWrapperTest extends BaseJDBCTestCase {
33     
34     //Default PreparedStatement used by the tests
35
private PreparedStatement ps = null;
36     //Default ParameterMetaData object used by the tests
37
private ParameterMetaData pmd = null;
38     
39     /**
40      * Create a test with the given name
41      *
42      * @param name String name of the test
43      */

44     public ParameterMetaDataWrapperTest(String JavaDoc name) {
45         super(name);
46     }
47     
48     /**
49      * Create a default Prepared Statement and connection.
50      *
51      * @throws SQLException if creation of connection or callable statement
52      * fail.
53      */

54     protected void setUp()
55         throws SQLException {
56         ps = prepareStatement("values 1");
57         pmd = ps.getParameterMetaData();
58     }
59
60     /**
61      * Close default Prepared Statement and connection.
62      *
63      * @throws SQLException if closing of the connection or the callable
64      * statement fail.
65      */

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

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