KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ProxoolDatabaseConnectionFactoryTest.java,v 1.7 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.error.OSSInternalErrorException;
33 import org.opensubsystems.core.persist.db.DatabaseTestSetup;
34 import org.opensubsystems.core.persist.db.DatabaseTestSuite;
35
36 /**
37  * Test of Proxool database connection factory.
38  *
39  * @version $Id: ProxoolDatabaseConnectionFactoryTest.java,v 1.7 2007/01/07 06:14:20 bastafidli Exp $
40  * @author Julian Legeny
41  * @code.reviewer Miro Halas
42  * @code.reviewed 1.6 2004/10/05 07:39:53 bastafidli
43  */

44 public final class ProxoolDatabaseConnectionFactoryTest
45 {
46    // Constructors /////////////////////////////////////////////////////////////
47

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

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

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

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

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

88       public ProxoolDatabaseConnectionFactoryTestInternal(
89          String JavaDoc strTestName
90       )
91       {
92          super(strTestName);
93       }
94    
95       /**
96        * Set up environment for the test case.
97        *
98        * @throws Exception - an error has occured during setting up test
99        */

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

112       protected boolean containsConnection(
113          List JavaDoc lstConnections,
114          Connection JavaDoc newConnection
115       ) throws OSSInternalErrorException
116       {
117          Connection JavaDoc cConnectionFromList = null;
118          Iterator JavaDoc itHelp;
119          boolean bReturn = false;
120    
121 // Connection testConn1 = null;
122
// Connection testConn2 = null;
123

124          // for each connection from the list test if new requested connection is
125
// contained in the list
126
itHelp = lstConnections.iterator();
127          while (itHelp.hasNext())
128          {
129             cConnectionFromList = (Connection JavaDoc)itHelp.next();
130 // TODO: Bug: Proxool 0.9.0RC2: Reported as bug# 1468635. This method was
131
// originally implemented as this but Proxool deprecated method
132
// ProxoolFacade.getDelegateConnection saying we should be able to just use the
133
// given connections. This seems to not work since test testRequestXReturnX is
134
// failing for Proxool. Investigate this please.
135
// try
136
// {
137
// testConn1 = ProxoolFacade.getDelegateConnection(cConnectionFromList);
138
// testConn2 = ProxoolFacade.getDelegateConnection(newConnection);
139
// bReturn = bReturn || (testConn1 == testConn2);
140
// }
141
// catch (ProxoolException peExc)
142
// {
143
// throw new OSSInternalErrorException("There was an error occured during getting" +
144
// " the proxool connection.", peExc);
145
// }
146
bReturn = bReturn || (cConnectionFromList == newConnection);
147          }
148    
149          return bReturn;
150       }
151    }
152 }
153
Popular Tags