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 static final 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
65 protected void before() {
67 xComposer
= UnoRuntime
.queryInterface(XSingleSelectQueryComposer
.class,
68 tEnv
.getObjRelation("xComposer"));
70 if (xComposer
== null) {
71 throw new StatusException(Status
.failed(
72 "Couldn't get object relation 'xComposer'. Test must be modified"));
78 * call <code>setQuery()</code> once with valid query, once with invalid
79 * query. Has ok if only on sceond call <code>SQLException</code> was thrwon
81 public void _setQuery() {
84 oObj
.setQuery("This is an invalid SQL query");
85 } catch (com
.sun
.star
.sdbc
.SQLException e
){
86 log
.println("expected Exception. ");
90 oObj
.setQuery(queryString
);
91 } catch (com
.sun
.star
.sdbc
.SQLException e
){
92 log
.println("unexpected Exception: " + e
.toString());
93 tRes
.tested("setQuery()", false);
95 tRes
.tested("setQuery()", true);
99 * checks of the returned value of <code>getQuery()</code>
100 * equals the string which was set by <code>setQuery()</code>
104 * <li><code>setQuery</code></li>
107 public void _getQuery() {
108 this.requiredMethod("setQuery()");
112 res
= oObj
.getQuery().equals(queryString
);
114 tRes
.tested("getQuery()", res
);
119 * Object relation <code>xComposer</code> set a filter. This filter
120 * must returned while calling <code>getFilter</code>
122 public void _getFilter() {
124 String filter
= "\"Identifier\" = 'BOR02b'";
125 xComposer
.setFilter(filter
);
126 tRes
.tested("getFilter()", (oObj
.getFilter().equals(filter
)));
128 } catch (com
.sun
.star
.sdbc
.SQLException e
){
129 log
.println("unexpected Exception: " + e
.toString());
130 tRes
.tested("getFilter()", false);
135 * Object relation <code>xComposer</code> set a complex filter with method
136 . <code>setFilter</code>. Then <code>getStructuredFilter</code> returns a
137 * sequenze of <code>PropertyValue</code> which was set with method
138 * <code>setStructuredFilter</code> from <xComposer>.
139 * Then test has ok status if <getFilter> returns the complex filter.
143 * <li><code>setQuery</code></li>
144 * <li><code>getFilter</code></li>
147 public void _getStructuredFilter() {
148 requiredMethod("setQuery()");
149 requiredMethod("getFilter()");
151 oObj
.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\"");
152 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' )";
153 xComposer
.setFilter(complexFilter
);
154 PropertyValue
[][] aStructuredFilter
= oObj
.getStructuredFilter();
155 xComposer
.setFilter("");
156 xComposer
.setStructuredFilter(aStructuredFilter
);
157 tRes
.tested("getStructuredFilter()", (oObj
.getFilter().equals(complexFilter
)));
159 } catch (com
.sun
.star
.sdbc
.SQLException e
){
160 log
.println("unexpected Exception: " + e
.toString());
161 tRes
.tested("getStructuredFilter()", false);
162 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
){
163 log
.println("unexpected Exception: " + e
.toString());
164 tRes
.tested("getStructuredFilter()", false);
169 * Object relation <code>xComposer</code> set a goup. This group
170 * must returned while calling <code>getGroup</code>
172 public void _getGroup() {
174 String group
= "\"Identifier\"";
175 xComposer
.setGroup(group
);
176 tRes
.tested("getGroup()", (oObj
.getGroup().equals(group
)));
178 } catch (com
.sun
.star
.sdbc
.SQLException e
){
179 log
.println("unexpected Exception: " + e
.toString());
180 tRes
.tested("getGroup()", false);
185 * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
186 * Test has ok status if returned value is an useable <code>XIndexAccess</code>
188 public void _getGroupColumns() {
190 XIndexAccess xGroupColumns
= oObj
.getGroupColumns();
192 tRes
.tested("getGroupColumns()", (xGroupColumns
!= null &&
193 xGroupColumns
.getCount() == 1 &&
194 xGroupColumns
.getByIndex(0) != null));
196 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
){
197 log
.println("unexpected Exception: " + e
.toString());
198 tRes
.tested("getGroupColumns()", false);
199 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
200 log
.println("unexpected Exception: " + e
.toString());
201 tRes
.tested("getGroupColumns()", false);
206 * Object relation <code>xComposer</code> set a clause. This clause
207 * must returned while calling <code>getHavingClause</code>
209 public void _getHavingClause() {
211 String clause
= "\"Identifier\" = 'BOR02b'";
212 xComposer
.setHavingClause(clause
);
213 tRes
.tested("getHavingClause()", (
214 oObj
.getHavingClause().equals(clause
)));
216 } catch (com
.sun
.star
.sdbc
.SQLException e
){
217 log
.println("unexpected Exception: " + e
.toString());
218 tRes
.tested("getHavingClause()", false);
223 * Object relation <code>xComposer</code> set a clause. This clause
224 * must returned while calling <code>getHavingClause</code>
228 * <li><code>setQuery</code></li>
229 * <li><code>getFilter</code></li>
230 * <li><code>getStructuredFilter</code></li>
233 public void _getStructuredHavingClause() {
234 requiredMethod("setQuery()");
235 requiredMethod("getFilter()");
236 executeMethod("getStructuredFilter()");
237 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' )";
240 xComposer
.setHavingClause(complexFilter
);
241 PropertyValue
[][] aStructuredHaving
= oObj
.getStructuredHavingClause();
242 xComposer
.setHavingClause("");
243 xComposer
.setStructuredHavingClause(aStructuredHaving
);
244 tRes
.tested("getStructuredHavingClause()",
245 (oObj
.getHavingClause().equals(complexFilter
)));
247 } catch (com
.sun
.star
.sdbc
.SQLException e
){
248 log
.println("unexpected Exception: " + e
.toString());
249 tRes
.tested("getStructuredHavingClause()", false);
254 * Object relation <code>xComposer</code> set an order. This order
255 * must returned while calling <code>getOrder</code>
257 public void _getOrder() {
259 String order
= "\"Identifier\"";
260 xComposer
.setOrder(order
);
261 tRes
.tested("getOrder()", (oObj
.getOrder().equals(order
)));
263 } catch (com
.sun
.star
.sdbc
.SQLException e
){
264 log
.println("unexpected Exception: " + e
.toString());
265 tRes
.tested("getOrder()", false);
270 * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
271 * Test has ok status if returned value is an useable <code>XIndexAccess</code>
273 public void _getOrderColumns() {
275 XIndexAccess xOrderColumns
= oObj
.getOrderColumns();
276 tRes
.tested("getOrderColumns()", (xOrderColumns
!= null &&
277 xOrderColumns
.getCount() == 1 &&
278 xOrderColumns
.getByIndex(0) != null));
280 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
){
281 log
.println("unexpected Exception: " + e
.toString());
282 tRes
.tested("getOrderColumns()", false);
283 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
284 log
.println("unexpected Exception: " + e
.toString());
285 tRes
.tested("getOrderColumns()", false);
290 } // finish class _XSingleSelectQueryAnalyzer