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 @ 42540
History | View | Annotate | Download (4.05 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.DataTypes; |
||
31 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
32 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
33 | import org.gvsig.fmap.dal.feature.Feature; |
||
34 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
35 | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
||
36 | import org.gvsig.fmap.geom.Geometry; |
||
37 | import org.gvsig.fmap.geom.GeometryLocator; |
||
38 | import org.gvsig.fmap.geom.GeometryManager; |
||
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#15671. 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 Bug15671Test extends TestCase { |
||
53 | |||
54 | public void testBug15671() throws Exception { |
||
55 | new DefaultLibrariesInitializer().fullInitialize();
|
||
56 | DataManager manager = DALLocator.getDataManager(); |
||
57 | GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
||
58 | |||
59 | |||
60 | NewFeatureStoreParameters destParams = |
||
61 | (NewFeatureStoreParameters) manager.createNewStoreParameters( |
||
62 | "FilesystemExplorer", "Shape"); |
||
63 | |||
64 | EditableFeatureType type = destParams.getDefaultFeatureType(); |
||
65 | GeometryType geometryType = |
||
66 | geometryManager.getGeometryType(Geometry.TYPES.POINT, |
||
67 | Geometry.SUBTYPES.GEOM2D); |
||
68 | type.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
|
||
69 | .setGeometryType(geometryType); |
||
70 | type.setDefaultGeometryAttributeName("GEOMETRY");
|
||
71 | type.add("double", DataTypes.DOUBLE);
|
||
72 | |||
73 | |||
74 | destParams.setDynValue("shpfile", "/tmp/mySHP.shp"); |
||
75 | destParams.setDynValue("dbffile", "/tmp/mySHP.dbf"); |
||
76 | destParams.setDynValue("shxfile", "/tmp/mySHP.shx"); |
||
77 | destParams.setDynValue("crs", "EPSG:23030"); |
||
78 | //destParams.setDefaultFeatureType(type);
|
||
79 | |||
80 | |||
81 | manager.newStore("FilesystemExplorer", "Shape", destParams, true); |
||
82 | FeatureStore store = |
||
83 | (FeatureStore) manager.openStore("Shape", destParams);
|
||
84 | |||
85 | store.edit(); |
||
86 | EditableFeature feature = store.createNewFeature().getEditable(); |
||
87 | 41610 | jjdelcerro | feature.setGeometry("GEOMETRY", null); |
88 | 40435 | jjdelcerro | feature.setDouble("double", 42.0d); |
89 | store.insert(feature); |
||
90 | store.finishEditing(); |
||
91 | |||
92 | store.accept(new Visitor() {
|
||
93 | |||
94 | public void visit(Object obj) throws VisitCanceledException, |
||
95 | BaseException { |
||
96 | Feature feature = (Feature) obj; |
||
97 | Geometry geometry = feature.getGeometry("GEOMETRY");
|
||
98 | assertEquals( |
||
99 | "Read geometry must be of Null Geometry type instead of "
|
||
100 | + geometry.getGeometryType().getName(), |
||
101 | Geometry.TYPES.NULL, geometry.getType()); |
||
102 | } |
||
103 | }); |
||
104 | store.dispose(); |
||
105 | } |
||
106 | |||
107 | } |