1 21 22 package org.apache.derbyTesting.functionTests.tests.lang; 23 24 import java.sql.Connection ; 25 import java.sql.Driver ; 26 import java.sql.DriverManager ; 27 import java.sql.DriverPropertyInfo ; 28 import java.sql.SQLException ; 29 import java.util.Properties ; 30 31 32 public class GetPropertyInfoTest 33 { 34 static String protocol = "jdbc:derby:"; 35 static String url = "EncryptedDB;create=true;dataEncryption=true"; 36 static String driver = "org.apache.derby.jdbc.EmbeddedDriver"; 37 38 public static void main(String [] args) throws SQLException , 39 InterruptedException , Exception 40 { 41 boolean passed = true; 42 43 String provider = System.getProperty("testEncryptionProvider"); 45 if (provider != null) 46 { 47 url = "EncryptedDB;create=true;dataEncryption=true;encryptionProvider=" + provider; 48 } 49 50 System.out.println("Test GetPropertyInfoTest starting"); 51 try 52 { 53 Properties info = new Properties (); 54 Class.forName(driver).newInstance(); 55 Driver cDriver = DriverManager.getDriver(protocol); 56 boolean canConnect = false; 57 58 for(int i = 0; i < 2; i++) 61 { 62 DriverPropertyInfo [] attributes = cDriver.getPropertyInfo(protocol+url,info); 66 67 if (attributes.length == 0) 69 { 70 canConnect = true; 71 break; 72 } 73 74 for (int j = 0; j < attributes.length; j++) 75 { 76 System.out.print(attributes[j].name + " - value: " + attributes[j].value); 77 String [] choices = attributes[j].choices; 79 System.out.print(" - description: " 80 + attributes[j].description + 81 " - required " + attributes[j].required); 82 if (choices != null) 83 { 84 for (int k = 0; k < choices.length; k++) 85 { 86 System.out.print(" - choices [" + k + "] : " + choices[k]); 87 } 88 System.out.print("\n"); 89 } 90 else 91 System.out.print(" - choices null \n"); 92 } 93 94 url = url + ";bootPassword=db2everyplace"; 98 } 99 100 if(canConnect == false) 101 { 102 System.out.println("More attributes are required to connect to the database"); 103 passed = false; 104 } 105 else 106 { 107 Connection conn = DriverManager.getConnection(protocol + url, info); 108 conn.close(); 109 } 110 111 canConnect = false; 112 113 info.put("create", "true"); 116 info.put("dataEncryption", "true"); 117 info.put("bootPassword", "db2everyplace"); 118 if (provider != null) 120 { 121 info.put("encryptionProvider", provider); 122 } 123 124 for(int i = 0; i < 2; i++) 125 { 126 DriverPropertyInfo [] attributes = cDriver.getPropertyInfo(protocol,info); 129 130 if (attributes.length == 0) 132 { 133 canConnect = true; 134 break; 135 } 136 137 for (int j = 0; j < attributes.length; j++) 138 { 139 System.out.print(attributes[j].name + " - value: " + attributes[j].value); 140 String [] choices = attributes[j].choices; 142 System.out.print(" - description: " 143 + attributes[j].description + 144 " - required " + attributes[j].required); 145 if (choices != null) 146 { 147 for (int k = 0; k < choices.length; k++) 148 { 149 System.out.print(" - choices [" + k + "] : " + choices[k]); 150 } 151 System.out.print("\n"); 152 } 153 else 154 System.out.print(" - choices null \n"); 155 } 156 157 info.put("databaseName", "EncryptedDB1"); 161 } 162 163 if(canConnect == false) 164 { 165 System.out.println("More attributes are required to connect to the database"); 166 passed = false; 167 } 168 else 169 { 170 Connection conn1 = DriverManager.getConnection(protocol, info); 171 conn1.close(); 172 } 173 174 } 175 catch(SQLException sqle) 176 { 177 passed = false; 178 do { 179 System.out.println(sqle.getSQLState() + ":" + sqle.getMessage()); 180 sqle = sqle.getNextException(); 181 } while (sqle != null); 182 } 183 catch (Throwable e) 184 { 185 System.out.println("FAIL -- unexpected exception caught in main():\n"); 186 System.out.println(e.getMessage()); 187 e.printStackTrace(); 188 passed = false; 189 } 190 191 if(passed) 192 System.out.println("Test GetPropertyInfoTest finished"); 193 else 194 System.out.println("Test GetPropertyInfoTest failed"); 195 } 196 } 197 198 199 200 201 202 203 204 205 206 207 208 | Popular Tags |