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