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