Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XDriver.java
blob4b0eb147f2ff846ffec89724af68ab2c8b151a7a
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.DriverPropertyInfo;
27 import com.sun.star.sdbc.SQLException;
28 import com.sun.star.sdbc.XConnection;
29 import com.sun.star.sdbc.XDriver;
31 /**
32 * Testing <code>com.sun.star.sdbc.XDriver</code>
33 * interface methods :
34 * <ul>
35 * <li><code> connect()</code></li>
36 * <li><code> acceptsURL()</code></li>
37 * <li><code> getPropertyInfo()</code></li>
38 * <li><code> getMajorVersion()</code></li>
39 * <li><code> getMinorVersion()</code></li>
40 * </ul> <p>
41 * Required object relations :
42 * <ul>
43 * <li> <code>'XDriver.URL'</code>:
44 * is the URL of the database to which to connect</code></li>
45 * <li><code>'XDriver.UNSUITABLE_URL'</code>:
46 * the wrong kind of URL to connect using given driver</li>
47 * <li><code>'XDriver.INFO'</code>:
48 * a list of arbitrary string tag/value pairs as connection arguments</li>
49 * </ul> <p>
50 * @see com.sun.star.sdbc.XDriver
52 public class _XDriver extends MultiMethodTest {
53 // oObj filled by MultiMethodTest
54 public XDriver oObj = null;
55 String url = null;
56 String wrongUrl = null;
57 String nbu = null;
58 PropertyValue[] info = null;
60 /**
61 * Retrieves relations.
62 * @throw StatusException If any relation not found.
64 @Override
65 protected void before() {
66 nbu = (String) tEnv.getObjRelation("NoBadURL");
67 url = (String)tEnv.getObjRelation("XDriver.URL");
68 if (url == null) {
69 throw new StatusException(Status.failed(
70 "Couldn't get relation 'XDriver.URL'"));
72 wrongUrl = (String)tEnv.getObjRelation("XDriver.UNSUITABLE_URL");
73 if (wrongUrl == null) {
74 throw new StatusException(Status.failed(
75 "Couldn't get relation 'XDriver.WRONG_URL'"));
77 info = (PropertyValue[])tEnv.getObjRelation("XDriver.INFO");
78 if (info == null) {
79 throw new StatusException(Status.failed(
80 "Couldn't get relation 'XDriver.INFO'"));
84 /**
85 * Connects to <code>'XDriver.URL'</code>,
86 * to <code>'XDriver.UNSUITABLE_URL'</code> and to wrong URL using
87 * <code>'XDriver.INFO'</code>.
88 * Has OK status if the method returns not null for <code>'XDriver.URL'</code>,
89 * null for <code>'XDriver.UNSUITABLE_URL'</code> and
90 * exception was thrown during the call with a wrong URL.
92 public void _connect() {
93 boolean res = true;
95 try {
96 log.println("Trying to connect to " + url);
97 XConnection connection = oObj.connect(url, info);
98 res = (connection != null);
99 log.println("Connected? " + res);
100 log.println("Trying to connect to " + wrongUrl);
101 connection = oObj.connect(wrongUrl, info);
102 res &= (connection == null);
103 log.println("Connected? " + !res);
104 } catch(SQLException e) {
105 log.println("Unexpected exception");
106 res &= false;
109 if (nbu==null) {
110 try {
111 String badUrl = url + "bla";
112 log.println("Trying to connect to " + badUrl);
113 oObj.connect(badUrl, info);
114 res &= false;
115 log.println("Expected exception isn't thrown");
116 } catch(SQLException e) {
117 log.println("Expected exception");
118 res &= true;
122 tRes.tested("connect()", res);
126 * Calls the method for <code>'XDriver.URL'</code> and
127 * for <code>'XDriver.UNSUITABLE_URL'</code>.
128 * Has OK status if the method returns true for <code>'XDriver.URL'</code>
129 * and false for <code>'XDriver.UNSUITABLE_URL'</code>.
131 public void _acceptsURL() {
132 boolean res = false;
134 try {
135 res = oObj.acceptsURL(url);
136 log.println("Accepts " + url + "? " + res);
137 res &= !oObj.acceptsURL(wrongUrl);
138 log.println("Accepts " + wrongUrl + "? " + !res);
139 } catch(SQLException e) {
140 log.println("Unexpected exception");
141 e.printStackTrace(log);
142 res = false;
145 tRes.tested("acceptsURL()", res);
149 * Calls the method with passed <code>'XDriver.URL'</code> and
150 * <code>'XDriver.INFO'</code>. Prints obtained driver properties info
151 * to log.
152 * Has OK status if returned value isn't null.
154 public void _getPropertyInfo() {
155 requiredMethod("acceptsURL()");
156 boolean res = false;
157 DriverPropertyInfo[] dpi = null;
158 try {
159 dpi = oObj.getPropertyInfo(url, info);
160 } catch(SQLException e) {
161 log.println("Unexpected exception");
162 e.printStackTrace(log);
163 res = false;
166 if (dpi != null) {
167 res = true;
168 log.println("Driver properties info:");
169 for(int i = 0; i < dpi.length; i++) {
170 log.println("Property: " + dpi[i].Name);
171 log.println("Description: " + dpi[i].Description);
172 log.println("IsRequired? " + dpi[i].IsRequired);
173 log.println("Value: " + dpi[i].Value);
174 log.println("Choices: ");
175 for(int j = 0; j < dpi[i].Choices.length; j++) {
176 log.println("\t" + dpi[i].Choices[j]);
181 tRes.tested("getPropertyInfo()", res);
185 * Calls the method.
186 * Has OK status if returned value is greater than or is equal to 1.
188 public void _getMajorVersion() {
189 int majorVer = oObj.getMajorVersion();
190 boolean res = majorVer >= 1;
191 log.println("Major version " + majorVer);
192 tRes.tested("getMajorVersion()", res);
196 * Calls the method.
197 * Has OK status if returned value is greater than or is equal to 0.
199 public void _getMinorVersion() {
200 int minorVer = oObj.getMinorVersion();
201 boolean res = minorVer >= 0;
202 log.println("Minor version " + minorVer);
203 tRes.tested("getMinorVersion()", res);