Statistics
| Revision:

root / trunk / applications / appgvSIG / src-test / com / iver / cit / gvsig / gui / panels / sqlQueryValidation / TestSQLQueryValidation.java @ 9611

History | View | Annotate | Download (5.11 KB)

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

    
3
import junit.framework.TestCase;
4

    
5
import com.iver.cit.gvsig.gui.panels.sqlQueryValidation.SQLQueryValidation;
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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