001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.dbcp;
019:
020: import java.sql.Connection;
021: import java.sql.PreparedStatement;
022:
023: import junit.framework.Test;
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: /**
028: * @author Rodney Waldhoff
029: * @author Dirk Verbeeck
030: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
031: */
032: public class TestDelegatingPreparedStatement extends TestCase {
033: public TestDelegatingPreparedStatement(String testName) {
034: super (testName);
035: }
036:
037: public static Test suite() {
038: return new TestSuite(TestDelegatingPreparedStatement.class);
039: }
040:
041: private DelegatingConnection conn = null;
042: private Connection delegateConn = null;
043: private DelegatingPreparedStatement stmt = null;
044: private PreparedStatement delegateStmt = null;
045:
046: public void setUp() throws Exception {
047: delegateConn = new TesterConnection("test", "test");
048: conn = new DelegatingConnection(delegateConn);
049: }
050:
051: public void testExecuteQueryReturnsNull() throws Exception {
052: delegateStmt = new TesterPreparedStatement(delegateConn, "null");
053: stmt = new DelegatingPreparedStatement(conn, delegateStmt);
054: assertNull(stmt.executeQuery());
055: }
056:
057: public void testExecuteQueryReturnsNotNull() throws Exception {
058: delegateStmt = new TesterPreparedStatement(delegateConn,
059: "select * from foo");
060: stmt = new DelegatingPreparedStatement(conn, delegateStmt);
061: assertTrue(null != stmt.executeQuery());
062: }
063:
064: public void testGetDelegate() throws Exception {
065: delegateStmt = new TesterPreparedStatement(delegateConn,
066: "select * from foo");
067: stmt = new DelegatingPreparedStatement(conn, delegateStmt);
068: assertEquals(delegateStmt, stmt.getDelegate());
069: }
070:
071: public void testHashCodeNull() {
072: stmt = new DelegatingPreparedStatement(conn, null);
073: assertEquals(0, stmt.hashCode());
074: }
075:
076: public void testHashCode() {
077: delegateStmt = new TesterPreparedStatement(delegateConn,
078: "select * from foo");
079: DelegatingPreparedStatement stmt = new DelegatingPreparedStatement(
080: conn, delegateStmt);
081: DelegatingPreparedStatement stmt2 = new DelegatingPreparedStatement(
082: conn, delegateStmt);
083: assertEquals(stmt.hashCode(), stmt2.hashCode());
084: }
085:
086: public void testEquals() {
087: delegateStmt = new TesterPreparedStatement(delegateConn,
088: "select * from foo");
089: DelegatingPreparedStatement stmt = new DelegatingPreparedStatement(
090: conn, delegateStmt);
091: DelegatingPreparedStatement stmt2 = new DelegatingPreparedStatement(
092: conn, delegateStmt);
093: DelegatingPreparedStatement stmt3 = new DelegatingPreparedStatement(
094: conn, null);
095:
096: assertTrue(!stmt.equals(null));
097: assertTrue(stmt.equals(stmt2));
098: assertTrue(!stmt.equals(stmt3));
099: }
100:
101: }
|