xref: /AOO41X/main/qadevOOo/tests/java/ifc/sdb/_XSingleSelectQueryAnalyzer.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.sdb;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import com.sun.star.sdb.XSingleSelectQueryAnalyzer;
31*cdf0e10cSrcweir import lib.MultiMethodTest;
32*cdf0e10cSrcweir import com.sun.star.sdb.XSingleSelectQueryComposer;
33*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
34*cdf0e10cSrcweir import lib.StatusException;
35*cdf0e10cSrcweir import lib.Status;
36*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
37*cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir /**
40*cdf0e10cSrcweir * Testing <code>com.sun.star.sdb.XSingleSelectQueryAnalyzer</code>
41*cdf0e10cSrcweir * interface methods :
42*cdf0e10cSrcweir * <ul>
43*cdf0e10cSrcweir *  <li><code>getQuery()</code></li>
44*cdf0e10cSrcweir *  <li><code>setQuery()</code></li>
45*cdf0e10cSrcweir *  <li><code>getFilter()</code></li>
46*cdf0e10cSrcweir *  <li><code>getStructuredFilter()</code></li>
47*cdf0e10cSrcweir *  <li><code>getGroup()</code></li>
48*cdf0e10cSrcweir *  <li><code>getGroupColumns()</code></li>
49*cdf0e10cSrcweir *  <li><code>getHavingClause()</code></li>
50*cdf0e10cSrcweir *  <li><code>getStructuredHavingClause()</code></li>
51*cdf0e10cSrcweir *  <li><code>getOrder()</code></li>
52*cdf0e10cSrcweir *  <li><code>getOrderColumns()</code></li>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir * </ul> <p>
55*cdf0e10cSrcweir * @see com.sun.star.sdb.XSingleSelectQueryAnalyzer
56*cdf0e10cSrcweir */
57*cdf0e10cSrcweir public class _XSingleSelectQueryAnalyzer extends MultiMethodTest {
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     // oObj filled by MultiMethodTest
60*cdf0e10cSrcweir     public XSingleSelectQueryAnalyzer oObj = null ;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir     private String queryString = "SELECT * FROM \"biblio\"";
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     private XSingleSelectQueryComposer xComposer = null;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     /**
67*cdf0e10cSrcweir      * Recieves the object relations:
68*cdf0e10cSrcweir     * <ul>
69*cdf0e10cSrcweir     *  <li><code>XSingleSelectQueryComposer xCompoer</code></li>
70*cdf0e10cSrcweir     * </ul> <p>
71*cdf0e10cSrcweir      * @see om.sun.star.sdb.XSingleSelectQueryComposer
72*cdf0e10cSrcweir      */
73*cdf0e10cSrcweir     protected void before() {
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir         xComposer = (XSingleSelectQueryComposer)
76*cdf0e10cSrcweir                       UnoRuntime.queryInterface(XSingleSelectQueryComposer.class,
77*cdf0e10cSrcweir                       tEnv.getObjRelation("xComposer"));
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir         if (xComposer == null) {
80*cdf0e10cSrcweir             throw new StatusException(Status.failed(
81*cdf0e10cSrcweir            "Couldn't get object relation 'xComposer'. Test must be modified"));
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir         }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir     /**
87*cdf0e10cSrcweir     * call <code>setQuery()</code> once with valid query, once with invalid
88*cdf0e10cSrcweir     * query. Has ok if only on sceond call <code>SQLException</code> was thrwon
89*cdf0e10cSrcweir     */
90*cdf0e10cSrcweir     public void _setQuery() {
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         try{
93*cdf0e10cSrcweir             oObj.setQuery("This is an invalid SQL query");
94*cdf0e10cSrcweir         } catch (com.sun.star.sdbc.SQLException e){
95*cdf0e10cSrcweir             log.println("expected Exception. ");
96*cdf0e10cSrcweir         }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir         try{
99*cdf0e10cSrcweir             oObj.setQuery(queryString);
100*cdf0e10cSrcweir         } catch (com.sun.star.sdbc.SQLException e){
101*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
102*cdf0e10cSrcweir             tRes.tested("setQuery()", false);
103*cdf0e10cSrcweir         }
104*cdf0e10cSrcweir         tRes.tested("setQuery()", true);
105*cdf0e10cSrcweir     }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     /**
108*cdf0e10cSrcweir     * checks of the returned value of <code>getQuery()</code>
109*cdf0e10cSrcweir     * equals the string which was set by <code>setQuery()</code>
110*cdf0e10cSrcweir     * <p>
111*cdf0e10cSrcweir     * required methods:
112*cdf0e10cSrcweir     *<ul>
113*cdf0e10cSrcweir     * <li><code>setQuery</code></li>
114*cdf0e10cSrcweir     *</ul>
115*cdf0e10cSrcweir     */
116*cdf0e10cSrcweir     public void _getQuery() {
117*cdf0e10cSrcweir         this.requiredMethod("setQuery()");
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         boolean res = false;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir         res = oObj.getQuery().equals(queryString);
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir         tRes.tested("getQuery()", res);
124*cdf0e10cSrcweir     }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     /**
128*cdf0e10cSrcweir     * Object relation <code>xComposer</code> set a filter. This filter
129*cdf0e10cSrcweir     * must returned while calling <code>getFilter</code>
130*cdf0e10cSrcweir     */
131*cdf0e10cSrcweir     public void _getFilter() {
132*cdf0e10cSrcweir         try{
133*cdf0e10cSrcweir             String filter = "\"Identifier\" = 'BOR02b'";
134*cdf0e10cSrcweir             xComposer.setFilter(filter);
135*cdf0e10cSrcweir             tRes.tested("getFilter()", (oObj.getFilter().equals(filter)));
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         } catch (com.sun.star.sdbc.SQLException e){
138*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
139*cdf0e10cSrcweir             tRes.tested("getFilter()", false);
140*cdf0e10cSrcweir         }
141*cdf0e10cSrcweir     }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     /**
144*cdf0e10cSrcweir     * Object relation <code>xComposer</code> set a complex filter with method
145*cdf0e10cSrcweir     . <code>setFilter</code>. Then <code>getStructuredFilter</code> returns a
146*cdf0e10cSrcweir     * sequenze of <code>PropertyValue</code> which was set with method
147*cdf0e10cSrcweir     * <code>setStructuredFilter</code> from <xComposer>.
148*cdf0e10cSrcweir     * Then test has ok status if <getFilter> returns the complex filter.
149*cdf0e10cSrcweir     * <p>
150*cdf0e10cSrcweir     * required methods:
151*cdf0e10cSrcweir     *<ul>
152*cdf0e10cSrcweir     * <li><code>setQuery</code></li>
153*cdf0e10cSrcweir     * <li><code>getFilter</code></li>
154*cdf0e10cSrcweir     *</ul>
155*cdf0e10cSrcweir     */
156*cdf0e10cSrcweir     public void _getStructuredFilter() {
157*cdf0e10cSrcweir         requiredMethod("setQuery()");
158*cdf0e10cSrcweir         requiredMethod("getFilter()");
159*cdf0e10cSrcweir         try{
160*cdf0e10cSrcweir             oObj.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\"");
161*cdf0e10cSrcweir             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*cdf0e10cSrcweir             xComposer.setFilter(complexFilter);
163*cdf0e10cSrcweir             PropertyValue[][] aStructuredFilter = oObj.getStructuredFilter();
164*cdf0e10cSrcweir             xComposer.setFilter("");
165*cdf0e10cSrcweir             xComposer.setStructuredFilter(aStructuredFilter);
166*cdf0e10cSrcweir             tRes.tested("getStructuredFilter()", (oObj.getFilter().equals(complexFilter)));
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         } catch (com.sun.star.sdbc.SQLException e){
169*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
170*cdf0e10cSrcweir             tRes.tested("getStructuredFilter()", false);
171*cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException e){
172*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
173*cdf0e10cSrcweir             tRes.tested("getStructuredFilter()", false);
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     /**
178*cdf0e10cSrcweir     * Object relation <code>xComposer</code> set a goup. This group
179*cdf0e10cSrcweir     * must returned while calling <code>getGroup</code>
180*cdf0e10cSrcweir     */
181*cdf0e10cSrcweir     public void _getGroup() {
182*cdf0e10cSrcweir         try{
183*cdf0e10cSrcweir             String group = "\"Identifier\"";
184*cdf0e10cSrcweir             xComposer.setGroup(group);
185*cdf0e10cSrcweir             tRes.tested("getGroup()", (oObj.getGroup().equals(group)));
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         } catch (com.sun.star.sdbc.SQLException e){
188*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
189*cdf0e10cSrcweir             tRes.tested("getGroup()", false);
190*cdf0e10cSrcweir         }
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     /**
194*cdf0e10cSrcweir     * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
195*cdf0e10cSrcweir     * Test has ok status if returned value is an useable <code>XIndexAccess</code>
196*cdf0e10cSrcweir     */
197*cdf0e10cSrcweir     public void _getGroupColumns() {
198*cdf0e10cSrcweir         try{
199*cdf0e10cSrcweir            XIndexAccess xGroupColumns = oObj.getGroupColumns();
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir            tRes.tested("getGroupColumns()", (xGroupColumns != null &&
202*cdf0e10cSrcweir                                             xGroupColumns.getCount() == 1 &&
203*cdf0e10cSrcweir                                         xGroupColumns.getByIndex(0) != null));
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e){
206*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
207*cdf0e10cSrcweir             tRes.tested("getGroupColumns()", false);
208*cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e){
209*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
210*cdf0e10cSrcweir             tRes.tested("getGroupColumns()", false);
211*cdf0e10cSrcweir         }
212*cdf0e10cSrcweir     }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir     /**
215*cdf0e10cSrcweir     * Object relation <code>xComposer</code> set a clause. This clause
216*cdf0e10cSrcweir     * must returned while calling <code>getHavingClause</code>
217*cdf0e10cSrcweir     */
218*cdf0e10cSrcweir     public void _getHavingClause() {
219*cdf0e10cSrcweir         try{
220*cdf0e10cSrcweir             String clause = "\"Identifier\" = 'BOR02b'";
221*cdf0e10cSrcweir             xComposer.setHavingClause(clause);
222*cdf0e10cSrcweir             tRes.tested("getHavingClause()", (
223*cdf0e10cSrcweir                                         oObj.getHavingClause().equals(clause)));
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         } catch (com.sun.star.sdbc.SQLException e){
226*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
227*cdf0e10cSrcweir             tRes.tested("getHavingClause()", false);
228*cdf0e10cSrcweir         }
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     /**
232*cdf0e10cSrcweir     * Object relation <code>xComposer</code> set a clause. This clause
233*cdf0e10cSrcweir     * must returned while calling <code>getHavingClause</code>
234*cdf0e10cSrcweir     * <p>
235*cdf0e10cSrcweir     * required methods:
236*cdf0e10cSrcweir     *<ul>
237*cdf0e10cSrcweir     * <li><code>setQuery</code></li>
238*cdf0e10cSrcweir     * <li><code>getFilter</code></li>
239*cdf0e10cSrcweir     * <li><code>getStructuredFilter</code></li>
240*cdf0e10cSrcweir     *</ul>
241*cdf0e10cSrcweir     */
242*cdf0e10cSrcweir     public void _getStructuredHavingClause() {
243*cdf0e10cSrcweir         requiredMethod("setQuery()");
244*cdf0e10cSrcweir         requiredMethod("getFilter()");
245*cdf0e10cSrcweir         executeMethod("getStructuredFilter()");
246*cdf0e10cSrcweir         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*cdf0e10cSrcweir 
248*cdf0e10cSrcweir         try{
249*cdf0e10cSrcweir            xComposer.setHavingClause(complexFilter);
250*cdf0e10cSrcweir            PropertyValue[][] aStructuredHaving = oObj.getStructuredHavingClause();
251*cdf0e10cSrcweir            xComposer.setHavingClause("");
252*cdf0e10cSrcweir            xComposer.setStructuredHavingClause(aStructuredHaving);
253*cdf0e10cSrcweir            tRes.tested("getStructuredHavingClause()",
254*cdf0e10cSrcweir                                 (oObj.getHavingClause().equals(complexFilter)));
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         } catch (com.sun.star.sdbc.SQLException e){
257*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
258*cdf0e10cSrcweir             tRes.tested("getStructuredHavingClause()", false);
259*cdf0e10cSrcweir         }
260*cdf0e10cSrcweir     }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     /**
263*cdf0e10cSrcweir     * Object relation <code>xComposer</code> set an order. This order
264*cdf0e10cSrcweir     * must returned while calling <code>getOrder</code>
265*cdf0e10cSrcweir     */
266*cdf0e10cSrcweir     public void _getOrder() {
267*cdf0e10cSrcweir         try{
268*cdf0e10cSrcweir             String order = "\"Identifier\"";
269*cdf0e10cSrcweir             xComposer.setOrder(order);
270*cdf0e10cSrcweir             tRes.tested("getOrder()", (oObj.getOrder().equals(order)));
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir         } catch (com.sun.star.sdbc.SQLException e){
273*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
274*cdf0e10cSrcweir             tRes.tested("getOrder()", false);
275*cdf0e10cSrcweir         }
276*cdf0e10cSrcweir     }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir     /**
279*cdf0e10cSrcweir     * Method <code>getGroupColumns</code> retunrs a <code>XIndexAccess</code>
280*cdf0e10cSrcweir     * Test has ok status if returned value is an useable <code>XIndexAccess</code>
281*cdf0e10cSrcweir     */
282*cdf0e10cSrcweir     public void _getOrderColumns() {
283*cdf0e10cSrcweir         try{
284*cdf0e10cSrcweir             XIndexAccess xOrderColumns = oObj.getOrderColumns();
285*cdf0e10cSrcweir             tRes.tested("getOrderColumns()", (xOrderColumns != null &&
286*cdf0e10cSrcweir                                               xOrderColumns.getCount() == 1 &&
287*cdf0e10cSrcweir                                          xOrderColumns.getByIndex(0) != null));
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e){
290*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
291*cdf0e10cSrcweir             tRes.tested("getOrderColumns()", false);
292*cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e){
293*cdf0e10cSrcweir             log.println("unexpected Exception: " + e.toString());
294*cdf0e10cSrcweir             tRes.tested("getOrderColumns()", false);
295*cdf0e10cSrcweir         }
296*cdf0e10cSrcweir     }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir }  // finish class _XSingleSelectQueryAnalyzer
300