Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbcx / _XDataDefinitionSupplier.java
bloba7c21573956ee29378630af0000c590a13e48305
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 @Override
64 protected void before() {
65 url = (String)tEnv.getObjRelation("XDriver.URL");
66 if (url == null) {
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");
76 if (info == null) {
77 throw new StatusException(Status.failed(
78 "Couldn't get relation 'XDriver.INFO'"));
82 XConnection connection = null;
84 /**
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
88 * isn't null.
90 public void _getDataDefinitionByConnection() {
91 boolean bRes = true;
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));
97 return;
99 try {
100 connection = xDriver.connect(url, info);
101 } catch(com.sun.star.sdbc.SQLException e) {
102 e.printStackTrace(log);
103 bRes = false;
105 if (connection == null) {
106 log.println("Couldn't get connection to specified url using " +
107 "specified info");
108 tRes.tested("getDataDefinitionByConnection()",
109 Status.skipped(false));
110 return;
112 XTablesSupplier xTS = null;
113 try {
114 log.println("getDataDefinitionByConnection(connection)");
115 xTS = oObj.getDataDefinitionByConnection(connection);
116 bRes = xTS != null;
117 } catch(com.sun.star.sdbc.SQLException e) {
118 log.println("Unexpected exception: " + e);
119 bRes = false;
122 try {
123 log.println("getDataDefinitionByConnection(null)");
124 xTS = oObj.getDataDefinitionByConnection(null);
125 bRes = xTS == null;
126 } catch(com.sun.star.sdbc.SQLException e) {
127 log.println("Exception: " + e);
128 bRes = true;
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() {
143 try {
144 log.println("getDataDefinitionByURL('" + url + "')");
145 oObj.getDataDefinitionByURL(url, info);
146 } catch (com.sun.star.sdbc.SQLException e) {
147 log.println("Unexpected exception: " + e);
150 try {
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