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 com
.sun
.star
.sdb
.XSingleSelectQueryAnalyzer
;
22 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.sdb
.XSingleSelectQueryComposer
;
24 import com
.sun
.star
.uno
.UnoRuntime
;
25 import lib
.StatusException
;
27 import com
.sun
.star
.beans
.PropertyValue
;
28 import com
.sun
.star
.container
.XIndexAccess
;
31 * Testing <code>com.sun.star.sdb.XSingleSelectQueryAnalyzer</code>
34 * <li><code>getQuery()</code></li>
35 * <li><code>setQuery()</code></li>
36 * <li><code>getFilter()</code></li>
37 * <li><code>getStructuredFilter()</code></li>
38 * <li><code>getGroup()</code></li>
39 * <li><code>getGroupColumns()</code></li>
40 * <li><code>getHavingClause()</code></li>
41 * <li><code>getStructuredHavingClause()</code></li>
42 * <li><code>getOrder()</code></li>
43 * <li><code>getOrderColumns()</code></li>
46 * @see com.sun.star.sdb.XSingleSelectQueryAnalyzer
48 public class _XSingleSelectQueryAnalyzer
extends MultiMethodTest
{
50 // oObj filled by MultiMethodTest
51 public XSingleSelectQueryAnalyzer oObj
= null ;
53 private String queryString
= "SELECT * FROM \"biblio\"";
55 private XSingleSelectQueryComposer xComposer
= null;
58 * Receives the object relations:
60 * <li><code>XSingleSelectQueryComposer xCompoer</code></li>
62 * @see com.sun.star.sdb.XSingleSelectQueryComposer
64 protected void before() {
66 xComposer
= UnoRuntime
.queryInterface(XSingleSelectQueryComposer
.class,
67 tEnv
.getObjRelation("xComposer"));
69 if (xComposer
== null) {
70 throw new StatusException(Status
.failed(
71 "Couldn't get object relation 'xComposer'. Test must be modified"));
77 * call <code>setQuery()</code> once with valid query, once with invalid
78 * query. Has ok if only on sceond call <code>SQLException</code> was thrwon
80 public void _setQuery() {
83 oObj
.setQuery("This is an invalid SQL query");
84 } catch (com
.sun
.star
.sdbc
.SQLException e
){
85 log
.println("expected Exception. ");
89 oObj
.setQuery(queryString
);
90 } catch (com
.sun
.star
.sdbc
.SQLException e
){
91 log
.println("unexpected Exception: " + e
.toString());
92 tRes
.tested("setQuery()", false);
94 tRes
.tested("setQuery()", true);
98 * checks of the returned value of <code>getQuery()</code>
99 * equals the string which was set by <code>setQuery()</code>
103 * <li><code>setQuery</code></li>
106 public void _getQuery() {
107 this.requiredMethod("setQuery()");
111 res
= oObj
.getQuery().equals(queryString
);
113 tRes
.tested("getQuery()", res
);
118 * Object relation <code>xComposer</code> set a filter. This filter
119 * must returned while calling <code>getFilter</code>
121 public void _getFilter() {
123 String filter
= "\"Identifier\" = 'BOR02b'";
124 xComposer
.setFilter(filter
);
125 tRes
.tested("getFilter()", (oObj
.getFilter().equals(filter
)));
127 } catch (com
.sun
.star
.sdbc
.SQLException e
){
128 log
.println("unexpected Exception: " + e
.toString());
129 tRes
.tested("getFilter()", false);
134 * Object relation <code>xComposer</code> set a complex filter with method
135 . <code>setFilter</code>. Then <code>getStructuredFilter</code> returns a
136 * sequenze of <code>PropertyValue</code> which was set with method
137 * <code>setStructuredFilter</code> from <xComposer>.
138 * Then test has ok status if <getFilter> returns the complex filter.
142 * <li><code>setQuery</code></li>
143 * <li><code>getFilter</code></li>
146 public void _getStructuredFilter() {
147 requiredMethod("setQuery()");
148 requiredMethod("getFilter()");
150 oObj
.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\"");
151 String complexFilter
= "( \"Identifier\" = '1' AND \"Type\" = '4' ) OR ( \"Identifier\" = '2' AND \"Type\" = '5' ) OR ( \"Identifier\" = '3' AND \"Type\" = '6' AND \"Address\" = '7' ) OR ( \"Address\" = '8' ) OR ( \"Type\" = '9' )";
152 xComposer
.setFilter(complexFilter
);
153 PropertyValue
[][] aStructuredFilter
= oObj
.getStructuredFilter();
154 xComposer
.setFilter("");
155 xComposer
.setStructuredFilter(aStructuredFilter
);
156 tRes
.tested("getStructuredFilter()", (oObj
.getFilter().equals(complexFilter
)));
158 } catch (com
.sun
.star
.sdbc
.SQLException e
){
159 log
.println("unexpected Exception: " + e
.toString());
160 tRes
.tested("getStructuredFilter()", false);
161 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
){
162 log
.println("unexpected Exception: " + e
.toString());
163 tRes
.tested("getStructuredFilter()", false);
168 * Object relation <code>xComposer</code> set a goup. This group
169 * must returned while calling <code>getGroup</code>
171 public void _getGroup() {
173 String group
= "\"Identifier\"";
174 xComposer
.setGroup(group
);
175 tRes
.tested("getGroup()", (oObj
.getGroup().equals(group
)));
177 } catch (com
.sun
.star
.sdbc
.SQLException e
){
178 log
.println("unexpected Exception: " + e
.toString());
179 tRes
.tested("getGroup()", false);
184 * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
185 * Test has ok status if returned value is an useable <code>XIndexAccess</code>
187 public void _getGroupColumns() {
189 XIndexAccess xGroupColumns
= oObj
.getGroupColumns();
191 tRes
.tested("getGroupColumns()", (xGroupColumns
!= null &&
192 xGroupColumns
.getCount() == 1 &&
193 xGroupColumns
.getByIndex(0) != null));
195 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
){
196 log
.println("unexpected Exception: " + e
.toString());
197 tRes
.tested("getGroupColumns()", false);
198 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
199 log
.println("unexpected Exception: " + e
.toString());
200 tRes
.tested("getGroupColumns()", false);
205 * Object relation <code>xComposer</code> set a clause. This clause
206 * must returned while calling <code>getHavingClause</code>
208 public void _getHavingClause() {
210 String clause
= "\"Identifier\" = 'BOR02b'";
211 xComposer
.setHavingClause(clause
);
212 tRes
.tested("getHavingClause()", (
213 oObj
.getHavingClause().equals(clause
)));
215 } catch (com
.sun
.star
.sdbc
.SQLException e
){
216 log
.println("unexpected Exception: " + e
.toString());
217 tRes
.tested("getHavingClause()", false);
222 * Object relation <code>xComposer</code> set a clause. This clause
223 * must returned while calling <code>getHavingClause</code>
227 * <li><code>setQuery</code></li>
228 * <li><code>getFilter</code></li>
229 * <li><code>getStructuredFilter</code></li>
232 public void _getStructuredHavingClause() {
233 requiredMethod("setQuery()");
234 requiredMethod("getFilter()");
235 executeMethod("getStructuredFilter()");
236 String complexFilter
= "( \"Identifier\" = '1' AND \"Type\" = '4' ) OR ( \"Identifier\" = '2' AND \"Type\" = '5' ) OR ( \"Identifier\" = '3' AND \"Type\" = '6' AND \"Address\" = '7' ) OR ( \"Address\" = '8' ) OR ( \"Type\" = '9' )";
239 xComposer
.setHavingClause(complexFilter
);
240 PropertyValue
[][] aStructuredHaving
= oObj
.getStructuredHavingClause();
241 xComposer
.setHavingClause("");
242 xComposer
.setStructuredHavingClause(aStructuredHaving
);
243 tRes
.tested("getStructuredHavingClause()",
244 (oObj
.getHavingClause().equals(complexFilter
)));
246 } catch (com
.sun
.star
.sdbc
.SQLException e
){
247 log
.println("unexpected Exception: " + e
.toString());
248 tRes
.tested("getStructuredHavingClause()", false);
253 * Object relation <code>xComposer</code> set an order. This order
254 * must returned while calling <code>getOrder</code>
256 public void _getOrder() {
258 String order
= "\"Identifier\"";
259 xComposer
.setOrder(order
);
260 tRes
.tested("getOrder()", (oObj
.getOrder().equals(order
)));
262 } catch (com
.sun
.star
.sdbc
.SQLException e
){
263 log
.println("unexpected Exception: " + e
.toString());
264 tRes
.tested("getOrder()", false);
269 * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
270 * Test has ok status if returned value is an useable <code>XIndexAccess</code>
272 public void _getOrderColumns() {
274 XIndexAccess xOrderColumns
= oObj
.getOrderColumns();
275 tRes
.tested("getOrderColumns()", (xOrderColumns
!= null &&
276 xOrderColumns
.getCount() == 1 &&
277 xOrderColumns
.getByIndex(0) != null));
279 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
){
280 log
.println("unexpected Exception: " + e
.toString());
281 tRes
.tested("getOrderColumns()", false);
282 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
283 log
.println("unexpected Exception: " + e
.toString());
284 tRes
.tested("getOrderColumns()", false);
289 } // finish class _XSingleSelectQueryAnalyzer