svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / test / java / org / gvsig / app / gui / filter / TestFilterExpressionFromWhereIsEmpty_Method.java @ 40558
History | View | Annotate | Download (4.12 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.app.gui.filter; |
25 | |||
26 | import junit.framework.TestCase; |
||
27 | |||
28 | |||
29 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
30 | *
|
||
31 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
32 | *
|
||
33 | * This program is free software; you can redistribute it and/or
|
||
34 | * modify it under the terms of the GNU General Public License
|
||
35 | * as published by the Free Software Foundation; either version 2
|
||
36 | * of the License, or (at your option) any later version.
|
||
37 | *
|
||
38 | * This program is distributed in the hope that it will be useful,
|
||
39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
41 | * GNU General Public License for more details.
|
||
42 | *
|
||
43 | * You should have received a copy of the GNU General Public License
|
||
44 | * along with this program; if not, write to the Free Software
|
||
45 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
46 | *
|
||
47 | * For more information, contact:
|
||
48 | *
|
||
49 | * Generalitat Valenciana
|
||
50 | * Conselleria d'Infraestructures i Transport
|
||
51 | * Av. Blasco Ib??ez, 50
|
||
52 | * 46010 VALENCIA
|
||
53 | * SPAIN
|
||
54 | *
|
||
55 | * +34 963862235
|
||
56 | * gvsig@gva.es
|
||
57 | * www.gvsig.gva.es
|
||
58 | *
|
||
59 | * or
|
||
60 | *
|
||
61 | * IVER T.I. S.A
|
||
62 | * Salamanca 50
|
||
63 | * 46005 Valencia
|
||
64 | * Spain
|
||
65 | *
|
||
66 | * +34 963163400
|
||
67 | * dac@iver.es
|
||
68 | */
|
||
69 | |||
70 | /**
|
||
71 | * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
||
72 | */
|
||
73 | public class TestFilterExpressionFromWhereIsEmpty_Method extends TestCase { |
||
74 | /*
|
||
75 | * (non-Javadoc)
|
||
76 | * @see junit.framework.TestCase#setUp()
|
||
77 | */
|
||
78 | protected void setUp() throws Exception { |
||
79 | super.setUp();
|
||
80 | } |
||
81 | |||
82 | /*
|
||
83 | * (non-Javadoc)
|
||
84 | * @see junit.framework.TestCase#tearDown()
|
||
85 | */
|
||
86 | protected void tearDown() throws Exception { |
||
87 | super.tearDown();
|
||
88 | } |
||
89 | |||
90 | /**
|
||
91 | * Test 1 (valid)
|
||
92 | */
|
||
93 | public void test1() { |
||
94 | String expression = new String("select * from 'gdbms144426c_10fc90fa1aa__7c18' where ;"); |
||
95 | |||
96 | System.out.println("? Es vac?o el filtro en: " + expression + " ? "); |
||
97 | |||
98 | if (this.filterExpressionFromWhereIsEmpty(expression)) |
||
99 | System.out.println("Si."); |
||
100 | else
|
||
101 | System.out.println("No."); |
||
102 | } |
||
103 | |||
104 | /**
|
||
105 | * Test 2 (invalid)
|
||
106 | */
|
||
107 | public void test2() { |
||
108 | String expression = new String("select * from 'gdbms158fd70_10fc92ee61e__7c18' where layer < '61';"); |
||
109 | |||
110 | System.out.println("? Es vac?o el filtro en: " + expression + " ? "); |
||
111 | |||
112 | if (this.filterExpressionFromWhereIsEmpty(expression)) |
||
113 | System.out.println("Si."); |
||
114 | else
|
||
115 | System.out.println("No."); |
||
116 | } |
||
117 | |||
118 | /**
|
||
119 | * Returns true if the WHERE subconsultation of the filterExpression is empty ("")
|
||
120 | *
|
||
121 | * @param expression An string
|
||
122 | * @return A boolean value
|
||
123 | */
|
||
124 | private boolean filterExpressionFromWhereIsEmpty(String expression) { |
||
125 | String subExpression = expression.trim();
|
||
126 | int pos;
|
||
127 | |||
128 | // Remove last ';' if exists
|
||
129 | if (subExpression.charAt(subExpression.length() -1) == ';') |
||
130 | subExpression = subExpression.substring(0, subExpression.length() -1).trim(); |
||
131 | |||
132 | // If there is no 'where' clause
|
||
133 | if ((pos = subExpression.indexOf("where")) == -1) |
||
134 | return false; |
||
135 | |||
136 | // If there is no subexpression in the WHERE clause -> true
|
||
137 | subExpression = subExpression.substring(pos + 5, subExpression.length()).trim(); // + 5 is the length of 'where' |
||
138 | if ( subExpression.length() == 0 ) |
||
139 | return true; |
||
140 | else
|
||
141 | return false; |
||
142 | } |
||
143 | } |