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