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 / Bug15643Test.java @ 40435

History | View | Annotate | Download (5.05 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 com.vividsolutions.jts.geom.Coordinate;
27
import com.vividsolutions.jts.geom.GeometryFactory;
28

    
29
import org.gvsig.fmap.dal.DALLocator;
30
import org.gvsig.fmap.dal.DataManager;
31
import org.gvsig.fmap.dal.DataTypes;
32
import org.gvsig.fmap.dal.feature.EditableFeature;
33
import org.gvsig.fmap.dal.feature.EditableFeatureType;
34
import org.gvsig.fmap.dal.feature.Feature;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.fmap.geom.GeometryLocator;
39
import org.gvsig.fmap.geom.GeometryManager;
40
import org.gvsig.fmap.geom.operation.GeometryOperation;
41
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
42
import org.gvsig.fmap.geom.operation.fromjts.FromJTS;
43
import org.gvsig.fmap.geom.type.GeometryType;
44
import org.gvsig.tools.exception.BaseException;
45
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
46
import org.gvsig.tools.visitor.VisitCanceledException;
47
import org.gvsig.tools.visitor.Visitor;
48

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

    
58
    public void testBug15643() throws Exception {
59
        new DefaultLibrariesInitializer().fullInitialize();
60
        DataManager manager = DALLocator.getDataManager();
61
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
62

    
63
        NewFeatureStoreParameters destParams =
64
                (NewFeatureStoreParameters) manager.createNewStoreParameters(
65
                    "FilesystemExplorer", "Shape");
66
        EditableFeatureType type = destParams.getDefaultFeatureType();
67
        GeometryType geometryType =
68
            geometryManager.getGeometryType(Geometry.TYPES.POINT,
69
                Geometry.SUBTYPES.GEOM2D);
70
        type.add("geom", org.gvsig.fmap.geom.DataTypes.GEOMETRY)
71
            .setGeometryType(geometryType);
72
        type.setDefaultGeometryAttributeName("geom");
73
        type.add("float", DataTypes.FLOAT).setSize(5);
74
        type.add("double", DataTypes.DOUBLE).setSize(5);
75
        type.add("int", DataTypes.INT).setSize(5);
76
        type.add("long", DataTypes.LONG).setSize(5);
77

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

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

    
88
        store.edit();
89
        EditableFeature feature = store.createNewFeature().getEditable();
90
        com.vividsolutions.jts.geom.Geometry g =
91
            new GeometryFactory().createPoint(new Coordinate(0, 0));
92

    
93
        int opCode = geometryManager.getGeometryOperationCode(FromJTS.NAME);
94
        GeometryOperation converter =
95
            geometryManager.getGeometryOperation(opCode, Geometry.TYPES.POINT,
96
                Geometry.SUBTYPES.GEOM2D);
97
        GeometryOperationContext ctx = new GeometryOperationContext();
98
        ctx.setAttribute(FromJTS.PARAM, g);
99
        Geometry fmapGeom = (Geometry) converter.invoke(null, ctx);
100
        feature.setGeometry(feature.getType()
101
            .getDefaultGeometryAttributeIndex(), fmapGeom);
102
        feature.setFloat("float", 34.0f);
103
        feature.setDouble("double", 34.0d);
104
        feature.setInt("int", 34);
105
        feature.setLong("long", 34l);
106
        store.insert(feature);
107
        store.finishEditing();
108

    
109
        store.accept(new Visitor() {
110

    
111
            public void visit(Object obj) throws VisitCanceledException,
112
                BaseException {
113
                Feature feature = (Feature) obj;
114
                assertEquals(34.0f, feature.getFloat("float"));
115
                assertEquals(34.0d, feature.getDouble("double"));
116
                assertEquals(34, feature.getInt("int"));
117
                assertEquals(34l, feature.getLong("long"));
118
            }
119
        });
120

    
121
        store.dispose();
122
    }
123

    
124
}