01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.dbcp;
19:
20: import java.sql.Connection;
21: import java.sql.SQLException;
22:
23: import junit.framework.Test;
24: import junit.framework.TestCase;
25: import junit.framework.TestSuite;
26:
27: /**
28: * @author Dirk Verbeeck
29: * @version $Revision: 479142 $ $Date: 2006-11-25 09:31:27 -0700 (Sat, 25 Nov 2006) $
30: */
31: public class TestDelegatingConnection extends TestCase {
32: public TestDelegatingConnection(String testName) {
33: super (testName);
34: }
35:
36: public static Test suite() {
37: return new TestSuite(TestDelegatingConnection.class);
38: }
39:
40: private DelegatingConnection conn = null;
41: private Connection delegateConn = null;
42: private Connection delegateConn2 = null;
43:
44: public void setUp() throws Exception {
45: delegateConn = new TesterConnection("test", "test");
46: delegateConn2 = new TesterConnection("test", "test");
47: conn = new DelegatingConnection(delegateConn);
48: }
49:
50: public void testGetDelegate() throws Exception {
51: assertEquals(delegateConn, conn.getDelegate());
52: }
53:
54: public void testConnectionToString() throws Exception {
55: String s = conn.toString();
56: assertNotNull(s);
57: assertTrue(s.length() > 0);
58: }
59:
60: public void testHashCodeEqual() {
61: DelegatingConnection conn = new DelegatingConnection(
62: delegateConn);
63: DelegatingConnection conn2 = new DelegatingConnection(
64: delegateConn);
65: assertEquals(conn.hashCode(), conn2.hashCode());
66: }
67:
68: public void testHashCodeNotEqual() {
69: DelegatingConnection conn = new DelegatingConnection(
70: delegateConn);
71: DelegatingConnection conn2 = new DelegatingConnection(
72: delegateConn2);
73: assertTrue(conn.hashCode() != conn2.hashCode());
74: }
75:
76: public void testEquals() {
77: DelegatingConnection conn = new DelegatingConnection(
78: delegateConn);
79: DelegatingConnection conn2 = new DelegatingConnection(
80: delegateConn);
81: DelegatingConnection conn3 = new DelegatingConnection(null);
82:
83: assertTrue(!conn.equals(null));
84: assertTrue(conn.equals(conn2));
85: assertTrue(!conn.equals(conn3));
86: assertTrue(conn.equals(conn));
87: }
88:
89: public void testCheckOpen() throws Exception {
90: conn.checkOpen();
91: conn.close();
92: try {
93: conn.checkOpen();
94: fail("Expecting SQLException");
95: } catch (SQLException ex) {
96: // expected
97: }
98: }
99: }
|