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