1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import lib
.StatusException
;
34 import com
.sun
.star
.beans
.PropertyValue
;
35 import com
.sun
.star
.sdbc
.XConnection
;
36 import com
.sun
.star
.sdbc
.XDriverManager
;
39 * Testing <code>com.sun.star.sdbc.XDriverManager</code>
42 * <li><code> getConnection()</code></li>
43 * <li><code> getConnectionWithInfo()</code></li>
44 * <li><code> setLoginTimeout()</code></li>
45 * <li><code> getLoginTimeout()</code></li>
47 * Required object relations :
49 * <li> <code>'SDBC.URL'</code>:
50 * is the URL of the database to which to connect using sdbc-driver
52 * <li> <code>'JDBC.URL'</code>:
53 * is the URL of the database to which to connect using jdbc-driver
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
60 * @see com.sun.star.sdbc.XDriverManager
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;
70 * Retrieves the required object relations.
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'"));
78 jdbcURL
= (String
)tEnv
.getObjRelation("JDBC.URL");
79 if (jdbcURL
== null) {
80 throw new StatusException(
81 Status
.failed("Couldn't get relation 'JDBC.URL'"));
83 jdbcINFO
= (PropertyValue
[])tEnv
.getObjRelation("JDBC.INFO");
84 if (jdbcINFO
== null) {
85 throw new StatusException(
86 Status
.failed("Couldn't get relation 'JDBC.INFO'"));
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.
96 public void _getConnection() {
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
);
109 tRes
.tested("getConnection()", res
);
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.
119 public void _getConnectionWithInfo() {
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
);
133 tRes
.tested("getConnectionWithInfo()", res
);
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.
141 public void _setLoginTimeout() {
142 requiredMethod("getLoginTimeout()");
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
);
154 public void _getLoginTimeout() {
155 int timeout
= oObj
.getLoginTimeout();
156 log
.println("getLoginTimeout(): " + timeout
);
158 tRes
.tested("getLoginTimeout()", true);