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 .
21 import lib
.MultiMethodTest
;
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
;
33 * Testing <code>com.sun.star.sdbcx.XDataDefinitionSupplier</code>
36 * <li><code> getDataDefinitionByConnection()</code></li>
37 * <li><code> getDataDefinitionByURL()</code></li>
39 * Required object relations :
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>
48 * @see com.sun.star.sdbcx.XDataDefinitionSupplier
50 public class _XDataDefinitionSupplier
extends MultiMethodTest
{
52 // oObj filled by MultiMethodTest
53 public XDataDefinitionSupplier oObj
= null ;
56 String wrongUrl
= null;
57 PropertyValue
[] info
= null;
60 * Retrieves relations.
61 * @throw StatusException If any relation not found.
64 protected void before() {
65 url
= (String
)tEnv
.getObjRelation("XDriver.URL");
67 throw new StatusException(Status
.failed(
68 "Couldn't get relation 'XDriver.URL'"));
70 wrongUrl
= (String
)tEnv
.getObjRelation("XDriver.UNSUITABLE_URL");
71 if (wrongUrl
== null) {
72 throw new StatusException(Status
.failed(
73 "Couldn't get relation 'XDriver.WRONG_URL'"));
75 info
= (PropertyValue
[])tEnv
.getObjRelation("XDriver.INFO");
77 throw new StatusException(Status
.failed(
78 "Couldn't get relation 'XDriver.INFO'"));
82 XConnection connection
= null;
85 * Obtains the connection to url(relation <code>'XDriver.URL'</code>)
86 * with info(relation <code>'XDriver.INFO'</code>).
87 * Calls the method with obtained connection and checks that returned value
90 public void _getDataDefinitionByConnection() {
92 XDriver xDriver
= UnoRuntime
.queryInterface(XDriver
.class, oObj
);
93 if (xDriver
== null) {
94 log
.println("The XDriver interface isn't supported");
95 tRes
.tested("getDataDefinitionByConnection()",
96 Status
.skipped(false));
100 connection
= xDriver
.connect(url
, info
);
101 } catch(com
.sun
.star
.sdbc
.SQLException e
) {
102 e
.printStackTrace(log
);
105 if (connection
== null) {
106 log
.println("Couldn't get connection to specified url using " +
108 tRes
.tested("getDataDefinitionByConnection()",
109 Status
.skipped(false));
112 XTablesSupplier xTS
= null;
114 log
.println("getDataDefinitionByConnection(connection)");
115 xTS
= oObj
.getDataDefinitionByConnection(connection
);
117 } catch(com
.sun
.star
.sdbc
.SQLException e
) {
118 log
.println("Unexpected exception: " + e
);
123 log
.println("getDataDefinitionByConnection(null)");
124 xTS
= oObj
.getDataDefinitionByConnection(null);
126 } catch(com
.sun
.star
.sdbc
.SQLException e
) {
127 log
.println("Exception: " + e
);
131 tRes
.tested("getDataDefinitionByConnection()", bRes
);
135 * Calls the method with url and info obtained from the relations
136 * <code>XDriver.URL</code> and <code>XDriver.INFO</code>.
137 * Checks that retuned value isn't null.
138 * Then calls the method with the unsuitable url obtained from the relation
139 * <code>XDriver.UNSUITABLE_URL</code> and checks that SQLException
140 * exception was thrown.
142 public void _getDataDefinitionByURL() {
144 log
.println("getDataDefinitionByURL('" + url
+ "')");
145 oObj
.getDataDefinitionByURL(url
, info
);
146 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
147 log
.println("Unexpected exception: " + e
);
151 log
.println("getDataDefinitionByURL('" + wrongUrl
+ "')");
152 oObj
.getDataDefinitionByURL(wrongUrl
, info
);
153 log
.println("Exception was expected");
154 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
155 log
.println("Expected exception");
158 tRes
.tested("getDataDefinitionByURL()", true);
161 } // finish class _XDataDefinitionSupplier