Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src-test / org / gvsig / fmap / dal / store / shp / Bug15671Test.java @ 38083

History | View | Annotate | Download (4.19 KB)

1
/* 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.dal.feature.impl.DefaultEditableFeatureType;
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.NullGeometry;
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
        EditableFeatureType type = new DefaultEditableFeatureType();
60
        GeometryType geometryType =
61
            geometryManager.getGeometryType(Geometry.TYPES.POINT,
62
                Geometry.SUBTYPES.GEOM2D);
63
        type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
64
            .setGeometryType(geometryType);
65
        type.setDefaultGeometryAttributeName("GEOMETRY");
66
        type.add("double", DataTypes.DOUBLE);
67

    
68
        NewFeatureStoreParameters destParams =
69
            (NewFeatureStoreParameters) manager.createNewStoreParameters(
70
                "FilesystemExplorer", "Shape");
71
        destParams.setDynValue("shpfile", "/tmp/mySHP.shp");
72
        destParams.setDynValue("dbffile", "/tmp/mySHP.dbf");
73
        destParams.setDynValue("shxfile", "/tmp/mySHP.shx");
74
        destParams.setDynValue("crs", "EPSG:23030");
75
        destParams.setDefaultFeatureType(type);
76

    
77
        manager.newStore("FilesystemExplorer", "Shape", destParams, true);
78
        FeatureStore store =
79
            (FeatureStore) manager.openStore("Shape", destParams);
80

    
81
        store.edit();
82
        EditableFeature feature = store.createNewFeature().getEditable();
83
        NullGeometry geom =
84
            geometryManager.createNullGeometry(Geometry.SUBTYPES.GEOM2D);
85
        feature.setGeometry("GEOMETRY", geom);
86
        feature.setDouble("double", 42.0d);
87
        store.insert(feature);
88
        store.finishEditing();
89

    
90
        store.accept(new Visitor() {
91

    
92
            public void visit(Object obj) throws VisitCanceledException,
93
                BaseException {
94
                Feature feature = (Feature) obj;
95
                Geometry geometry = feature.getGeometry("GEOMETRY");
96
                assertEquals(
97
                    "Read geometry must be of Null Geometry type instead of "
98
                        + geometry.getGeometryType().getName(),
99
                    Geometry.TYPES.NULL, geometry.getType());
100
            }
101
        });
102
        store.dispose();
103
    }
104

    
105
}