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 @ 40559
History | View | Annotate | Download (3.83 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.fmap.dal.store.shp; |
||
25 | |||
26 | import junit.framework.TestCase; |
||
27 | |||
28 | import org.gvsig.fmap.dal.DALLocator; |
||
29 | import org.gvsig.fmap.dal.DataManager; |
||
30 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
31 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
32 | import org.gvsig.fmap.dal.feature.Feature; |
||
33 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
34 | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
||
35 | import org.gvsig.fmap.geom.Geometry; |
||
36 | import org.gvsig.fmap.geom.GeometryLocator; |
||
37 | import org.gvsig.fmap.geom.GeometryManager; |
||
38 | import org.gvsig.fmap.geom.primitive.Point; |
||
39 | import org.gvsig.fmap.geom.type.GeometryType; |
||
40 | import org.gvsig.tools.exception.BaseException; |
||
41 | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
||
42 | import org.gvsig.tools.visitor.VisitCanceledException; |
||
43 | import org.gvsig.tools.visitor.Visitor; |
||
44 | |||
45 | /**
|
||
46 | * Code to test bug gvsig-desktop#15670. This is based on the code provided by
|
||
47 | * the bug reporter (see ticket), thanks to him!!
|
||
48 | *
|
||
49 | * @author gvSIG Team
|
||
50 | * @version $Id$
|
||
51 | */
|
||
52 | public class Bug15670Test extends TestCase { |
||
53 | |||
54 | public void testBug15670() 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 | EditableFeatureType type = destParams.getDefaultFeatureType(); |
||
63 | GeometryType geometryType = |
||
64 | geometryManager.getGeometryType(Geometry.TYPES.POINT, |
||
65 | Geometry.SUBTYPES.GEOM2D); |
||
66 | type.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
|
||
67 | .setGeometryType(geometryType); |
||
68 | type.setDefaultGeometryAttributeName("GEOMETRY");
|
||
69 | |||
70 | destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
||
71 | destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
||
72 | destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
||
73 | destParams.setDynValue("crs", "EPSG:23030"); |
||
74 | destParams.setDefaultFeatureType(type); |
||
75 | |||
76 | manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
||
77 | FeatureStore store = |
||
78 | (FeatureStore) manager.openStore("Shape", destParams);
|
||
79 | |||
80 | store.edit(); |
||
81 | EditableFeature feature = store.createNewFeature().getEditable(); |
||
82 | final Point geom = |
||
83 | geometryManager.createPoint(10.0, 10.0, Geometry.SUBTYPES.GEOM2D); |
||
84 | feature.setGeometry("GEOMETRY", geom);
|
||
85 | store.insert(feature); |
||
86 | store.finishEditing(); |
||
87 | |||
88 | store.accept(new Visitor() {
|
||
89 | |||
90 | public void visit(Object obj) throws VisitCanceledException, |
||
91 | BaseException { |
||
92 | Feature feature = (Feature) obj; |
||
93 | assertEquals(geom, feature.getGeometry("GEOMETRY"));
|
||
94 | } |
||
95 | }); |
||
96 | store.dispose(); |
||
97 | } |
||
98 | } |