Source Code Cross Referenced for TestDatasource.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » database » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.database 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: TestDatasource.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.database;
009:
010:        import junit.framework.TestCase;
011:
012:        import org.postgresql.ds.PGSimpleDataSource;
013:
014:        import com.uwyn.rife.database.exceptions.DatabaseException;
015:        import com.uwyn.rife.tools.ExceptionUtils;
016:
017:        public class TestDatasource extends TestCase {
018:            public TestDatasource(String name) {
019:                super (name);
020:            }
021:
022:            public void testInstantiation() {
023:                Datasource datasource1 = new Datasource();
024:                assertNotNull(datasource1);
025:                assertNull(datasource1.getDriver());
026:                assertNull(datasource1.getDataSource());
027:                assertNull(datasource1.getUrl());
028:                assertNull(datasource1.getUser());
029:                assertNull(datasource1.getPassword());
030:                assertEquals(datasource1.getPoolsize(), 0);
031:                assertTrue(!datasource1.isPooled());
032:
033:                String driver = "driver";
034:                String url = "url";
035:                String user = "user";
036:                String password = "password";
037:                int poolsize = 5;
038:
039:                Datasource datasource2 = new Datasource(driver, url, user,
040:                        password, poolsize);
041:                assertNotNull(datasource2);
042:                assertEquals(datasource2.getDriver(), driver);
043:                assertEquals(datasource2.getUrl(), url);
044:                assertEquals(datasource2.getUser(), user);
045:                assertEquals(datasource2.getPassword(), password);
046:                assertEquals(datasource2.getPoolsize(), poolsize);
047:                assertTrue(datasource2.isPooled());
048:
049:                PGSimpleDataSource pgdatasource = new PGSimpleDataSource();
050:                Datasource datasource3 = new Datasource(pgdatasource, driver,
051:                        user, password, poolsize);
052:                assertNotNull(datasource3);
053:                assertEquals(datasource3.getDriver(), driver);
054:                assertSame(datasource3.getDataSource(), pgdatasource);
055:                assertEquals(datasource3.getUser(), user);
056:                assertEquals(datasource3.getPassword(), password);
057:                assertEquals(datasource3.getPoolsize(), poolsize);
058:                assertTrue(datasource3.isPooled());
059:            }
060:
061:            public void testPopulation() {
062:                String driver = "driver";
063:                String url = "url";
064:                String user = "user";
065:                String password = "password";
066:                int poolsize = 5;
067:                PGSimpleDataSource pgdatasource = new PGSimpleDataSource();
068:
069:                Datasource datasource = new Datasource();
070:                datasource.setDriver(driver);
071:                datasource.setDataSource(pgdatasource);
072:                datasource.setUrl(url);
073:                datasource.setUser(user);
074:                datasource.setPassword(password);
075:                datasource.setPoolsize(poolsize);
076:                assertEquals(datasource.getDriver(), driver);
077:                assertSame(datasource.getDataSource(), pgdatasource);
078:                assertEquals(datasource.getUrl(), url);
079:                assertEquals(datasource.getUser(), user);
080:                assertEquals(datasource.getPassword(), password);
081:                assertEquals(datasource.getPoolsize(), poolsize);
082:                assertTrue(datasource.isPooled());
083:            }
084:
085:            public void testDriverAlias() {
086:                String driver_aliased = "org.gjt.mm.mysql.Driver";
087:                String driver_unaliased = "com.mysql.jdbc.Driver";
088:
089:                Datasource datasource = new Datasource();
090:
091:                datasource.setDriver(driver_aliased);
092:                assertEquals(datasource.getDriver(), driver_aliased);
093:                assertEquals(datasource.getAliasedDriver(), driver_unaliased);
094:
095:                datasource.setDriver(driver_unaliased);
096:                assertEquals(datasource.getDriver(), driver_unaliased);
097:                assertEquals(datasource.getAliasedDriver(), driver_unaliased);
098:            }
099:
100:            public void testEquality() {
101:                String driver = "driver";
102:                String url = "url";
103:                String user = "user";
104:                String password = "password";
105:                int poolsize = 5;
106:
107:                Datasource datasource1 = new Datasource();
108:                datasource1.setDriver(driver);
109:                datasource1.setUrl(url);
110:                datasource1.setUser(user);
111:                datasource1.setPassword(password);
112:                datasource1.setPoolsize(poolsize);
113:
114:                Datasource datasource2 = new Datasource(driver, url, user,
115:                        password, poolsize);
116:
117:                assertNotSame(datasource1, datasource2);
118:
119:                assertEquals(datasource1.getDriver(), datasource2.getDriver());
120:                assertEquals(datasource1.getUrl(), datasource2.getUrl());
121:                assertEquals(datasource1.getUser(), datasource2.getUser());
122:                assertEquals(datasource1.getPassword(), datasource2
123:                        .getPassword());
124:                assertEquals(datasource1.getPoolsize(), datasource2
125:                        .getPoolsize());
126:                assertEquals(datasource1.isPooled(), datasource2.isPooled());
127:                assertEquals(datasource1, datasource2);
128:
129:                datasource2.setDriver("otherdriver");
130:                assertTrue(!datasource1.equals(datasource2));
131:                datasource2.setDriver(driver);
132:                assertTrue(datasource1.equals(datasource2));
133:
134:                datasource2.setUrl("otherurl");
135:                assertTrue(!datasource1.equals(datasource2));
136:                datasource2.setUrl(url);
137:                assertTrue(datasource1.equals(datasource2));
138:
139:                datasource2.setUser("otheruser");
140:                assertTrue(!datasource1.equals(datasource2));
141:                datasource2.setUser(user);
142:                assertTrue(datasource1.equals(datasource2));
143:
144:                datasource2.setPassword("otherpassword");
145:                assertTrue(!datasource1.equals(datasource2));
146:                datasource2.setPassword(password);
147:                assertTrue(datasource1.equals(datasource2));
148:
149:                datasource2.setPoolsize(poolsize + 1);
150:                assertTrue(datasource1.equals(datasource2));
151:
152:                PGSimpleDataSource pgdatasource = new PGSimpleDataSource();
153:
154:                Datasource datasource3 = new Datasource();
155:                datasource3.setDriver(driver);
156:                datasource3.setDataSource(pgdatasource);
157:                datasource3.setUser(user);
158:                datasource3.setPassword(password);
159:                datasource3.setPoolsize(poolsize);
160:
161:                Datasource datasource4 = new Datasource(pgdatasource, driver,
162:                        user, password, poolsize);
163:
164:                assertNotSame(datasource3, datasource4);
165:
166:                assertEquals(datasource3.getDriver(), datasource4.getDriver());
167:                assertEquals(datasource3.getUrl(), datasource4.getUrl());
168:                assertEquals(datasource3.getUser(), datasource4.getUser());
169:                assertEquals(datasource3.getPassword(), datasource4
170:                        .getPassword());
171:                assertEquals(datasource3.getPoolsize(), datasource4
172:                        .getPoolsize());
173:                assertEquals(datasource3.isPooled(), datasource4.isPooled());
174:                assertEquals(datasource3, datasource4);
175:
176:                datasource4.setDriver("otherdriver");
177:                assertTrue(!datasource3.equals(datasource4));
178:                datasource4.setDriver(driver);
179:                assertTrue(datasource3.equals(datasource4));
180:
181:                datasource4.setDataSource(new PGSimpleDataSource());
182:                assertTrue(!datasource3.equals(datasource4));
183:                datasource4.setDataSource(pgdatasource);
184:                assertTrue(datasource3.equals(datasource4));
185:
186:                datasource4.setUser("otheruser");
187:                assertTrue(!datasource3.equals(datasource4));
188:                datasource4.setUser(user);
189:                assertTrue(datasource3.equals(datasource4));
190:
191:                datasource4.setPassword("otherpassword");
192:                assertTrue(!datasource3.equals(datasource4));
193:                datasource4.setPassword(password);
194:                assertTrue(datasource3.equals(datasource4));
195:
196:                datasource4.setPoolsize(poolsize + 1);
197:                assertTrue(datasource3.equals(datasource4));
198:            }
199:
200:            public void testConnection() {
201:                Datasource datasource = Datasources.getRepInstance()
202:                        .getDatasource("unittestspgsql");
203:                if (null == datasource) {
204:                    System.out
205:                            .println("WARNING : Datasource testConnection test not executed (postgresql missing)");
206:                    return;
207:                }
208:
209:                DbConnection connection = null;
210:                try {
211:                    connection = datasource.getConnection();
212:                } catch (DatabaseException e) {
213:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
214:                }
215:                assertNotNull(connection);
216:                try {
217:                    connection.close();
218:                } catch (DatabaseException e) {
219:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
220:                }
221:            }
222:
223:            public void testConnectionDataSource1() {
224:                Datasource declared_datasource = Datasources.getRepInstance()
225:                        .getDatasource("unittestspgsql");
226:                if (null == declared_datasource) {
227:                    System.out
228:                            .println("WARNING : Datasource testConnectionDataSource test not executed (postgresql missing)");
229:                    return;
230:                }
231:                PGSimpleDataSource pgdatasource = new PGSimpleDataSource();
232:                pgdatasource.setDatabaseName("unittests");
233:                pgdatasource.setServerName("localhost");
234:                pgdatasource.setPortNumber(5432);
235:                pgdatasource.setUser("unittests");
236:                pgdatasource.setPassword("password");
237:                Datasource datasource = new Datasource(pgdatasource,
238:                        declared_datasource.getDriver(), "unittests",
239:                        "password", 5);
240:
241:                DbConnection connection = null;
242:                try {
243:                    connection = datasource.getConnection();
244:                } catch (DatabaseException e) {
245:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
246:                }
247:                assertNotNull(connection);
248:                try {
249:                    connection.close();
250:                } catch (DatabaseException e) {
251:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
252:                }
253:            }
254:
255:            public void testConnectionDataSource2() {
256:                Datasource declared_datasource = Datasources.getRepInstance()
257:                        .getDatasource("unittestspgsql");
258:                if (null == declared_datasource) {
259:                    System.out
260:                            .println("WARNING : Datasource testConnectionDataSource test not executed (postgresql missing)");
261:                    return;
262:                }
263:                PGSimpleDataSource pgdatasource = new PGSimpleDataSource();
264:                pgdatasource.setDatabaseName("unittests");
265:                pgdatasource.setServerName("localhost");
266:                pgdatasource.setPortNumber(5432);
267:                pgdatasource.setUser("unittests");
268:                pgdatasource.setPassword("password");
269:                Datasource datasource = new Datasource(pgdatasource, 5);
270:
271:                DbConnection connection = null;
272:                try {
273:                    connection = datasource.getConnection();
274:                } catch (DatabaseException e) {
275:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
276:                }
277:                assertNotNull(connection);
278:                try {
279:                    connection.close();
280:                } catch (DatabaseException e) {
281:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
282:                }
283:            }
284:
285:            public void testConnectionDataSourceJndi() {
286:                Datasource datasource = Datasources.getRepInstance()
287:                        .getDatasource("jndipgsql");
288:
289:                assertNotNull(datasource.getSqlConversion());
290:
291:                Datasource datasource2 = Datasources.getRepInstance()
292:                        .getDatasource("jndipgsql2");
293:                assertNotNull(datasource2.getCapabilitiesCompensator());
294:
295:                DbConnection connection = null;
296:                try {
297:                    connection = datasource.getConnection();
298:                } catch (DatabaseException e) {
299:                    fail(ExceptionUtils.getExceptionStackTrace(e));
300:                }
301:                assertNotNull(connection);
302:                try {
303:                    connection.close();
304:                } catch (DatabaseException e) {
305:                    fail(ExceptionUtils.getExceptionStackTrace(e));
306:                }
307:            }
308:
309:            public void testConnectionPreservation() {
310:                Datasource datasource = Datasources.getRepInstance()
311:                        .getDatasource("unittestspgsql");
312:                if (null == datasource) {
313:                    System.out
314:                            .println("WARNING : Datasource testConnectionPreservation test not executed (postgresql missing)");
315:                    return;
316:                }
317:
318:                try {
319:                    DbConnection connection1 = null;
320:                    DbConnection connection2 = null;
321:
322:                    connection1 = datasource.getConnection();
323:                    connection2 = datasource.getConnection();
324:                    assertTrue(connection1 != connection2);
325:                    connection1.close();
326:                    connection2.close();
327:
328:                    connection1 = datasource.getConnection();
329:                    connection1.beginTransaction();
330:                    connection2 = datasource.getConnection();
331:                    assertTrue(connection1 == connection2);
332:                    connection1.rollback();
333:                    connection1.close();
334:                } catch (DatabaseException e) {
335:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
336:                }
337:            }
338:
339:            public void testConnectionPreservationDatasource1() {
340:                Datasource declared_datasource = Datasources.getRepInstance()
341:                        .getDatasource("unittestspgsql");
342:                if (null == declared_datasource) {
343:                    System.out
344:                            .println("WARNING : Datasource testConnectionPreservationDatasource test not executed (postgresql missing)");
345:                    return;
346:                }
347:                PGSimpleDataSource pgdatasource = new PGSimpleDataSource();
348:                pgdatasource.setDatabaseName("unittests");
349:                pgdatasource.setServerName("localhost");
350:                pgdatasource.setPortNumber(5432);
351:                pgdatasource.setUser("unittests");
352:                pgdatasource.setPassword("password");
353:                Datasource datasource = new Datasource(pgdatasource,
354:                        declared_datasource.getDriver(), "unittests",
355:                        "password", 5);
356:
357:                try {
358:                    DbConnection connection1 = null;
359:                    DbConnection connection2 = null;
360:
361:                    connection1 = datasource.getConnection();
362:                    connection2 = datasource.getConnection();
363:                    assertTrue(connection1 != connection2);
364:                    connection1.close();
365:                    connection2.close();
366:
367:                    connection1 = datasource.getConnection();
368:                    connection1.beginTransaction();
369:                    connection2 = datasource.getConnection();
370:                    assertTrue(connection1 == connection2);
371:                    connection1.rollback();
372:                    connection1.close();
373:                } catch (DatabaseException e) {
374:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
375:                }
376:            }
377:
378:            public void testConnectionPreservationDatasource2() {
379:                Datasource declared_datasource = Datasources.getRepInstance()
380:                        .getDatasource("unittestspgsql");
381:                if (null == declared_datasource) {
382:                    System.out
383:                            .println("WARNING : Datasource testConnectionPreservationDatasource test not executed (postgresql missing)");
384:                    return;
385:                }
386:                PGSimpleDataSource pgdatasource = new PGSimpleDataSource();
387:                pgdatasource.setDatabaseName("unittests");
388:                pgdatasource.setServerName("localhost");
389:                pgdatasource.setPortNumber(5432);
390:                pgdatasource.setUser("unittests");
391:                pgdatasource.setPassword("password");
392:                Datasource datasource = new Datasource(pgdatasource, 5);
393:
394:                try {
395:                    DbConnection connection1 = null;
396:                    DbConnection connection2 = null;
397:
398:                    connection1 = datasource.getConnection();
399:                    connection2 = datasource.getConnection();
400:                    assertTrue(connection1 != connection2);
401:                    connection1.close();
402:                    connection2.close();
403:
404:                    connection1 = datasource.getConnection();
405:                    connection1.beginTransaction();
406:                    connection2 = datasource.getConnection();
407:                    assertTrue(connection1 == connection2);
408:                    connection1.rollback();
409:                    connection1.close();
410:                } catch (DatabaseException e) {
411:                    assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
412:                }
413:            }
414:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.