Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / sdbcx / _XDataDefinitionSupplier.java
blob9c3587910ac38e1373b910a93e678171764d6742
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDataDefinitionSupplier.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package ifc.sdbcx;
33 import lib.MultiMethodTest;
34 import lib.Status;
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;
44 /**
45 * Testing <code>com.sun.star.sdbcx.XDataDefinitionSupplier</code>
46 * interface methods :
47 * <ul>
48 * <li><code> getDataDefinitionByConnection()</code></li>
49 * <li><code> getDataDefinitionByURL()</code></li>
50 * </ul> <p>
51 * Required object relations :
52 * <ul>
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>
59 * </ul> <p>
60 * @see com.sun.star.sdbcx.XDataDefinitionSupplier
62 public class _XDataDefinitionSupplier extends MultiMethodTest {
64 // oObj filled by MultiMethodTest
65 public XDataDefinitionSupplier oObj = null ;
67 String url = null;
68 String wrongUrl = null;
69 PropertyValue[] info = null;
71 /**
72 * Retrieves relations.
73 * @throw StatusException If any relation not found.
75 protected void before() {
76 url = (String)tEnv.getObjRelation("XDriver.URL");
77 if (url == null) {
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");
87 if (info == null) {
88 throw new StatusException(Status.failed(
89 "Couldn't get relation 'XDriver.INFO'"));
93 XConnection connection = null;
95 /**
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
99 * isn't null.
101 public void _getDataDefinitionByConnection() {
102 boolean bRes = true;
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));
109 return;
111 try {
112 connection = xDriver.connect(url, info);
113 } catch(com.sun.star.sdbc.SQLException e) {
114 e.printStackTrace(log);
115 bRes = false;
117 if (connection == null) {
118 log.println("Couldn't get connection to specified url using " +
119 "specified info");
120 tRes.tested("getDataDefinitionByConnection()",
121 Status.skipped(false));
122 return;
124 XTablesSupplier xTS = null;
125 try {
126 log.println("getDataDefinitionByConnection(connection)");
127 xTS = oObj.getDataDefinitionByConnection(connection);
128 bRes = xTS != null;
129 } catch(com.sun.star.sdbc.SQLException e) {
130 log.println("Unexpected exception: " + e);
131 bRes = false;
134 try {
135 log.println("getDataDefinitionByConnection(null)");
136 xTS = oObj.getDataDefinitionByConnection(null);
137 bRes = xTS == null;
138 } catch(com.sun.star.sdbc.SQLException e) {
139 log.println("Exception: " + e);
140 bRes = true;
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;
158 try {
159 log.println("getDataDefinitionByURL('" + url + "')");
160 xTS = oObj.getDataDefinitionByURL(url, info);
161 bRes = xTS != null;
162 } catch (com.sun.star.sdbc.SQLException e) {
163 log.println("Unexpected exception: " + e);
164 bRes = false;
167 try {
168 log.println("getDataDefinitionByURL('" + wrongUrl + "')");
169 xTS = oObj.getDataDefinitionByURL(wrongUrl, info);
170 log.println("Exception was expected");
171 bRes = false;
172 } catch (com.sun.star.sdbc.SQLException e) {
173 log.println("Expected exception");
174 bRes &= true;
177 tRes.tested("getDataDefinitionByURL()", true);
180 } // finish class _XDataDefinitionSupplier