1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDriverManager.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
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
;
42 * Testing <code>com.sun.star.sdbc.XDriverManager</code>
45 * <li><code> getConnection()</code></li>
46 * <li><code> getConnectionWithInfo()</code></li>
47 * <li><code> setLoginTimeout()</code></li>
48 * <li><code> getLoginTimeout()</code></li>
50 * Required object relations :
52 * <li> <code>'SDBC.URL'</code>:
53 * is the URL of the database to which to connect using sdbc-driver
55 * <li> <code>'JDBC.URL'</code>:
56 * is the URL of the database to which to connect using jdbc-driver
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
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;
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'"));
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() {
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
);
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() {
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
);
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()");
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
);
157 public void _getLoginTimeout() {
158 int timeout
= oObj
.getLoginTimeout();
159 log
.println("getLoginTimeout(): " + timeout
);
161 tRes
.tested("getLoginTimeout()", true);