Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dalfile / src-test / org / gvsig / fmap / dal / store / dbf / TestDBF.java @ 27723

History | View | Annotate | Download (5.63 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.ArrayList;
32
import java.util.Iterator;
33

    
34
import org.gvsig.fmap.dal.DALFileLibrary;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore;
38
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.feature.FeatureQuery;
40
import org.gvsig.fmap.dal.feature.FeatureStore;
41
import org.gvsig.fmap.dal.feature.FeatureType;
42
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
43
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
44
import org.gvsig.tools.ToolsLocator;
45
import org.gvsig.tools.persistence.xmlentity.XMLEntityManager;
46

    
47
public class TestDBF extends BaseTestEditableFeatureStore {
48

    
49
        protected boolean testDBFInitialized = false;
50

    
51

    
52
        public static final File dbf_prueba = new File(TestDBF.class.getResource(
53
                        "data/prueba.dbf").getFile());
54
        public static final File dbf_prueba_destino= new File(TestDBF.class.getResource(
55
                        "data").getFile()+"/pruebaTemp.dbf");
56
        public static final File dbf_pruebaNull = new File(TestDBF.class
57
                        .getResource("data/pruebaNull.dbf").getFile());
58

    
59
        private FilesystemServerExplorer myExplorer = null;
60

    
61
        public TestDBF() {
62
                super();
63
        }
64

    
65
        /**
66
         * @param dataManager
67
         */
68
        public TestDBF(boolean initializeBase, boolean initializeDBF) {
69
                this.baseTestInitialized = !initializeBase;
70
                this.testDBFInitialized = !initializeDBF;
71
        }
72

    
73
        protected void setUp() throws Exception {
74
                super.setUp();
75
                if (testDBFInitialized) {
76
                        return;
77
                }
78
                ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
79

    
80
                DALFileLibrary libFile = new DALFileLibrary();
81
                libFile.initialize();
82

    
83
                DBFLibrary dbfLib = new DBFLibrary();
84
                dbfLib.initialize();
85

    
86
                libFile.postInitialize();
87
                dbfLib.postInitialize();
88
                testDBFInitialized = true;
89
        }
90

    
91

    
92
        public DataStoreParameters getDefaultDataStoreParameters() throws DataException {
93
                DBFStoreParameters dbfParameters = null;
94
                dbfParameters = (DBFStoreParameters) dataManager
95
                                .createStoreParameters(DBFStoreProvider.NAME);
96

    
97
                dbfParameters.setFile(dbf_prueba);
98

    
99
                return dbfParameters;
100
        }
101

    
102
        public void testExplorerList() throws Exception {
103
                this.testExplorerList(2);
104
        }
105

    
106
        public void testJoin() throws Exception {
107
                DBFStoreParameters dbfParameters = null;
108
                FeatureStore store1, store2;
109

    
110
                dbfParameters = (DBFStoreParameters) dataManager
111
                                .createStoreParameters(DBFStoreProvider.NAME);
112

    
113
                dbfParameters.setFile(dbf_prueba);
114

    
115
                store1 = (FeatureStore) dataManager.createStore(dbfParameters);
116
                store2 = (FeatureStore) dataManager.createStore(dbfParameters);
117

    
118
                JoinTransform join = new JoinTransform();
119

    
120
                ArrayList names = new ArrayList();// <String>
121
                Iterator iter = store2.getDefaultFeatureType().iterator();// <FeatureAttributeDescriptor>
122
                while (iter.hasNext()) {
123
                        names.add(((FeatureAttributeDescriptor) iter.next()).getName());
124
                }
125

    
126
                join.initialize(store1, store2, "NOMBRE", "NOMBRE", null, null,
127
                                (String[]) names.toArray(new String[0]));
128
                store1.getTransforms().add(join);
129

    
130
                this.testSimpleIteration(store1);
131

    
132
                FeatureQuery query = store1.createFeatureQuery();
133
                FeatureType ftFinal = store1.getDefaultFeatureType();
134
                String[] queryNames = new String[] {
135
                                ftFinal.getAttributeDescriptor(0).getName(),
136
                                ftFinal.getAttributeDescriptor(1).getName(),
137
                                ftFinal.getAttributeDescriptor(ftFinal.size() - 1).getName() };
138
                query.setAttributeNames(queryNames);
139

    
140
                this.testSimpleIteration(store1, query);
141

    
142
                queryNames = new String[] {
143
                                ftFinal.getAttributeDescriptor(ftFinal.size() - 1).getName(),
144
                                ftFinal.getAttributeDescriptor(1).getName(),
145
                                ftFinal.getAttributeDescriptor(0).getName(),
146
                                ftFinal.getAttributeDescriptor(ftFinal.size() - 2).getName() };
147

    
148
                query.setAttributeNames(queryNames);
149
                this.testSimpleIteration(store1, query);
150

    
151
                store1.dispose();
152
                store2.dispose();
153

    
154

    
155

    
156

    
157
        }
158

    
159
        /*
160
         * (non-Javadoc)
161
         *
162
         * @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
163
         */
164
        public boolean hasExplorer() {
165
                return true;
166
        }
167

    
168
        /*
169
         * (non-Javadoc)
170
         *
171
         * @seeorg.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore#
172
         * getDefaultNewDataStoreParameters()
173
         */
174
        public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
175
                        throws Exception {
176
                if (this.myExplorer == null) {
177
                        DBFStoreParameters dbfParameters = (DBFStoreParameters) this
178
                                        .getDefaultDataStoreParameters();
179
                        FeatureStore store = (FeatureStore) dataManager
180
                                        .createStore(dbfParameters);
181
                        myExplorer = (FilesystemServerExplorer) store.getExplorer();
182
                        store.dispose();
183
                }
184

    
185
                return (NewFeatureStoreParameters) myExplorer
186
                                .getAddParameters(dbf_prueba_destino);
187
        }
188

    
189
        public boolean usesResources() {
190
                return true;
191
        }
192

    
193
}