Source Code Cross Referenced for TestHelper_DriverManager.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » sql » tests » java » sql » 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 » Apache Harmony Java SE » org package » org.apache.harmony.sql.tests.java.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.harmony.sql.tests.java.sql;
019:
020:        import java.sql.Driver;
021:        import java.sql.DriverManager;
022:        import java.sql.SQLException;
023:
024:        import junit.framework.TestCase;
025:
026:        /**
027:         * Helper class for the Driver manager tes - it allows the test code to be
028:         * loaded under a different classloader, necessary for testing the
029:         * DeregisterDriver function of DriverManager
030:         * 
031:         */
032:        public class TestHelper_DriverManager extends TestCase {
033:
034:            static Driver testDriver = null;
035:
036:            static TestHelper_DriverManager theHelper;
037:
038:            static {
039:                theHelper = new TestHelper_DriverManager();
040:                // theHelper.testDeregister();
041:            } // end static
042:
043:            public TestHelper_DriverManager() {
044:                super ();
045:            } // end constructor TestHelper_DriverManager()
046:
047:            public static void setDriver(Driver theDriver) {
048:                testDriver = theDriver;
049:                // System.out.println("TestHelper_DriverManager: Test Driver set!");
050:
051:                theHelper.checkDeregister();
052:            } // end method setDriver( Driver )
053:
054:            public void checkDeregister() {
055:
056:                String baseURL = "jdbc:mikes1";
057:
058:                // System.out.println("Calling checkDeregister in
059:                // TestHelper_DriverManager....");
060:
061:                Driver aDriver;
062:
063:                // System.out.println("checkDeregister classloader: " +
064:                // this.getClass().getClassLoader() );
065:
066:                // Try to get a driver from the general pool... this should fail
067:                try {
068:                    aDriver = DriverManager.getDriver(baseURL);
069:                    fail("testDeregisterDriver: Didn't get exception when getting valid driver from other classloader.");
070:                } catch (SQLException e) {
071:                    // e.printStackTrace();
072:                    assertTrue(
073:                            "testDeregisterDriver: Got exception when getting valid driver from other classloader.",
074:                            true);
075:                    // return;
076:                } // end try
077:
078:                // OK, now THIS driver was loaded by someone else....
079:                aDriver = testDriver;
080:
081:                // printClassLoader( aDriver );
082:
083:                // Deregister this driver
084:                try {
085:                    DriverManager.deregisterDriver(aDriver);
086:                    // We shouldn't get here - but if we do, we need to re-register the
087:                    // driver to
088:                    // prevent subsequent tests from failing due to inability to get to
089:                    // this driver...
090:                    DriverManager.registerDriver(aDriver);
091:                    fail("checkDeregisterDriver: Didn't get Security Exception deregistering invalid driver.");
092:                } catch (SecurityException s) {
093:                    // This is the exception we should get...
094:                    // System.out.println("checkDeregisterDriver: got expected Security
095:                    // Exception");
096:                } catch (Exception e) {
097:                    fail("checkDeregisterDriver: Got wrong exception type when deregistering invalid driver.");
098:                } // end try
099:
100:            } // end method testDeRegister
101:
102:            static void printClassLoader(Object theObject) {
103:                Class<? extends Object> theClass = theObject.getClass();
104:                ClassLoader theClassLoader = theClass.getClassLoader();
105:                System.out.println("ClassLoader is: "
106:                        + theClassLoader.toString() + " for object: "
107:                        + theObject.toString());
108:            } // end method printClassLoader( Object )
109:
110:        } // end class TestHelper_DriverManager
www._ja_v_a_2__s.__c_o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.