root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src-test / org / gvsig / fmap / dal / store / dbf / TestDBF.java @ 24498
History | View | Annotate | Download (3.22 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 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 IVER T.I. S.A. {{Task}}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.dal.store.dbf; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.Iterator; |
32 |
|
33 |
import junit.framework.TestCase; |
34 |
|
35 |
import org.gvsig.fmap.dal.DALFileLibrary; |
36 |
import org.gvsig.fmap.dal.DALLibrary; |
37 |
import org.gvsig.fmap.dal.DALLocator; |
38 |
import org.gvsig.fmap.dal.DataManager; |
39 |
import org.gvsig.fmap.dal.exceptions.DataException; |
40 |
import org.gvsig.fmap.dal.feature.Feature; |
41 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
42 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
43 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
44 |
import org.gvsig.fmap.dal.feature.FeatureType; |
45 |
import org.gvsig.fmap.dal.store.dbf.DBFLibrary; |
46 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreParameters; |
47 |
import org.gvsig.fmap.dal.store.dbf.DBFStoreProvider; |
48 |
|
49 |
public class TestDBF extends TestCase { |
50 |
|
51 |
public static final File file = new File(TestDBF.class.getResource( |
52 |
"data/prueba.dbf").getFile());
|
53 |
|
54 |
private static DataManager dataManager = null; |
55 |
|
56 |
|
57 |
protected void setUp() throws Exception { |
58 |
super.setUp();
|
59 |
DALLibrary lib = new DALLibrary();
|
60 |
lib.initialize(); |
61 |
lib.postInitialize(); |
62 |
|
63 |
DALFileLibrary libFile = new DALFileLibrary();
|
64 |
libFile.initialize(); |
65 |
libFile.postInitialize(); |
66 |
|
67 |
DBFLibrary dbfLib = new DBFLibrary();
|
68 |
dbfLib.initialize(); |
69 |
dbfLib.postInitialize(); |
70 |
|
71 |
dataManager = DALLocator.getDataManager(); |
72 |
} |
73 |
|
74 |
public void testSimpleIteration() { |
75 |
FeatureStore store = null;
|
76 |
DBFStoreParameters dbfParameters = null;
|
77 |
|
78 |
try {
|
79 |
dbfParameters = (DBFStoreParameters) dataManager |
80 |
.createStoreParameters(DBFStoreProvider.NAME); |
81 |
|
82 |
dbfParameters.setFile(file); |
83 |
|
84 |
store = (FeatureStore) dataManager.createStore(dbfParameters); |
85 |
FeatureSet set; |
86 |
FeatureType type = store.getDefaultFeatureType(); |
87 |
set = store.getFeatureSet(); |
88 |
|
89 |
Iterator it = set.iterator();
|
90 |
Iterator ftIt;
|
91 |
FeatureAttributeDescriptor desc; |
92 |
|
93 |
Feature feature; |
94 |
while (it.hasNext()) {
|
95 |
ftIt = type.iterator(); |
96 |
|
97 |
feature = (Feature) it.next(); |
98 |
// while (ftIt.hasNext()) {
|
99 |
// desc = (FeatureAttributeDescriptor) ftIt.next();
|
100 |
// System.out.println(desc.getName() + ":"
|
101 |
// + feature.get(desc.getIndex()));
|
102 |
//
|
103 |
// }
|
104 |
System.out.println(feature.get("NOMBRE")); |
105 |
|
106 |
|
107 |
} |
108 |
|
109 |
set.dispose(); |
110 |
|
111 |
|
112 |
} catch (DataException e3) {
|
113 |
e3.printStackTrace(); |
114 |
fail(); |
115 |
return;
|
116 |
} |
117 |
|
118 |
|
119 |
} |
120 |
|
121 |
} |