Source Code Cross Referenced for ConnectionTest.java in  » Report » datavision-1.1.0 » jimm » datavision » test » 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 » Report » datavision 1.1.0 » jimm.datavision.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package jimm.datavision.test;
002:
003:        import jimm.datavision.Report;
004:        import jimm.datavision.layout.CharSepLE;
005:        import jimm.datavision.source.Column;
006:        import jimm.datavision.source.sql.Database;
007:        import jimm.datavision.source.sql.SQLQuery;
008:        import java.io.File;
009:        import java.io.PrintWriter;
010:        import java.io.FileWriter;
011:        import java.sql.*;
012:        import junit.framework.TestCase;
013:        import junit.framework.TestSuite;
014:        import junit.framework.Test;
015:
016:        /**
017:         * Tests the {@link Database} class and the ability to give a connection to a
018:         * report and the state of a connection's query after reconnecting.
019:         *
020:         * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
021:         */
022:        public class ConnectionTest extends TestCase {
023:
024:            protected static final File EXAMPLE_REPORT = new File(AllTests
025:                    .testDataFile("test.xml"));
026:            protected static final String PARAMETER_XML_FILE_NAME = AllTests
027:                    .testDataFile("test_parameters.xml");
028:            protected static final File OUT_FILE = new File(System
029:                    .getProperty("java.io.tmpdir"),
030:                    "datavision_connection_test_out.txt");
031:
032:            protected static final String DRIVER_CLASS_NAME = "org.postgresql.Driver";
033:            protected static final String CONNECTION_INFO = "jdbc:postgresql://127.0.0.1/dv_example";
034:            protected static final String DB_NAME = "dv_example";
035:            protected static final String DB_USER = "jimm";
036:            protected static final String DB_PASSWORD = "";
037:
038:            public static Test suite() {
039:                return new TestSuite(ConnectionTest.class);
040:            }
041:
042:            public ConnectionTest(String name) {
043:                super (name);
044:            }
045:
046:            public void testConnection() {
047:                Connection conn = null;
048:
049:                try {
050:                    Driver d = (Driver) Class.forName(DRIVER_CLASS_NAME)
051:                            .newInstance();
052:                    DriverManager.registerDriver(d);
053:                    conn = DriverManager.getConnection(CONNECTION_INFO,
054:                            DB_USER, DB_PASSWORD);
055:
056:                    Report report = new Report();
057:                    report.setDatabaseConnection(conn);
058:
059:                    OUT_FILE.deleteOnExit();
060:                    PrintWriter out = new PrintWriter(new FileWriter(OUT_FILE));
061:                    report.setLayoutEngine(new CharSepLE(out, '\t'));
062:
063:                    report.runReport();
064:                } catch (Exception e) {
065:                    e.printStackTrace();
066:                    fail("exception thrown: " + e);
067:                } finally {
068:                    if (conn != null) {
069:                        try {
070:                            conn.close();
071:                        } catch (SQLException sqle) {
072:                            fail("SQL exception thrown: " + sqle);
073:                        }
074:                    }
075:                    if (OUT_FILE.exists())
076:                        OUT_FILE.delete();
077:                }
078:            }
079:
080:            public void testQueryAfterReset() {
081:                Report report = new Report();
082:                try {
083:                    report.setDatabasePassword(DB_PASSWORD);
084:                    report.read(EXAMPLE_REPORT);
085:
086:                    Database db = (Database) report.getDataSource();
087:                    SQLQuery query = (SQLQuery) db.getQuery();
088:
089:                    assertEquals("{jobs.ID} < 100", query.getWhereClause());
090:                    assertNotNull(db.findColumn("ALL_CAPS.COL1"));
091:                    assertNotNull(db.findColumn("jobs.fk_office_id"));
092:                    assertNotNull(db.findColumn("office.email"));
093:                    assertNotNull(db.findColumn("aggregate_test.value"));
094:
095:                    // We should only have two tables in the query.
096:                    query.findSelectablesUsed();
097:                    assertEquals(2, query.getNumTables());
098:
099:                    db.reset(DRIVER_CLASS_NAME, CONNECTION_INFO, DB_NAME,
100:                            DB_USER, DB_PASSWORD);
101:                    // The query doesn't have to be the same object, but it's where
102:                    // clause (and all other information) should darned well be the same.
103:                    assertEquals("{jobs.ID} < 100", query.getWhereClause());
104:                    assertNotNull(db.findColumn("public.ALL_CAPS.COL1"));
105:                    assertNotNull(db.findColumn("public.jobs.fk_office_id"));
106:                    assertNotNull(db.findColumn("public.office.email"));
107:                    assertNotNull(db.findColumn("public.aggregate_test.value"));
108:
109:                    // Make sure we still have two tables in the query.
110:                    query.findSelectablesUsed();
111:                    assertEquals(2, query.getNumTables());
112:                } catch (Exception e) {
113:                    fail(e.toString());
114:                }
115:            }
116:
117:            public void testDatabaseReset() throws Exception {
118:                Report report = new Report();
119:                report.setDatabasePassword(DB_PASSWORD);
120:                report.read(EXAMPLE_REPORT);
121:
122:                Database db = (Database) report.getDataSource();
123:                SQLQuery origQuery = (SQLQuery) db.getQuery();
124:
125:                db.reset(db.getDriverClassName(), db.getConnectionInfo(), db
126:                        .getName(), db.getUserName(), "");
127:                SQLQuery q = (SQLQuery) db.getQuery();
128:
129:                // Unfortunately, we can't just compare query strings. That's because
130:                // the table and column lists aren't guaranteed to be sorted.
131:                //
132:                // At least these tests detect the bug we're fixing.
133:                assertEquals(origQuery.getNumTables(), q.getNumTables());
134:                assertEquals(origQuery.getNumSelectables(), q
135:                        .getNumSelectables());
136:            }
137:
138:            public void testSchemaNamesInColumns() throws Exception {
139:                Report report = new Report();
140:                report.setDatabasePassword(DB_PASSWORD);
141:                report.read(EXAMPLE_REPORT);
142:
143:                // Found because we try blank schema
144:                Column col = report.findColumn("jobs.ID");
145:                assertNotNull(col);
146:                assertEquals("public.jobs.ID", col.getId());
147:
148:                // Found due to exact match
149:                col = report.findColumn("public.jobs.ID");
150:                assertNotNull(col);
151:                assertEquals("public.jobs.ID", col.getId());
152:
153:                // Not found because schema doesn't match table's schema
154:                col = report.findColumn("dv_example.jobs.ID");
155:                assertNull(col);
156:            }
157:
158:            public static void main(String[] args) {
159:                junit.textui.TestRunner.run(suite());
160:                System.exit(0);
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.