Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / impl / DefaultMapContextManagerTest.java @ 30754

History | View | Annotate | Download (8.43 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (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

    
71
        protected void tearDown() throws Exception {
72
                super.tearDown();
73
        }
74

    
75
        /**
76
         * Test method for
77
         * {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#createDefaultMapContextDrawerInstance()}
78
         * .
79
         */
80
        public void testGetDefaultMapContextDrawerInstance() throws Exception {
81

    
82
                manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class);
83

    
84
                MapContextDrawer drawer = manager
85
                                .createDefaultMapContextDrawerInstance();
86

    
87
                assertNotNull("The created MapContextDrawer instance can't be null",
88
                                drawer);
89
                assertTrue(
90
                                "The created MapContextDrawer is not instance of the registered class"
91
                                                + DummyMapContextDrawer.class,
92
                                drawer instanceof DummyMapContextDrawer);
93
        }
94

    
95
        /**
96
         * Test method for
97
         * {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#setDefaultMapContextDrawer(java.lang.Class)}
98
         * .
99
         */
100
        public void testSetDefaultMapContextDrawer() throws Exception {
101

    
102
                // First, try to register an invalid class
103
                try {
104
                        manager.setDefaultMapContextDrawer(Object.class);
105
                        fail("Error, a class that does not implement the MapContextDrawer "
106
                                        + "interface has been accepted");
107
                } catch (MapContextRuntimeException e) {
108
                        // OK
109
                }
110

    
111
                // Next, try to register a valid class
112
                manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class);
113
        }
114

    
115
        public void testCreateGraphicsLayer() throws Exception {
116
                assertNotNull(manager.createGraphicsLayer(CRSFactory.getCRS("EPSG:23030")));
117
        }
118

    
119
        public void testCreateDefaultVectorLegend() throws Exception {
120

    
121
                manager.registerLegend("DummyLegend", DummyVectorLegend.class);
122
                manager.setDefaultVectorLegend("DummyLegend");
123

    
124
                IVectorLegend legend = manager.createDefaultVectorLegend(1);
125
                assertNotNull(legend);
126
                assertTrue(legend instanceof DummyVectorLegend);
127
        }
128

    
129
        public void testRegisterCreateLegend() throws Exception {
130

    
131
                manager.registerLegend("DummyLegend", DummyVectorLegend.class);
132

    
133
                ILegend legend = manager.createLegend("DummyLegend");
134
                assertNotNull(legend);
135
                assertTrue(legend instanceof DummyVectorLegend);
136

    
137
                assertNull(manager.createLegend("NONE"));
138
        }
139

    
140
        public void testRegisterCreateLegendReader() throws Exception {
141

    
142
                manager.registerLegendReader("Dummy", DummyLegendReader.class);
143

    
144
                ILegendReader legendReader = manager.createLegendReader("Dummy");
145
                assertNotNull(legendReader);
146
                assertTrue(legendReader instanceof DummyLegendReader);
147

    
148
                assertNull(manager.createLegendReader("NONE"));
149
        }
150

    
151
        public void testRegisterCreateLegendWriter() throws Exception {
152

    
153
                manager.registerLegend("DummyLegend", DummyVectorLegend.class);
154

    
155
                manager.registerLegendWriter("DummyLegend", "Dummy",
156
                                DummyLegendWriter.class);
157

    
158
                // Test the registered writer is created
159
                ILegendWriter legendWriter = manager.createLegendWriter("DummyLegend",
160
                                "Dummy");
161
                assertNotNull(legendWriter);
162
                assertTrue(legendWriter instanceof DummyLegendWriter);
163

    
164
                // Test non registered cases
165
                assertNull(manager.createLegendWriter("NONE", "Dummy"));
166
                assertNull(manager.createLegendWriter("DummyLegend", "NONE"));
167
                assertNull(manager.createLegendWriter("NONE", "NONE"));
168
        }
169

    
170
        public static class DummyMapContextDrawer implements MapContextDrawer {
171

    
172
                public void dispose() {
173
                }
174

    
175
                public void draw(FLayers root, BufferedImage image, Graphics2D g,
176
                                Cancellable cancel, double scale) throws ReadException {
177
                }
178

    
179
                public void print(FLayers root, Graphics2D g, Cancellable cancel,
180
                                double scale, PrintAttributes properties) throws ReadException {
181
                }
182

    
183
                public void setMapContext(MapContext mapContext) {
184
                }
185

    
186
                public void setViewPort(ViewPort viewPort) {
187
                }
188

    
189
        }
190

    
191
        public static class DummyLegendReader implements ILegendReader {
192

    
193
        }
194

    
195
        public static class DummyLegendWriter implements ILegendWriter {
196

    
197
        }
198

    
199
        public static class DummyVectorLegend implements IVectorLegend {
200

    
201
                public void draw(BufferedImage image, Graphics2D graphics2d,
202
                                ViewPort viewPort, Cancellable cancel, double scale,
203
                                Map queryParameters, ICoordTrans coordTrans,
204
                                FeatureStore featureStore) throws LegendException {
205
                        // Empty method
206
                }
207

    
208
                public int getShapeType() {
209
                        // Empty method
210
                        return 0;
211
                }
212

    
213
                public ISymbol getSymbolByFeature(Feature feat)
214
                                throws MapContextException {
215
                        // Empty method
216
                        return null;
217
                }
218

    
219
                public boolean isSuitableForShapeType(int shapeType) {
220
                        // Empty method
221
                        return false;
222
                }
223

    
224
                public boolean isUseDefaultSymbol() {
225
                        // Empty method
226
                        return false;
227
                }
228

    
229
                public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
230
                                double scale, Map queryParameters, ICoordTrans coordTrans,
231
                                FeatureStore featureStore, PrintAttributes properties)
232
                                throws LegendException {
233
                        // Empty method
234
                }
235

    
236
                public void setDefaultSymbol(ISymbol s) {
237
                        // Empty method
238
                }
239

    
240
                public void setShapeType(int shapeType) {
241
                        // Empty method
242
                }
243

    
244
                public void useDefaultSymbol(boolean b) {
245
                        // Empty method
246
                }
247

    
248
                public void addLegendListener(LegendContentsChangedListener listener) {
249
                        // Empty method
250
                }
251

    
252
                public ILegend cloneLegend() {
253
                        // Empty method
254
                        return null;
255
                }
256

    
257
                public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) {
258
                        // Empty method
259
                }
260

    
261
                public ISymbol getDefaultSymbol() {
262
                        // Empty method
263
                        return null;
264
                }
265

    
266
                public LegendContentsChangedListener[] getListeners() {
267
                        // Empty method
268
                        return null;
269
                }
270

    
271
                public void removeLegendListener(LegendContentsChangedListener listener) {
272
                        // Empty method
273
                }
274

    
275
                public void loadFromState(PersistentState state)
276
                                throws PersistenceException {
277
                        // Empty method
278
                }
279

    
280
                public void saveToState(PersistentState state)
281
                                throws PersistenceException {
282
                        // Empty method
283
                }
284

    
285
                public void addDrawingObserver(Observer observer) {
286
                        // Empty method
287
                }
288

    
289
                public void deleteDrawingObserver(Observer observer) {
290
                        // Empty method
291
                }
292

    
293
                public void deleteDrawingObservers() {
294
                        // Empty method
295
                }
296
        }
297
}