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 / Bug15671Test.java @ 40435
History | View | Annotate | Download (4.15 KB)
1 | 40435 | jjdelcerro | /* 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.DataTypes; |
||
29 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
30 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
31 | import org.gvsig.fmap.dal.feature.Feature; |
||
32 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
33 | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
||
34 | import org.gvsig.fmap.geom.Geometry; |
||
35 | import org.gvsig.fmap.geom.GeometryLocator; |
||
36 | import org.gvsig.fmap.geom.GeometryManager; |
||
37 | import org.gvsig.fmap.geom.primitive.NullGeometry; |
||
38 | import org.gvsig.fmap.geom.type.GeometryType; |
||
39 | import org.gvsig.tools.exception.BaseException; |
||
40 | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
||
41 | import org.gvsig.tools.visitor.VisitCanceledException; |
||
42 | import org.gvsig.tools.visitor.Visitor; |
||
43 | |||
44 | /**
|
||
45 | * Code to test bug gvsig-desktop#15671. 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 Bug15671Test extends TestCase { |
||
52 | |||
53 | public void testBug15671() throws Exception { |
||
54 | new DefaultLibrariesInitializer().fullInitialize();
|
||
55 | DataManager manager = DALLocator.getDataManager(); |
||
56 | GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
||
57 | |||
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("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
|
||
68 | .setGeometryType(geometryType); |
||
69 | type.setDefaultGeometryAttributeName("GEOMETRY");
|
||
70 | type.add("double", DataTypes.DOUBLE);
|
||
71 | |||
72 | |||
73 | destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
||
74 | destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
||
75 | destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
||
76 | destParams.setDynValue("crs", "EPSG:23030"); |
||
77 | //destParams.setDefaultFeatureType(type);
|
||
78 | |||
79 | |||
80 | manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
||
81 | FeatureStore store = |
||
82 | (FeatureStore) manager.openStore("Shape", destParams);
|
||
83 | |||
84 | store.edit(); |
||
85 | EditableFeature feature = store.createNewFeature().getEditable(); |
||
86 | NullGeometry geom = |
||
87 | geometryManager.createNullGeometry(Geometry.SUBTYPES.GEOM2D); |
||
88 | feature.setGeometry("GEOMETRY", geom);
|
||
89 | feature.setDouble("double", 42.0d); |
||
90 | store.insert(feature); |
||
91 | store.finishEditing(); |
||
92 | |||
93 | store.accept(new Visitor() {
|
||
94 | |||
95 | public void visit(Object obj) throws VisitCanceledException, |
||
96 | BaseException { |
||
97 | Feature feature = (Feature) obj; |
||
98 | Geometry geometry = feature.getGeometry("GEOMETRY");
|
||
99 | assertEquals( |
||
100 | "Read geometry must be of Null Geometry type instead of "
|
||
101 | + geometry.getGeometryType().getName(), |
||
102 | Geometry.TYPES.NULL, geometry.getType()); |
||
103 | } |
||
104 | }); |
||
105 | store.dispose(); |
||
106 | } |
||
107 | |||
108 | } |