KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > persist > db > connectionpool > DBCPDatabaseConnectionFactoryTest


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: DBCPDatabaseConnectionFactoryTest.java,v 1.5 2007/01/07 06:14:20 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.persist.db.connectionpool;
23
24 import java.sql.Connection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import junit.extensions.TestSetup;
29 import junit.framework.Test;
30 import junit.framework.TestSuite;
31
32 import org.opensubsystems.core.persist.db.DatabaseTestSetup;
33 import org.opensubsystems.core.persist.db.DatabaseTestSuite;
34
35 /**
36  * Test of DBCP database connection factory.
37  *
38  * @version $Id: DBCPDatabaseConnectionFactoryTest.java,v 1.5 2007/01/07 06:14:20 bastafidli Exp $
39  * @author Julian Legeny
40  * @code.reviewer Miro Halas
41  * @code.reviewed 1.7 2004/10/05 07:39:53 bastafidli
42  */

43 public final class DBCPDatabaseConnectionFactoryTest
44 {
45    // Constructors /////////////////////////////////////////////////////////////
46

47    /**
48     * Private constructor since this class cannot be instantiated
49     */

50    private DBCPDatabaseConnectionFactoryTest(
51    )
52    {
53       // Do nothing
54
}
55    
56    // Public methods ///////////////////////////////////////////////////////////
57

58    /**
59     * Create the suite for this test since this is the only way how to create
60     * test setup which can initialize and shutdown the database for us
61     *
62     * @return Test - suite of tests to run for this database
63     */

64    public static Test suite(
65    )
66    {
67       TestSuite suite = new DatabaseTestSuite("DBCPDatabaseConnectionFactoryTest");
68       suite.addTestSuite(DBCPDatabaseConnectionFactoryTestInternal.class);
69       TestSetup wrapper = new DatabaseTestSetup(suite);
70
71       return wrapper;
72    }
73
74    /**
75     * Internal class which can be included in other test suites directly without
76     * including the above suite. This allows us to group multiple tests
77     * together and the execute the DatabaseTestSetup only once
78     */

79    public static class DBCPDatabaseConnectionFactoryTestInternal
80                           extends PooledDatabaseConnectionFactoryImplBaseTest
81    {
82       /**
83        * Create new DBCPDatabaseConnectionFactoryTest.
84        *
85        * @param strTestName - name of the test
86        */

87       public DBCPDatabaseConnectionFactoryTestInternal(
88          String JavaDoc strTestName
89       )
90       {
91          super(strTestName);
92       }
93    
94       /**
95        * {@inheritDoc}
96        */

97       protected void setUp(
98       ) throws Exception JavaDoc
99       {
100          // initialize connection factory
101
m_connectionFactory = new DBCPDatabaseConnectionFactoryImpl();
102          
103          super.setUp();
104       }
105    
106       /**
107        * {@inheritDoc}
108        */

109       protected boolean containsConnection(
110          List JavaDoc lstConnections,
111          Connection JavaDoc newConnection
112       )
113       {
114          Connection JavaDoc cConnectionFromList = null;
115          Iterator JavaDoc itHelp;
116          boolean bReturn = false;
117    
118          // for each connection from the list test if new requested connection is
119
// contained in the list
120
itHelp = lstConnections.iterator();
121          while (itHelp.hasNext())
122          {
123             cConnectionFromList = (Connection JavaDoc) itHelp.next();
124             bReturn = bReturn || (cConnectionFromList == newConnection);
125          }
126    
127          return bReturn;
128       }
129    }
130 }
131
Popular Tags