Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWFS2 / src-test / com / iver / cit / gvsig / gui / panels / sqlQueryValidation / TestSQLQueryValidation.java @ 9486

History | View | Annotate | Download (5.03 KB)

1
package com.iver.cit.gvsig.gui.panels.sqlQueryValidation;
2

    
3
import junit.framework.TestCase;
4

    
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45

    
46
/**
47
 * Tests the methods of the class SQLQueryValidation
48
 *    (This class is made without inner static methods for don't create problems to Zql, in this way,
49
 *     it's possible to add more tests, with or without long queries.)
50
 * 
51
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
52
 */
53
 public class TestSQLQueryValidation extends TestCase{
54
        
55
        /*
56
         *  (non-Javadoc)
57
         * @see junit.framework.TestCase#setUp()
58
         */
59
        protected void setUp() throws Exception {
60
                super.setUp();
61
        }
62

    
63
        /*
64
         *  (non-Javadoc)
65
         * @see junit.framework.TestCase#tearDown()
66
         */
67
        protected void tearDown() throws Exception {
68
                super.tearDown();
69
        }
70
        
71
        /**
72
         * A test (Correct)
73
         */
74
        public void test1() {
75
                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);";
76
                
77
                System.out.println("?Es v?lida '" + query + "' ?");
78
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, false);
79

    
80
                if (sqlQueryValidation.validateQuery()) {
81
                        System.out.println("Yes.");
82
                }
83
                else {
84
                        System.out.println("No.");
85
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
86
                        System.out.println(sqlQueryValidation.getErrorMessage());
87
                        fail();
88
                }
89
        }
90
        
91
        /**
92
         * A test (Correct)
93
         */
94
        public void test2() {
95
                String query = "SELECT * FROM House;";
96

    
97
                System.out.println("?Es v?lida '" + query + "' ?");
98
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, false);
99

    
100
                if (sqlQueryValidation.validateQuery()) {
101
                        System.out.println("Yes.");
102
                }
103
                else {
104
                        System.out.println("No.");
105
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
106
                        System.out.println(sqlQueryValidation.getErrorMessage());
107
                        fail();
108
                }
109
        }
110

    
111
        /**
112
         * A test (Incorrect)
113
         */
114
        public void test3() {
115
                String query = "SELECT a* FROM House;";
116

    
117
                System.out.println("?Es v?lida '" + query + "' ?");
118
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, false);
119

    
120
                if (sqlQueryValidation.validateQuery()) {
121
                        System.out.println("Yes.");
122
                }
123
                else {
124
                        System.out.println("No.");
125
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
126
                        System.out.println(sqlQueryValidation.getErrorMessage());
127
                        fail();
128
                }
129
        }
130
        
131
        /**
132
         * A test (Correct)
133
         */
134
        public void test4() {
135
                String query = "SELECT * FROM House;";
136

    
137
                System.out.println("?Es v?lida '" + query + "' ?");
138
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, false);
139

    
140
                if (sqlQueryValidation.validateQuery()) {
141
                        System.out.println("Yes.");
142
                }
143
                else {
144
                        System.out.println("No.");
145
                        System.out.println(sqlQueryValidation.getErrorPositionAsMessage());
146
                        System.out.println(sqlQueryValidation.getErrorMessage());
147
                        fail();
148
                }
149
        }
150

    
151
        /**
152
         * A test (Correct)
153
         */
154
        public void test5() {
155
                String query = "r.level = f.level AND r.user_name LIKE \'P%\';";
156

    
157
                System.out.println("?Es v?lida '" + query + "' ?");
158
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
159

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

    
171
        /**
172
         * A test (Incorrect)
173
         */
174
        public void test6() {
175
                String query = "r.level = f.level a e3 w         q3          ?32        9'}97AND r.user_name LIKE \'P%\';";
176

    
177
                System.out.println("?Es v?lida '" + query + "' ?");
178
                SQLQueryValidation sqlQueryValidation = new SQLQueryValidation(query, true);
179

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