Revision 41545

View differences:

tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
28

  
29
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
30

  
31
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
32
		<layout class="org.apache.log4j.PatternLayout">
33
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
34
		</layout>
35
	</appender>
36

  
37
	<category name="org.gvsig.tools">
38
		<priority value="DEBUG" />
39
	</category>
40
	<category name="org.gvsig.fmap.mapcontext">
41
		<priority value="DEBUG" /> 
42
	</category>
43

  
44
	<root>
45
		<priority value="INFO" />
46
		<appender-ref ref="CONSOLE" />
47
	</root>
48
</log4j:configuration>
0 49

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/ExtentHistoryTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {}  {{Task}}
27
 */
28
package org.gvsig.fmap.mapcontext;
29

  
30
import java.awt.Rectangle;
31
import java.awt.geom.Rectangle2D;
32

  
33
import junit.framework.TestCase;
34

  
35
/**
36
 * Unit tests for the class {@link ExtentHistory}.
37
 * 
38
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
39
 */
40
public class ExtentHistoryTest extends TestCase {
41

  
42
	protected void setUp() throws Exception {
43
		super.setUp();
44
	}
45

  
46
	/**
47
	 * Test method for
48
	 * {@link org.gvsig.fmap.mapcontext.ExtentHistory#put(java.awt.geom.Rectangle2D)}
49
	 * .
50
	 */
51
	public void testPut() {
52
		ExtentHistory history = new ExtentHistory();
53

  
54
		Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
55
		Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
56
		Rectangle2D rectangle3 = new Rectangle2D.Double(3, 3, 4, 4);
57
		history.put(rectangle3);
58
		history.put(rectangle2);
59
		history.put(rectangle);
60

  
61
		assertEquals(rectangle, history.get());
62

  
63
		history = new ExtentHistory(2);
64

  
65
		history.put(rectangle);
66
		history.put(rectangle2);
67
		history.put(rectangle3);
68

  
69
		assertEquals(rectangle3, history.get());
70
	}
71

  
72
	/**
73
	 * Test method for
74
	 * {@link org.gvsig.fmap.mapcontext.ExtentHistory#hasPrevious()}.
75
	 */
76
	public void testHasPrevious() {
77
		ExtentHistory history = new ExtentHistory();
78

  
79
		assertFalse(history.hasPrevious());
80

  
81
		Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
82
		history.put(rectangle);
83

  
84
		assertTrue(history.hasPrevious());
85

  
86
		history.removePrev();
87
		assertFalse(history.hasPrevious());
88
	}
89

  
90
	/**
91
	 * Test method for {@link org.gvsig.fmap.mapcontext.ExtentHistory#get()}.
92
	 */
93
	public void testGet() {
94
		ExtentHistory history = new ExtentHistory();
95

  
96
		assertNull("The ExtentHistory has got an element without adding one",
97
				history.get());
98

  
99
		Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
100
		Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
101

  
102
		history.put(rectangle);
103
		assertEquals(rectangle, history.get());
104

  
105
		history.put(rectangle2);
106
		assertEquals(rectangle2, history.get());
107

  
108
		history.removePrev();
109
		assertEquals(rectangle, history.get());
110

  
111
		history.removePrev();
112
		assertNull("The ExtentHistory has got an element, "
113
				+ "but all have been previously removed", history.get());
114
	}
115

  
116
	/**
117
	 * Test method for
118
	 * {@link org.gvsig.fmap.mapcontext.ExtentHistory#removePrev()}.
119
	 */
120
	public void testRemovePrev() {
121
		ExtentHistory history = new ExtentHistory();
122

  
123
		assertNull(
124
				"The ExtentHistory allows removing an element without adding "
125
						+ "at least one", history.removePrev());
126

  
127
		Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2);
128
		Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3);
129

  
130
		history.put(rectangle);
131
		history.put(rectangle2);
132

  
133
		history.removePrev();
134
		assertEquals(rectangle, history.get());
135

  
136
		history.removePrev();
137
		assertNull("The ExtentHistory allows to remove the last element, "
138
				+ "but all have been previously removed", history.removePrev());
139
	}
140
}
0 141

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/rendering/symbol/DummySymbol.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.mapcontext.rendering.symbol;
25

  
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.Rectangle;
29
import java.awt.geom.AffineTransform;
30
import java.awt.geom.PathIterator;
31
import java.util.ArrayList;
32

  
33
import org.gvsig.compat.print.PrintAttributes;
34
import org.gvsig.fmap.dal.feature.Feature;
35
import org.gvsig.fmap.geom.Geometry;
36
import org.gvsig.fmap.geom.Geometry.TYPES;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.fmap.mapcontext.ViewPort;
39
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
40
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
41
import org.gvsig.tools.persistence.PersistentState;
42
import org.gvsig.tools.persistence.exception.PersistenceException;
43
import org.gvsig.tools.task.Cancellable;
44

  
45
public class DummySymbol implements ISymbol {
46

  
47
	private Color color = Color.GREEN;
48
	private int type = TYPES.SOLID;
49
	
50
	public DummySymbol(Color c, int geomtype) {
51
		color = c;
52
		type = geomtype;
53
	}
54
	
55
	public Object clone() {
56
		return null;
57
	}
58
	
59
	public void draw(Graphics2D g, AffineTransform affineTransform,
60
			Geometry geom, Feature f, Cancellable cancel) {
61
		
62
		g.setColor(color);
63
		
64
		if (geom instanceof Point) {
65
			Point p = (Point) geom;
66
			p.transform(affineTransform);
67
			g.drawRect((int) p.getX(), (int) p.getY(), 3, 3);
68
		} else {
69
			PathIterator piter = geom.getPathIterator(affineTransform); 
70
			drawPathIterator(g, piter);
71
		}
72
	}
73

  
74
	public void drawInsideRectangle(Graphics2D g,
75
			AffineTransform scaleInstance, Rectangle r,
76
			PrintAttributes properties) throws SymbolDrawingException {
77
		// TODO Auto-generated method stub
78

  
79
	}
80

  
81
	public Color getColor() {
82
		return color;
83
	}
84

  
85
	public String getDescription() {
86
		return "a dummy symbol";
87
	}
88

  
89
	public int getOnePointRgb() {
90
		return color.getRGB();
91
	}
92

  
93
	public void getPixExtentPlus(Geometry geom, float[] distances,
94
			ViewPort viewPort, int dpi) {
95
		// TODO Auto-generated method stub
96

  
97
	}
98

  
99
	public ISymbol getSymbolForSelection() {
100
		return new DummySymbol(Color.YELLOW, type);
101
	}
102

  
103
	public int getSymbolType() {
104
		return type;
105
	}
106

  
107
	public boolean isOneDotOrPixel(Geometry geom,
108
			double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) {
109
		// TODO Auto-generated method stub
110
		return false;
111
	}
112

  
113
	public boolean isShapeVisible() {
114
		return true;
115
	}
116

  
117
	public boolean isSuitableFor(Geometry geom) {
118
		return type == geom.getType();
119
	}
120

  
121
	public void setColor(Color c) {
122
		color = c;
123
	}
124

  
125
	public void setDescription(String desc) {
126
	}
127

  
128
	public void loadFromState(PersistentState state)
129
			throws PersistenceException {
130
	}
131

  
132
	public void saveToState(PersistentState state) throws PersistenceException {
133
	}
134

  
135
	public void print(Graphics2D g, AffineTransform at, Geometry shape,
136
			PrintAttributes properties) {
137
	}
138
	
139
	
140
	
141
	/**
142
	 * Draws the general path on the graphics object with the given affine transformation
143
	 * @param g the graphics object
144
	 * @param gp the general path
145
	 */
146
	public static void drawPathIterator(Graphics2D g, PathIterator pit) {
147
		
148
		ArrayList x = new ArrayList();
149
		ArrayList y = new ArrayList();
150
		double[] current = new double[6];
151
		
152
		while (!pit.isDone()) {
153
			pit.currentSegment(current);
154
			x.add(new Integer((int) current[0]));
155
			y.add(new Integer((int) current[1]));
156
			pit.next();
157
		}
158
		
159
		int[] gx = integerArrayListToIntArray(x);
160
		int[] gy = integerArrayListToIntArray(y);
161

  
162
		g.drawPolyline(gx, gy, gx.length);
163
	}
164
	
165
	
166
	/**
167
	 * Converts array list of Integer objects into array of int
168
	 * @param l
169
	 * @return array of int
170
	 */
171
	public static int[] integerArrayListToIntArray(ArrayList l) {
172

  
173
		int size = l.size();
174
		int[] resp = new int[size];
175
		for (int i=0; i<size; i++) {
176
			resp[i] = ((Integer) l.get(i)).intValue();
177
		}
178
		return resp;
179
	}
180

  
181
}
0 182

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/rendering/symbol/DummyVectorLegend.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.mapcontext.rendering.symbol;
25

  
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.image.BufferedImage;
29
import java.util.Iterator;
30
import java.util.Map;
31

  
32
import org.cresques.cts.ICoordTrans;
33

  
34
import org.gvsig.compat.print.PrintAttributes;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.feature.Feature;
37
import org.gvsig.fmap.dal.feature.FeatureQuery;
38
import org.gvsig.fmap.dal.feature.FeatureSet;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.geom.Geometry.TYPES;
41
import org.gvsig.fmap.mapcontext.ViewPort;
42
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
43
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
44
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
45
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
46
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
47
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
48
import org.gvsig.tools.ToolsLocator;
49
import org.gvsig.tools.dynobject.DynStruct;
50
import org.gvsig.tools.evaluator.Evaluator;
51
import org.gvsig.tools.observer.Observer;
52
import org.gvsig.tools.persistence.PersistenceManager;
53
import org.gvsig.tools.persistence.PersistentState;
54
import org.gvsig.tools.persistence.exception.PersistenceException;
55
import org.gvsig.tools.task.Cancellable;
56

  
57
public class DummyVectorLegend implements IVectorLegend {
58

  
59
    private long shpType = -1;
60

  
61
    private ISymbol sym = new DummySymbol(Color.RED, TYPES.SOLID);
62

  
63
    public DummyVectorLegend() {
64
        shpType = System.currentTimeMillis() % 1000000;
65
    }
66

  
67
    public DummyVectorLegend(int type) {
68
        shpType = type; // System.currentTimeMillis() % 1000000;
69
    }
70

  
71
    public void draw(BufferedImage image, Graphics2D graphics2D,
72
        ViewPort viewPort, Cancellable cancel, double scale,
73
        Map queryParameters, ICoordTrans coordTrans,
74
        FeatureStore featureStore, FeatureQuery featureQuery) throws LegendException {
75

  
76
    }
77
    public void draw(BufferedImage image, Graphics2D graphics2D,
78
        ViewPort viewPort, Cancellable cancel, double scale,
79
        Map queryParameters, ICoordTrans coordTrans,
80
        FeatureStore featureStore) throws LegendException {
81

  
82
        try {
83
            FeatureSet fs = featureStore.getFeatureSet();
84
            Iterator iter = fs.iterator();
85
            Feature feat = null;
86
            ISymbol symb = null;
87
            while (iter.hasNext()) {
88
                feat = (Feature) iter.next();
89
                symb = this.getSymbolByFeature(feat);
90
                symb.draw(graphics2D, viewPort.getAffineTransform(), feat.getDefaultGeometry(), feat, null);
91
            }
92
        } catch (DataException e) {
93
            // TODO Auto-generated catch block
94
            e.printStackTrace();
95
        }
96
        // TODO Auto-generated method stub
97

  
98
    }
99

  
100
    public int getShapeType() {
101
        // TODO Auto-generated method stub
102
        return (int) shpType;
103
    }
104

  
105
    public ISymbol getSymbolByFeature(Feature feat) {
106
        return sym;
107
    }
108

  
109
    public boolean isSuitableForShapeType(int shapeType) {
110
        return sym.getSymbolType() == shapeType;
111
    }
112

  
113
    public boolean isUseDefaultSymbol() {
114
        return true;
115
    }
116

  
117
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
118
        double scale, Object object, ICoordTrans coordTrans,
119
        FeatureStore featureStore, Evaluator evaluator, PrintAttributes properties)
120
    throws LegendException {
121
        // TODO Auto-generated method stub
122

  
123
    }
124

  
125
    public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException {
126
        sym = s;
127
    }
128

  
129
    public void setShapeType(int shapeType) {
130
        shpType = shapeType;
131
    }
132

  
133
    public void useDefaultSymbol(boolean b) {
134
    }
135

  
136
    public void addLegendListener(LegendContentsChangedListener listener) {
137
        // TODO Auto-generated method stub
138

  
139
    }
140

  
141
    public ILegend cloneLegend() {
142
        // TODO Auto-generated method stub
143
        return null;
144
    }
145

  
146
    public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) {
147
        // TODO Auto-generated method stub
148

  
149
    }
150

  
151
    public ISymbol getDefaultSymbol() {
152
        return sym;
153
    }
154

  
155
    public LegendContentsChangedListener[] getListeners() {
156
        // TODO Auto-generated method stub
157
        return null;
158
    }
159

  
160
    public void removeLegendListener(LegendContentsChangedListener listener) {
161
        // TODO Auto-generated method stub
162

  
163
    }
164

  
165
    public String getClassName() {
166
        return this.getClass().getName();
167
    }
168

  
169

  
170

  
171

  
172
    public void addDrawingObserver(Observer observer) {
173
        // TODO Auto-generated method stub
174

  
175
    }
176

  
177
    public void deleteDrawingObserver(Observer observer) {
178
        // TODO Auto-generated method stub
179

  
180
    }
181

  
182
    public void deleteDrawingObservers() {
183
        // TODO Auto-generated method stub
184

  
185
    }
186

  
187
    public void loadFromState(PersistentState state) throws PersistenceException {
188
        shpType = state.getLong("shpType");
189
    }
190

  
191

  
192
    public void saveToState(PersistentState state) throws PersistenceException {
193
        state.set("shpType", shpType);
194
    }
195

  
196
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
197
        double scale, Map queryParameters, ICoordTrans coordTrans,
198
        FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties)
199
    throws LegendException {
200
        // TODO Auto-generated method stub
201

  
202
    }
203

  
204
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
205
        double scale, Map queryParameters, ICoordTrans coordTrans,
206
        FeatureStore featureStore, PrintAttributes properties)
207
    throws LegendException {
208
        // TODO Auto-generated method stub
209

  
210
    }
211

  
212
    public static void registerPersistent() {
213
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
214
        DynStruct definition = manager.addDefinition(
215
            DummyVectorLegend.class,
216
            "DummyVectorLegend",
217
            "DummyVectorLegend Persistence definition",
218
            null, 
219
            null
220
        );
221
        definition.addDynFieldLong("shpType")
222
        .setMandatory(true);
223
    }
224

  
225

  
226
    public Object clone() throws CloneNotSupportedException {
227
        return super.clone();
228
    }
229

  
230

  
231
}
0 232

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/Point2DPersistenceFactoryTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {}  {{Task}}
27
 */
28
package org.gvsig.fmap.mapcontext.tools.persistence;
29

  
30
import java.awt.geom.Point2D;
31

  
32
import org.easymock.MockControl;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
35
import org.gvsig.tools.persistence.PersistenceManager;
36
import org.gvsig.tools.persistence.PersistentState;
37

  
38
/**
39
 * Unit tests for the class {@link Point2DPersistenceFactory}.
40
 * 
41
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
42
 */
43
public class Point2DPersistenceFactoryTest extends
44
		AbstractLibraryAutoInitTestCase {
45

  
46
	private Point2DPersistenceFactory factory;
47
	private MockControl stateControl;
48
	private PersistentState state;
49
	private Point2D point;
50

  
51
	protected void doSetUp() throws Exception {
52
		PersistenceManager persistenceManager = ToolsLocator
53
				.getPersistenceManager();
54
		factory = (Point2DPersistenceFactory) persistenceManager.getFactories()
55
				.get(Point2D.class);
56
		stateControl = MockControl.createNiceControl(PersistentState.class);
57
		state = (PersistentState) stateControl.getMock();
58
		double x = Math.random() * 1000d;
59
		double y = Math.random() * 1000d;
60
		point = new Point2D.Double(x, y);
61
	}
62

  
63
	/**
64
	 * Test method for
65
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#createFromState(PersistentState, Class)}
66
	 * .
67
	 */
68
	public void testCreateFromState() throws Exception {
69
		stateControl.expectAndReturn(state
70
				.getDouble(Point2DPersistenceFactory.FIELD_X), point.getX());
71
		stateControl.expectAndReturn(state
72
				.getDouble(Point2DPersistenceFactory.FIELD_Y), point.getY());
73
		stateControl.replay();
74

  
75
		Point2D newPoint = (Point2D) factory.createFromState(state);
76
		assertTrue(newPoint.equals(point));
77

  
78
		stateControl.verify();
79
	}
80

  
81
	/**
82
	 * Test method for
83
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
84
	 * .
85
	 */
86
	public void testSaveToState() throws Exception {
87
		state.set(Point2DPersistenceFactory.FIELD_X, point.getX());
88
		state.set(Point2DPersistenceFactory.FIELD_Y, point.getY());
89
		stateControl.replay();
90

  
91
		factory.saveToState(state, point);
92

  
93
		stateControl.verify();
94
	}
95
}
0 96

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/DimensionPersistenceFactoryTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {}  {{Task}}
27
 */
28
package org.gvsig.fmap.mapcontext.tools.persistence;
29

  
30
import java.awt.Dimension;
31

  
32
import org.easymock.MockControl;
33

  
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
36
import org.gvsig.tools.persistence.PersistenceManager;
37
import org.gvsig.tools.persistence.PersistentState;
38

  
39
/**
40
 * Unit tests for the class {@link DimensionPersistenceFactory}.
41
 * 
42
 * @author gvSIG team
43
 */
44
public class DimensionPersistenceFactoryTest extends
45
		AbstractLibraryAutoInitTestCase {
46

  
47
	private DimensionPersistenceFactory factory;
48
	private MockControl stateControl;
49
	private PersistentState state;
50
	private Dimension dimension;
51

  
52
	protected void doSetUp() throws Exception {
53
		PersistenceManager persistenceManager = ToolsLocator
54
				.getPersistenceManager();
55
		factory = (DimensionPersistenceFactory) persistenceManager
56
				.getFactories().get(Dimension.class);
57
		stateControl = MockControl.createNiceControl(PersistentState.class);
58
		state = (PersistentState) stateControl.getMock();
59
		dimension = new Dimension(320, 200);
60
	}
61

  
62
	/**
63
	 * Test method for
64
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.DimensionPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)}
65
	 * .
66
	 */
67
	public void testCreateFromState() throws Exception {
68
		stateControl.expectAndReturn(state
69
				.getInt(DimensionPersistenceFactory.FIELD_WIDTH), dimension.width);			
70
		stateControl.expectAndReturn(state
71
				.getInt(DimensionPersistenceFactory.FIELD_HEIGHT), dimension.height);				
72
		stateControl.replay();
73

  
74
		Dimension newDimension = (Dimension) factory.createFromState(state);
75
		assertTrue(newDimension.equals(dimension));
76

  
77
		stateControl.verify();
78
	}
79

  
80
	/**
81
	 * Test method for
82
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.DimensionPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
83
	 * .
84
	 */
85
	public void testSaveToState() throws Exception {
86
		state.set(DimensionPersistenceFactory.FIELD_WIDTH, dimension.width);
87
		state.set(DimensionPersistenceFactory.FIELD_HEIGHT, dimension.height);
88
				
89
		stateControl.replay();
90

  
91
		factory.saveToState(state, dimension);
92

  
93
		stateControl.verify();
94
	}
95

  
96
}
0 97

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/FontPersistenceFactoryTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {}  {{Task}}
27
 */
28
package org.gvsig.fmap.mapcontext.tools.persistence;
29

  
30
import java.awt.Font;
31

  
32
import org.easymock.MockControl;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
35
import org.gvsig.tools.persistence.PersistenceManager;
36
import org.gvsig.tools.persistence.PersistentState;
37

  
38
/**
39
 * Unit tests for the class {@link FontPersistenceFactory}.
40
 * 
41
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
42
 */
43
public class FontPersistenceFactoryTest extends AbstractLibraryAutoInitTestCase {
44

  
45
	private FontPersistenceFactory factory;
46
	private MockControl stateControl;
47
	private PersistentState state;
48
	private Font font;
49

  
50
	protected void doSetUp() throws Exception {
51
		PersistenceManager persistenceManager = ToolsLocator
52
				.getPersistenceManager();
53
		factory = (FontPersistenceFactory) persistenceManager.getFactories()
54
				.get(Font.class);
55
		stateControl = MockControl.createNiceControl(PersistentState.class);
56
		state = (PersistentState) stateControl.getMock();
57
		font = new Font("Arial", Font.BOLD, 18);
58
	}
59

  
60
	/**
61
	 * Test method for
62
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)}
63
	 * .
64
	 */
65
	public void testCreateFromState() throws Exception {
66
		stateControl.expectAndReturn(state
67
				.getString(FontPersistenceFactory.FIELD_NAME), font.getName());
68
		stateControl.expectAndReturn(state
69
				.getInt(FontPersistenceFactory.FIELD_STYLE), font.getStyle());
70
		stateControl.expectAndReturn(state
71
				.getInt(FontPersistenceFactory.FIELD_SIZE), font.getSize());
72
		stateControl.replay();
73

  
74
		Font newFont = (Font) factory.createFromState(state);
75
		assertTrue(newFont.equals(font));
76

  
77
		stateControl.verify();
78
	}
79

  
80
	/**
81
	 * Test method for
82
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
83
	 * .
84
	 */
85
	public void testSaveToState() throws Exception {
86
		state.set(FontPersistenceFactory.FIELD_NAME, font.getName());
87
		state.set(FontPersistenceFactory.FIELD_STYLE, font.getStyle());
88
		state.set(FontPersistenceFactory.FIELD_SIZE, font.getSize());
89
		stateControl.replay();
90

  
91
		factory.saveToState(state, font);
92

  
93
		stateControl.verify();
94
	}
95

  
96
}
0 97

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/Rectangle2DPersistenceFactoryTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {}  {{Task}}
27
 */
28
package org.gvsig.fmap.mapcontext.tools.persistence;
29

  
30
import java.awt.geom.Rectangle2D;
31

  
32
import org.easymock.MockControl;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
35
import org.gvsig.tools.persistence.PersistenceManager;
36
import org.gvsig.tools.persistence.PersistentState;
37

  
38
/**
39
 * Unit tests for the class {@link Rectangle2DPersistenceFactory}.
40
 * 
41
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
42
 */
43
public class Rectangle2DPersistenceFactoryTest extends
44
		AbstractLibraryAutoInitTestCase {
45

  
46
	private Rectangle2DPersistenceFactory factory;
47
	private MockControl stateControl;
48
	private PersistentState state;
49
	private Rectangle2D rectangle;
50

  
51
	protected void doSetUp() throws Exception {
52
		PersistenceManager persistenceManager = ToolsLocator
53
				.getPersistenceManager();
54
		factory = (Rectangle2DPersistenceFactory) persistenceManager
55
				.getFactories().get(Rectangle2D.class);
56
		stateControl = MockControl.createNiceControl(PersistentState.class);
57
		state = (PersistentState) stateControl.getMock();
58
		double x = Math.random() * 1000d;
59
		double y = Math.random() * 1000d;
60
		rectangle = new Rectangle2D.Double(x, y, 320, 200);
61
	}
62

  
63
	/**
64
	 * Test method for
65
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#createFromState(PersistentState, Class)}
66
	 * .
67
	 */
68
	public void testCreateFromState() throws Exception {
69
		stateControl.expectAndReturn(state
70
				.getDouble(Rectangle2DPersistenceFactory.FIELD_X), rectangle
71
				.getX());
72
		stateControl.expectAndReturn(state
73
				.getDouble(Rectangle2DPersistenceFactory.FIELD_Y), rectangle
74
				.getY());
75
		stateControl.expectAndReturn(state
76
				.getDouble(Rectangle2DPersistenceFactory.FIELD_WIDTH),
77
				rectangle.getWidth());
78
		stateControl.expectAndReturn(state
79
				.getDouble(Rectangle2DPersistenceFactory.FIELD_HEIGHT),
80
				rectangle.getHeight());
81
		stateControl.replay();
82

  
83
		Rectangle2D newRectangle = (Rectangle2D) factory.createFromState(state);
84

  
85
		System.out.println("Orig x = " + rectangle.getX() + " - New x = "
86
				+ newRectangle.getX());
87
		assertEquals(rectangle.getX(), newRectangle.getX(), 0.0d);
88
		System.out.println("Orig y = " + rectangle.getY() + " - New y = "
89
				+ newRectangle.getY());
90
		assertEquals(rectangle.getY(), newRectangle.getY(), 0.0d);
91
		System.out.println("Orig width = " + rectangle.getWidth()
92
				+ " - New width = " + newRectangle.getWidth());
93
		assertEquals(rectangle.getWidth(), newRectangle.getWidth(), 0.0d);
94
		System.out.println("Orig height = " + rectangle.getHeight()
95
				+ " - New height = " + newRectangle.getHeight());
96
		assertEquals(rectangle.getHeight(), newRectangle.getHeight(), 0.0d);
97

  
98
		assertTrue(newRectangle.equals(rectangle));
99

  
100
		stateControl.verify();
101
	}
102

  
103
	/**
104
	 * Test method for
105
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
106
	 * .
107
	 */
108
	public void testSaveToState() throws Exception {
109
		state.set(Rectangle2DPersistenceFactory.FIELD_X, rectangle.getX());
110
		state.set(Rectangle2DPersistenceFactory.FIELD_Y, rectangle.getY());
111
		state.set(Rectangle2DPersistenceFactory.FIELD_WIDTH, rectangle
112
				.getWidth());
113
		state.set(Rectangle2DPersistenceFactory.FIELD_HEIGHT, rectangle
114
				.getHeight());
115
		stateControl.replay();
116

  
117
		factory.saveToState(state, rectangle);
118

  
119
		stateControl.verify();
120
	}
121
}
0 122

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/ColorPersistenceFactoryTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {}  {{Task}}
27
 */
28
package org.gvsig.fmap.mapcontext.tools.persistence;
29

  
30
import java.awt.Color;
31

  
32
import org.easymock.MockControl;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
35
import org.gvsig.tools.persistence.PersistenceManager;
36
import org.gvsig.tools.persistence.PersistentState;
37

  
38
/**
39
 * Unit tests for the class {@link ColorPersistenceFactory}.
40
 * 
41
 * @author gvSIG team
42
 */
43
public class ColorPersistenceFactoryTest extends
44
		AbstractLibraryAutoInitTestCase {
45

  
46
	private ColorPersistenceFactory factory;
47
	private MockControl stateControl;
48
	private PersistentState state;
49
	private Color color;
50

  
51
	protected void doSetUp() throws Exception {
52
		PersistenceManager persistenceManager = ToolsLocator
53
				.getPersistenceManager();
54
		factory = (ColorPersistenceFactory) persistenceManager.getFactories()
55
				.get(Color.class);
56
		stateControl = MockControl.createNiceControl(PersistentState.class);
57
		state = (PersistentState) stateControl.getMock();
58
		color = Color.magenta;
59
	}
60

  
61
	/**
62
	 * Test method for
63
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)}
64
	 * .
65
	 */
66
	public void testCreateFromState() throws Exception {
67
		stateControl.expectAndReturn(state
68
				.getInt(ColorPersistenceFactory.FIELD_RED), color.getRed());
69
		stateControl.expectAndReturn(state
70
				.getInt(ColorPersistenceFactory.FIELD_GREEN), color.getGreen());
71
		stateControl.expectAndReturn(state
72
				.getInt(ColorPersistenceFactory.FIELD_BLUE), color.getBlue());
73
		stateControl.expectAndReturn(state
74
				.getInt(ColorPersistenceFactory.FIELD_ALPHA), color.getAlpha());
75
		stateControl.replay();
76

  
77
		Color newColor = (Color) factory.createFromState(state);
78
		assertTrue(newColor.equals(color));
79

  
80
		stateControl.verify();
81
	}
82

  
83
	/**
84
	 * Test method for
85
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
86
	 * .
87
	 */
88
	public void testSaveToState() throws Exception {
89
		state.set(ColorPersistenceFactory.FIELD_RED, color.getRed());
90
		state.set(ColorPersistenceFactory.FIELD_GREEN, color.getGreen());
91
		state.set(ColorPersistenceFactory.FIELD_BLUE, color.getBlue());
92
		state.set(ColorPersistenceFactory.FIELD_ALPHA, color.getAlpha());
93
		stateControl.replay();
94

  
95
		factory.saveToState(state, color);
96

  
97
		stateControl.verify();
98
	}
99

  
100
}
0 101

  
tags/org.gvsig.desktop-2.0.45/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManagerTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2009 {DiSiD Technologies}  {{Task}}
27
 */
28
package org.gvsig.fmap.mapcontext.impl;
29

  
30
import java.awt.Graphics2D;
31
import java.awt.image.BufferedImage;
32
import java.io.File;
33
import java.io.IOException;
34
import java.util.Map;
35

  
36
import org.cresques.cts.ICoordTrans;
37

  
38
import org.gvsig.compat.print.PrintAttributes;
39
import org.gvsig.fmap.crs.CRSFactory;
40
import org.gvsig.fmap.dal.exception.ReadException;
41
import org.gvsig.fmap.dal.feature.Feature;
42
import org.gvsig.fmap.dal.feature.FeatureQuery;
43
import org.gvsig.fmap.dal.feature.FeatureStore;
44
import org.gvsig.fmap.mapcontext.MapContext;
45
import org.gvsig.fmap.mapcontext.MapContextDrawer;
46
import org.gvsig.fmap.mapcontext.MapContextException;
47
import org.gvsig.fmap.mapcontext.MapContextRuntimeException;
48
import org.gvsig.fmap.mapcontext.ViewPort;
49
import org.gvsig.fmap.mapcontext.exceptions.IncompatibleLegendReadException;
50
import org.gvsig.fmap.mapcontext.exceptions.ReadLegendException;
51
import org.gvsig.fmap.mapcontext.exceptions.WriteLegendException;
52
import org.gvsig.fmap.mapcontext.layers.FLayers;
53
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
54
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend;
55
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
56
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend;
57
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException;
58
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader;
59
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter;
60
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
61
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
62
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
63
import org.gvsig.tools.evaluator.Evaluator;
64
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
65
import org.gvsig.tools.observer.Observer;
66
import org.gvsig.tools.persistence.PersistentState;
67
import org.gvsig.tools.persistence.exception.PersistenceException;
68
import org.gvsig.tools.task.Cancellable;
69

  
70
/**
71
 * @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
72
 */
73
public class DefaultMapContextManagerTest extends
74
AbstractLibraryAutoInitTestCase {
75

  
76
    private DefaultMapContextManager manager;
77

  
78
    protected void doSetUp() throws Exception {
79
        manager = new DefaultMapContextManager();
80

  
81
        manager.registerLegend("DummyLegend", DummyVectorLegend.class);
82
        manager.setDefaultVectorLegend("DummyLegend");
83
        manager.registerLegendReader("Dummy", DummyLegendReader.class);
84
        // manager.registerLegendWriter("DummyLegend".getClass(), "Dummy", DummyLegendWriter.class);
85
    }
86

  
87
    protected void tearDown() throws Exception {
88
        super.tearDown();
89
    }
90

  
91
    /**
92
     * Test method for
93
     * {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#createDefaultMapContextDrawerInstance()}
94
     * .
95
     */
96
    public void testGetDefaultMapContextDrawerInstance() throws Exception {
97

  
98
        manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class);
99

  
100
        MapContextDrawer drawer = manager
101
        .createDefaultMapContextDrawerInstance();
102

  
103
        assertNotNull("The created MapContextDrawer instance can't be null",
104
            drawer);
105
        assertTrue(
106
            "The created MapContextDrawer is not instance of the registered class"
107
            + DummyMapContextDrawer.class,
108
            drawer instanceof DummyMapContextDrawer);
109
    }
110

  
111
    /**
112
     * Test method for
113
     * {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#setDefaultMapContextDrawer(java.lang.Class)}
114
     * .
115
     */
116
    public void testSetDefaultMapContextDrawer() throws Exception {
117

  
118
        // First, try to register an invalid class
119
        try {
120
            manager.setDefaultMapContextDrawer(Object.class);
121
            fail("Error, a class that does not implement the MapContextDrawer "
122
                + "interface has been accepted");
123
        } catch (MapContextRuntimeException e) {
124
            // OK
125
        }
126

  
127
        // Next, try to register a valid class
128
        manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class);
129
    }
130

  
131
    public void testCreateGraphicsLayer() throws Exception {
132
        assertNotNull(manager.createGraphicsLayer(CRSFactory.getCRS("EPSG:23030")));
133
    }
134

  
135
    public void testCreateDefaultVectorLegend() throws Exception {
136

  
137
        IVectorLegend legend = manager.createDefaultVectorLegend(1);
138
        assertNotNull(legend);
139
        assertTrue(legend instanceof DummyVectorLegend);
140
    }
141

  
142
    public void testRegisterCreateLegend() throws Exception {
143

  
144
        manager.registerLegend("DummyLegend", DummyVectorLegend.class);
145

  
146
        ILegend legend = manager.createLegend("DummyLegend");
147
        assertNotNull(legend);
148
        assertTrue(legend instanceof DummyVectorLegend);
149

  
150
        assertNull(manager.createLegend("NONE"));
151
    }
152

  
153
    public void testRegisterCreateLegendReader() throws Exception {
154

  
155
        manager.registerLegendReader("Dummy", DummyLegendReader.class);
156

  
157
        ILegendReader legendReader = manager.createLegendReader("Dummy");
158
        assertNotNull(legendReader);
159
        assertTrue(legendReader instanceof DummyLegendReader);
160

  
161
        assertNull(manager.createLegendReader("NONE"));
162
    }
163

  
164
    public void testRegisterCreateLegendWriter() throws Exception {
165

  
166
        manager.registerLegend("DummyLegend", DummyVectorLegend.class);
167

  
168
        manager.registerLegendWriter(ISingleSymbolLegend.class, "Dummy",
169
            DummyLegendWriter.class);
170

  
171
        // Test the registered writer is created
172
        ILegendWriter legendWriter = manager.createLegendWriter(
173
            ISingleSymbolLegend.class, "Dummy");
174
        assertNotNull(legendWriter);
175
        assertTrue(legendWriter instanceof DummyLegendWriter);
176

  
177
        // Test non registered cases
178
        assertNull(manager.createLegendWriter(IVectorialIntervalLegend.class, "Dummy"));
179
        assertNull(manager.createLegendWriter(IVectorialIntervalLegend.class, "NONE"));
180
        assertNull(manager.createLegendWriter(IVectorialIntervalLegend.class, "NONE"));
181
    }
182

  
183
    public static class DummyMapContextDrawer implements MapContextDrawer {
184

  
185
        public void dispose() {
186
        }
187

  
188
        public void draw(FLayers root, BufferedImage image, Graphics2D g,
189
            Cancellable cancel, double scale) throws ReadException {
190
        }
191

  
192
        public void print(FLayers root, Graphics2D g, Cancellable cancel,
193
            double scale, PrintAttributes properties) throws ReadException {
194
        }
195

  
196
        public void setMapContext(MapContext mapContext) {
197
        }
198

  
199
        public void setViewPort(ViewPort viewPort) {
200
        }
201

  
202
    }
203

  
204
    public static class DummyLegendReader implements ILegendReader {
205

  
206
        public ILegend read(File inFile, int geometryType)
207
            throws ReadLegendException, IncompatibleLegendReadException,
208
            IOException {
209
            // TODO Auto-generated method stub
210
            return null;
211
        }
212

  
213
    }
214

  
215
    public static class DummyLegendWriter implements ILegendWriter {
216

  
217
        public void write(ILegend legend, File outFile, String format)
218
            throws WriteLegendException, IOException {
219
            // TODO Auto-generated method stub
220
            
221
        }
222

  
223
    }
224

  
225
    public static class DummyVectorLegend implements IVectorLegend {
226

  
227
        public void draw(BufferedImage image, Graphics2D graphics2d,
228
            ViewPort viewPort, Cancellable cancel, double scale,
229
            Map queryParameters, ICoordTrans coordTrans,
230
            FeatureStore featureStore, FeatureQuery featureQuery) throws LegendException {
231
            // Empty method
232
        }
233

  
234
        public void draw(BufferedImage image, Graphics2D graphics2d,
235
            ViewPort viewPort, Cancellable cancel, double scale,
236
            Map queryParameters, ICoordTrans coordTrans,
237
            FeatureStore featureStore) throws LegendException {
238
            // Empty method
239
        }
240

  
241
        public int getShapeType() {
242
            // Empty method
243
            return 0;
244
        }
245

  
246
        public ISymbol getSymbolByFeature(Feature feat)
247
        throws MapContextException {
248
            // Empty method
249
            return null;
250
        }
251

  
252
        public boolean isSuitableForShapeType(int shapeType) {
253
            // Empty method
254
            return false;
255
        }
256

  
257
        public boolean isUseDefaultSymbol() {
258
            // Empty method
259
            return false;
260
        }
261

  
262
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
263
            double scale, Map queryParameters, ICoordTrans coordTrans,
264
            FeatureStore featureStore, PrintAttributes properties)
265
        throws LegendException {
266
            // Empty method
267
        }
268

  
269
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
270
            double scale, Map queryParameters, ICoordTrans coordTrans,
271
            FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties)
272
        throws LegendException {
273
            // Empty method
274
        }
275

  
276
        public void setDefaultSymbol(ISymbol s) {
277
            // Empty method
278
        }
279

  
280
        public void setShapeType(int shapeType) {
281
            // Empty method
282
        }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff