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: import java.sql.Statement;
23:
24: import junit.framework.Test;
25: import junit.framework.TestCase;
26: import junit.framework.TestSuite;
27:
28: /**
29: * @author Rodney Waldhoff
30: * @author Dirk Verbeeck
31: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
32: */
33: public class TestDelegatingStatement extends TestCase {
34: public TestDelegatingStatement(String testName) {
35: super (testName);
36: }
37:
38: public static Test suite() {
39: return new TestSuite(TestDelegatingStatement.class);
40: }
41:
42: private DelegatingConnection conn = null;
43: private Connection delegateConn = null;
44: private DelegatingStatement stmt = null;
45: private Statement delegateStmt = null;
46:
47: public void setUp() throws Exception {
48: delegateConn = new TesterConnection("test", "test");
49: delegateStmt = new TesterStatement(delegateConn);
50: conn = new DelegatingConnection(delegateConn);
51: stmt = new DelegatingStatement(conn, delegateStmt);
52: }
53:
54: public void testExecuteQueryReturnsNull() throws Exception {
55: assertNull(stmt.executeQuery("null"));
56: }
57:
58: public void testGetDelegate() throws Exception {
59: assertEquals(delegateStmt, stmt.getDelegate());
60: }
61:
62: public void testHashCode() {
63: delegateStmt = new TesterPreparedStatement(delegateConn,
64: "select * from foo");
65: DelegatingStatement stmt = new DelegatingStatement(conn,
66: delegateStmt);
67: DelegatingStatement stmt2 = new DelegatingStatement(conn,
68: delegateStmt);
69: assertEquals(stmt.hashCode(), stmt2.hashCode());
70: }
71:
72: public void testEquals() {
73: delegateStmt = new TesterPreparedStatement(delegateConn,
74: "select * from foo");
75: DelegatingStatement stmt = new DelegatingStatement(conn,
76: delegateStmt);
77: DelegatingStatement stmt2 = new DelegatingStatement(conn,
78: delegateStmt);
79: DelegatingStatement stmt3 = new DelegatingStatement(conn, null);
80:
81: assertTrue(!stmt.equals(null));
82: assertTrue(stmt.equals(stmt2));
83: assertTrue(!stmt.equals(stmt3));
84: }
85:
86: public void testCheckOpen() throws Exception {
87: stmt.checkOpen();
88: stmt.close();
89: try {
90: stmt.checkOpen();
91: fail("Expecting SQLException");
92: } catch (SQLException ex) {
93: // expected
94: }
95: }
96: }
|