1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.sdbc; 29 30 import lib.MultiMethodTest; 31 import lib.Status; 32 import lib.StatusException; 33 34 import com.sun.star.beans.PropertyValue; 35 import com.sun.star.sdbc.XConnection; 36 import com.sun.star.sdbc.XDriverManager; 37 38 /** 39 * Testing <code>com.sun.star.sdbc.XDriverManager</code> 40 * interface methods : 41 * <ul> 42 * <li><code> getConnection()</code></li> 43 * <li><code> getConnectionWithInfo()</code></li> 44 * <li><code> setLoginTimeout()</code></li> 45 * <li><code> getLoginTimeout()</code></li> 46 * </ul> <p> 47 * Required object relations : 48 * <ul> 49 * <li> <code>'SDBC.URL'</code>: 50 * is the URL of the database to which to connect using sdbc-driver 51 * </code></li> 52 * <li> <code>'JDBC.URL'</code>: 53 * is the URL of the database to which to connect using jdbc-driver 54 * </code></li> 55 * <li> <code>'JDBC.INFO'</code> of type <code>PropertyValue[]</code>: 56 * a list of arbitrary string tag/value pairs as connection arguments; 57 * normally at least a "user" and "password" property should be included 58 * </code></li> 59 * </ul> <p> 60 * @see com.sun.star.sdbc.XDriverManager 61 */ 62 public class _XDriverManager extends MultiMethodTest { 63 // oObj filled by MultiMethodTest 64 public XDriverManager oObj = null; 65 String sdbcURL = null; 66 String jdbcURL = null; 67 PropertyValue[] jdbcINFO = null; 68 69 /** 70 * Retrieves the required object relations. 71 */ 72 protected void before() { 73 sdbcURL = (String)tEnv.getObjRelation("SDBC.URL"); 74 if (sdbcURL == null) { 75 throw new StatusException( 76 Status.failed("Couldn't get relation 'SDBC.URL'")); 77 } 78 jdbcURL = (String)tEnv.getObjRelation("JDBC.URL"); 79 if (jdbcURL == null) { 80 throw new StatusException( 81 Status.failed("Couldn't get relation 'JDBC.URL'")); 82 } 83 jdbcINFO = (PropertyValue[])tEnv.getObjRelation("JDBC.INFO"); 84 if (jdbcINFO == null) { 85 throw new StatusException( 86 Status.failed("Couldn't get relation 'JDBC.INFO'")); 87 } 88 } 89 90 /** 91 * Calls the method with the url received from the relation 92 * <code>SDBC.URL</code>. 93 * Has OK status if exception wasn't thrown and 94 * if returned value isn't null. 95 */ 96 public void _getConnection() { 97 boolean res = true; 98 99 try { 100 log.println("getConnection(" + sdbcURL + ")"); 101 XConnection connection = oObj.getConnection(sdbcURL); 102 res = connection != null; 103 } catch(com.sun.star.sdbc.SQLException e) { 104 log.println("Unexpected exception"); 105 e.printStackTrace(log); 106 res = false; 107 } 108 109 tRes.tested("getConnection()", res); 110 } 111 112 /** 113 * Calls the method with the url received from the relation 114 * <code>JDBC.URL</code> and with info received from the relation 115 * <code>JDBC.INFO</code>. 116 * Has OK status if exception wasn't thrown and 117 * if returned value isn't null. 118 */ 119 public void _getConnectionWithInfo() { 120 boolean res = true; 121 122 try { 123 log.println("getConnectionWithInfo(" + jdbcURL + ")"); 124 XConnection connection = 125 oObj.getConnectionWithInfo(jdbcURL, jdbcINFO); 126 res = connection != null; 127 } catch(com.sun.star.sdbc.SQLException e) { 128 log.println("Unexpected exception"); 129 e.printStackTrace(log); 130 res = false; 131 } 132 133 tRes.tested("getConnectionWithInfo()", res); 134 } 135 136 /** 137 * Calls the method and checks returned value. 138 * Has OK status if timeout that was set and timeout that was returned by 139 * the method <code>getLoginTimeout()</code> are equal. 140 */ 141 public void _setLoginTimeout() { 142 requiredMethod("getLoginTimeout()"); 143 final int TO = 111; 144 log.println("setLoginTimeout(" + TO + ")"); 145 oObj.setLoginTimeout(TO); 146 int timeout = oObj.getLoginTimeout(); 147 log.println("getLoginTimeout(): " + timeout); 148 tRes.tested("setLoginTimeout()", timeout == TO); 149 } 150 151 /** 152 * Calls the method. 153 */ 154 public void _getLoginTimeout() { 155 int timeout = oObj.getLoginTimeout(); 156 log.println("getLoginTimeout(): " + timeout); 157 158 tRes.tested("getLoginTimeout()", true); 159 } 160 }