bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XDriverManager.java
blob0b531c03afbf6b0cee60f1be25809a8ea7235715
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.sdbc;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
25 import com.sun.star.beans.PropertyValue;
26 import com.sun.star.sdbc.XConnection;
27 import com.sun.star.sdbc.XDriverManager;
29 /**
30 * Testing <code>com.sun.star.sdbc.XDriverManager</code>
31 * interface methods :
32 * <ul>
33 * <li><code> getConnection()</code></li>
34 * <li><code> getConnectionWithInfo()</code></li>
35 * <li><code> setLoginTimeout()</code></li>
36 * <li><code> getLoginTimeout()</code></li>
37 * </ul> <p>
38 * Required object relations :
39 * <ul>
40 * <li> <code>'SDBC.URL'</code>:
41 * is the URL of the database to which to connect using sdbc-driver
42 * </code></li>
43 * <li> <code>'JDBC.URL'</code>:
44 * is the URL of the database to which to connect using jdbc-driver
45 * </code></li>
46 * <li> <code>'JDBC.INFO'</code> of type <code>PropertyValue[]</code>:
47 * a list of arbitrary string tag/value pairs as connection arguments;
48 * normally at least a "user" and "password" property should be included
49 * </code></li>
50 * </ul> <p>
51 * @see com.sun.star.sdbc.XDriverManager
53 public class _XDriverManager extends MultiMethodTest {
54 // oObj filled by MultiMethodTest
55 public XDriverManager oObj = null;
56 String sdbcURL = null;
57 String jdbcURL = null;
58 PropertyValue[] jdbcINFO = null;
60 /**
61 * Retrieves the required object relations.
63 protected void before() {
64 sdbcURL = (String)tEnv.getObjRelation("SDBC.URL");
65 if (sdbcURL == null) {
66 throw new StatusException(
67 Status.failed("Couldn't get relation 'SDBC.URL'"));
69 jdbcURL = (String)tEnv.getObjRelation("JDBC.URL");
70 if (jdbcURL == null) {
71 throw new StatusException(
72 Status.failed("Couldn't get relation 'JDBC.URL'"));
74 jdbcINFO = (PropertyValue[])tEnv.getObjRelation("JDBC.INFO");
75 if (jdbcINFO == null) {
76 throw new StatusException(
77 Status.failed("Couldn't get relation 'JDBC.INFO'"));
81 /**
82 * Calls the method with the url received from the relation
83 * <code>SDBC.URL</code>.
84 * Has OK status if exception wasn't thrown and
85 * if returned value isn't null.
87 public void _getConnection() {
88 boolean res = true;
90 try {
91 log.println("getConnection(" + sdbcURL + ")");
92 XConnection connection = oObj.getConnection(sdbcURL);
93 res = connection != null;
94 } catch(com.sun.star.sdbc.SQLException e) {
95 log.println("Unexpected exception");
96 e.printStackTrace(log);
97 res = false;
100 tRes.tested("getConnection()", res);
104 * Calls the method with the url received from the relation
105 * <code>JDBC.URL</code> and with info received from the relation
106 * <code>JDBC.INFO</code>.
107 * Has OK status if exception wasn't thrown and
108 * if returned value isn't null.
110 public void _getConnectionWithInfo() {
111 boolean res = true;
113 try {
114 log.println("getConnectionWithInfo(" + jdbcURL + ")");
115 XConnection connection =
116 oObj.getConnectionWithInfo(jdbcURL, jdbcINFO);
117 res = connection != null;
118 } catch(com.sun.star.sdbc.SQLException e) {
119 log.println("Unexpected exception");
120 e.printStackTrace(log);
121 res = false;
124 tRes.tested("getConnectionWithInfo()", res);
128 * Calls the method and checks returned value.
129 * Has OK status if timeout that was set and timeout that was returned by
130 * the method <code>getLoginTimeout()</code> are equal.
132 public void _setLoginTimeout() {
133 requiredMethod("getLoginTimeout()");
134 final int TO = 111;
135 log.println("setLoginTimeout(" + TO + ")");
136 oObj.setLoginTimeout(TO);
137 int timeout = oObj.getLoginTimeout();
138 log.println("getLoginTimeout(): " + timeout);
139 tRes.tested("setLoginTimeout()", timeout == TO);
143 * Calls the method.
145 public void _getLoginTimeout() {
146 int timeout = oObj.getLoginTimeout();
147 log.println("getLoginTimeout(): " + timeout);
149 tRes.tested("getLoginTimeout()", true);