KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

51    private XAPoolDatabaseConnectionFactoryTest(
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("XAPoolDatabaseConnectionFactoryTest");
69       suite.addTestSuite(XAPoolDatabaseConnectionFactoryTestInternal.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 XAPoolDatabaseConnectionFactoryTestInternal
81                           extends PooledDatabaseConnectionFactoryImplBaseTest
82    {
83       /**
84        * Create new XAPoolDatabaseConnectionFactoryTest.
85        *
86        * @param strTestName - name of the test
87        */

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

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

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