Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataFile / src-test / org / gvsig / fmap / data / feature / file / dbf / DBFTest.java @ 22373

History | View | Annotate | Download (4.05 KB)

1 22373 jmvivo
package org.gvsig.fmap.data.feature.file.dbf;
2 19401 vcaballero
3
import java.io.File;
4
import java.util.Iterator;
5
6
import junit.framework.TestCase;
7
8 21911 jmvivo
import org.gvsig.fmap.data.CloseException;
9
import org.gvsig.fmap.data.DataManager;
10
import org.gvsig.fmap.data.InitializeException;
11
import org.gvsig.fmap.data.OpenException;
12
import org.gvsig.fmap.data.ReadException;
13 22373 jmvivo
import org.gvsig.fmap.data.feature.file.DataStoreTest;
14 22360 jmvivo
import org.gvsig.fmap.data.feature.Feature;
15
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
16
import org.gvsig.fmap.data.feature.FeatureCollection;
17
import org.gvsig.fmap.data.feature.FeatureStore;
18
import org.gvsig.fmap.data.feature.FeatureType;
19 22373 jmvivo
import org.gvsig.fmap.data.feature.file.dbf.DBFStore;
20
import org.gvsig.fmap.data.feature.file.dbf.DBFStoreParameters;
21
import org.gvsig.fmap.data.feature.file.dbf.Register;
22 19401 vcaballero
23
public class DBFTest extends TestCase {
24 19603 vcaballero
        private File file = new File(DataStoreTest.class.getResource("data/prueba.dbf").getFile());
25 19401 vcaballero
26 19603 vcaballero
27 19401 vcaballero
        public static void main(String[] args) {
28 20921 vcaballero
                junit.textui.TestRunner.run(DBFTest.class);
29 19401 vcaballero
        }
30
31
        protected void setUp() throws Exception {
32
                super.setUp();
33
        }
34
35
        public void testInitialize() {
36 19976 jmvivo
                DataManager manager = DataManager.getManager();
37
                Register.selfRegister();
38
39 21716 jmvivo
                FeatureStore store=null;
40 21594 jmvivo
                DBFStoreParameters dbfParameters=null;
41 19976 jmvivo
42 21594 jmvivo
                try {
43
                        dbfParameters=(DBFStoreParameters)manager.createDataStoreParameters(DBFStore.DATASTORE_NAME);
44
                } catch (InitializeException e3) {
45
                        e3.printStackTrace();
46
                        fail();
47
                }
48 20424 vcaballero
                dbfParameters.setFile(file);
49 19976 jmvivo
50
51 19443 vcaballero
                try {
52 21716 jmvivo
                        store = (FeatureStore)manager.createDataStore(dbfParameters);
53 19443 vcaballero
                } catch (InitializeException e) {
54
                        // TODO Auto-generated catch block
55
                        e.printStackTrace();
56
                }
57 19401 vcaballero
58 21045 jmvivo
                FeatureType ft=store.getDefaultFeatureType();
59
                FeatureCollection featureCollection=null;
60 19658 vcaballero
                try {
61 21045 jmvivo
                        featureCollection = (FeatureCollection)store.getDataCollection(ft,null,null);
62 19658 vcaballero
                } catch (ReadException e1) {
63
                        // TODO Auto-generated catch block
64
                        e1.printStackTrace();
65
                }
66 19401 vcaballero
                Iterator iter = featureCollection.iterator();
67
                while (iter.hasNext()) {
68
69 21045 jmvivo
                        Feature feature = (Feature)iter.next();
70 19401 vcaballero
                        System.out.println("DBF Feature ------------------- ");
71 20414 vcaballero
                        Iterator iterator=ft.iterator();
72
                        while (iterator.hasNext()) {
73 21045 jmvivo
                                FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) iterator.next();
74 20414 vcaballero
                                int i=descriptor.ordinal();
75 19401 vcaballero
                                String type=descriptor.getDataType();
76 21045 jmvivo
                                if (type.equals(FeatureAttributeDescriptor.TYPE_BOOLEAN)){
77 19401 vcaballero
                                        System.out.println("Boolean ----- "+ feature.getBoolean(i));
78 21045 jmvivo
                                }else if (type.equals(FeatureAttributeDescriptor.TYPE_BYTE)){
79 19401 vcaballero
                                        System.out.println("Byte ----- "+ feature.getByte(i));
80 21045 jmvivo
                                }else if (type.equals(FeatureAttributeDescriptor.TYPE_DATE)){
81 19401 vcaballero
                                        System.out.println("Date ----- "+ feature.getDate(i));
82 21045 jmvivo
                                }else if (type.equals(FeatureAttributeDescriptor.TYPE_DOUBLE)){
83 19401 vcaballero
                                        System.out.println("Double ----- "+ feature.getDouble(i));
84 21045 jmvivo
                                }else if (type.equals(FeatureAttributeDescriptor.TYPE_FLOAT)){
85 19401 vcaballero
                                        System.out.println("Float ----- "+ feature.getFloat(i));
86 21045 jmvivo
                                }else if (type.equals(FeatureAttributeDescriptor.TYPE_INT)){
87 19401 vcaballero
                                        System.out.println("Integer ----- "+ feature.getInt(i));
88 21045 jmvivo
                                }else if (type.equals(FeatureAttributeDescriptor.TYPE_LONG)){
89 19401 vcaballero
                                        System.out.println("Long ----- "+ feature.getLong(i));
90 21045 jmvivo
                                }else if (type.equals(FeatureAttributeDescriptor.TYPE_STRING)){
91 19401 vcaballero
                                        System.out.println("String ----- "+ feature.getString(i));
92
                                }
93
                        }
94
                }
95 19976 jmvivo
                iter = null;
96
                featureCollection.dispose();
97 19401 vcaballero
98 19443 vcaballero
                try {
99 20626 jmvivo
                        store.dispose();
100 19443 vcaballero
                } catch (CloseException e) {
101
                        // TODO Auto-generated catch block
102
                        e.printStackTrace();
103
                }
104 20626 jmvivo
105 19401 vcaballero
        }
106 20626 jmvivo
107
        public void test_Resources(){
108
109
                DataManager manager = DataManager.getManager();
110
                Register.selfRegister();
111
112 21594 jmvivo
                DBFStoreParameters dbfParameters=null;
113 20626 jmvivo
114 21594 jmvivo
                try {
115
                        dbfParameters=(DBFStoreParameters)manager.createDataStoreParameters(DBFStore.DATASTORE_NAME);
116
                } catch (InitializeException e) {
117
                        e.printStackTrace();
118
                        fail();
119
                }
120 20626 jmvivo
                dbfParameters.setFile(file);
121
122 20661 jmvivo
                DataStoreTest.doFileResourceTest(dbfParameters);
123 20626 jmvivo
        }
124 19401 vcaballero
}