svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.shp / src / test / java / org / gvsig / fmap / dal / store / shp / Bug15670Test.java @ 40435
History | View | Annotate | Download (3.78 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 |
package org.gvsig.fmap.dal.store.shp; |
23 |
|
24 |
import junit.framework.TestCase; |
25 |
|
26 |
import org.gvsig.fmap.dal.DALLocator; |
27 |
import org.gvsig.fmap.dal.DataManager; |
28 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
29 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
30 |
import org.gvsig.fmap.dal.feature.Feature; |
31 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
32 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
33 |
import org.gvsig.fmap.geom.Geometry; |
34 |
import org.gvsig.fmap.geom.GeometryLocator; |
35 |
import org.gvsig.fmap.geom.GeometryManager; |
36 |
import org.gvsig.fmap.geom.primitive.Point; |
37 |
import org.gvsig.fmap.geom.type.GeometryType; |
38 |
import org.gvsig.tools.exception.BaseException; |
39 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
40 |
import org.gvsig.tools.visitor.VisitCanceledException; |
41 |
import org.gvsig.tools.visitor.Visitor; |
42 |
|
43 |
/**
|
44 |
* Code to test bug gvsig-desktop#15670. This is based on the code provided by
|
45 |
* the bug reporter (see ticket), thanks to him!!
|
46 |
*
|
47 |
* @author gvSIG Team
|
48 |
* @version $Id$
|
49 |
*/
|
50 |
public class Bug15670Test extends TestCase { |
51 |
|
52 |
public void testBug15670() throws Exception { |
53 |
new DefaultLibrariesInitializer().fullInitialize();
|
54 |
DataManager manager = DALLocator.getDataManager(); |
55 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
56 |
|
57 |
NewFeatureStoreParameters destParams = |
58 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
59 |
"FilesystemExplorer", "Shape"); |
60 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
61 |
GeometryType geometryType = |
62 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
63 |
Geometry.SUBTYPES.GEOM2D); |
64 |
type.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
|
65 |
.setGeometryType(geometryType); |
66 |
type.setDefaultGeometryAttributeName("GEOMETRY");
|
67 |
|
68 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
69 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
70 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
71 |
destParams.setDynValue("crs", "EPSG:23030"); |
72 |
destParams.setDefaultFeatureType(type); |
73 |
|
74 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
75 |
FeatureStore store = |
76 |
(FeatureStore) manager.openStore("Shape", destParams);
|
77 |
|
78 |
store.edit(); |
79 |
EditableFeature feature = store.createNewFeature().getEditable(); |
80 |
final Point geom = |
81 |
geometryManager.createPoint(10.0, 10.0, Geometry.SUBTYPES.GEOM2D); |
82 |
feature.setGeometry("GEOMETRY", geom);
|
83 |
store.insert(feature); |
84 |
store.finishEditing(); |
85 |
|
86 |
store.accept(new Visitor() {
|
87 |
|
88 |
public void visit(Object obj) throws VisitCanceledException, |
89 |
BaseException { |
90 |
Feature feature = (Feature) obj; |
91 |
assertEquals(geom, feature.getGeometry("GEOMETRY"));
|
92 |
} |
93 |
}); |
94 |
store.dispose(); |
95 |
} |
96 |
} |