1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import com
.sun
.star
.sdb
.XSingleSelectQueryAnalyzer
;
31 import lib
.MultiMethodTest
;
32 import com
.sun
.star
.sdb
.XSingleSelectQueryComposer
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import lib
.StatusException
;
36 import com
.sun
.star
.beans
.PropertyValue
;
37 import com
.sun
.star
.container
.XIndexAccess
;
40 * Testing <code>com.sun.star.sdb.XSingleSelectQueryAnalyzer</code>
43 * <li><code>getQuery()</code></li>
44 * <li><code>setQuery()</code></li>
45 * <li><code>getFilter()</code></li>
46 * <li><code>getStructuredFilter()</code></li>
47 * <li><code>getGroup()</code></li>
48 * <li><code>getGroupColumns()</code></li>
49 * <li><code>getHavingClause()</code></li>
50 * <li><code>getStructuredHavingClause()</code></li>
51 * <li><code>getOrder()</code></li>
52 * <li><code>getOrderColumns()</code></li>
55 * @see com.sun.star.sdb.XSingleSelectQueryAnalyzer
57 public class _XSingleSelectQueryAnalyzer
extends MultiMethodTest
{
59 // oObj filled by MultiMethodTest
60 public XSingleSelectQueryAnalyzer oObj
= null ;
62 private String queryString
= "SELECT * FROM \"biblio\"";
64 private XSingleSelectQueryComposer xComposer
= null;
67 * Recieves the object relations:
69 * <li><code>XSingleSelectQueryComposer xCompoer</code></li>
71 * @see om.sun.star.sdb.XSingleSelectQueryComposer
73 protected void before() {
75 xComposer
= (XSingleSelectQueryComposer
)
76 UnoRuntime
.queryInterface(XSingleSelectQueryComposer
.class,
77 tEnv
.getObjRelation("xComposer"));
79 if (xComposer
== null) {
80 throw new StatusException(Status
.failed(
81 "Couldn't get object relation 'xComposer'. Test must be modified"));
87 * call <code>setQuery()</code> once with valid query, once with invalid
88 * query. Has ok if only on sceond call <code>SQLException</code> was thrwon
90 public void _setQuery() {
93 oObj
.setQuery("This is an invalid SQL query");
94 } catch (com
.sun
.star
.sdbc
.SQLException e
){
95 log
.println("expected Exception. ");
99 oObj
.setQuery(queryString
);
100 } catch (com
.sun
.star
.sdbc
.SQLException e
){
101 log
.println("unexpected Exception: " + e
.toString());
102 tRes
.tested("setQuery()", false);
104 tRes
.tested("setQuery()", true);
108 * checks of the returned value of <code>getQuery()</code>
109 * equals the string which was set by <code>setQuery()</code>
113 * <li><code>setQuery</code></li>
116 public void _getQuery() {
117 this.requiredMethod("setQuery()");
121 res
= oObj
.getQuery().equals(queryString
);
123 tRes
.tested("getQuery()", res
);
128 * Object relation <code>xComposer</code> set a filter. This filter
129 * must returned while calling <code>getFilter</code>
131 public void _getFilter() {
133 String filter
= "\"Identifier\" = 'BOR02b'";
134 xComposer
.setFilter(filter
);
135 tRes
.tested("getFilter()", (oObj
.getFilter().equals(filter
)));
137 } catch (com
.sun
.star
.sdbc
.SQLException e
){
138 log
.println("unexpected Exception: " + e
.toString());
139 tRes
.tested("getFilter()", false);
144 * Object relation <code>xComposer</code> set a complex filter with method
145 . <code>setFilter</code>. Then <code>getStructuredFilter</code> returns a
146 * sequenze of <code>PropertyValue</code> which was set with method
147 * <code>setStructuredFilter</code> from <xComposer>.
148 * Then test has ok status if <getFilter> returns the complex filter.
152 * <li><code>setQuery</code></li>
153 * <li><code>getFilter</code></li>
156 public void _getStructuredFilter() {
157 requiredMethod("setQuery()");
158 requiredMethod("getFilter()");
160 oObj
.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\"");
161 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' )";
162 xComposer
.setFilter(complexFilter
);
163 PropertyValue
[][] aStructuredFilter
= oObj
.getStructuredFilter();
164 xComposer
.setFilter("");
165 xComposer
.setStructuredFilter(aStructuredFilter
);
166 tRes
.tested("getStructuredFilter()", (oObj
.getFilter().equals(complexFilter
)));
168 } catch (com
.sun
.star
.sdbc
.SQLException e
){
169 log
.println("unexpected Exception: " + e
.toString());
170 tRes
.tested("getStructuredFilter()", false);
171 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
){
172 log
.println("unexpected Exception: " + e
.toString());
173 tRes
.tested("getStructuredFilter()", false);
178 * Object relation <code>xComposer</code> set a goup. This group
179 * must returned while calling <code>getGroup</code>
181 public void _getGroup() {
183 String group
= "\"Identifier\"";
184 xComposer
.setGroup(group
);
185 tRes
.tested("getGroup()", (oObj
.getGroup().equals(group
)));
187 } catch (com
.sun
.star
.sdbc
.SQLException e
){
188 log
.println("unexpected Exception: " + e
.toString());
189 tRes
.tested("getGroup()", false);
194 * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
195 * Test has ok status if returned value is an useable <code>XIndexAccess</code>
197 public void _getGroupColumns() {
199 XIndexAccess xGroupColumns
= oObj
.getGroupColumns();
201 tRes
.tested("getGroupColumns()", (xGroupColumns
!= null &&
202 xGroupColumns
.getCount() == 1 &&
203 xGroupColumns
.getByIndex(0) != null));
205 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
){
206 log
.println("unexpected Exception: " + e
.toString());
207 tRes
.tested("getGroupColumns()", false);
208 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
209 log
.println("unexpected Exception: " + e
.toString());
210 tRes
.tested("getGroupColumns()", false);
215 * Object relation <code>xComposer</code> set a clause. This clause
216 * must returned while calling <code>getHavingClause</code>
218 public void _getHavingClause() {
220 String clause
= "\"Identifier\" = 'BOR02b'";
221 xComposer
.setHavingClause(clause
);
222 tRes
.tested("getHavingClause()", (
223 oObj
.getHavingClause().equals(clause
)));
225 } catch (com
.sun
.star
.sdbc
.SQLException e
){
226 log
.println("unexpected Exception: " + e
.toString());
227 tRes
.tested("getHavingClause()", false);
232 * Object relation <code>xComposer</code> set a clause. This clause
233 * must returned while calling <code>getHavingClause</code>
237 * <li><code>setQuery</code></li>
238 * <li><code>getFilter</code></li>
239 * <li><code>getStructuredFilter</code></li>
242 public void _getStructuredHavingClause() {
243 requiredMethod("setQuery()");
244 requiredMethod("getFilter()");
245 executeMethod("getStructuredFilter()");
246 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' )";
249 xComposer
.setHavingClause(complexFilter
);
250 PropertyValue
[][] aStructuredHaving
= oObj
.getStructuredHavingClause();
251 xComposer
.setHavingClause("");
252 xComposer
.setStructuredHavingClause(aStructuredHaving
);
253 tRes
.tested("getStructuredHavingClause()",
254 (oObj
.getHavingClause().equals(complexFilter
)));
256 } catch (com
.sun
.star
.sdbc
.SQLException e
){
257 log
.println("unexpected Exception: " + e
.toString());
258 tRes
.tested("getStructuredHavingClause()", false);
263 * Object relation <code>xComposer</code> set an order. This order
264 * must returned while calling <code>getOrder</code>
266 public void _getOrder() {
268 String order
= "\"Identifier\"";
269 xComposer
.setOrder(order
);
270 tRes
.tested("getOrder()", (oObj
.getOrder().equals(order
)));
272 } catch (com
.sun
.star
.sdbc
.SQLException e
){
273 log
.println("unexpected Exception: " + e
.toString());
274 tRes
.tested("getOrder()", false);
279 * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
280 * Test has ok status if returned value is an useable <code>XIndexAccess</code>
282 public void _getOrderColumns() {
284 XIndexAccess xOrderColumns
= oObj
.getOrderColumns();
285 tRes
.tested("getOrderColumns()", (xOrderColumns
!= null &&
286 xOrderColumns
.getCount() == 1 &&
287 xOrderColumns
.getByIndex(0) != null));
289 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
){
290 log
.println("unexpected Exception: " + e
.toString());
291 tRes
.tested("getOrderColumns()", false);
292 } catch (com
.sun
.star
.lang
.WrappedTargetException e
){
293 log
.println("unexpected Exception: " + e
.toString());
294 tRes
.tested("getOrderColumns()", false);
299 } // finish class _XSingleSelectQueryAnalyzer