Source Code Cross Referenced for ConfigurationListenerTest.java in  » Database-JDBC-Connection-Pool » proxool » org » logicalcobwebs » proxool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » proxool » org.logicalcobwebs.proxool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This software is released under a licence similar to the Apache Software Licence.
003:         * See org.logicalcobwebs.proxool.package.html for details.
004:         * The latest version is available at http://proxool.sourceforge.net
005:         */
006:        package org.logicalcobwebs.proxool;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:
011:        import java.util.Properties;
012:        import java.sql.DriverManager;
013:
014:        /**
015:         * Test that registering a {@link org.logicalcobwebs.proxool.ConfigurationListenerIF}
016:         * with the {@link org.logicalcobwebs.proxool.ProxoolFacade}
017:         * works.
018:         *
019:         * @version $Revision: 1.13 $, $Date: 2006/01/18 14:40:06 $
020:         * @author Christian Nedregaard (christian_nedregaard@email.com)
021:         * @author $Author: billhorsman $ (current maintainer)
022:         * @since Proxool 0.7
023:         */
024:        public class ConfigurationListenerTest extends AbstractProxoolTest {
025:
026:            private static final Log LOG = LogFactory
027:                    .getLog(ConfigurationListenerTest.class);
028:
029:            /**
030:             * @see junit.framework.TestCase#TestCase
031:             */
032:            public ConfigurationListenerTest(String s) {
033:                super (s);
034:            }
035:
036:            /**
037:             * Add a listener
038:             *
039:             * @throws Exception if anything goes wrong
040:             */
041:            public void testAddAndRemove() throws Exception {
042:
043:                String testName = "addAndRemove";
044:                String alias = testName;
045:
046:                // Register pool
047:                String url = TestHelper.buildProxoolUrl(alias,
048:                        TestConstants.HYPERSONIC_DRIVER,
049:                        TestConstants.HYPERSONIC_TEST_URL);
050:                Properties info = new Properties();
051:                info.setProperty(ProxoolConstants.USER_PROPERTY,
052:                        TestConstants.HYPERSONIC_USER);
053:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
054:                        TestConstants.HYPERSONIC_PASSWORD);
055:                ProxoolFacade.registerConnectionPool(url, info);
056:
057:                // add a listener
058:                MyConfigurationListener mcl1 = new MyConfigurationListener();
059:                ProxoolFacade.addConfigurationListener(alias, mcl1);
060:
061:                // Update the definition
062:                Properties newInfo = new Properties();
063:                newInfo.setProperty(ProxoolConstants.VERBOSE_PROPERTY,
064:                        Boolean.TRUE.toString());
065:                ProxoolFacade.updateConnectionPool(url, newInfo);
066:                assertEquals("definitionReceived", true, mcl1
067:                        .isUpdateReceived());
068:                mcl1.reset();
069:
070:                // add another listener
071:                MyConfigurationListener mcl2 = new MyConfigurationListener();
072:                ProxoolFacade.addConfigurationListener(alias, mcl2);
073:
074:                // Update the definition
075:                newInfo = new Properties();
076:                newInfo.setProperty(ProxoolConstants.VERBOSE_PROPERTY,
077:                        Boolean.FALSE.toString());
078:                ProxoolFacade.updateConnectionPool(url, newInfo);
079:                assertEquals("definitionReceived", true, mcl1
080:                        .isUpdateReceived());
081:                assertEquals("definitionReceived", true, mcl2
082:                        .isUpdateReceived());
083:                mcl1.reset();
084:                mcl2.reset();
085:
086:                // Remove the first listener
087:                ProxoolFacade.removeConfigurationListener(alias, mcl1);
088:
089:                // Update the definition
090:                newInfo = new Properties();
091:                newInfo.setProperty(ProxoolConstants.VERBOSE_PROPERTY,
092:                        Boolean.TRUE.toString());
093:                ProxoolFacade.updateConnectionPool(url, newInfo);
094:                assertEquals("definitionReceived", false, mcl1
095:                        .isUpdateReceived());
096:                assertEquals("definitionReceived", true, mcl2
097:                        .isUpdateReceived());
098:                mcl1.reset();
099:                mcl2.reset();
100:
101:                // Check that just asking for another Connection (without config
102:                // change) doesn't trigger another event
103:                DriverManager.getConnection(url).close();
104:                assertEquals("definitionReceived", false, mcl2
105:                        .isUpdateReceived());
106:                mcl2.reset();
107:
108:                // Now try again, but this time pass in the properties (without
109:                // change)
110:                LOG
111:                        .debug("Getting another connection to trigger any pending config changes");
112:                DriverManager.getConnection(url, info).close();
113:                mcl2.reset();
114:                LOG
115:                        .debug("Getting another connection which shouldn't cause another config change");
116:                DriverManager.getConnection(url, info).close();
117:                assertEquals("definitionReceived", false, mcl2
118:                        .isUpdateReceived());
119:                mcl2.reset();
120:
121:                // This time pass in the properties (WITH change)
122:                LOG.debug("Expecting a change now");
123:                info.setProperty(ProxoolConstants.VERBOSE_PROPERTY,
124:                        Boolean.FALSE.toString());
125:                DriverManager.getConnection(url, info).close();
126:                assertEquals("definitionReceived", true, mcl2
127:                        .isUpdateReceived());
128:                mcl2.reset();
129:
130:                // Remove the second listener
131:                ProxoolFacade.removeConfigurationListener(alias, mcl2);
132:
133:                // Update the definition
134:                newInfo = new Properties();
135:                newInfo.setProperty(ProxoolConstants.VERBOSE_PROPERTY,
136:                        Boolean.FALSE.toString());
137:                ProxoolFacade.updateConnectionPool(url, newInfo);
138:                assertEquals("definitionReceived", false, mcl1
139:                        .isUpdateReceived());
140:                assertEquals("definitionReceived", false, mcl2
141:                        .isUpdateReceived());
142:                mcl1.reset();
143:                mcl2.reset();
144:
145:            }
146:
147:            /**
148:             * Do configuration listeners work
149:             *
150:             * @throws Exception if anything goes wrong
151:             */
152:            public void testConfigurationListeners() throws Exception {
153:
154:                String testName = "configurationListener";
155:                String alias = testName;
156:
157:                // Register pool
158:                final String delegateUrl1 = TestConstants.HYPERSONIC_TEST_URL;
159:                final String delegateUrl2 = TestConstants.HYPERSONIC_TEST_URL2;
160:
161:                final String url1 = TestHelper.buildProxoolUrl(alias,
162:                        TestConstants.HYPERSONIC_DRIVER, delegateUrl1);
163:                final String url2 = TestHelper.buildProxoolUrl(alias,
164:                        TestConstants.HYPERSONIC_DRIVER, delegateUrl2);
165:
166:                Properties info = new Properties();
167:                info.setProperty(ProxoolConstants.USER_PROPERTY,
168:                        TestConstants.HYPERSONIC_USER);
169:                info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
170:                        TestConstants.HYPERSONIC_PASSWORD);
171:                ProxoolFacade.registerConnectionPool(url1, info);
172:
173:                int propertyCount = info.size();
174:
175:                // listen to the configuration
176:                MyConfigurationListener mcl = new MyConfigurationListener();
177:                ProxoolFacade.addConfigurationListener(alias, mcl);
178:
179:                // Update the URL
180:                ProxoolFacade.updateConnectionPool(url2, null);
181:                LOG.debug("changed: " + mcl.getChangedInfo());
182:                LOG.debug("complete: " + mcl.getCompleteInfo());
183:                assertEquals("changed size", 0, mcl.getChangedInfo().size());
184:                assertEquals("complete size", propertyCount, mcl
185:                        .getCompleteInfo().size());
186:                assertEquals("url", delegateUrl2, mcl
187:                        .getConnectionPoolDefinition().getUrl());
188:                mcl.reset();
189:
190:                // Add the verbose property
191:                Properties newInfo = new Properties();
192:                newInfo.setProperty(ProxoolConstants.VERBOSE_PROPERTY,
193:                        Boolean.TRUE.toString());
194:                ProxoolFacade.updateConnectionPool(url2, newInfo);
195:                LOG.debug("changed: " + mcl.getChangedInfo());
196:                LOG.debug("complete: " + mcl.getCompleteInfo());
197:                assertEquals("completeInfo size", propertyCount + 1, mcl
198:                        .getCompleteInfo().size());
199:                assertEquals("changedInfo size", 1, mcl.getChangedInfo().size());
200:                assertEquals("url", true, mcl.getConnectionPoolDefinition()
201:                        .isVerbose());
202:                mcl.reset();
203:
204:                // modify the verbose property
205:                newInfo = new Properties();
206:                newInfo.setProperty(ProxoolConstants.VERBOSE_PROPERTY,
207:                        Boolean.FALSE.toString());
208:                ProxoolFacade.updateConnectionPool(url2, newInfo);
209:                LOG.debug("changed: " + mcl.getChangedInfo());
210:                LOG.debug("complete: " + mcl.getCompleteInfo());
211:                assertEquals("completeInfo size", propertyCount + 1, mcl
212:                        .getCompleteInfo().size());
213:                assertEquals("changedInfo size", 1, mcl.getChangedInfo().size());
214:                assertEquals("url", false, mcl.getConnectionPoolDefinition()
215:                        .isVerbose());
216:                mcl.reset();
217:
218:            }
219:
220:            class MyConfigurationListener implements  ConfigurationListenerIF {
221:
222:                private Properties completeInfo;
223:
224:                private Properties changedInfo;
225:
226:                private ConnectionPoolDefinitionIF connectionPoolDefinition;
227:
228:                private boolean updateReceived;
229:
230:                public void definitionUpdated(
231:                        ConnectionPoolDefinitionIF connectionPoolDefinition,
232:                        Properties completeInfo, Properties changedInfo) {
233:                    this .connectionPoolDefinition = connectionPoolDefinition;
234:                    this .completeInfo = completeInfo;
235:                    this .changedInfo = changedInfo;
236:                    updateReceived = true;
237:                }
238:
239:                public Properties getCompleteInfo() {
240:                    return completeInfo;
241:                }
242:
243:                public Properties getChangedInfo() {
244:                    return changedInfo;
245:                }
246:
247:                public ConnectionPoolDefinitionIF getConnectionPoolDefinition() {
248:                    return connectionPoolDefinition;
249:                }
250:
251:                public boolean isUpdateReceived() {
252:                    return updateReceived;
253:                }
254:
255:                public void reset() {
256:                    completeInfo.clear();
257:                    changedInfo.clear();
258:                    updateReceived = false;
259:                }
260:
261:            }
262:
263:        }
264:
265:        /*
266:         Revision history:
267:         $Log: ConfigurationListenerTest.java,v $
268:         Revision 1.13  2006/01/18 14:40:06  billhorsman
269:         Unbundled Jakarta's Commons Logging.
270:
271:         Revision 1.12  2004/05/26 17:19:09  brenuart
272:         Allow JUnit tests to be executed against another database.
273:         By default the test configuration will be taken from the 'testconfig-hsqldb.properties' file located in the org.logicalcobwebs.proxool package.
274:         This behavior can be overriden by setting the 'testConfig' environment property to another location.
275:
276:         Revision 1.11  2003/04/27 15:44:19  billhorsman
277:         better tests
278:
279:         Revision 1.10  2003/04/10 21:48:58  billhorsman
280:         enhanced to trap bug where config change event gets fired
281:         all the time
282:
283:         Revision 1.9  2003/03/04 10:24:40  billhorsman
284:         removed try blocks around each test
285:
286:         Revision 1.8  2003/03/03 17:08:54  billhorsman
287:         all tests now extend AbstractProxoolTest
288:
289:         Revision 1.7  2003/03/03 11:12:03  billhorsman
290:         fixed licence
291:
292:         Revision 1.6  2003/02/27 18:01:47  billhorsman
293:         completely rethought the test structure. it's now
294:         more obvious. no new tests yet though.
295:
296:         Revision 1.5  2003/02/26 16:05:49  billhorsman
297:         widespread changes caused by refactoring the way we
298:         update and redefine pool definitions.
299:
300:         Revision 1.4  2003/02/24 18:04:07  chr32
301:         Fixde some eroneous property names.
302:
303:         Revision 1.3  2003/02/19 17:00:51  chr32
304:         Fixed eroneous method names.
305:
306:         Revision 1.2  2003/02/19 15:14:22  billhorsman
307:         fixed copyright (copy and paste error,
308:         not copyright change)
309:
310:         Revision 1.1  2003/02/19 13:47:31  chr32
311:         Added configuration listener test.
312:
313:         Revision 1.2  2003/02/18 16:58:12  chr32
314:         Checkstyle.
315:
316:         Revision 1.1  2003/02/18 16:51:20  chr32
317:         Added tests for ConnectionListeners.
318:
319:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.