Revision 16396 trunk/libraries/libTopology/src-test/org/gvsig/topology/TopologyTest.java
TopologyTest.java | ||
---|---|---|
49 | 49 |
*/ |
50 | 50 |
package org.gvsig.topology; |
51 | 51 |
|
52 |
import java.io.File; |
|
53 |
import java.net.URL; |
|
54 |
import java.util.HashMap; |
|
52 | 55 |
import java.util.List; |
56 |
import java.util.Map; |
|
53 | 57 |
|
54 | 58 |
import junit.framework.TestCase; |
55 | 59 |
|
56 | 60 |
import org.cresques.cts.IProjection; |
57 | 61 |
import org.gvsig.topology.topologyrules.MustBeLargerThanClusterTolerance; |
58 | 62 |
import org.gvsig.topology.topologyrules.MustNotHaveRepeatedPoints; |
63 |
import org.gvsig.topology.topologyrules.jtsisvalidrules.GeometryMustHaveValidCoordinates; |
|
59 | 64 |
import org.gvsig.topology.util.LayerFactory; |
60 | 65 |
|
66 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
|
61 | 67 |
import com.iver.cit.gvsig.fmap.MapContext; |
62 | 68 |
import com.iver.cit.gvsig.fmap.ViewPort; |
63 | 69 |
import com.iver.cit.gvsig.fmap.core.FShape; |
64 | 70 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
71 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
65 | 72 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
66 | 73 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
67 | 74 |
|
... | ... | |
72 | 79 |
* |
73 | 80 |
*/ |
74 | 81 |
public class TopologyTest extends TestCase { |
75 |
|
|
82 |
File baseDataPath; |
|
83 |
|
|
84 |
File baseDriversPath; |
|
85 |
|
|
86 |
IProjection PROJECTION_DEFAULT; |
|
87 |
|
|
88 |
ViewPort VIEWPORT; |
|
89 |
|
|
90 |
FLayers ROOT; |
|
91 |
|
|
92 |
SimpleTopologyErrorContainer errorContainer; |
|
93 |
|
|
76 | 94 |
Topology topology = null; |
77 | 95 |
|
78 | 96 |
Topology topology2 = null; |
... | ... | |
81 | 99 |
|
82 | 100 |
FLyrVect lineLyrWithCollapsedCoords; |
83 | 101 |
|
102 |
FLyrVect shapeBasedLinearLyr; |
|
84 | 103 |
|
104 |
MapContext mapContext; |
|
105 |
|
|
106 |
|
|
85 | 107 |
public void setUp() throws Exception{ |
86 | 108 |
super.setUp(); |
109 |
URL url = TopologyTest.class.getResource("testdata"); |
|
110 |
if (url == null) |
|
111 |
throw new Exception("No se encuentra el directorio con datos de prueba"); |
|
112 |
|
|
113 |
baseDataPath = new File(url.getFile()); |
|
114 |
if (!baseDataPath.exists()) |
|
115 |
throw new Exception("No se encuentra el directorio con datos de prueba"); |
|
116 |
|
|
117 |
baseDriversPath = new File("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"); |
|
118 |
if (!baseDriversPath.exists()) |
|
119 |
throw new Exception("Can't find drivers path " ); |
|
120 |
|
|
121 |
com.iver.cit.gvsig.fmap.layers.LayerFactory.setDriversPath(baseDriversPath.getAbsolutePath()); |
|
87 | 122 |
|
88 |
IProjection projectionDefault = |
|
89 |
CRSFactory.getCRS("EPSG:23030"); |
|
90 |
ViewPort vp = new ViewPort(projectionDefault); |
|
91 |
MapContext mapContext = new MapContext(vp); |
|
92 |
FLayers root = mapContext.getLayers(); |
|
93 |
SimpleTopologyErrorContainer errorContainer = new SimpleTopologyErrorContainer(); |
|
94 |
topology = new Topology(mapContext, root, 0.01, 1000, errorContainer ); |
|
95 | 123 |
|
96 |
topology2 = new Topology(0.01, 1000, errorContainer); |
|
124 |
PROJECTION_DEFAULT = CRSFactory.getCRS("EPSG:23030"); |
|
125 |
VIEWPORT = new ViewPort(PROJECTION_DEFAULT); |
|
126 |
mapContext = new MapContext(VIEWPORT); |
|
127 |
ROOT = mapContext.getLayers(); |
|
128 |
errorContainer = new SimpleTopologyErrorContainer(); |
|
97 | 129 |
|
130 |
topology = new Topology(mapContext, ROOT, 0.01, 1000, errorContainer ); |
|
131 |
topology2 = new Topology(mapContext, ROOT, 0.01, 1000, errorContainer); |
|
132 |
|
|
133 |
|
|
98 | 134 |
multiPointLayer = LayerFactory.getLyrWithRepeatedCoords(); |
99 | 135 |
lineLyrWithCollapsedCoords = LayerFactory.getLineLayerWithCollapsedCoords(); |
136 |
shapeBasedLinearLyr = (FLyrVect) newLayer("vc1-1500.shp", "gvSIG shp driver"); |
|
100 | 137 |
} |
101 | 138 |
|
102 | 139 |
public void tearDown() throws Exception{ |
... | ... | |
107 | 144 |
lineLyrWithCollapsedCoords = null; |
108 | 145 |
} |
109 | 146 |
|
147 |
public FLayer newLayer(String fileName, |
|
148 |
String driverName) |
|
149 |
throws LoadLayerException { |
|
150 |
FLayer solution = null; |
|
151 |
File file = new File(baseDataPath, fileName); |
|
152 |
solution = com.iver.cit.gvsig.fmap.layers.LayerFactory.createLayer(fileName, |
|
153 |
driverName, |
|
154 |
file, PROJECTION_DEFAULT); |
|
155 |
solution.setAvailable(true); |
|
156 |
return solution; |
|
157 |
|
|
158 |
} |
|
159 |
|
|
110 | 160 |
/* |
111 | 161 |
* To test in a Topology: |
112 | 162 |
* |
... | ... | |
262 | 312 |
errorList = topology.getTopologyErrorsByShapeType(FShape.LINE, null, true); |
263 | 313 |
assertTrue(errorList.size() == 1); |
264 | 314 |
|
315 |
|
|
265 | 316 |
} |
266 | 317 |
|
267 |
public void testSaveTopology(){ |
|
318 |
public void testTopologyPersistence() throws RuleNotAllowedException, TopologyRuleDefinitionException{ |
|
319 |
topology2 = new Topology(mapContext, ROOT, 0.01, 1000, errorContainer); |
|
320 |
topology2.addLayer(this.shapeBasedLinearLyr); |
|
321 |
MustNotHaveRepeatedPoints ruleA = new MustNotHaveRepeatedPoints(topology2, shapeBasedLinearLyr); |
|
322 |
topology2.addRule(ruleA); |
|
323 |
GeometryMustHaveValidCoordinates ruleB = new |
|
324 |
GeometryMustHaveValidCoordinates(topology2, shapeBasedLinearLyr); |
|
325 |
topology2.addRule(ruleB); |
|
268 | 326 |
|
327 |
String fileToSave1 = "/testTopology.xml"; |
|
328 |
Map<String, Object> storageParams = new HashMap<String, Object>(); |
|
329 |
storageParams.put(TopologyPersister.FILE_PARAM_NAME, fileToSave1); |
|
330 |
TopologyPersister.persist(topology2, storageParams); |
|
331 |
Topology topologyA = TopologyPersister.load(mapContext, storageParams); |
|
332 |
|
|
333 |
assertTrue(topology2.getRuleCount() == topologyA.getRuleCount()); |
|
334 |
assertTrue(topology2.getLayerCount() == topologyA.getLayerCount()); |
|
269 | 335 |
} |
270 | 336 |
|
271 |
|
|
272 | 337 |
} |
273 | 338 |
|
Also available in: Unified diff