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


001:        /*
002:
003:           Derby - Class org.apache.derbyTesting.functionTests.tests.lang.GetPropertyInfoTest
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:        package org.apache.derbyTesting.functionTests.tests.lang;
023:
024:        import java.sql.Connection;
025:        import java.sql.Driver;
026:        import java.sql.DriverManager;
027:        import java.sql.DriverPropertyInfo;
028:        import java.sql.SQLException;
029:        import java.util.Properties;
030:
031:        public class GetPropertyInfoTest {
032:            static String protocol = "jdbc:derby:";
033:            static String url = "EncryptedDB;create=true;dataEncryption=true";
034:            static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
035:
036:            public static void main(String[] args) throws SQLException,
037:                    InterruptedException, Exception {
038:                boolean passed = true;
039:
040:                // adjust URL to compensate for other encryption providers
041:                String provider = System.getProperty("testEncryptionProvider");
042:                if (provider != null) {
043:                    url = "EncryptedDB;create=true;dataEncryption=true;encryptionProvider="
044:                            + provider;
045:                }
046:
047:                System.out.println("Test GetPropertyInfoTest starting");
048:                try {
049:                    Properties info = new Properties();
050:                    Class.forName(driver).newInstance();
051:                    Driver cDriver = DriverManager.getDriver(protocol);
052:                    boolean canConnect = false;
053:
054:                    // Test getPropertyInfo by passing attributes in the
055:                    // url.
056:                    for (int i = 0; i < 2; i++) {
057:                        // In order to check for inadequate properties, we omit the
058:                        // bootPassword and call getPropertyInfo. (bootPassword is
059:                        // required because dataEncryption is true)
060:                        DriverPropertyInfo[] attributes = cDriver
061:                                .getPropertyInfo(protocol + url, info);
062:
063:                        // zero length means a connection attempt can be made
064:                        if (attributes.length == 0) {
065:                            canConnect = true;
066:                            break;
067:                        }
068:
069:                        for (int j = 0; j < attributes.length; j++) {
070:                            System.out.print(attributes[j].name + " - value: "
071:                                    + attributes[j].value);
072:                            // Also check on the other PropertyInfo fields
073:                            String[] choices = attributes[j].choices;
074:                            System.out.print(" - description: "
075:                                    + attributes[j].description
076:                                    + " - required " + attributes[j].required);
077:                            if (choices != null) {
078:                                for (int k = 0; k < choices.length; k++) {
079:                                    System.out.print("     - choices [" + k
080:                                            + "] : " + choices[k]);
081:                                }
082:                                System.out.print("\n");
083:                            } else
084:                                System.out.print(" - choices null \n");
085:                        }
086:
087:                        // Now set bootPassword and call getPropertyInfo again.  
088:                        // This time attribute length should be zero, sice we pass all
089:                        // minimum required properties. 
090:                        url = url + ";bootPassword=db2everyplace";
091:                    }
092:
093:                    if (canConnect == false) {
094:                        System.out
095:                                .println("More attributes are required to connect to the database");
096:                        passed = false;
097:                    } else {
098:                        Connection conn = DriverManager.getConnection(protocol
099:                                + url, info);
100:                        conn.close();
101:                    }
102:
103:                    canConnect = false;
104:
105:                    // Test getPropertyInfo by passing attributes in the
106:                    // Properties array.
107:                    info.put("create", "true");
108:                    info.put("dataEncryption", "true");
109:                    info.put("bootPassword", "db2everyplace");
110:                    // Use alternate encryption provider if necessary.
111:                    if (provider != null) {
112:                        info.put("encryptionProvider", provider);
113:                    }
114:
115:                    for (int i = 0; i < 2; i++) {
116:                        // In order to check for inadequate properties, we omit the
117:                        // database name and call getPropertyInfo. 
118:                        DriverPropertyInfo[] attributes = cDriver
119:                                .getPropertyInfo(protocol, info);
120:
121:                        // zero length means a connection attempt can be made
122:                        if (attributes.length == 0) {
123:                            canConnect = true;
124:                            break;
125:                        }
126:
127:                        for (int j = 0; j < attributes.length; j++) {
128:                            System.out.print(attributes[j].name + " - value: "
129:                                    + attributes[j].value);
130:                            // Also check on the other PropertyInfo fields
131:                            String[] choices = attributes[j].choices;
132:                            System.out.print(" - description: "
133:                                    + attributes[j].description
134:                                    + " - required " + attributes[j].required);
135:                            if (choices != null) {
136:                                for (int k = 0; k < choices.length; k++) {
137:                                    System.out.print("     - choices [" + k
138:                                            + "] : " + choices[k]);
139:                                }
140:                                System.out.print("\n");
141:                            } else
142:                                System.out.print(" - choices null \n");
143:                        }
144:
145:                        // Now set database name and call getPropertyInfo again.  
146:                        // This time attribute length should be zero, sice we pass all
147:                        // minimum required properties. 
148:                        info.put("databaseName", "EncryptedDB1");
149:                    }
150:
151:                    if (canConnect == false) {
152:                        System.out
153:                                .println("More attributes are required to connect to the database");
154:                        passed = false;
155:                    } else {
156:                        Connection conn1 = DriverManager.getConnection(
157:                                protocol, info);
158:                        conn1.close();
159:                    }
160:
161:                } catch (SQLException sqle) {
162:                    passed = false;
163:                    do {
164:                        System.out.println(sqle.getSQLState() + ":"
165:                                + sqle.getMessage());
166:                        sqle = sqle.getNextException();
167:                    } while (sqle != null);
168:                } catch (Throwable e) {
169:                    System.out
170:                            .println("FAIL -- unexpected exception caught in main():\n");
171:                    System.out.println(e.getMessage());
172:                    e.printStackTrace();
173:                    passed = false;
174:                }
175:
176:                if (passed)
177:                    System.out.println("Test GetPropertyInfoTest finished");
178:                else
179:                    System.out.println("Test GetPropertyInfoTest failed");
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.