Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / test / java / org / gvsig / app / sqlQueryValidation / TestSQLQueryValidation.java @ 40558

History | View | Annotate | Download (11.5 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.sqlQueryValidation;
25

    
26
import junit.framework.TestCase;
27

    
28
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
29
 *
30
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
31
 *
32
 * This program is free software; you can redistribute it and/or
33
 * modify it under the terms of the GNU General Public License
34
 * as published by the Free Software Foundation; either version 2
35
 * of the License, or (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
45
 *
46
 * For more information, contact:
47
 *
48
 *  Generalitat Valenciana
49
 *   Conselleria d'Infraestructures i Transport
50
 *   Av. Blasco Ib??ez, 50
51
 *   46010 VALENCIA
52
 *   SPAIN
53
 *
54
 *      +34 963862235
55
 *   gvsig@gva.es
56
 *      www.gvsig.gva.es
57
 *
58
 *    or
59
 *
60
 *   IVER T.I. S.A
61
 *   Salamanca 50
62
 *   46005 Valencia
63
 *   Spain
64
 *
65
 *   +34 963163400
66
 *   dac@iver.es
67
 */
68

    
69
/**
70
 * Tests the methods of the class SQLQueryValidation
71
 *    (This class is made without inner static methods for don't create problems to Zql, in this way,
72
 *     it's possible to add more tests, with or without long queries.)
73
 * 
74
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
75
 */
76
 public class TestSQLQueryValidation extends TestCase{
77
        
78
        /*
79
         *  (non-Javadoc)
80
         * @see junit.framework.TestCase#setUp()
81
         */
82
        protected void setUp() throws Exception {
83
                super.setUp();
84
        }
85

    
86
        /*
87
         *  (non-Javadoc)
88
         * @see junit.framework.TestCase#tearDown()
89
         */
90
        protected void tearDown() throws Exception {
91
                super.tearDown();
92
        }
93
        
94
        /**
95
         * A test (Correct)
96
         */
97
        public void test1() {
98
                String query = "SELECT r.name, f.id FROM room r, flat f WHERE (r.user_name LIKE 'P%') AND (r.flat = f.id) AND (r.color_wall LIKE 'white') AND (r.height < 2.20);";
99
                
100
                System.out.println("?Es v?lida '" + query + "' ?");
101
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, false);
102

    
103
                if (sqlQueryValidation.validateQuery()) {
104
                        System.out.println("Yes.");
105
                }
106
                else {
107
                        System.out.println("No.");
108
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
109
                        System.out.println(sqlQueryValidation.getErrorMessage());
110
                        fail();
111
                }
112
        }
113
        
114
        /**
115
         * A test (Correct)
116
         */
117
        public void test2() {
118
                String query = "SELECT * FROM House;";
119

    
120
                System.out.println("?Es v?lida '" + query + "' ?");
121
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, false);
122

    
123
                if (sqlQueryValidation.validateQuery()) {
124
                        System.out.println("Yes.");
125
                }
126
                else {
127
                        System.out.println("No.");
128
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
129
                        System.out.println(sqlQueryValidation.getErrorMessage());
130
                        fail();
131
                }
132
        }
133

    
134
        /**
135
         * A test (Incorrect)
136
         */
137
        public void test3() {
138
                String query = "SELECT a* FROM House;";
139

    
140
                System.out.println("?Es v?lida '" + query + "' ?");
141
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, false);
142

    
143
                if (sqlQueryValidation.validateQuery()) {
144
                        System.out.println("Yes.");
145
                }
146
                else {
147
                        System.out.println("No.");
148
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
149
                        System.out.println(sqlQueryValidation.getErrorMessage());
150
                        fail();
151
                }
152
        }
153
        
154
        /**
155
         * A test (Correct)
156
         */
157
        public void test4() {
158
                String query = "SELECT * FROM House;";
159

    
160
                System.out.println("?Es v?lida '" + query + "' ?");
161
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, false);
162

    
163
                if (sqlQueryValidation.validateQuery()) {
164
                        System.out.println("Yes.");
165
                }
166
                else {
167
                        System.out.println("No.");
168
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
169
                        System.out.println(sqlQueryValidation.getErrorMessage());
170
                        fail();
171
                }
172
        }
173

    
174
        /**
175
         * A test (Correct)
176
         */
177
        public void test5() {
178
                String query = "r.level = f.level AND r.user_name LIKE \'P%\';";
179

    
180
                System.out.println("?Es v?lida '" + query + "' ?");
181
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
182

    
183
                if (sqlQueryValidation.validateQuery()) {
184
                        System.out.println("Yes.");
185
                }
186
                else {
187
                        System.out.println("No.");
188
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
189
                        System.out.println(sqlQueryValidation.getErrorMessage());
190
                        fail();
191
                }
192
        }
193

    
194
        /**
195
         * A test (Incorrect)
196
         */
197
        public void test6() {
198
                String query = "r.level = f.level a e3 w         q3          ?32        9'}97AND r.user_name LIKE \'P%\';";
199

    
200
                System.out.println("?Es v?lida '" + query + "' ?");
201
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
202

    
203
                if (sqlQueryValidation.validateQuery()) {
204
                        System.out.println("Yes.");
205
                }
206
                else {
207
                        System.out.println("No.");
208
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
209
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
210
                        fail();
211
                }
212
        }
213
        
214
        /**
215
         * A test (Correct)
216
         */
217
        public void test7() {
218
                String query = "\"codigo\" = 'Canal d'Elx'";
219

    
220
                System.out.println("?Es v?lida '" + query + "' ?");
221
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
222

    
223
                if (sqlQueryValidation.validateQuery()) {
224
                        System.out.println("Yes.");
225
                }
226
                else {
227
                        System.out.println("No.");
228
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
229
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
230
                        fail();
231
                }
232
        }
233
        
234
        /**
235
         * A test (Correct)
236
         */
237
        public void test8() {
238
                String query = "\"codigo\" = 'Canal de la M?nega'";
239

    
240
                System.out.println("?Es v?lida '" + query + "' ?");
241
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
242

    
243
                if (sqlQueryValidation.validateQuery()) {
244
                        System.out.println("Yes.");
245
                }
246
                else {
247
                        System.out.println("No.");
248
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
249
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
250
                        fail();
251
                }
252
        }
253
        
254
        /**
255
         * A test (Correct)
256
         */
257
        public void test9() {
258
                String query = "\"codigo\" = 'Espa?a'";
259

    
260
                System.out.println("?Es v?lida '" + query + "' ?");
261
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
262

    
263
                if (sqlQueryValidation.validateQuery()) {
264
                        System.out.println("Yes.");
265
                }
266
                else {
267
                        System.out.println("No.");
268
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
269
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
270
                        fail();
271
                }
272
        }
273
        
274
        /**
275
         * A test (Correct)
276
         */
277
        public void test10() {
278
                String query = "\"codigo\" = ('Canal d'Elx')";
279

    
280
                System.out.println("?Es v?lida '" + query + "' ?");
281
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
282

    
283
                if (sqlQueryValidation.validateQuery()) {
284
                        System.out.println("Yes.");
285
                }
286
                else {
287
                        System.out.println("No.");
288
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
289
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
290
                        fail();
291
                }
292
        }
293
        
294
        /**
295
         * A test (Correct)
296
         */
297
        public void test11() {
298
                String query = "\"codigo\" = ( 'Canal d'Elx' )";
299

    
300
                System.out.println("?Es v?lida '" + query + "' ?");
301
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
302

    
303
                if (sqlQueryValidation.validateQuery()) {
304
                        System.out.println("Yes.");
305
                }
306
                else {
307
                        System.out.println("No.");
308
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
309
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
310
                        fail();
311
                }
312
        }
313
        
314
        /**
315
         * A test (Correct)
316
         */
317
        public void test12() {
318
                String query = "\"codigo\" = ( 'Canal d'Elx')";
319

    
320
                System.out.println("?Es v?lida '" + query + "' ?");
321
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
322

    
323
                if (sqlQueryValidation.validateQuery()) {
324
                        System.out.println("Yes.");
325
                }
326
                else {
327
                        System.out.println("No.");
328
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
329
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
330
                        fail();
331
                }
332
        }
333
        
334
        /**
335
         * A test (Correct)
336
         */
337
        public void test13() {
338
                String query = "\"codigo\" = ('Canal d'Elx' )";
339

    
340
                System.out.println("?Es v?lida '" + query + "' ?");
341
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
342

    
343
                if (sqlQueryValidation.validateQuery()) {
344
                        System.out.println("Yes.");
345
                }
346
                else {
347
                        System.out.println("No.");
348
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
349
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
350
                        fail();
351
                }
352
        }        
353
        
354
        /**
355
         * A test (Incorrect)
356
         */
357
        public void test14() {
358
                String query = "\"codigo\" = ('Canal d' Elx' )";
359

    
360
                System.out.println("?Es v?lida '" + query + "' ?");
361
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
362

    
363
                if (sqlQueryValidation.validateQuery()) {
364
                        System.out.println("Yes.");
365
                }
366
                else {
367
                        System.out.println("No.");
368
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
369
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
370
                        fail();
371
                }
372
        }
373
                
374
        /**
375
         * A test (Incorrect)
376
         */
377
        public void test15() {
378
                String query = "\"codigo\" = ('Canal d'Elx d'Alacant' )";
379

    
380
                System.out.println("?Es v?lida '" + query + "' ?");
381
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
382

    
383
                if (sqlQueryValidation.validateQuery()) {
384
                        System.out.println("Yes.");
385
                }
386
                else {
387
                        System.out.println("No.");
388
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
389
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
390
                        fail();
391
                }
392
        }        
393
        
394
        /**
395
         * A test (Incorrect)
396
         */
397
        public void test16() {
398
                String query = "\"fecha\" = Date(11-ene-2004)";
399

    
400
                System.out.println("?Es v?lida '" + query + "' ?");
401
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
402

    
403
                if (sqlQueryValidation.validateQuery()) {
404
                        System.out.println("Yes.");
405
                }
406
                else {
407
                        System.out.println("No.");
408
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
409
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
410
                        fail();
411
                }
412
        }
413
        
414
        /**
415
         * A test (Correct)
416
         */
417
        public void test17() {
418
                String query = "\"fecha\" = 11-ene-2004";
419

    
420
                System.out.println("?Es v?lida '" + query + "' ?");
421
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
422

    
423
                if (sqlQueryValidation.validateQuery()) {
424
                        System.out.println("Yes.");
425
                }
426
                else {
427
                        System.out.println("No.");
428
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
429
                        System.out.println(sqlQueryValidation.getErrorMessage());                        
430
                        fail();
431
                }
432
        }
433
 }