bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbcx / _XDataDefinitionSupplier.java
blobe6aad78638a651bf053df01e764dd5ab25dad62b
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.sdbcx;
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.XDriver;
28 import com.sun.star.sdbcx.XDataDefinitionSupplier;
29 import com.sun.star.sdbcx.XTablesSupplier;
30 import com.sun.star.uno.UnoRuntime;
32 /**
33 * Testing <code>com.sun.star.sdbcx.XDataDefinitionSupplier</code>
34 * interface methods :
35 * <ul>
36 * <li><code> getDataDefinitionByConnection()</code></li>
37 * <li><code> getDataDefinitionByURL()</code></li>
38 * </ul> <p>
39 * Required object relations :
40 * <ul>
41 * <li> <code>'XDriver.URL'</code>:
42 * is the URL of the database to which to connect</code></li>
43 * <li><code>'XDriver.UNSUITABLE_URL'</code>:
44 * the wrong kind of URL to connect using given driver</li>
45 * <li><code>'XDriver.INFO'</code>:
46 * a list of arbitrary string tag/value pairs as connection arguments</li>
47 * </ul> <p>
48 * @see com.sun.star.sdbcx.XDataDefinitionSupplier
50 public class _XDataDefinitionSupplier extends MultiMethodTest {
52 // oObj filled by MultiMethodTest
53 public XDataDefinitionSupplier oObj = null ;
55 String url = null;
56 String wrongUrl = null;
57 PropertyValue[] info = null;
59 /**
60 * Retrieves relations.
61 * @throw StatusException If any relation not found.
63 protected void before() {
64 url = (String)tEnv.getObjRelation("XDriver.URL");
65 if (url == null) {
66 throw new StatusException(Status.failed(
67 "Couldn't get relation 'XDriver.URL'"));
69 wrongUrl = (String)tEnv.getObjRelation("XDriver.UNSUITABLE_URL");
70 if (wrongUrl == null) {
71 throw new StatusException(Status.failed(
72 "Couldn't get relation 'XDriver.WRONG_URL'"));
74 info = (PropertyValue[])tEnv.getObjRelation("XDriver.INFO");
75 if (info == null) {
76 throw new StatusException(Status.failed(
77 "Couldn't get relation 'XDriver.INFO'"));
81 XConnection connection = null;
83 /**
84 * Obtains the connection to url(relation <code>'XDriver.URL'</code>)
85 * with info(relation <code>'XDriver.INFO'</code>).
86 * Calls the method with obtained connection and checks that returned value
87 * isn't null.
89 public void _getDataDefinitionByConnection() {
90 boolean bRes = true;
91 XDriver xDriver = UnoRuntime.queryInterface(XDriver.class, oObj);
92 if (xDriver == null) {
93 log.println("The XDriver interface isn't supported");
94 tRes.tested("getDataDefinitionByConnection()",
95 Status.skipped(false));
96 return;
98 try {
99 connection = xDriver.connect(url, info);
100 } catch(com.sun.star.sdbc.SQLException e) {
101 e.printStackTrace(log);
102 bRes = false;
104 if (connection == null) {
105 log.println("Couldn't get connection to specified url using " +
106 "specified info");
107 tRes.tested("getDataDefinitionByConnection()",
108 Status.skipped(false));
109 return;
111 XTablesSupplier xTS = null;
112 try {
113 log.println("getDataDefinitionByConnection(connection)");
114 xTS = oObj.getDataDefinitionByConnection(connection);
115 bRes = xTS != null;
116 } catch(com.sun.star.sdbc.SQLException e) {
117 log.println("Unexpected exception: " + e);
118 bRes = false;
121 try {
122 log.println("getDataDefinitionByConnection(null)");
123 xTS = oObj.getDataDefinitionByConnection(null);
124 bRes = xTS == null;
125 } catch(com.sun.star.sdbc.SQLException e) {
126 log.println("Exception: " + e);
127 bRes = true;
130 tRes.tested("getDataDefinitionByConnection()", bRes);
134 * Calls the method with url and info obtained from the relations
135 * <code>XDriver.URL</code> and <code>XDriver.INFO</code>.
136 * Checks that retuned value isn't null.
137 * Then calls the method with the unsuitable url obtained from the relation
138 * <code>XDriver.UNSUITABLE_URL</code> and checks that SQLException
139 * exception was thrown.
141 public void _getDataDefinitionByURL() {
142 try {
143 log.println("getDataDefinitionByURL('" + url + "')");
144 oObj.getDataDefinitionByURL(url, info);
145 } catch (com.sun.star.sdbc.SQLException e) {
146 log.println("Unexpected exception: " + e);
149 try {
150 log.println("getDataDefinitionByURL('" + wrongUrl + "')");
151 oObj.getDataDefinitionByURL(wrongUrl, info);
152 log.println("Exception was expected");
153 } catch (com.sun.star.sdbc.SQLException e) {
154 log.println("Expected exception");
157 tRes.tested("getDataDefinitionByURL()", true);
160 } // finish class _XDataDefinitionSupplier