Statistics
| Revision:

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 @ 40559

History | View | Annotate | Download (4.2 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
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.primitive.NullGeometry;
40
import org.gvsig.fmap.geom.type.GeometryType;
41
import org.gvsig.tools.exception.BaseException;
42
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
43
import org.gvsig.tools.visitor.VisitCanceledException;
44
import org.gvsig.tools.visitor.Visitor;
45

    
46
/**
47
 * Code to test bug gvsig-desktop#15671. This is based on the code provided by
48
 * the bug reporter (see ticket), thanks to him!!
49
 * 
50
 * @author gvSIG Team
51
 * @version $Id$
52
 */
53
public class Bug15671Test extends TestCase {
54

    
55
    public void testBug15671() throws Exception {
56
        new DefaultLibrariesInitializer().fullInitialize();
57
        DataManager manager = DALLocator.getDataManager();
58
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
59

    
60

    
61
        NewFeatureStoreParameters destParams =
62
            (NewFeatureStoreParameters) manager.createNewStoreParameters(
63
                "FilesystemExplorer", "Shape");
64

    
65
        EditableFeatureType type = destParams.getDefaultFeatureType();
66
        GeometryType geometryType =
67
            geometryManager.getGeometryType(Geometry.TYPES.POINT,
68
                Geometry.SUBTYPES.GEOM2D);
69
        type.add("GEOMETRY", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
70
            .setGeometryType(geometryType);
71
        type.setDefaultGeometryAttributeName("GEOMETRY");
72
        type.add("double", DataTypes.DOUBLE);
73

    
74
        
75
        destParams.setDynValue("shpfile", "/tmp/mySHP.shp");
76
        destParams.setDynValue("dbffile", "/tmp/mySHP.dbf");
77
        destParams.setDynValue("shxfile", "/tmp/mySHP.shx");
78
        destParams.setDynValue("crs", "EPSG:23030");
79
        //destParams.setDefaultFeatureType(type);
80
        
81

    
82
        manager.newStore("FilesystemExplorer", "Shape", destParams, true);
83
        FeatureStore store =
84
            (FeatureStore) manager.openStore("Shape", destParams);
85

    
86
        store.edit();
87
        EditableFeature feature = store.createNewFeature().getEditable();
88
        NullGeometry geom =
89
            geometryManager.createNullGeometry(Geometry.SUBTYPES.GEOM2D);
90
        feature.setGeometry("GEOMETRY", geom);
91
        feature.setDouble("double", 42.0d);
92
        store.insert(feature);
93
        store.finishEditing();
94

    
95
        store.accept(new Visitor() {
96

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

    
110
}