1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package ifc.sdb;
import com.sun.star.sdb.XSingleSelectQueryComposer;
import lib.MultiMethodTest;
import com.sun.star.sdb.XSingleSelectQueryAnalyzer;
import com.sun.star.sdbc.XResultSet;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import lib.StatusException;
import lib.Status;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.sdb.SQLFilterOperator;
import com.sun.star.sdbc.SQLException;
/**
* Testing <code>com.sun.star.sdb.XSingleSelectQueryComposer</code>
* interface methods :
* <ul>
* <li><code>setFilter()</code></li>
* <li><code>setStructuredFilter()</code></li>
* <li><code>appendFilterByColumn()</code></li>
* <li><code>appendGroupByColumn()</code></li>
* <li><code>setGroup()</code></li>
* <li><code>setHavingClause()</code></li>
* <li><code>setStructuredHavingClause()</code></li>
* <li><code>appendHavingClauseByColumn()</code></li>
* <li><code>appendOrderByColumn()</code></li>
* <li><code>setOrder()</code></li>
* </ul> <p>
* @see com.sun.star.sdb.XSingleSelectQueryComposer
*/
public class _XSingleSelectQueryComposer extends MultiMethodTest {
// oObj filled by MultiMethodTest
public XSingleSelectQueryComposer oObj = null ;
private XSingleSelectQueryAnalyzer xQueryAna = null;
private XPropertySet xProp = null;
private String colName = null;
private XResultSet xReSet = null;
/**
* Retrieves the object relations:
* <ul>
* <li><code>XSingleSelectQueryAnalyzer xQueryAna</code></li>
* <li><code>XPropertySet xProp</code></li>
* <li><code>String colName</code></li>
* </ul> <p>
* @see com.sun.star.sdb.XSingleSelectQueryAnalyzer
* @see com.sun.star.beans.XPropertySet
*/
@Override
protected void before() /* throws Exception*/ {
xQueryAna = UnoRuntime.queryInterface(XSingleSelectQueryAnalyzer.class,
tEnv.getObjRelation("xQueryAna"));
if (xQueryAna == null) {
throw new StatusException(Status.failed(
"Couldn't get object relation 'xQueryAna'. Test must be modified"));
}
xProp = UnoRuntime.queryInterface(XPropertySet.class,
tEnv.getObjRelation("xProp"));
if (xProp == null) {
throw new StatusException(Status.failed(
"Couldn't get object relation 'xProp'. Test must be modified"));
}
xReSet = UnoRuntime.queryInterface(XResultSet.class,
tEnv.getObjRelation("xResultSet"));
if (xReSet == null) {
throw new StatusException(Status.failed(
"Couldn't get object relation 'xResultSet'. Test must be modified"));
}
try
{
colName = AnyConverter.toString(tEnv.getObjRelation("colName"));
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
colName = null;
}
if (colName == null) {
throw new StatusException(Status.failed(
"Couldn't get object relation 'colName'. Test must be modified"));
}
}
/**
* Object relation <code>xQueryAna</code> set a filter. This filter
* must returned while calling <code>getFilter</code>
*/
public void _setFilter() {
try{
String filter = "\"Identifier\" = 'BOR02b'";
oObj.setFilter(filter);
tRes.tested("setFilter()", xQueryAna.getFilter().equals(filter));
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("setFilter()", false);
}
}
/**
* Object relation <code>xQueryAna</code> set a complex filter with method
. <code>setFilter</code>. Then <code>getStructuredFilter</code> returns a
* sequence of <code>PropertyValue</code> which was set with method
* <code>setStructuredFilter</code> from <code>xQueryAna</code>.
* Then test has ok status if <code>getFilter</code> returns the complex filter.
*/
public void _setStructuredFilter() {
requiredMethod("setFilter()");
try{
xQueryAna.setQuery("SELECT \"Identifier\", \"Type\", \"Address\" FROM \"biblio\" \"biblio\"");
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' )";
oObj.setFilter(complexFilter);
PropertyValue[][] aStructuredFilter = xQueryAna.getStructuredFilter();
oObj.setFilter("");
oObj.setStructuredFilter(aStructuredFilter);
tRes.tested("setStructuredFilter()", xQueryAna.getFilter().equals(complexFilter));
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("setStructuredFilter()", false);
} catch (com.sun.star.lang.IllegalArgumentException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("setStructuredFilter()", false);
}
}
/**
* At first the object relation <code>xProp</code> was set as parameter.
* Relation <code>xQueryAna</code> was used to check if relation
* <code>colName</code> was found.
* Second an empty <code>XPropertySet</code> was used as parameter. A
* <code>SQLException</code> must be thrown.
*/
public void _appendFilterByColumn() {
boolean ok = true;
try
{
xReSet.beforeFirst();
}
catch (SQLException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
try
{
oObj.appendFilterByColumn(xProp, true,SQLFilterOperator.EQUAL);
log.println("expected Exception was not thrown");
tRes.tested("appendFilterByColumn()", false);
ok = false;
}
catch (com.sun.star.uno.RuntimeException e)
{
log.println("expected Exception: " + e.toString());
ok = ok && true;
}
catch (SQLException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
catch (com.sun.star.lang.WrappedTargetException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
try
{
xReSet.first();
}
catch (SQLException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
try{
oObj.appendFilterByColumn(xProp, true,SQLFilterOperator.EQUAL);
log.println("appendFilterByColumn: " + xQueryAna.getFilter());
ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
catch (com.sun.star.lang.WrappedTargetException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
try{
oObj.appendFilterByColumn(xProp, false,SQLFilterOperator.EQUAL);
log.println("appendFilterByColumn: " + xQueryAna.getFilter());
ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
} catch (com.sun.star.lang.WrappedTargetException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
try{
XPropertySet dummy = null;
oObj.appendFilterByColumn(dummy, true,SQLFilterOperator.EQUAL);
log.println("expected Exception was not thrown");
tRes.tested("appendFilterByColumn()", false);
} catch (SQLException e){
log.println("expected Exception");
ok = ok && true;
} catch (com.sun.star.lang.WrappedTargetException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
try
{
xReSet.beforeFirst();
}
catch (SQLException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendFilterByColumn()", false);
}
tRes.tested("appendFilterByColumn()", ok);
}
/**
* At first the object relation <code>xProp</code> was used as parameter.
* Relation <code>xQueryAna</code> was used to check if relation
* <code>colName</code> was found.
* Second an empty <code>XPropertySet</code> was used as parameter. An
* <code>SQLException</code> must be thrown.
*/
public void _appendGroupByColumn() {
boolean ok = true;
try{
oObj.appendGroupByColumn(xProp);
log.println("appendGroupByColumn: " + xQueryAna.getFilter());
ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendGroupByColumn()", false);
}
try{
XPropertySet dummy = null;
oObj.appendGroupByColumn(dummy);
log.println("expected Exception was not thrown");
tRes.tested("appendGroupByColumn()", false);
} catch (SQLException e){
log.println("expected Exception");
ok = ok && true;
}
tRes.tested("appendGroupByColumn()", ok);
}
/**
* The group which was set by <code>setGroup</code> must be returned
* while calling from object relation <code>XQueryAna</code>
* method <code>getGroup</code>
*/
public void _setGroup() {
try{
String group = "\"Identifier\"";
oObj.setGroup(group);
tRes.tested("setGroup()", xQueryAna.getGroup().equals(group));
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("setGroup()", false);
}
}
/**
* The clause which was set by <code>setHavingClause</code> must be returned
* while calling from object relation <code>XQueryAna</code>
* method <code>getHavingClause</code>
*/
public void _setHavingClause() {
try{
String clause = "\"Identifier\" = 'BOR02b'";
oObj.setHavingClause(clause);
tRes.tested("setHavingClause()",
xQueryAna.getHavingClause().equals(clause));
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("setHavingClause()", false);
}
}
/**
* At first <code>setHavingClause</code> sets a complex clause.
* Then method <code>getStructuredHavingClause</code> from object relation
* <code>xQueryAna</code> returns a valid <code>PropertyValue[][]</code>
* Method <code>setHavingClause</code> was called with an empty string to
* reset filter. Now <code>setStructuredHavingClause</code> with the valid
* <code>PropertyValue[][]</code> as parameter was called.
* Test is ok if <code>getHavingClause</code> from <code>xQueryAna</code>
* returns the complex clause from beginning.
* <p>
* required methods:
*<ul>
* <li><code>setHavingClause</code></li>
* <li><code>setStructuredFilter</code></li>
*</ul>
*/
public void _setStructuredHavingClause() {
requiredMethod("setHavingClause()");
executeMethod("setStructuredFilter()");
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' )";
try{
oObj.setHavingClause(complexFilter);
PropertyValue[][] aStructuredHaving =
xQueryAna.getStructuredHavingClause();
oObj.setHavingClause("");
oObj.setStructuredHavingClause(aStructuredHaving);
tRes.tested("setStructuredHavingClause()",
xQueryAna.getHavingClause().equals(complexFilter));
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("setStructuredHavingClause()", false);
}
}
/**
* First object relation <code>xProp</code> was used as parameter. Relation
* <code>xQueryAna</code> was used to check if relation <code>colName</code>
* was found.
* Second an empty <code>XPropertySet</code> was given as parameter. An
* <code>SQLException</code> must be thrown.
*/
public void _appendHavingClauseByColumn() {
boolean ok = true;
try
{
xReSet.beforeFirst();
}
catch (SQLException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendHavingClauseByColumn()", false);
}
try{
oObj.appendHavingClauseByColumn(xProp, true,SQLFilterOperator.EQUAL);
log.println("expected Exception was not thrown");
tRes.tested("appendHavingClauseByColumn()", false);
ok = false;
}
catch (com.sun.star.uno.RuntimeException e)
{
log.println("expected Exception: " + e.toString());
ok = ok && true;
}
catch (SQLException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendHavingClauseByColumn()", false);
} catch (com.sun.star.lang.WrappedTargetException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendHavingClauseByColumn()", false);
}
try
{
xReSet.first();
}
catch (SQLException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendHavingClauseByColumn()", false);
}
try{
oObj.appendHavingClauseByColumn(xProp, true,SQLFilterOperator.EQUAL);
log.println("appendHavingClauseByColumn: " + xQueryAna.getFilter());
ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendHavingClauseByColumn()", false);
} catch (com.sun.star.lang.WrappedTargetException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendHavingClauseByColumn()", false);
}
try{
XPropertySet dummy = null;
oObj.appendHavingClauseByColumn(dummy, true,SQLFilterOperator.EQUAL);
log.println("expected Exception was not thrown");
tRes.tested("appendHavingClauseByColumn()", false);
} catch (SQLException e){
log.println("expected Exception");
ok = ok && true;
} catch (com.sun.star.lang.WrappedTargetException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendHavingClauseByColumn()", false);
}
// cleanup
try
{
xReSet.beforeFirst();
}
catch (SQLException e)
{
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendHavingClauseByColumn()", false);
}
tRes.tested("appendHavingClauseByColumn()", ok);
}
/**
* First object relation <code>xProp</code> was set as parameter. Relation
* <code>xQueryAna</code> was used to check if relation <code>colName</code>
* was found.
* Second an empty <code>XPropertySet</code> was given as parameter. An
* <code>SQLException</code> must be thrown.
*/
public void _appendOrderByColumn() {
boolean ok = true;
try{
oObj.appendOrderByColumn(xProp, true);
log.println("appendOrderByColumn: " + xQueryAna.getFilter());
ok = ok && (xQueryAna.getFilter().indexOf(colName) > 0);
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("appendOrderByColumn()", false);
}
try{
XPropertySet dummy = null;
oObj.appendOrderByColumn(dummy, true);
log.println("expected Exception was not thrown");
tRes.tested("appendOrderByColumn()", false);
} catch (SQLException e){
log.println("expected Exception");
ok = ok && true;
}
tRes.tested("appendOrderByColumn()", ok);
}
/**
* Method <code>getOrder</code> from object relation <code>xQueryAna</code>
* checks the order which was set while calling <code>setOrder</code>
*/
public void _setOrder() {
try{
String order = "\"Identifier\"";
oObj.setOrder(order);
tRes.tested("setOrder()", xQueryAna.getOrder().equals(order));
} catch (SQLException e){
log.println("unexpected Exception: " + e.toString());
tRes.tested("setOrder()", false);
}
}
} // finish class _XSingleSelectQueryComposer
|