Source Code Cross Referenced for AutoloadTest.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » jdbc4 » 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 DBMS » db derby 10.2 » org.apache.derbyTesting.functionTests.tests.jdbc4 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.AutoloadTest
004:
005:           Licensed to the Apache Software Foundation (ASF) under one or more
006:           contributor license agreements.  See the NOTICE file distributed with
007:           this work for additional information regarding copyright ownership.
008:           The ASF licenses this file to you under the Apache License, Version 2.0
009:           (the "License"); you may not use this file except in compliance with
010:           the License.  You may obtain a copy of the License at
011:
012:              http://www.apache.org/licenses/LICENSE-2.0
013:
014:           Unless required by applicable law or agreed to in writing, software
015:           distributed under the License is distributed on an "AS IS" BASIS,
016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:           See the License for the specific language governing permissions and
018:           limitations under the License.
019:
020:         */
021:        /**
022:         * <p>
023:         * This JUnit test verifies the autoloading of the jdbc driver under JDBC4.
024:         * This test must be run in its own VM because we want to verify that the
025:         * driver was not accidentally loaded by some other test.
026:         * </p>
027:         *
028:         * @author Rick
029:         */package org.apache.derbyTesting.functionTests.tests.jdbc4;
030:
031:        import java.sql.*;
032:        import java.util.*;
033:        import junit.framework.*;
034:
035:        import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
036:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
037:        import org.apache.derbyTesting.junit.JDBC;
038:        import org.apache.derbyTesting.junit.TestConfiguration;
039:
040:        public class AutoloadTest extends BaseJDBCTestCase {
041:            /////////////////////////////////////////////////////////////
042:            //
043:            //	CONSTANTS
044:            //
045:            /////////////////////////////////////////////////////////////
046:
047:            private static final String NONEXISTENT_DATABASE = "nonexistentDatabase";
048:
049:            /////////////////////////////////////////////////////////////
050:            //
051:            //	STATE
052:            //
053:            /////////////////////////////////////////////////////////////
054:
055:            /////////////////////////////////////////////////////////////
056:            //
057:            //	CONSTRUCTOR
058:            //
059:            /////////////////////////////////////////////////////////////
060:
061:            public AutoloadTest(String name) {
062:                super (name);
063:            }
064:
065:            /////////////////////////////////////////////////////////////
066:            //
067:            //	ENTRY POINT
068:            //
069:            /////////////////////////////////////////////////////////////
070:
071:            /////////////////////////////////////////////////////////////
072:            //
073:            //	JUnit BEHAVIOR
074:            //
075:            /////////////////////////////////////////////////////////////
076:
077:            /**
078:             * Only run a test if the driver will be auto-loaded.
079:             */
080:            public static Test suite() {
081:                TestSuite suite = new TestSuite();
082:
083:                // need DriverManager at least and Derby drivers
084:                // no interest in testing DB2's client.
085:                if (JDBC.vmSupportsJDBC2()
086:                        && (usingEmbedded() || usingDerbyNetClient())) {
087:
088:                    boolean autoloadingCurrentDriver = false;
089:
090:                    // Autoloading if the current driver is defined in the
091:                    // system property jdbc.drivers, see java.sql.DriverManager.
092:                    try {
093:                        String jdbcDrivers = getSystemProperty("jdbc.drivers");
094:                        if (jdbcDrivers != null) {
095:                            // Simple test to see if the driver class is
096:                            // in the value. Could get fancy and see if it is
097:                            // correctly formatted but not worth it.
098:                            String driver = TestConfiguration.getCurrent()
099:                                    .getJDBCClient().getJDBCDriverName();
100:
101:                            if (jdbcDrivers.indexOf(driver) != -1)
102:                                autoloadingCurrentDriver = true;
103:                        }
104:
105:                    } catch (SecurityException e) {
106:                        // can't read property, assume not autoloading.
107:                    }
108:
109:                    // Also auto loading if this is JDBC 4 and loading from the
110:                    // jar files, due to the required manifest entry.
111:                    if (JDBC.vmSupportsJDBC4()
112:                            && TestConfiguration.loadingFromJars())
113:                        autoloadingCurrentDriver = true;
114:
115:                    if (autoloadingCurrentDriver)
116:                        suite.addTestSuite(AutoloadTest.class);
117:
118:                }
119:
120:                return suite;
121:            }
122:
123:            /////////////////////////////////////////////////////////////
124:            //
125:            //	TEST ENTRY POINTS
126:            //
127:            /////////////////////////////////////////////////////////////
128:
129:            /**
130:             * <p>
131:             * Tests the autoloading of the client driver by JDBC 4. This behavior
132:             * is described in section 10.2.1 of the JDBC 4 spec. The driver is
133:             * autoloaded if we are running under jdk1.6 or later and one of the
134:             * following is true:
135:             * </p>
136:             *
137:             * <ul>
138:             * <li>Classes are being loaded out of the Derby jar files.</li>
139:             * <li>OR the system property jdbc.drivers names the drivers.</li>
140:             * </ul>
141:             */
142:            public void testAutoloading() throws Exception {
143:                //CONFIG.setVerbosity( true );
144:
145:                //
146:                // We expect that the connection to the database will fail for
147:                // one reason or another.
148:                //
149:
150:                println("We ARE autoloading...");
151:
152:                //
153:                // The DriverManager should have autoloaded the client driver.
154:                // This means that the connection request is passed on to the
155:                // server. The server then determines that the database does
156:                // not exist. This raises a different error depending on whether
157:                // we're running embedded or with the Derby client.
158:                //
159:                String expectedError = usingEmbedded() ? "XJ004" : "08004";
160:
161:                failToConnect(expectedError);
162:
163:                // Test we can connect successfully to a database!
164:                String url = getTestConfiguration().getJDBCUrl();
165:                url = url.concat(";create=true");
166:                String user = getTestConfiguration().getUserName();
167:                String password = getTestConfiguration().getUserPassword();
168:                DriverManager.getConnection(url, user, password).close();
169:
170:            }
171:
172:            /**
173:             * <p>
174:             * Verify that we fail to connect to the database for the expected
175:             * reason.
176:             * </p>
177:             */
178:            private void failToConnect(String expectedSQLState)
179:                    throws Exception {
180:                String connectionURL = getTestConfiguration().getJDBCUrl(
181:                        NONEXISTENT_DATABASE);
182:                Properties properties = new Properties();
183:                SQLException se = null;
184:
185:                properties.put("user", getTestConfiguration().getUserName());
186:                properties.put("password", getTestConfiguration()
187:                        .getUserPassword());
188:
189:                try {
190:                    println("Attempting to connect with this URL: '"
191:                            + connectionURL + "'");
192:
193:                    DriverManager.getConnection(connectionURL, properties);
194:
195:                    fail("Connection succeed, expected to fail.");
196:                } catch (SQLException e) {
197:                    se = e;
198:                }
199:
200:                println("Caught expected SQLException: " + se);
201:
202:                assertSQLState(expectedSQLState, expectedSQLState, se);
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.