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 / Bug15617Test.java @ 42540
History | View | Annotate | Download (4.57 KB)
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.dal.store.shp; |
25 |
|
26 |
import junit.framework.TestCase; |
27 |
|
28 |
|
29 |
import org.gvsig.fmap.dal.DALLocator; |
30 |
import org.gvsig.fmap.dal.DataManager; |
31 |
import org.gvsig.fmap.dal.DataTypes; |
32 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
33 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
34 |
import org.gvsig.fmap.dal.feature.Feature; |
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
36 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
37 |
import org.gvsig.fmap.geom.Geometry; |
38 |
import org.gvsig.fmap.geom.GeometryLocator; |
39 |
import org.gvsig.fmap.geom.GeometryManager; |
40 |
import org.gvsig.fmap.geom.type.GeometryType; |
41 |
import org.gvsig.tools.exception.BaseException; |
42 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
43 |
import org.gvsig.tools.visitor.VisitCanceledException; |
44 |
import org.gvsig.tools.visitor.Visitor; |
45 |
|
46 |
/**
|
47 |
* Code to test bug gvsig-desktop#15617.
|
48 |
*
|
49 |
* @author gvSIG Team
|
50 |
* @version $Id$
|
51 |
*/
|
52 |
public class Bug15617Test extends TestCase { |
53 |
|
54 |
public void testBug15617() throws Exception { |
55 |
new DefaultLibrariesInitializer().fullInitialize();
|
56 |
DataManager manager = DALLocator.getDataManager(); |
57 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
58 |
|
59 |
NewFeatureStoreParameters destParams = |
60 |
(NewFeatureStoreParameters) manager.createNewStoreParameters( |
61 |
"FilesystemExplorer", "Shape"); |
62 |
|
63 |
EditableFeatureType type = destParams.getDefaultFeatureType(); |
64 |
GeometryType geometryType = |
65 |
geometryManager.getGeometryType(Geometry.TYPES.POINT, |
66 |
Geometry.SUBTYPES.GEOM2D); |
67 |
type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
|
68 |
.setGeometryType(geometryType); |
69 |
type.setDefaultGeometryAttributeName("geom");
|
70 |
// type.add("float", DataTypes.FLOAT).setSize(5);
|
71 |
// type.add("double", DataTypes.DOUBLE).setSize(5);
|
72 |
type.add("int", DataTypes.INT).setSize(5); |
73 |
// type.add("long", DataTypes.LONG).setSize(5);
|
74 |
type.add("bool", DataTypes.BOOLEAN);
|
75 |
|
76 |
destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
77 |
destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
78 |
destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
79 |
destParams.setDynValue("crs", "EPSG:23030"); |
80 |
destParams.setDefaultFeatureType(type); |
81 |
|
82 |
manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
83 |
FeatureStore store = |
84 |
(FeatureStore) manager.openStore("Shape", destParams);
|
85 |
|
86 |
store.edit(); |
87 |
EditableFeature feature = store.createNewFeature().getEditable(); |
88 |
|
89 |
Geometry fmapGeom = GeometryLocator.getGeometryManager().createPoint(0,0,Geometry.SUBTYPES.GEOM2D); |
90 |
|
91 |
feature.setGeometry(feature.getType() |
92 |
.getDefaultGeometryAttributeIndex(), fmapGeom); |
93 |
// feature.setFloat("float", 34.0f);
|
94 |
// feature.setDouble("double", 34.0d);
|
95 |
feature.setInt("int", 25); |
96 |
// feature.setLong("long", 34l);
|
97 |
feature.setBoolean("bool", true); |
98 |
assertEquals(true, feature.getBoolean("bool")); |
99 |
store.insert(feature); |
100 |
store.finishEditing(); |
101 |
|
102 |
store.accept(new Visitor() {
|
103 |
|
104 |
public void visit(Object obj) throws VisitCanceledException, |
105 |
BaseException { |
106 |
Feature feature = (Feature) obj; |
107 |
// assertEquals(34.0f, feature.getFloat("float"));
|
108 |
// assertEquals(34.0d, feature.getDouble("double"));
|
109 |
assertEquals(25, feature.getInt("int")); |
110 |
// assertEquals(34l, feature.getLong("long"));
|
111 |
assertEquals(true, feature.getBoolean("bool")); |
112 |
} |
113 |
}); |
114 |
|
115 |
store.dispose(); |
116 |
} |
117 |
|
118 |
} |