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