Source Code Cross Referenced for EscapeProcessingTest.java in  » Database-JDBC-Connection-Pool » mysql » testsuite » simple » 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 » mysql » testsuite.simple 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         Copyright (C) 2002-2004 MySQL AB
003:
004:         This program is free software; you can redistribute it and/or modify
005:         it under the terms of version 2 of the GNU General Public License as 
006:         published by the Free Software Foundation.
007:
008:         There are special exceptions to the terms and conditions of the GPL 
009:         as it is applied to this software. View the full text of the 
010:         exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
011:         software distribution.
012:
013:         This program is distributed in the hope that it will be useful,
014:         but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         GNU General Public License for more details.
017:
018:         You should have received a copy of the GNU General Public License
019:         along with this program; if not, write to the Free Software
020:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
021:
022:
023:
024:         */
025:        package testsuite.simple;
026:
027:        import java.sql.Connection;
028:        import java.util.Properties;
029:        import java.util.TimeZone;
030:
031:        import testsuite.BaseTestCase;
032:
033:        /**
034:         * Tests escape processing
035:         * 
036:         * @author Mark Matthews
037:         */
038:        public class EscapeProcessingTest extends BaseTestCase {
039:            // ~ Constructors
040:            // -----------------------------------------------------------
041:
042:            /**
043:             * Constructor for EscapeProcessingTest.
044:             * 
045:             * @param name
046:             *            the test to run
047:             */
048:            public EscapeProcessingTest(String name) {
049:                super (name);
050:            }
051:
052:            // ~ Methods
053:            // ----------------------------------------------------------------
054:
055:            /**
056:             * Tests the escape processing functionality
057:             * 
058:             * @throws Exception
059:             *             if an error occurs
060:             */
061:            public void testEscapeProcessing() throws Exception {
062:                String results = "select dayname (abs(now())),   -- Today    \n"
063:                        + "           '1997-05-24',  -- a date                    \n"
064:                        + "           '10:30:29',  -- a time                     \n"
065:                        + "           '1997-05-24 10:30:29', -- a timestamp  \n"
066:                        + "          '{string data with { or } will not be altered'   \n"
067:                        + "--  Also note that you can safely include { and } in comments";
068:
069:                String exSql = "select {fn dayname ({fn abs({fn now()})})},   -- Today    \n"
070:                        + "           {d '1997-05-24'},  -- a date                    \n"
071:                        + "           {t '10:30:29' },  -- a time                     \n"
072:                        + "           {ts '1997-05-24 10:30:29.123'}, -- a timestamp  \n"
073:                        + "          '{string data with { or } will not be altered'   \n"
074:                        + "--  Also note that you can safely include { and } in comments";
075:
076:                String escapedSql = this .conn.nativeSQL(exSql);
077:
078:                assertTrue(results.equals(escapedSql));
079:
080:            }
081:
082:            /**
083:             * Runs all test cases in this test suite
084:             * 
085:             * @param args
086:             */
087:            public static void main(String[] args) {
088:                junit.textui.TestRunner.run(EscapeProcessingTest.class);
089:            }
090:
091:            /**
092:             * JDBC-4.0 spec will allow either SQL_ or not for type in {fn convert ...}
093:             * 
094:             * @throws Exception
095:             *             if the test fails
096:             */
097:            public void testConvertEscape() throws Exception {
098:                assertEquals(conn.nativeSQL("{fn convert(abcd, SQL_INTEGER)}"),
099:                        conn.nativeSQL("{fn convert(abcd, INTEGER)}"));
100:            }
101:
102:            /**
103:             * Tests that the escape tokenizer converts timestamp values
104:             * wrt. timezones when useTimezone=true.
105:             * 
106:             * @throws Exception if the test fails.
107:             */
108:            public void testTimestampConversion() throws Exception {
109:                TimeZone currentTimezone = TimeZone.getDefault();
110:                String[] availableIds = TimeZone
111:                        .getAvailableIDs(currentTimezone.getRawOffset()
112:                                + (3600 * 1000 * 2));
113:                String newTimezone = null;
114:
115:                if (availableIds.length > 0) {
116:                    newTimezone = availableIds[0];
117:                } else {
118:                    newTimezone = "UTC"; // punt
119:                }
120:
121:                Properties props = new Properties();
122:
123:                props.setProperty("useTimezone", "true");
124:                props.setProperty("serverTimezone", newTimezone);
125:                Connection tzConn = null;
126:
127:                try {
128:                    String escapeToken = "SELECT {ts '2002-11-12 10:00:00'} {t '05:11:02'}";
129:                    tzConn = getConnectionWithProps(props);
130:                    assertTrue(!tzConn.nativeSQL(escapeToken).equals(
131:                            this.conn.nativeSQL(escapeToken)));
132:                } finally {
133:                    if (tzConn != null) {
134:                        tzConn.close();
135:                    }
136:                }
137:
138:            }
139:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.