svn-gvsig-desktop / trunk / libraries / libGPE / src-test / org / gvsig / gpe / readers / GPEReaderBaseTest.java @ 19579
History | View | Annotate | Download (6.42 KB)
1 |
package org.gvsig.gpe.readers; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileInputStream; |
5 |
import java.io.FileNotFoundException; |
6 |
import java.io.InputStream; |
7 |
import java.util.ArrayList; |
8 |
|
9 |
import junit.framework.TestCase; |
10 |
|
11 |
import org.gvsig.gpe.GPEContentHandlerTest; |
12 |
import org.gvsig.gpe.GPEErrorHandlerTest; |
13 |
import org.gvsig.gpe.GPERegister; |
14 |
import org.gvsig.gpe.containers.Layer; |
15 |
import org.gvsig.gpe.parser.GPEContentHandler; |
16 |
import org.gvsig.gpe.parser.GPEErrorHandler; |
17 |
import org.gvsig.gpe.parser.GPEParser; |
18 |
|
19 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
20 |
*
|
21 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
22 |
*
|
23 |
* This program is free software; you can redistribute it and/or
|
24 |
* modify it under the terms of the GNU General Public License
|
25 |
* as published by the Free Software Foundation; either version 2
|
26 |
* of the License, or (at your option) any later version.
|
27 |
*
|
28 |
* This program is distributed in the hope that it will be useful,
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
* GNU General Public License for more details.
|
32 |
*
|
33 |
* You should have received a copy of the GNU General Public License
|
34 |
* along with this program; if not, write to the Free Software
|
35 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
36 |
*
|
37 |
* For more information, contact:
|
38 |
*
|
39 |
* Generalitat Valenciana
|
40 |
* Conselleria d'Infraestructures i Transport
|
41 |
* Av. Blasco Ib??ez, 50
|
42 |
* 46010 VALENCIA
|
43 |
* SPAIN
|
44 |
*
|
45 |
* +34 963862235
|
46 |
* gvsig@gva.es
|
47 |
* www.gvsig.gva.es
|
48 |
*
|
49 |
* or
|
50 |
*
|
51 |
* IVER T.I. S.A
|
52 |
* Salamanca 50
|
53 |
* 46005 Valencia
|
54 |
* Spain
|
55 |
*
|
56 |
* +34 963163400
|
57 |
* dac@iver.es
|
58 |
*/
|
59 |
/* CVS MESSAGES:
|
60 |
*
|
61 |
* $Id: GPEReaderBaseTest.java 173 2007-11-06 12:10:57Z jpiera $
|
62 |
* $Log$
|
63 |
* Revision 1.7 2007/05/09 06:54:07 jorpiell
|
64 |
* Change the File by URI
|
65 |
*
|
66 |
* Revision 1.6 2007/04/20 12:04:10 csanchez
|
67 |
* Actualizacion protoripo libGPE, A?adidos test para el parser, parseo con XSOM
|
68 |
*
|
69 |
* Revision 1.5 2007/04/19 11:50:20 csanchez
|
70 |
* Actualizacion protoripo libGPE
|
71 |
*
|
72 |
* Revision 1.4 2007/04/19 07:23:20 jorpiell
|
73 |
* Add the add methods to teh contenhandler and change the register mode
|
74 |
*
|
75 |
* Revision 1.3 2007/04/14 16:06:35 jorpiell
|
76 |
* Add the container classes
|
77 |
*
|
78 |
* Revision 1.2 2007/04/13 13:14:55 jorpiell
|
79 |
* Created the base tests and add some methods to the content handler
|
80 |
*
|
81 |
* Revision 1.1 2007/04/13 07:17:54 jorpiell
|
82 |
* Add the writting tests for the simple geometries
|
83 |
*
|
84 |
*
|
85 |
*/
|
86 |
/**
|
87 |
* This class must be implementend by all the classes that
|
88 |
* implements a GPE reader Parser.
|
89 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
90 |
*/
|
91 |
public abstract class GPEReaderBaseTest extends TestCase { |
92 |
private File file = null; |
93 |
private GPEParser parser = null; |
94 |
private GPEContentHandler contenHandler = null; |
95 |
private GPEErrorHandler errorHandler = null; |
96 |
private String parserName="FORMAT VERSION"; |
97 |
private String parserDescription="default parser description"; |
98 |
|
99 |
|
100 |
public void setUp() throws Exception{ |
101 |
//Register the parser
|
102 |
GPERegister.addGpeParser(getGPEParserName(), |
103 |
getGPEParserDescription(), |
104 |
getGPEParserClass()); |
105 |
System.out.println("INFO: Parser registrado"); |
106 |
file = new File(getFile()); |
107 |
System.out.println("INFO: Abriendo Fichero: "+file.getName()); |
108 |
assertEquals(GPERegister.accept(file.toURI()),true);
|
109 |
System.out.println("INFO: Existe parser registrado para el fomato "); |
110 |
parser = GPERegister.createParser(getGPEParserName()); |
111 |
System.out.println("INFO: Creado el parser "); |
112 |
assertNotNull(parser); |
113 |
} |
114 |
|
115 |
/**
|
116 |
* This test parses the file and make the
|
117 |
* asserts.
|
118 |
* @throws Exception
|
119 |
*/
|
120 |
public void testParse() throws Exception{ |
121 |
parseFile(); |
122 |
parseInputStream(); |
123 |
} |
124 |
|
125 |
/**
|
126 |
* Parses the file
|
127 |
*/
|
128 |
private void parseFile(){ |
129 |
System.out.println("INFO: PARSING THE FILE..."); |
130 |
parser.parse(getContenHandler() , getErrorHandler(), file.toURI()); |
131 |
System.out.println("INFO: ??? SUCCESS !!!"); |
132 |
makeAsserts(); |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Parses the file like an inputstream
|
137 |
* @throws FileNotFoundException
|
138 |
*/
|
139 |
private void parseInputStream() throws Exception{ |
140 |
InputStream is = getInputStream();
|
141 |
errorHandler = null;
|
142 |
contenHandler = null;
|
143 |
System.out.println("INFO: PARSING THE INPUTSTREAM..."); |
144 |
parser.parse(getContenHandler() , getErrorHandler(), is); |
145 |
System.out.println("INFO: ??? SUCCESS !!!"); |
146 |
makeAsserts(); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* This method has to be override by the tests that use
|
151 |
* other InputStream (KMZ...)
|
152 |
* @return
|
153 |
* @throws FileNotFoundException
|
154 |
*/
|
155 |
public InputStream getInputStream() throws Exception{ |
156 |
return new FileInputStream(new File(getFile())); |
157 |
} |
158 |
|
159 |
/**
|
160 |
* This method must be used by the subclasses
|
161 |
* to make the comparations. With getLayers
|
162 |
* it can retrieve the parsed layers
|
163 |
*/
|
164 |
public abstract void makeAsserts(); |
165 |
|
166 |
/**
|
167 |
* Each test must to return its parser name
|
168 |
* to register it before to start the parsing
|
169 |
* process
|
170 |
*/
|
171 |
public String getGPEParserName(){ |
172 |
return parserName;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Each test must to return its parser description
|
177 |
* to register it before to start the parsing
|
178 |
* process
|
179 |
*/
|
180 |
public String getGPEParserDescription(){ |
181 |
return parserDescription ;
|
182 |
} |
183 |
/**
|
184 |
* Each test must to return its parser name
|
185 |
* to register it before to start the parsing
|
186 |
* process
|
187 |
*/
|
188 |
public void setGPEParserName(String name){ |
189 |
parserName=name; |
190 |
} |
191 |
|
192 |
/**
|
193 |
* Each test must to return its parser description
|
194 |
* to register it before to start the parsing
|
195 |
* process
|
196 |
*/
|
197 |
public void setGPEParserDescription(String description){ |
198 |
parserDescription=description; |
199 |
} |
200 |
/**
|
201 |
* Each test must to return its parser class
|
202 |
* that will be used to create new parsers.
|
203 |
*/
|
204 |
public abstract Class getGPEParserClass(); |
205 |
|
206 |
/**
|
207 |
* Gets the GML file to open
|
208 |
* @return
|
209 |
*/
|
210 |
public abstract String getFile(); |
211 |
|
212 |
/**
|
213 |
* Gets a list of parsed layers
|
214 |
* @return
|
215 |
*/
|
216 |
public Layer[] getLayers(){ |
217 |
ArrayList layers = ((GPEContentHandlerTest)parser.getContentHandler()).getLayers();
|
218 |
Layer[] aLayers = new Layer[layers.size()]; |
219 |
for (int i=0 ; i<layers.size() ; i++){ |
220 |
aLayers[i] = (Layer)layers.get(i); |
221 |
} |
222 |
return aLayers;
|
223 |
} |
224 |
|
225 |
/**
|
226 |
* @return the contenHandler
|
227 |
*/
|
228 |
public GPEContentHandler getContenHandler() {
|
229 |
if (contenHandler == null){ |
230 |
contenHandler = new GPEContentHandlerTest();
|
231 |
} |
232 |
return contenHandler;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* @return the errorHandler
|
237 |
*/
|
238 |
public GPEErrorHandler getErrorHandler() {
|
239 |
if (errorHandler == null){ |
240 |
errorHandler = new GPEErrorHandlerTest();
|
241 |
} |
242 |
return errorHandler;
|
243 |
} |
244 |
|
245 |
} |