1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDataDefinitionSupplier.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import lib
.StatusException
;
37 import com
.sun
.star
.beans
.PropertyValue
;
38 import com
.sun
.star
.sdbc
.XConnection
;
39 import com
.sun
.star
.sdbc
.XDriver
;
40 import com
.sun
.star
.sdbcx
.XDataDefinitionSupplier
;
41 import com
.sun
.star
.sdbcx
.XTablesSupplier
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
45 * Testing <code>com.sun.star.sdbcx.XDataDefinitionSupplier</code>
48 * <li><code> getDataDefinitionByConnection()</code></li>
49 * <li><code> getDataDefinitionByURL()</code></li>
51 * Required object relations :
53 * <li> <code>'XDriver.URL'</code>:
54 * is the URL of the database to which to connect</code></li>
55 * <li><code>'XDriver.UNSUITABLE_URL'</code>:
56 * the wrong kind of URL to connect using given driver</li>
57 * <li><code>'XDriver.INFO'</code>:
58 * a list of arbitrary string tag/value pairs as connection arguments</li>
60 * @see com.sun.star.sdbcx.XDataDefinitionSupplier
62 public class _XDataDefinitionSupplier
extends MultiMethodTest
{
64 // oObj filled by MultiMethodTest
65 public XDataDefinitionSupplier oObj
= null ;
68 String wrongUrl
= null;
69 PropertyValue
[] info
= null;
72 * Retrieves relations.
73 * @throw StatusException If any relation not found.
75 protected void before() {
76 url
= (String
)tEnv
.getObjRelation("XDriver.URL");
78 throw new StatusException(Status
.failed(
79 "Couldn't get relation 'XDriver.URL'"));
81 wrongUrl
= (String
)tEnv
.getObjRelation("XDriver.UNSUITABLE_URL");
82 if (wrongUrl
== null) {
83 throw new StatusException(Status
.failed(
84 "Couldn't get relation 'XDriver.WRONG_URL'"));
86 info
= (PropertyValue
[])tEnv
.getObjRelation("XDriver.INFO");
88 throw new StatusException(Status
.failed(
89 "Couldn't get relation 'XDriver.INFO'"));
93 XConnection connection
= null;
96 * Obtains the connection to url(relation <code>'XDriver.URL'</code>)
97 * with info(relation <code>'XDriver.INFO'</code>).
98 * Calls the method with obtained connection and checks that returned value
101 public void _getDataDefinitionByConnection() {
103 XDriver xDriver
= (XDriver
)
104 UnoRuntime
.queryInterface(XDriver
.class, oObj
);
105 if (xDriver
== null) {
106 log
.println("The XDriver interface isn't supported");
107 tRes
.tested("getDataDefinitionByConnection()",
108 Status
.skipped(false));
112 connection
= xDriver
.connect(url
, info
);
113 } catch(com
.sun
.star
.sdbc
.SQLException e
) {
114 e
.printStackTrace(log
);
117 if (connection
== null) {
118 log
.println("Couldn't get connection to specified url using " +
120 tRes
.tested("getDataDefinitionByConnection()",
121 Status
.skipped(false));
124 XTablesSupplier xTS
= null;
126 log
.println("getDataDefinitionByConnection(connection)");
127 xTS
= oObj
.getDataDefinitionByConnection(connection
);
129 } catch(com
.sun
.star
.sdbc
.SQLException e
) {
130 log
.println("Unexpected exception: " + e
);
135 log
.println("getDataDefinitionByConnection(null)");
136 xTS
= oObj
.getDataDefinitionByConnection(null);
138 } catch(com
.sun
.star
.sdbc
.SQLException e
) {
139 log
.println("Exception: " + e
);
143 tRes
.tested("getDataDefinitionByConnection()", bRes
);
147 * Calls the method with url and info obtained from the relations
148 * <code>XDriver.URL</code> and <code>XDriver.INFO</code>.
149 * Checks that retuned value isn't null.
150 * Then calls the method with the unsuitable url obtained from the relation
151 * <code>XDriver.UNSUITABLE_URL</code> and checks that SQLException
152 * exception was thrown.
154 public void _getDataDefinitionByURL() {
155 boolean bRes
= false;
156 XTablesSupplier xTS
= null;
159 log
.println("getDataDefinitionByURL('" + url
+ "')");
160 xTS
= oObj
.getDataDefinitionByURL(url
, info
);
162 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
163 log
.println("Unexpected exception: " + e
);
168 log
.println("getDataDefinitionByURL('" + wrongUrl
+ "')");
169 xTS
= oObj
.getDataDefinitionByURL(wrongUrl
, info
);
170 log
.println("Exception was expected");
172 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
173 log
.println("Expected exception");
177 tRes
.tested("getDataDefinitionByURL()", true);
180 } // finish class _XDataDefinitionSupplier