merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / sdb / _XSingleSelectQueryComposer.java
blob61b2a227ad8fac98c90cac4160ce787ad41c619e
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: _XSingleSelectQueryComposer.java,v $
10 * $Revision: 1.6 $
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.sdb;
33 import com.sun.star.sdb.XSingleSelectQueryComposer;
34 import lib.MultiMethodTest;
35 import com.sun.star.sdb.XSingleSelectQueryAnalyzer;
36 import com.sun.star.uno.AnyConverter;
37 import com.sun.star.uno.UnoRuntime;
38 import lib.StatusException;
39 import lib.Status;
40 import com.sun.star.beans.PropertyValue;
41 import com.sun.star.beans.XPropertySet;
43 /**
44 * Testing <code>com.sun.star.sdb.XSingleSelectQueryComposer</code>
45 * interface methods :
46 * <ul>
47 * <li><code>setFilter()</code></li>
48 * <li><code>setStructuredFilter()</code></li>
49 * <li><code>appendFilterByColumn()</code></li>
50 * <li><code>appendGroupByColumn()</code></li>
51 * <li><code>setGroup()</code></li>
52 * <li><code>setHavingClause()</code></li>
53 * <li><code>setStructuredHavingClause()</code></li>
54 * <li><code>appendHavingClauseByColumn()</code></li>
55 * <li><code>appendOrderByColumn()</code></li>
56 * <li><code>setOrder()</code></li>
58 * </ul> <p>
59 * @see com.sun.star.sdb.XSingleSelectQueryComposer
61 public class _XSingleSelectQueryComposer extends MultiMethodTest {
63 // oObj filled by MultiMethodTest
64 public XSingleSelectQueryComposer oObj = null ;
66 private String queryString = "SELECT * FROM \"biblio\"";
68 private XSingleSelectQueryAnalyzer xQueryAna = null;
70 private XPropertySet xProp = null;
72 private String colName = null;
74 /**
75 * Retcieves the object relations:
76 * <ul>
77 * <li><code>XSingleSelectQueryAnalyzer xQueryAna</code></li>
78 * <li><code>XPropertySet xProp</code></li>
79 * <li><code>String colName</code></li>
80 * </ul> <p>
81 * @see om.sun.star.sdb.XSingleSelectQueryAnalyzer
82 * @see com.sun.star.beans.XPropertySet
84 protected void before() throws Exception {
86 xQueryAna = (XSingleSelectQueryAnalyzer)
87 UnoRuntime.queryInterface(XSingleSelectQueryAnalyzer.class,
88 tEnv.getObjRelation("xQueryAna"));
90 if (xQueryAna == null) {
91 throw new StatusException(Status.failed(
92 "Couldn't get object relation 'xQueryAna'. Test must be modified"));
96 xProp = (XPropertySet)
97 UnoRuntime.queryInterface(XPropertySet.class,
98 tEnv.getObjRelation("xProp"));
100 if (xProp == null) {
101 throw new StatusException(Status.failed(
102 "Couldn't get object relation 'xProp'. Test must be modified"));
106 colName = AnyConverter.toString(tEnv.getObjRelation("colName"));
108 if (colName == null) {
109 throw new StatusException(Status.failed(
110 "Couldn't get object relation 'colName'. Test must be modified"));
118 * Object relation <code>xQueryAna</code> set a filter. This filter
119 * must returned while calling <code>getFilter</code>
121 public void _setFilter() {
122 try{
123 String filter = "\"Identifier\" = 'BOR02b'";
124 oObj.setFilter(filter);
125 tRes.tested("setFilter()", (xQueryAna.getFilter().equals(filter)));
127 } catch (com.sun.star.sdbc.SQLException e){
128 log.println("unexpected Exception: " + e.toString());
129 tRes.tested("setFilter()", false);
134 * Object relation <code>xQueryAna</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 <code>xQueryAna</code>.
138 * Then test has ok status if <code>getFilter</code> returns the complex filter.
140 public void _setStructuredFilter() {
141 requiredMethod("setFilter()");
142 try{
143 xQueryAna.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\"");
144 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' )";
145 oObj.setFilter(complexFilter);
146 PropertyValue[][] aStructuredFilter = xQueryAna.getStructuredFilter();
147 oObj.setFilter("");
148 oObj.setStructuredFilter(aStructuredFilter);
149 tRes.tested("setStructuredFilter()", (xQueryAna.getFilter().equals(complexFilter)));
151 } catch (com.sun.star.sdbc.SQLException e){
152 log.println("unexpected Exception: " + e.toString());
153 tRes.tested("setStructuredFilter()", false);
154 } catch (com.sun.star.lang.IllegalArgumentException e){
155 log.println("unexpected Exception: " + e.toString());
156 tRes.tested("setStructuredFilter()", false);
161 * At first the object relation <code>xProp</code> was set as parameter.
162 * Relation <code>xQueryAna</code> was used to chek if realtion
163 * <code>colName</code> was found.
164 * Second an empty <code>XPropertySet</code> was used as parameter. A
165 * <code>com.sun.star.sdbc.SQLException</code> must be thrown.
167 public void _appendFilterByColumn() {
168 boolean ok = true;
169 try{
171 oObj.appendFilterByColumn(xProp, true);
172 log.println("appendFilterByColumn: " + xQueryAna.getFilter());
173 ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
175 } catch (com.sun.star.sdbc.SQLException e){
176 log.println("unexpected Exception: " + e.toString());
177 tRes.tested("appendFilterByColumn()", false);
180 try{
182 oObj.appendFilterByColumn(xProp, false);
183 log.println("appendFilterByColumn: " + xQueryAna.getFilter());
184 ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
186 } catch (com.sun.star.sdbc.SQLException e){
187 log.println("unexpected Exception: " + e.toString());
188 tRes.tested("appendFilterByColumn()", false);
191 try{
192 XPropertySet dummy = null;
193 oObj.appendFilterByColumn(dummy, true);
194 log.println("unexpected Exception was not thorwn");
195 tRes.tested("appendFilterByColumn()", false);
197 } catch (com.sun.star.sdbc.SQLException e){
198 log.println("expected Exception");
199 ok = ok && true;
201 tRes.tested("appendFilterByColumn()", ok);
205 * At first the object relation <code>xProp</code> was used as parameter.
206 * Relation <code>xQueryAna</code> was used to chek if realtion
207 * <code>colName</code> was found.
208 * Second an empty <code>XPropertySet</code> was used as parameter. An
209 * <code>com.sun.star.sdbc.SQLException</code> must be thrown.
211 public void _appendGroupByColumn() {
212 boolean ok = true;
213 try{
215 oObj.appendGroupByColumn(xProp);
216 log.println("appendGroupByColumn: " + xQueryAna.getFilter());
217 ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
219 } catch (com.sun.star.sdbc.SQLException e){
220 log.println("unexpected Exception: " + e.toString());
221 tRes.tested("appendGroupByColumn()", false);
223 try{
224 XPropertySet dummy = null;
225 oObj.appendGroupByColumn(dummy);
226 log.println("unexpected Exception was not thorwn");
227 tRes.tested("appendGroupByColumn()", false);
229 } catch (com.sun.star.sdbc.SQLException e){
230 log.println("expected Exception");
231 ok = ok && true;
233 tRes.tested("appendGroupByColumn()", ok);
237 * The group which was setted by <code>setGroup</code> must be returned
238 * while calling from object relation <code>XQueryAna</code>
239 * method <code>getGroup</code>
241 public void _setGroup() {
242 try{
243 String group = "\"Identifier\"";
244 oObj.setGroup(group);
245 tRes.tested("setGroup()", (xQueryAna.getGroup().equals(group)));
247 } catch (com.sun.star.sdbc.SQLException e){
248 log.println("unexpected Exception: " + e.toString());
249 tRes.tested("setGroup()", false);
255 * The cluase which was setted by <code>setHavingClause</code> must be returned
256 * while calling from object relation <code>XQueryAna</code>
257 * method <code>getHavingClause</code>
259 public void _setHavingClause() {
260 try{
261 String clause = "\"Identifier\" = 'BOR02b'";
262 oObj.setHavingClause(clause);
263 tRes.tested("setHavingClause()", (
264 xQueryAna.getHavingClause().equals(clause)));
266 } catch (com.sun.star.sdbc.SQLException e){
267 log.println("unexpected Exception: " + e.toString());
268 tRes.tested("setHavingClause()", false);
273 * At first <code>setHavingClause</code> sets a complex clause.
274 * Then method <code>getStructuredHavingClause</code> from object relation
275 * <code>xQueryAna</code> returns a valid <code>PropertyValue[][]</code>
276 * Method <code>setHavingClause</code> was called with an empty sting to
277 * reset filter. Now <code>setStructuredHavingClause</code> with the valid
278 * <code>PropertyValue[][]</code> as parameter was called.
279 * Test is ok if <code>getHavingClause</code> from <code>xQueryAna</code>
280 * returns the complex clause from beginning.
281 * <p>
282 * required methods:
283 *<ul>
284 * <li><code>setHavingClause</code></li>
285 * <li><code>setStructuredFilter</code></li>
286 *</ul>
288 public void _setStructuredHavingClause() {
289 requiredMethod("setHavingClause()");
290 executeMethod("setStructuredFilter()");
291 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' )";
293 try{
294 oObj.setHavingClause(complexFilter);
295 PropertyValue[][] aStructuredHaving =
296 xQueryAna.getStructuredHavingClause();
297 oObj.setHavingClause("");
298 oObj.setStructuredHavingClause(aStructuredHaving);
299 tRes.tested("setStructuredHavingClause()",
300 (xQueryAna.getHavingClause().equals(complexFilter)));
302 } catch (com.sun.star.sdbc.SQLException e){
303 log.println("unexpected Exception: " + e.toString());
304 tRes.tested("setStructuredHavingClause()", false);
309 * First object relation <code>xProp</code> was used as parameter. Relation
310 * <code>xQueryAna</code> was used to chek if realtion <code>colName</code>
311 * was found.
312 * Second an empty <code>XPropertySet</code> was given as parameter. An
313 * <code>com.sun.star.sdbc.SQLException</code> must be thrown.
315 public void _appendHavingClauseByColumn() {
316 boolean ok = true;
317 try{
319 oObj.appendHavingClauseByColumn(xProp, true);
320 log.println("appendHavingClauseByColumn: " + xQueryAna.getFilter());
321 ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
323 } catch (com.sun.star.sdbc.SQLException e){
324 log.println("unexpected Exception: " + e.toString());
325 tRes.tested("appendHavingClauseByColumn()", false);
327 try{
328 XPropertySet dummy = null;
329 oObj.appendHavingClauseByColumn(dummy, true);
330 log.println("unexpected Exception was not thorwn");
331 tRes.tested("appendHavingClauseByColumn()", false);
333 } catch (com.sun.star.sdbc.SQLException e){
334 log.println("expected Exception");
335 ok = ok && true;
337 tRes.tested("appendHavingClauseByColumn()", ok);
341 * First object relation <code>xProp</code> was set as parameter. Relation
342 * <code>xQueryAna</code> was used to chek if realtion <code>colName</code>
343 * was found.
344 * Second an empty <code>XPropertySet</code> was given as parameter. An
345 * <code>com.sun.star.sdbc.SQLException</code> must be thrown.
347 public void _appendOrderByColumn() {
348 boolean ok = true;
349 try{
351 oObj.appendOrderByColumn(xProp, true);
352 log.println("appendOrderByColumn: " + xQueryAna.getFilter());
353 ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
355 } catch (com.sun.star.sdbc.SQLException e){
356 log.println("unexpected Exception: " + e.toString());
357 tRes.tested("appendOrderByColumn()", false);
359 try{
360 XPropertySet dummy = null;
361 oObj.appendOrderByColumn(dummy, true);
362 log.println("unexpected Exception was not thorwn");
363 tRes.tested("appendOrderByColumn()", false);
365 } catch (com.sun.star.sdbc.SQLException e){
366 log.println("expected Exception");
367 ok = ok && true;
369 tRes.tested("appendOrderByColumn()", ok);
374 * Method <code>getOrder</code> from object relation <code>xQueryAna</code>
375 * checks the order which was setted while calling <code>setOrder</code>
377 public void _setOrder() {
378 try{
379 String order = "\"Identifier\"";
380 oObj.setOrder(order);
381 tRes.tested("setOrder()", (xQueryAna.getOrder().equals(order)));
383 } catch (com.sun.star.sdbc.SQLException e){
384 log.println("unexpected Exception: " + e.toString());
385 tRes.tested("setOrder()", false);
391 } // finish class _XSingleSelectQueryComposer