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