1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.sdbc; 25 26 import lib.MultiMethodTest; 27 import lib.Status; 28 import lib.StatusException; 29 30 import com.sun.star.beans.PropertyValue; 31 import com.sun.star.sdbc.XConnection; 32 import com.sun.star.sdbc.XDriverManager; 33 34 /** 35 * Testing <code>com.sun.star.sdbc.XDriverManager</code> 36 * interface methods : 37 * <ul> 38 * <li><code> getConnection()</code></li> 39 * <li><code> getConnectionWithInfo()</code></li> 40 * <li><code> setLoginTimeout()</code></li> 41 * <li><code> getLoginTimeout()</code></li> 42 * </ul> <p> 43 * Required object relations : 44 * <ul> 45 * <li> <code>'SDBC.URL'</code>: 46 * is the URL of the database to which to connect using sdbc-driver 47 * </code></li> 48 * <li> <code>'JDBC.URL'</code>: 49 * is the URL of the database to which to connect using jdbc-driver 50 * </code></li> 51 * <li> <code>'JDBC.INFO'</code> of type <code>PropertyValue[]</code>: 52 * a list of arbitrary string tag/value pairs as connection arguments; 53 * normally at least a "user" and "password" property should be included 54 * </code></li> 55 * </ul> <p> 56 * @see com.sun.star.sdbc.XDriverManager 57 */ 58 public class _XDriverManager extends MultiMethodTest { 59 // oObj filled by MultiMethodTest 60 public XDriverManager oObj = null; 61 String sdbcURL = null; 62 String jdbcURL = null; 63 PropertyValue[] jdbcINFO = null; 64 65 /** 66 * Retrieves the required object relations. 67 */ before()68 protected void before() { 69 sdbcURL = (String)tEnv.getObjRelation("SDBC.URL"); 70 if (sdbcURL == null) { 71 throw new StatusException( 72 Status.failed("Couldn't get relation 'SDBC.URL'")); 73 } 74 jdbcURL = (String)tEnv.getObjRelation("JDBC.URL"); 75 if (jdbcURL == null) { 76 throw new StatusException( 77 Status.failed("Couldn't get relation 'JDBC.URL'")); 78 } 79 jdbcINFO = (PropertyValue[])tEnv.getObjRelation("JDBC.INFO"); 80 if (jdbcINFO == null) { 81 throw new StatusException( 82 Status.failed("Couldn't get relation 'JDBC.INFO'")); 83 } 84 } 85 86 /** 87 * Calls the method with the url received from the relation 88 * <code>SDBC.URL</code>. 89 * Has OK status if exception wasn't thrown and 90 * if returned value isn't null. 91 */ _getConnection()92 public void _getConnection() { 93 boolean res = true; 94 95 try { 96 log.println("getConnection(" + sdbcURL + ")"); 97 XConnection connection = oObj.getConnection(sdbcURL); 98 res = connection != null; 99 } catch(com.sun.star.sdbc.SQLException e) { 100 log.println("Unexpected exception"); 101 e.printStackTrace(log); 102 res = false; 103 } 104 105 tRes.tested("getConnection()", res); 106 } 107 108 /** 109 * Calls the method with the url received from the relation 110 * <code>JDBC.URL</code> and with info received from the relation 111 * <code>JDBC.INFO</code>. 112 * Has OK status if exception wasn't thrown and 113 * if returned value isn't null. 114 */ _getConnectionWithInfo()115 public void _getConnectionWithInfo() { 116 boolean res = true; 117 118 try { 119 log.println("getConnectionWithInfo(" + jdbcURL + ")"); 120 XConnection connection = 121 oObj.getConnectionWithInfo(jdbcURL, jdbcINFO); 122 res = connection != null; 123 } catch(com.sun.star.sdbc.SQLException e) { 124 log.println("Unexpected exception"); 125 e.printStackTrace(log); 126 res = false; 127 } 128 129 tRes.tested("getConnectionWithInfo()", res); 130 } 131 132 /** 133 * Calls the method and checks returned value. 134 * Has OK status if timeout that was set and timeout that was returned by 135 * the method <code>getLoginTimeout()</code> are equal. 136 */ _setLoginTimeout()137 public void _setLoginTimeout() { 138 requiredMethod("getLoginTimeout()"); 139 final int TO = 111; 140 log.println("setLoginTimeout(" + TO + ")"); 141 oObj.setLoginTimeout(TO); 142 int timeout = oObj.getLoginTimeout(); 143 log.println("getLoginTimeout(): " + timeout); 144 tRes.tested("setLoginTimeout()", timeout == TO); 145 } 146 147 /** 148 * Calls the method. 149 */ _getLoginTimeout()150 public void _getLoginTimeout() { 151 int timeout = oObj.getLoginTimeout(); 152 log.println("getLoginTimeout(): " + timeout); 153 154 tRes.tested("getLoginTimeout()", true); 155 } 156 }