svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / impl / DefaultMapContextManagerTest.java @ 35329
History | View | Annotate | Download (10.5 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {DiSiD Technologies} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.fmap.mapcontext.impl; |
28 |
|
29 |
import java.awt.Graphics2D; |
30 |
import java.awt.image.BufferedImage; |
31 |
import java.util.Map; |
32 |
|
33 |
import org.cresques.cts.ICoordTrans; |
34 |
|
35 |
import org.gvsig.compat.print.PrintAttributes; |
36 |
import org.gvsig.fmap.crs.CRSFactory; |
37 |
import org.gvsig.fmap.dal.exception.ReadException; |
38 |
import org.gvsig.fmap.dal.feature.Feature; |
39 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
40 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
41 |
import org.gvsig.fmap.mapcontext.MapContext; |
42 |
import org.gvsig.fmap.mapcontext.MapContextDrawer; |
43 |
import org.gvsig.fmap.mapcontext.MapContextException; |
44 |
import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
45 |
import org.gvsig.fmap.mapcontext.ViewPort; |
46 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
47 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
48 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
49 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
50 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
51 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
52 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
54 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
55 |
import org.gvsig.tools.evaluator.Evaluator; |
56 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
57 |
import org.gvsig.tools.observer.Observer; |
58 |
import org.gvsig.tools.persistence.PersistentState; |
59 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
60 |
import org.gvsig.tools.task.Cancellable; |
61 |
|
62 |
/**
|
63 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
|
64 |
*/
|
65 |
public class DefaultMapContextManagerTest extends |
66 |
AbstractLibraryAutoInitTestCase { |
67 |
|
68 |
private DefaultMapContextManager manager;
|
69 |
|
70 |
protected void doSetUp() throws Exception { |
71 |
manager = new DefaultMapContextManager();
|
72 |
|
73 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class);
|
74 |
manager.setDefaultVectorLegend("DummyLegend");
|
75 |
manager.registerLegendReader("Dummy", DummyLegendReader.class);
|
76 |
manager.registerLegendWriter("DummyLegend", "Dummy", DummyLegendWriter.class); |
77 |
} |
78 |
|
79 |
protected void tearDown() throws Exception { |
80 |
super.tearDown();
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Test method for
|
85 |
* {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#createDefaultMapContextDrawerInstance()}
|
86 |
* .
|
87 |
*/
|
88 |
public void testGetDefaultMapContextDrawerInstance() throws Exception { |
89 |
|
90 |
manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class); |
91 |
|
92 |
MapContextDrawer drawer = manager |
93 |
.createDefaultMapContextDrawerInstance(); |
94 |
|
95 |
assertNotNull("The created MapContextDrawer instance can't be null",
|
96 |
drawer); |
97 |
assertTrue( |
98 |
"The created MapContextDrawer is not instance of the registered class"
|
99 |
+ DummyMapContextDrawer.class, |
100 |
drawer instanceof DummyMapContextDrawer);
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* Test method for
|
105 |
* {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#setDefaultMapContextDrawer(java.lang.Class)}
|
106 |
* .
|
107 |
*/
|
108 |
public void testSetDefaultMapContextDrawer() throws Exception { |
109 |
|
110 |
// First, try to register an invalid class
|
111 |
try {
|
112 |
manager.setDefaultMapContextDrawer(Object.class);
|
113 |
fail("Error, a class that does not implement the MapContextDrawer "
|
114 |
+ "interface has been accepted");
|
115 |
} catch (MapContextRuntimeException e) {
|
116 |
// OK
|
117 |
} |
118 |
|
119 |
// Next, try to register a valid class
|
120 |
manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class); |
121 |
} |
122 |
|
123 |
public void testCreateGraphicsLayer() throws Exception { |
124 |
assertNotNull(manager.createGraphicsLayer(CRSFactory.getCRS("EPSG:23030")));
|
125 |
} |
126 |
|
127 |
public void testCreateDefaultVectorLegend() throws Exception { |
128 |
|
129 |
IVectorLegend legend = manager.createDefaultVectorLegend(1);
|
130 |
assertNotNull(legend); |
131 |
assertTrue(legend instanceof DummyVectorLegend);
|
132 |
} |
133 |
|
134 |
public void testRegisterCreateLegend() throws Exception { |
135 |
|
136 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class);
|
137 |
|
138 |
ILegend legend = manager.createLegend("DummyLegend");
|
139 |
assertNotNull(legend); |
140 |
assertTrue(legend instanceof DummyVectorLegend);
|
141 |
|
142 |
assertNull(manager.createLegend("NONE"));
|
143 |
} |
144 |
|
145 |
public void testRegisterCreateLegendReader() throws Exception { |
146 |
|
147 |
manager.registerLegendReader("Dummy", DummyLegendReader.class);
|
148 |
|
149 |
ILegendReader legendReader = manager.createLegendReader("Dummy");
|
150 |
assertNotNull(legendReader); |
151 |
assertTrue(legendReader instanceof DummyLegendReader);
|
152 |
|
153 |
assertNull(manager.createLegendReader("NONE"));
|
154 |
} |
155 |
|
156 |
public void testRegisterCreateLegendWriter() throws Exception { |
157 |
|
158 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class);
|
159 |
|
160 |
manager.registerLegendWriter("DummyLegend", "Dummy", |
161 |
DummyLegendWriter.class); |
162 |
|
163 |
// Test the registered writer is created
|
164 |
ILegendWriter legendWriter = manager.createLegendWriter("DummyLegend",
|
165 |
"Dummy");
|
166 |
assertNotNull(legendWriter); |
167 |
assertTrue(legendWriter instanceof DummyLegendWriter);
|
168 |
|
169 |
// Test non registered cases
|
170 |
assertNull(manager.createLegendWriter("NONE", "Dummy")); |
171 |
assertNull(manager.createLegendWriter("DummyLegend", "NONE")); |
172 |
assertNull(manager.createLegendWriter("NONE", "NONE")); |
173 |
} |
174 |
|
175 |
public static class DummyMapContextDrawer implements MapContextDrawer { |
176 |
|
177 |
public void dispose() { |
178 |
} |
179 |
|
180 |
public void draw(FLayers root, BufferedImage image, Graphics2D g, |
181 |
Cancellable cancel, double scale) throws ReadException { |
182 |
} |
183 |
|
184 |
public void print(FLayers root, Graphics2D g, Cancellable cancel, |
185 |
double scale, PrintAttributes properties) throws ReadException { |
186 |
} |
187 |
|
188 |
public void setMapContext(MapContext mapContext) { |
189 |
} |
190 |
|
191 |
public void setViewPort(ViewPort viewPort) { |
192 |
} |
193 |
|
194 |
} |
195 |
|
196 |
public static class DummyLegendReader implements ILegendReader { |
197 |
|
198 |
} |
199 |
|
200 |
public static class DummyLegendWriter implements ILegendWriter { |
201 |
|
202 |
} |
203 |
|
204 |
public static class DummyVectorLegend implements IVectorLegend { |
205 |
|
206 |
public void draw(BufferedImage image, Graphics2D graphics2d, |
207 |
ViewPort viewPort, Cancellable cancel, double scale,
|
208 |
Map queryParameters, ICoordTrans coordTrans,
|
209 |
FeatureStore featureStore, FeatureQuery featureQuery) throws LegendException {
|
210 |
// Empty method
|
211 |
} |
212 |
|
213 |
public void draw(BufferedImage image, Graphics2D graphics2d, |
214 |
ViewPort viewPort, Cancellable cancel, double scale,
|
215 |
Map queryParameters, ICoordTrans coordTrans,
|
216 |
FeatureStore featureStore) throws LegendException {
|
217 |
// Empty method
|
218 |
} |
219 |
|
220 |
public int getShapeType() { |
221 |
// Empty method
|
222 |
return 0; |
223 |
} |
224 |
|
225 |
public ISymbol getSymbolByFeature(Feature feat)
|
226 |
throws MapContextException {
|
227 |
// Empty method
|
228 |
return null; |
229 |
} |
230 |
|
231 |
public boolean isSuitableForShapeType(int shapeType) { |
232 |
// Empty method
|
233 |
return false; |
234 |
} |
235 |
|
236 |
public boolean isUseDefaultSymbol() { |
237 |
// Empty method
|
238 |
return false; |
239 |
} |
240 |
|
241 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
242 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
243 |
FeatureStore featureStore, PrintAttributes properties) |
244 |
throws LegendException {
|
245 |
// Empty method
|
246 |
} |
247 |
|
248 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
249 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
250 |
FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties) |
251 |
throws LegendException {
|
252 |
// Empty method
|
253 |
} |
254 |
|
255 |
public void setDefaultSymbol(ISymbol s) { |
256 |
// Empty method
|
257 |
} |
258 |
|
259 |
public void setShapeType(int shapeType) { |
260 |
// Empty method
|
261 |
} |
262 |
|
263 |
public void useDefaultSymbol(boolean b) { |
264 |
// Empty method
|
265 |
} |
266 |
|
267 |
public void addLegendListener(LegendContentsChangedListener listener) { |
268 |
// Empty method
|
269 |
} |
270 |
|
271 |
public ILegend cloneLegend() {
|
272 |
// Empty method
|
273 |
return null; |
274 |
} |
275 |
|
276 |
public Object clone() throws CloneNotSupportedException { |
277 |
// TODO Auto-generated method stub
|
278 |
return super.clone(); |
279 |
} |
280 |
|
281 |
public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
282 |
// Empty method
|
283 |
} |
284 |
|
285 |
public ISymbol getDefaultSymbol() {
|
286 |
// Empty method
|
287 |
return null; |
288 |
} |
289 |
|
290 |
public LegendContentsChangedListener[] getListeners() { |
291 |
// Empty method
|
292 |
return null; |
293 |
} |
294 |
|
295 |
public void removeLegendListener(LegendContentsChangedListener listener) { |
296 |
// Empty method
|
297 |
} |
298 |
|
299 |
public void loadFromState(PersistentState state) |
300 |
throws PersistenceException {
|
301 |
// Empty method
|
302 |
} |
303 |
|
304 |
public void saveToState(PersistentState state) |
305 |
throws PersistenceException {
|
306 |
// Empty method
|
307 |
} |
308 |
|
309 |
public void addDrawingObserver(Observer observer) { |
310 |
// Empty method
|
311 |
} |
312 |
|
313 |
public void deleteDrawingObserver(Observer observer) { |
314 |
// Empty method
|
315 |
} |
316 |
|
317 |
public void deleteDrawingObservers() { |
318 |
// Empty method
|
319 |
} |
320 |
} |
321 |
} |