bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdb / _XSingleSelectQueryAnalyzer.java
blobf0ff54731561b9ecdc8e9de7d08a21300543c952
1 /*
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 .
19 package ifc.sdb;
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;
26 import lib.Status;
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.container.XIndexAccess;
30 /**
31 * Testing <code>com.sun.star.sdb.XSingleSelectQueryAnalyzer</code>
32 * interface methods :
33 * <ul>
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>
45 * </ul> <p>
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;
57 /**
58 * Receives the object relations:
59 * <ul>
60 * <li><code>XSingleSelectQueryComposer xCompoer</code></li>
61 * </ul> <p>
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"));
76 /**
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() {
82 try{
83 oObj.setQuery("This is an invalid SQL query");
84 } catch (com.sun.star.sdbc.SQLException e){
85 log.println("expected Exception. ");
88 try{
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);
97 /**
98 * checks of the returned value of <code>getQuery()</code>
99 * equals the string which was set by <code>setQuery()</code>
100 * <p>
101 * required methods:
102 *<ul>
103 * <li><code>setQuery</code></li>
104 *</ul>
106 public void _getQuery() {
107 this.requiredMethod("setQuery()");
109 boolean res = false;
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() {
122 try{
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.
139 * <p>
140 * required methods:
141 *<ul>
142 * <li><code>setQuery</code></li>
143 * <li><code>getFilter</code></li>
144 *</ul>
146 public void _getStructuredFilter() {
147 requiredMethod("setQuery()");
148 requiredMethod("getFilter()");
149 try{
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() {
172 try{
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() {
188 try{
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() {
209 try{
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>
224 * <p>
225 * required methods:
226 *<ul>
227 * <li><code>setQuery</code></li>
228 * <li><code>getFilter</code></li>
229 * <li><code>getStructuredFilter</code></li>
230 *</ul>
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' )";
238 try{
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() {
257 try{
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() {
273 try{
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