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