xref: /AOO41X/main/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryAnalyzer.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 package ifc.sdb;
29 
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;
35 import lib.Status;
36 import com.sun.star.beans.PropertyValue;
37 import com.sun.star.container.XIndexAccess;
38 
39 /**
40 * Testing <code>com.sun.star.sdb.XSingleSelectQueryAnalyzer</code>
41 * interface methods :
42 * <ul>
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>
53 
54 * </ul> <p>
55 * @see com.sun.star.sdb.XSingleSelectQueryAnalyzer
56 */
57 public class _XSingleSelectQueryAnalyzer extends MultiMethodTest {
58 
59     // oObj filled by MultiMethodTest
60     public XSingleSelectQueryAnalyzer oObj = null ;
61 
62     private String queryString = "SELECT * FROM \"biblio\"";
63 
64     private XSingleSelectQueryComposer xComposer = null;
65 
66     /**
67      * Recieves the object relations:
68     * <ul>
69     *  <li><code>XSingleSelectQueryComposer xCompoer</code></li>
70     * </ul> <p>
71      * @see om.sun.star.sdb.XSingleSelectQueryComposer
72      */
73     protected void before() {
74 
75         xComposer = (XSingleSelectQueryComposer)
76                       UnoRuntime.queryInterface(XSingleSelectQueryComposer.class,
77                       tEnv.getObjRelation("xComposer"));
78 
79         if (xComposer == null) {
80             throw new StatusException(Status.failed(
81            "Couldn't get object relation 'xComposer'. Test must be modified"));
82 
83         }
84 
85     }
86     /**
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
89     */
90     public void _setQuery() {
91 
92         try{
93             oObj.setQuery("This is an invalid SQL query");
94         } catch (com.sun.star.sdbc.SQLException e){
95             log.println("expected Exception. ");
96         }
97 
98         try{
99             oObj.setQuery(queryString);
100         } catch (com.sun.star.sdbc.SQLException e){
101             log.println("unexpected Exception: " + e.toString());
102             tRes.tested("setQuery()", false);
103         }
104         tRes.tested("setQuery()", true);
105     }
106 
107     /**
108     * checks of the returned value of <code>getQuery()</code>
109     * equals the string which was set by <code>setQuery()</code>
110     * <p>
111     * required methods:
112     *<ul>
113     * <li><code>setQuery</code></li>
114     *</ul>
115     */
116     public void _getQuery() {
117         this.requiredMethod("setQuery()");
118 
119         boolean res = false;
120 
121         res = oObj.getQuery().equals(queryString);
122 
123         tRes.tested("getQuery()", res);
124     }
125 
126 
127     /**
128     * Object relation <code>xComposer</code> set a filter. This filter
129     * must returned while calling <code>getFilter</code>
130     */
131     public void _getFilter() {
132         try{
133             String filter = "\"Identifier\" = 'BOR02b'";
134             xComposer.setFilter(filter);
135             tRes.tested("getFilter()", (oObj.getFilter().equals(filter)));
136 
137         } catch (com.sun.star.sdbc.SQLException e){
138             log.println("unexpected Exception: " + e.toString());
139             tRes.tested("getFilter()", false);
140         }
141     }
142 
143     /**
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.
149     * <p>
150     * required methods:
151     *<ul>
152     * <li><code>setQuery</code></li>
153     * <li><code>getFilter</code></li>
154     *</ul>
155     */
156     public void _getStructuredFilter() {
157         requiredMethod("setQuery()");
158         requiredMethod("getFilter()");
159         try{
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)));
167 
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);
174         }
175     }
176 
177     /**
178     * Object relation <code>xComposer</code> set a goup. This group
179     * must returned while calling <code>getGroup</code>
180     */
181     public void _getGroup() {
182         try{
183             String group = "\"Identifier\"";
184             xComposer.setGroup(group);
185             tRes.tested("getGroup()", (oObj.getGroup().equals(group)));
186 
187         } catch (com.sun.star.sdbc.SQLException e){
188             log.println("unexpected Exception: " + e.toString());
189             tRes.tested("getGroup()", false);
190         }
191     }
192 
193     /**
194     * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
195     * Test has ok status if returned value is an useable <code>XIndexAccess</code>
196     */
197     public void _getGroupColumns() {
198         try{
199            XIndexAccess xGroupColumns = oObj.getGroupColumns();
200 
201            tRes.tested("getGroupColumns()", (xGroupColumns != null &&
202                                             xGroupColumns.getCount() == 1 &&
203                                         xGroupColumns.getByIndex(0) != null));
204 
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);
211         }
212     }
213 
214     /**
215     * Object relation <code>xComposer</code> set a clause. This clause
216     * must returned while calling <code>getHavingClause</code>
217     */
218     public void _getHavingClause() {
219         try{
220             String clause = "\"Identifier\" = 'BOR02b'";
221             xComposer.setHavingClause(clause);
222             tRes.tested("getHavingClause()", (
223                                         oObj.getHavingClause().equals(clause)));
224 
225         } catch (com.sun.star.sdbc.SQLException e){
226             log.println("unexpected Exception: " + e.toString());
227             tRes.tested("getHavingClause()", false);
228         }
229     }
230 
231     /**
232     * Object relation <code>xComposer</code> set a clause. This clause
233     * must returned while calling <code>getHavingClause</code>
234     * <p>
235     * required methods:
236     *<ul>
237     * <li><code>setQuery</code></li>
238     * <li><code>getFilter</code></li>
239     * <li><code>getStructuredFilter</code></li>
240     *</ul>
241     */
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' )";
247 
248         try{
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)));
255 
256         } catch (com.sun.star.sdbc.SQLException e){
257             log.println("unexpected Exception: " + e.toString());
258             tRes.tested("getStructuredHavingClause()", false);
259         }
260     }
261 
262     /**
263     * Object relation <code>xComposer</code> set an order. This order
264     * must returned while calling <code>getOrder</code>
265     */
266     public void _getOrder() {
267         try{
268             String order = "\"Identifier\"";
269             xComposer.setOrder(order);
270             tRes.tested("getOrder()", (oObj.getOrder().equals(order)));
271 
272         } catch (com.sun.star.sdbc.SQLException e){
273             log.println("unexpected Exception: " + e.toString());
274             tRes.tested("getOrder()", false);
275         }
276     }
277 
278     /**
279     * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
280     * Test has ok status if returned value is an useable <code>XIndexAccess</code>
281     */
282     public void _getOrderColumns() {
283         try{
284             XIndexAccess xOrderColumns = oObj.getOrderColumns();
285             tRes.tested("getOrderColumns()", (xOrderColumns != null &&
286                                               xOrderColumns.getCount() == 1 &&
287                                          xOrderColumns.getByIndex(0) != null));
288 
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);
295         }
296     }
297 
298 
299 }  // finish class _XSingleSelectQueryAnalyzer
300