Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XDriverManager.java
blob57477b4a718951ec7710e6dc264fe9edd225c08a
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 @Override
64 protected void before() {
65 sdbcURL = (String)tEnv.getObjRelation("SDBC.URL");
66 if (sdbcURL == null) {
67 throw new StatusException(
68 Status.failed("Couldn't get relation 'SDBC.URL'"));
70 jdbcURL = (String)tEnv.getObjRelation("JDBC.URL");
71 if (jdbcURL == null) {
72 throw new StatusException(
73 Status.failed("Couldn't get relation 'JDBC.URL'"));
75 jdbcINFO = (PropertyValue[])tEnv.getObjRelation("JDBC.INFO");
76 if (jdbcINFO == null) {
77 throw new StatusException(
78 Status.failed("Couldn't get relation 'JDBC.INFO'"));
82 /**
83 * Calls the method with the url received from the relation
84 * <code>SDBC.URL</code>.
85 * Has OK status if exception wasn't thrown and
86 * if returned value isn't null.
88 public void _getConnection() {
89 boolean res = true;
91 try {
92 log.println("getConnection(" + sdbcURL + ")");
93 XConnection connection = oObj.getConnection(sdbcURL);
94 res = connection != null;
95 } catch(com.sun.star.sdbc.SQLException e) {
96 log.println("Unexpected exception");
97 e.printStackTrace(log);
98 res = false;
101 tRes.tested("getConnection()", res);
105 * Calls the method with the url received from the relation
106 * <code>JDBC.URL</code> and with info received from the relation
107 * <code>JDBC.INFO</code>.
108 * Has OK status if exception wasn't thrown and
109 * if returned value isn't null.
111 public void _getConnectionWithInfo() {
112 boolean res = true;
114 try {
115 log.println("getConnectionWithInfo(" + jdbcURL + ")");
116 XConnection connection =
117 oObj.getConnectionWithInfo(jdbcURL, jdbcINFO);
118 res = connection != null;
119 } catch(com.sun.star.sdbc.SQLException e) {
120 log.println("Unexpected exception");
121 e.printStackTrace(log);
122 res = false;
125 tRes.tested("getConnectionWithInfo()", res);
129 * Calls the method and checks returned value.
130 * Has OK status if timeout that was set and timeout that was returned by
131 * the method <code>getLoginTimeout()</code> are equal.
133 public void _setLoginTimeout() {
134 requiredMethod("getLoginTimeout()");
135 final int TO = 111;
136 log.println("setLoginTimeout(" + TO + ")");
137 oObj.setLoginTimeout(TO);
138 int timeout = oObj.getLoginTimeout();
139 log.println("getLoginTimeout(): " + timeout);
140 tRes.tested("setLoginTimeout()", timeout == TO);
144 * Calls the method.
146 public void _getLoginTimeout() {
147 int timeout = oObj.getLoginTimeout();
148 log.println("getLoginTimeout(): " + timeout);
150 tRes.tested("getLoginTimeout()", true);