Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / sdb / _XSingleSelectQueryAnalyzer.java
blob6df8b1bad98196659a0342e560a1dc6105546694
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: _XSingleSelectQueryAnalyzer.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.XSingleSelectQueryAnalyzer;
34 import lib.MultiMethodTest;
35 import com.sun.star.sdb.XSingleSelectQueryComposer;
36 import com.sun.star.uno.UnoRuntime;
37 import lib.StatusException;
38 import lib.Status;
39 import com.sun.star.beans.PropertyValue;
40 import com.sun.star.container.XIndexAccess;
42 /**
43 * Testing <code>com.sun.star.sdb.XSingleSelectQueryAnalyzer</code>
44 * interface methods :
45 * <ul>
46 * <li><code>getQuery()</code></li>
47 * <li><code>setQuery()</code></li>
48 * <li><code>getFilter()</code></li>
49 * <li><code>getStructuredFilter()</code></li>
50 * <li><code>getGroup()</code></li>
51 * <li><code>getGroupColumns()</code></li>
52 * <li><code>getHavingClause()</code></li>
53 * <li><code>getStructuredHavingClause()</code></li>
54 * <li><code>getOrder()</code></li>
55 * <li><code>getOrderColumns()</code></li>
57 * </ul> <p>
58 * @see com.sun.star.sdb.XSingleSelectQueryAnalyzer
60 public class _XSingleSelectQueryAnalyzer extends MultiMethodTest {
62 // oObj filled by MultiMethodTest
63 public XSingleSelectQueryAnalyzer oObj = null ;
65 private String queryString = "SELECT * FROM \"biblio\"";
67 private XSingleSelectQueryComposer xComposer = null;
69 /**
70 * Recieves the object relations:
71 * <ul>
72 * <li><code>XSingleSelectQueryComposer xCompoer</code></li>
73 * </ul> <p>
74 * @see om.sun.star.sdb.XSingleSelectQueryComposer
76 protected void before() {
78 xComposer = (XSingleSelectQueryComposer)
79 UnoRuntime.queryInterface(XSingleSelectQueryComposer.class,
80 tEnv.getObjRelation("xComposer"));
82 if (xComposer == null) {
83 throw new StatusException(Status.failed(
84 "Couldn't get object relation 'xComposer'. Test must be modified"));
89 /**
90 * call <code>setQuery()</code> once with valid query, once with invalid
91 * query. Has ok if only on sceond call <code>SQLException</code> was thrwon
93 public void _setQuery() {
95 try{
96 oObj.setQuery("This is an invalid SQL query");
97 } catch (com.sun.star.sdbc.SQLException e){
98 log.println("expected Exception. ");
101 try{
102 oObj.setQuery(queryString);
103 } catch (com.sun.star.sdbc.SQLException e){
104 log.println("unexpected Exception: " + e.toString());
105 tRes.tested("setQuery()", false);
107 tRes.tested("setQuery()", true);
111 * checks of the returned value of <code>getQuery()</code>
112 * equals the string which was set by <code>setQuery()</code>
113 * <p>
114 * required methods:
115 *<ul>
116 * <li><code>setQuery</code></li>
117 *</ul>
119 public void _getQuery() {
120 this.requiredMethod("setQuery()");
122 boolean res = false;
124 res = oObj.getQuery().equals(queryString);
126 tRes.tested("getQuery()", res);
131 * Object relation <code>xComposer</code> set a filter. This filter
132 * must returned while calling <code>getFilter</code>
134 public void _getFilter() {
135 try{
136 String filter = "\"Identifier\" = 'BOR02b'";
137 xComposer.setFilter(filter);
138 tRes.tested("getFilter()", (oObj.getFilter().equals(filter)));
140 } catch (com.sun.star.sdbc.SQLException e){
141 log.println("unexpected Exception: " + e.toString());
142 tRes.tested("getFilter()", false);
147 * Object relation <code>xComposer</code> set a complex filter with method
148 . <code>setFilter</code>. Then <code>getStructuredFilter</code> returns a
149 * sequenze of <code>PropertyValue</code> which was set with method
150 * <code>setStructuredFilter</code> from <xComposer>.
151 * Then test has ok status if <getFilter> returns the complex filter.
152 * <p>
153 * required methods:
154 *<ul>
155 * <li><code>setQuery</code></li>
156 * <li><code>getFilter</code></li>
157 *</ul>
159 public void _getStructuredFilter() {
160 requiredMethod("setQuery()");
161 requiredMethod("getFilter()");
162 try{
163 oObj.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\"");
164 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' )";
165 xComposer.setFilter(complexFilter);
166 PropertyValue[][] aStructuredFilter = oObj.getStructuredFilter();
167 xComposer.setFilter("");
168 xComposer.setStructuredFilter(aStructuredFilter);
169 tRes.tested("getStructuredFilter()", (oObj.getFilter().equals(complexFilter)));
171 } catch (com.sun.star.sdbc.SQLException e){
172 log.println("unexpected Exception: " + e.toString());
173 tRes.tested("getStructuredFilter()", false);
174 } catch (com.sun.star.lang.IllegalArgumentException e){
175 log.println("unexpected Exception: " + e.toString());
176 tRes.tested("getStructuredFilter()", false);
181 * Object relation <code>xComposer</code> set a goup. This group
182 * must returned while calling <code>getGroup</code>
184 public void _getGroup() {
185 try{
186 String group = "\"Identifier\"";
187 xComposer.setGroup(group);
188 tRes.tested("getGroup()", (oObj.getGroup().equals(group)));
190 } catch (com.sun.star.sdbc.SQLException e){
191 log.println("unexpected Exception: " + e.toString());
192 tRes.tested("getGroup()", false);
197 * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
198 * Test has ok status if returned value is an useable <code>XIndexAccess</code>
200 public void _getGroupColumns() {
201 try{
202 XIndexAccess xGroupColumns = oObj.getGroupColumns();
204 tRes.tested("getGroupColumns()", (xGroupColumns != null &&
205 xGroupColumns.getCount() == 1 &&
206 xGroupColumns.getByIndex(0) != null));
208 } catch (com.sun.star.lang.IndexOutOfBoundsException e){
209 log.println("unexpected Exception: " + e.toString());
210 tRes.tested("getGroupColumns()", false);
211 } catch (com.sun.star.lang.WrappedTargetException e){
212 log.println("unexpected Exception: " + e.toString());
213 tRes.tested("getGroupColumns()", false);
218 * Object relation <code>xComposer</code> set a clause. This clause
219 * must returned while calling <code>getHavingClause</code>
221 public void _getHavingClause() {
222 try{
223 String clause = "\"Identifier\" = 'BOR02b'";
224 xComposer.setHavingClause(clause);
225 tRes.tested("getHavingClause()", (
226 oObj.getHavingClause().equals(clause)));
228 } catch (com.sun.star.sdbc.SQLException e){
229 log.println("unexpected Exception: " + e.toString());
230 tRes.tested("getHavingClause()", false);
235 * Object relation <code>xComposer</code> set a clause. This clause
236 * must returned while calling <code>getHavingClause</code>
237 * <p>
238 * required methods:
239 *<ul>
240 * <li><code>setQuery</code></li>
241 * <li><code>getFilter</code></li>
242 * <li><code>getStructuredFilter</code></li>
243 *</ul>
245 public void _getStructuredHavingClause() {
246 requiredMethod("setQuery()");
247 requiredMethod("getFilter()");
248 executeMethod("getStructuredFilter()");
249 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' )";
251 try{
252 xComposer.setHavingClause(complexFilter);
253 PropertyValue[][] aStructuredHaving = oObj.getStructuredHavingClause();
254 xComposer.setHavingClause("");
255 xComposer.setStructuredHavingClause(aStructuredHaving);
256 tRes.tested("getStructuredHavingClause()",
257 (oObj.getHavingClause().equals(complexFilter)));
259 } catch (com.sun.star.sdbc.SQLException e){
260 log.println("unexpected Exception: " + e.toString());
261 tRes.tested("getStructuredHavingClause()", false);
266 * Object relation <code>xComposer</code> set an order. This order
267 * must returned while calling <code>getOrder</code>
269 public void _getOrder() {
270 try{
271 String order = "\"Identifier\"";
272 xComposer.setOrder(order);
273 tRes.tested("getOrder()", (oObj.getOrder().equals(order)));
275 } catch (com.sun.star.sdbc.SQLException e){
276 log.println("unexpected Exception: " + e.toString());
277 tRes.tested("getOrder()", false);
282 * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
283 * Test has ok status if returned value is an useable <code>XIndexAccess</code>
285 public void _getOrderColumns() {
286 try{
287 XIndexAccess xOrderColumns = oObj.getOrderColumns();
288 tRes.tested("getOrderColumns()", (xOrderColumns != null &&
289 xOrderColumns.getCount() == 1 &&
290 xOrderColumns.getByIndex(0) != null));
292 } catch (com.sun.star.lang.IndexOutOfBoundsException e){
293 log.println("unexpected Exception: " + e.toString());
294 tRes.tested("getOrderColumns()", false);
295 } catch (com.sun.star.lang.WrappedTargetException e){
296 log.println("unexpected Exception: " + e.toString());
297 tRes.tested("getOrderColumns()", false);
302 } // finish class _XSingleSelectQueryAnalyzer