001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.DataSourceTest
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:
022: package org.apache.derbyTesting.functionTests.tests.jdbc4;
023:
024: import junit.framework.*;
025:
026: import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory;
027: import org.apache.derbyTesting.junit.BaseJDBCTestCase;
028:
029: import java.sql.*;
030: import javax.sql.*;
031:
032: /**
033: * Tests of the <code>javax.sql.DataSource</code> JDBC40 API.
034: */
035:
036: public class DataSourceTest extends BaseJDBCTestCase {
037:
038: //Default DataSource that will be used by the tests
039: private DataSource ds = null;
040:
041: /**
042: *
043: * Create a test with the given name.
044: *
045: * @param name name of the test.
046: *
047: */
048: public DataSourceTest(String name) {
049: super (name);
050: }
051:
052: /**
053: * Create a default DataSource
054: */
055: public void setUp() {
056: ds = TestDataSourceFactory.getDataSource();
057: }
058:
059: /**
060: *
061: * Initialize the ds to null once the tests that need to be run have been
062: * run
063: */
064: public void tearDown() {
065: ds = null;
066: }
067:
068: public void testIsWrapperForDataSource() throws SQLException {
069: assertTrue(ds.isWrapperFor(DataSource.class));
070: }
071:
072: public void testIsNotWrapperForPoolDataSource() throws SQLException {
073: assertFalse(ds.isWrapperFor(ConnectionPoolDataSource.class));
074: }
075:
076: public void testIsNotWrapperForXADataSource() throws SQLException {
077: assertFalse(ds.isWrapperFor(XADataSource.class));
078: }
079:
080: public void testIsNotWrapperForResultSet() throws SQLException {
081: assertFalse(ds.isWrapperFor(ResultSet.class));
082: }
083:
084: public void testUnwrapDataSource() throws SQLException {
085: DataSource ds2 = ds.unwrap(DataSource.class);
086: assertSame("Unwrap returned wrong object.", ds, ds2);
087: }
088:
089: public void testUnwrapConnectionPoolDataSource() {
090: try {
091: ConnectionPoolDataSource cpds = ds
092: .unwrap(ConnectionPoolDataSource.class);
093: fail("Unwrap didn't fail.");
094: } catch (SQLException e) {
095: assertSQLState("XJ128", e);
096: }
097: }
098:
099: 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: }
|