KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  
3    Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.DataSourceTest
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
22 package org.apache.derbyTesting.functionTests.tests.jdbc4;
23
24 import junit.framework.*;
25
26 import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory;
27 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
28
29 import java.sql.*;
30 import javax.sql.*;
31
32 /**
33  * Tests of the <code>javax.sql.DataSource</code> JDBC40 API.
34  */

35
36 public class DataSourceTest extends BaseJDBCTestCase {
37     
38     //Default DataSource that will be used by the tests
39
private DataSource ds = null;
40     
41     /**
42      *
43      * Create a test with the given name.
44      *
45      * @param name name of the test.
46      *
47      */

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

55     public void setUp() {
56         ds = TestDataSourceFactory.getDataSource();
57     }
58     
59     /**
60      *
61      * Initialize the ds to null once the tests that need to be run have been
62      * run
63      */

64     public void tearDown() {
65         ds = null;
66     }
67
68     public void testIsWrapperForDataSource() throws SQLException {
69         assertTrue(ds.isWrapperFor(DataSource.class));
70     }
71
72     public void testIsNotWrapperForPoolDataSource() throws SQLException {
73         assertFalse(ds.isWrapperFor(ConnectionPoolDataSource.class));
74     }
75
76     public void testIsNotWrapperForXADataSource() throws SQLException {
77         assertFalse(ds.isWrapperFor(XADataSource.class));
78     }
79
80     public void testIsNotWrapperForResultSet() throws SQLException {
81         assertFalse(ds.isWrapperFor(ResultSet.class));
82     }
83
84     public void testUnwrapDataSource() throws SQLException {
85         DataSource ds2 = ds.unwrap(DataSource.class);
86         assertSame("Unwrap returned wrong object.", ds, ds2);
87     }
88
89     public void testUnwrapConnectionPoolDataSource() {
90         try {
91             ConnectionPoolDataSource cpds =
92                 ds.unwrap(ConnectionPoolDataSource.class);
93             fail("Unwrap didn't fail.");
94         } catch (SQLException e) {
95             assertSQLState("XJ128", e);
96         }
97     }
98
99     public void testUnwrapXADataSource() {
100         try {
101             XADataSource xads = ds.unwrap(XADataSource.class);
102             fail("Unwrap didn't fail.");
103         } catch (SQLException e) {
104             assertSQLState("XJ128", e);
105         }
106     }
107
108     public void testUnwrapResultSet() {
109         try {
110             ResultSet rs = ds.unwrap(ResultSet.class);
111             fail("Unwrap didn't fail.");
112         } catch (SQLException e) {
113             assertSQLState("XJ128", e);
114         }
115     }
116
117     /**
118      * Return suite with all tests of the class.
119      */

120     public static Test suite() {
121         return (new TestSuite(DataSourceTest.class,
122                               "DataSourceTest suite"));
123     }
124 }
125
Popular Tags