Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dataFile / src-test / org / gvsig / fmap / data / feature / file / DataStoreTest.java @ 24250

History | View | Annotate | Download (44 KB)

1 22373 jmvivo
package org.gvsig.fmap.data.feature.file;
2 19401 vcaballero
3
import java.io.File;
4 19468 jmvivo
import java.util.Iterator;
5 19401 vcaballero
6 19402 vcaballero
import junit.framework.TestCase;
7
8 19603 vcaballero
import org.cresques.cts.IProjection;
9 21177 vcaballero
import org.gvsig.fmap.crs.CRSFactory;
10 23842 jjdelcerro
import org.gvsig.fmap.data.DataSet;
11 21911 jmvivo
import org.gvsig.fmap.data.DataManager;
12 23543 jmvivo
import org.gvsig.fmap.data.DataParameters;
13 21911 jmvivo
import org.gvsig.fmap.data.DataStoreParameters;
14 23754 jjdelcerro
import org.gvsig.fmap.data.exceptions.CloseException;
15
import org.gvsig.fmap.data.exceptions.DataException;
16
import org.gvsig.fmap.data.exceptions.InitializeException;
17
import org.gvsig.fmap.data.exceptions.OpenException;
18
import org.gvsig.fmap.data.exceptions.ReadException;
19
import org.gvsig.fmap.data.exceptions.WriteException;
20 22360 jmvivo
import org.gvsig.fmap.data.feature.AttributeDescriptor;
21
import org.gvsig.fmap.data.feature.Feature;
22
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
23 23842 jjdelcerro
import org.gvsig.fmap.data.feature.FeatureSet;
24 22360 jmvivo
import org.gvsig.fmap.data.feature.FeatureStore;
25
import org.gvsig.fmap.data.feature.FeatureType;
26
import org.gvsig.fmap.data.feature.MemoryFeature;
27 22373 jmvivo
import org.gvsig.fmap.data.feature.file.dbf.DBFStore;
28
import org.gvsig.fmap.data.feature.file.dbf.DBFStoreParameters;
29
import org.gvsig.fmap.data.feature.file.dgn.DGNStore;
30
import org.gvsig.fmap.data.feature.file.dgn.DGNStoreParameters;
31
import org.gvsig.fmap.data.feature.file.dxf.DXFStore;
32
import org.gvsig.fmap.data.feature.file.dxf.DXFStoreParameters;
33
import org.gvsig.fmap.data.feature.file.shp.SHPStore;
34
import org.gvsig.fmap.data.feature.file.shp.SHPStoreParameters;
35 23754 jjdelcerro
import org.gvsig.fmap.data.feature.impl.AbstractFeatureStore;
36 22360 jmvivo
import org.gvsig.fmap.data.feature.visitor.PrintlnFeaturesVisitor;
37 23754 jjdelcerro
import org.gvsig.fmap.data.impl.DefaultDataManager;
38 23878 jjdelcerro
import org.gvsig.fmap.data.resource.ResourceManager;
39
import org.gvsig.fmap.data.resource.impl.DefaultResourceManager;
40
import org.gvsig.fmap.data.resource.spi.AbstractResource;
41 23010 jmvivo
import org.gvsig.fmap.geom.Geometry;
42
import org.gvsig.fmap.geom.handler.Handler;
43 23303 jmvivo
import org.gvsig.tools.exception.BaseException;
44 23066 jmvivo
import org.gvsig.tools.observer.Observer;
45 19401 vcaballero
46 23010 jmvivo
import com.iver.utiles.XMLEntity;
47 23181 vcaballero
import com.iver.utiles.XMLException;
48 23010 jmvivo
49 19401 vcaballero
public class DataStoreTest extends TestCase {
50
51 23010 jmvivo
        private File dbffile = new File(DataStoreTest.class.getResource(
52
                        "data/prueba.dbf").getFile());
53
        private File shpfile = new File(DataStoreTest.class.getResource(
54
                        "data/prueba.shp").getFile());
55
        private File dxffile = new File(DataStoreTest.class.getResource(
56
                        "data/prueba.dxf").getFile());
57
        private File dgnfile = new File(DataStoreTest.class.getResource(
58
                        "data/prueba.dgn").getFile());
59 19401 vcaballero
60
        public static void main(String[] args) {
61
                junit.textui.TestRunner.run(DataStoreTest.class);
62
        }
63
64
        protected void setUp() throws Exception {
65
                super.setUp();
66
67
        }
68
69
        public void testDBF() {
70 19658 vcaballero
                try {
71 20579 jmvivo
                        System.out.println("======= DBF ==============");
72 22373 jmvivo
                        org.gvsig.fmap.data.feature.file.dbf.Register.selfRegister();
73 19401 vcaballero
74 23754 jjdelcerro
                        DataManager dsm = DefaultDataManager.getManager();
75 19401 vcaballero
76 23010 jmvivo
                        DataStoreParameters dp = dsm
77 24081 jjdelcerro
                                        .createStoreParameters(DBFStore.DATASTORE_NAME);
78 23010 jmvivo
                        ((DBFStoreParameters) dp).setFile(dbffile);
79 19401 vcaballero
80 23010 jmvivo
                        driverTest(dp, null, null, true);
81
                        FeatureStore fs = null;
82 20579 jmvivo
                        try {
83 24081 jjdelcerro
                                fs = (FeatureStore) dsm.createStore(dp);
84 20579 jmvivo
                        } catch (InitializeException e) {
85
                                e.printStackTrace();
86
                                fail("Exception:" + e);
87
                        }
88
                        assertNotNull("Can't create Feature Store", fs);
89 19468 jmvivo
90 23010 jmvivo
                        //                        fs.open();
91 19658 vcaballero
92 20579 jmvivo
                        Iterator it;
93 23842 jjdelcerro
                        FeatureSet fc;
94 23010 jmvivo
                        Comparable v1, v2;
95
                        Feature feature, pfeature;
96 20579 jmvivo
                        long count;
97 19468 jmvivo
98 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataSet();
99 19468 jmvivo
100 20579 jmvivo
                        assertEquals(9, fc.size());
101 19468 jmvivo
102 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
103 23010 jmvivo
                                        .getDefaultFeatureType(), "lower(NOMBRE) like 'b%'", null);
104 19468 jmvivo
105 20579 jmvivo
                        assertEquals(2, fc.size());
106 19468 jmvivo
107 20579 jmvivo
                        it = fc.iterator();
108 23010 jmvivo
                        count = 0;
109
                        while (it.hasNext()) {
110
                                feature = (Feature) it.next();
111
                                assertTrue("Filter error", feature.getString("NOMBRE")
112
                                                .toLowerCase().startsWith("b"));
113 20579 jmvivo
                                count++;
114
                        }
115 23010 jmvivo
                        assertEquals("Iteration error", 2, count);
116 19468 jmvivo
117 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
118 23010 jmvivo
                                        .getDefaultFeatureType(), null, "NOMBRE ASC");
119 20579 jmvivo
                        assertEquals(9, fc.size());
120
                        it = fc.iterator();
121 23010 jmvivo
                        count = 0;
122
                        pfeature = (Feature) it.next();
123 19470 jmvivo
                        count++;
124 23010 jmvivo
                        while (it.hasNext()) {
125
                                feature = (Feature) it.next();
126
                                v1 = (Comparable) pfeature.get("NOMBRE");
127
                                v2 = (Comparable) feature.get("NOMBRE");
128
                                pfeature = feature;
129 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) <= 0));
130
                                count++;
131
                        }
132 23010 jmvivo
                        assertEquals("Iteration error", 9, count);
133 19468 jmvivo
134 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
135 23010 jmvivo
                                        .getDefaultFeatureType(), null, "NOMBRE DESC");
136 20579 jmvivo
                        assertEquals(9, fc.size());
137
                        it = fc.iterator();
138 19468 jmvivo
139 23010 jmvivo
                        count = 0;
140
                        pfeature = (Feature) it.next();
141 19470 jmvivo
                        count++;
142 23010 jmvivo
                        while (it.hasNext()) {
143
                                feature = (Feature) it.next();
144
                                v1 = (Comparable) pfeature.get("NOMBRE");
145
                                v2 = (Comparable) feature.get("NOMBRE");
146
                                pfeature = feature;
147 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) >= 0));
148
                                count++;
149
                        }
150 23010 jmvivo
                        assertEquals("Iteration error", 9, count);
151 19468 jmvivo
152 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
153 23010 jmvivo
                                        .getDefaultFeatureType(), "lower(NOMBRE) like 'b%'",
154
                                        "NOMBRE");
155 19468 jmvivo
156 20579 jmvivo
                        assertEquals(2, fc.size());
157 19468 jmvivo
158 20579 jmvivo
                        it = fc.iterator();
159 19468 jmvivo
160 23010 jmvivo
                        count = 0;
161
                        pfeature = (Feature) it.next();
162
                        assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith(
163
                                        "b"));
164 19470 jmvivo
                        count++;
165 23010 jmvivo
                        while (it.hasNext()) {
166
                                feature = (Feature) it.next();
167
                                assertTrue("Filter error", feature.getString("NOMBRE")
168
                                                .toLowerCase().startsWith("b"));
169
                                v1 = (Comparable) pfeature.get("NOMBRE");
170
                                v2 = (Comparable) feature.get("NOMBRE");
171
                                pfeature = feature;
172 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) <= 0));
173
                                count++;
174
                        }
175 23010 jmvivo
                        assertEquals("Iteration error", 2, count);
176 19468 jmvivo
177 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
178 23010 jmvivo
                                        .getDefaultFeatureType(), null, "Tipo,lower(NOMBRE) Desc");
179 20579 jmvivo
                        assertEquals(9, fc.size());
180
                        it = fc.iterator();
181 23010 jmvivo
                        count = 0;
182
                        pfeature = (Feature) it.next();
183 19480 jmvivo
                        System.out.println(pfeature.getString("NOMBRE"));
184
                        count++;
185 23010 jmvivo
                        while (it.hasNext()) {
186
                                feature = (Feature) it.next();
187
                                v1 = ((String) pfeature.get("NOMBRE")).toLowerCase();
188
                                v2 = ((String) feature.get("NOMBRE")).toLowerCase();
189
                                pfeature = feature;
190 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) >= 0));
191
                                System.out.println(pfeature.getString("NOMBRE"));
192
                                count++;
193
                        }
194 23010 jmvivo
                        assertEquals("Iteration error", 9, count);
195 19480 jmvivo
196 20579 jmvivo
                        /// CON  EDICION
197 19664 jmvivo
198 23754 jjdelcerro
                        fs.edit();
199 19664 jmvivo
200 24183 jjdelcerro
                        Feature newFeature = fs.createNewFeature(true);
201 20579 jmvivo
                        newFeature.editing();
202 24250 jjdelcerro
                        newFeature.setAttribute("NOMBRE", "BuRjaSOT");
203
                        newFeature.setAttribute("TIPO", "MUNICIPIO");
204 20579 jmvivo
                        fs.insert(newFeature);
205 19664 jmvivo
206 20579 jmvivo
                        try {
207 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataSet();
208 20579 jmvivo
                        } catch (ReadException e1) {
209
                                e1.printStackTrace();
210
                                fail();
211
                        }
212 19664 jmvivo
213 20579 jmvivo
                        assertEquals(10, fc.size());
214 19664 jmvivo
215 20579 jmvivo
                        try {
216 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
217 23010 jmvivo
                                                .getDefaultFeatureType(), "lower(NOMBRE) like 'b%'",
218
                                                null);
219 20579 jmvivo
                        } catch (ReadException e1) {
220
                                e1.printStackTrace();
221
                                fail();
222
                        }
223 19664 jmvivo
224 20579 jmvivo
                        assertEquals(3, fc.size());
225 19664 jmvivo
226 20579 jmvivo
                        it = fc.iterator();
227 23010 jmvivo
                        count = 0;
228
                        while (it.hasNext()) {
229
                                feature = (Feature) it.next();
230
                                assertTrue("Filter error", feature.getString("NOMBRE")
231
                                                .toLowerCase().startsWith("b"));
232 20579 jmvivo
                                count++;
233
                        }
234 23010 jmvivo
                        assertEquals("Iteration error", 3, count);
235 19664 jmvivo
236 20579 jmvivo
                        try {
237 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
238 23010 jmvivo
                                                .getDefaultFeatureType(), null, "NOMBRE ASC");
239 20579 jmvivo
                        } catch (ReadException e1) {
240
                                e1.printStackTrace();
241
                                fail();
242
                        }
243
                        assertEquals(10, fc.size());
244
                        it = fc.iterator();
245 23010 jmvivo
                        count = 0;
246
                        pfeature = (Feature) it.next();
247 19664 jmvivo
                        count++;
248 23010 jmvivo
                        while (it.hasNext()) {
249
                                feature = (Feature) it.next();
250
                                v1 = (Comparable) pfeature.get("NOMBRE");
251
                                v2 = (Comparable) feature.get("NOMBRE");
252
                                pfeature = feature;
253 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) <= 0));
254
                                count++;
255
                        }
256 23010 jmvivo
                        assertEquals("Iteration error", 10, count);
257 19664 jmvivo
258 20579 jmvivo
                        try {
259 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
260 23010 jmvivo
                                                .getDefaultFeatureType(), null, "NOMBRE DESC");
261 20579 jmvivo
                        } catch (ReadException e1) {
262
                                e1.printStackTrace();
263
                                fail();
264
                        }
265 21177 vcaballero
                        assertEquals(10, fc.size());
266 20579 jmvivo
                        it = fc.iterator();
267 19664 jmvivo
268 23010 jmvivo
                        count = 0;
269
                        pfeature = (Feature) it.next();
270 19664 jmvivo
                        count++;
271 23010 jmvivo
                        while (it.hasNext()) {
272
                                feature = (Feature) it.next();
273
                                v1 = (Comparable) pfeature.get("NOMBRE");
274
                                v2 = (Comparable) feature.get("NOMBRE");
275
                                pfeature = feature;
276
                                if (v1 != null && v2 != null) {
277 20579 jmvivo
                                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
278 23010 jmvivo
                                }
279 20579 jmvivo
                                count++;
280
                        }
281 23010 jmvivo
                        assertEquals("Iteration error", 10, count);
282 19664 jmvivo
283 20579 jmvivo
                        try {
284 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(
285 23010 jmvivo
                                                new String[] { "NOMBRE" }, "lower(NOMBRE) like 'b%'",
286
                                                "NOMBRE");
287 20579 jmvivo
                        } catch (ReadException e1) {
288
                                e1.printStackTrace();
289
                                fail();
290
                        }
291 19664 jmvivo
292 20579 jmvivo
                        assertEquals(3, fc.size());
293 19664 jmvivo
294 20579 jmvivo
                        it = fc.iterator();
295 19664 jmvivo
296 23010 jmvivo
                        count = 0;
297
                        pfeature = (Feature) it.next();
298
                        assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith(
299
                                        "b"));
300 19664 jmvivo
                        count++;
301 23010 jmvivo
                        while (it.hasNext()) {
302
                                feature = (Feature) it.next();
303
                                if (!(feature instanceof MemoryFeature)) { //FIXME OJO con los featureType de los Feature en memoria
304 21120 jmvivo
                                        assertEquals(1, feature.getType().size());
305
                                }
306 23010 jmvivo
                                assertTrue("Filter error", feature.getString("NOMBRE")
307
                                                .toLowerCase().startsWith("b"));
308
                                v1 = (Comparable) pfeature.get("NOMBRE");
309
                                v2 = (Comparable) feature.get("NOMBRE");
310
                                pfeature = feature;
311 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) <= 0));
312
                                count++;
313
                        }
314 23010 jmvivo
                        assertEquals("Iteration error", 3, count);
315 19664 jmvivo
316 20579 jmvivo
                        try {
317 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
318 23010 jmvivo
                                                .getDefaultFeatureType(), null,
319
                                                "Tipo,lower(NOMBRE) Desc");
320 20579 jmvivo
                        } catch (ReadException e1) {
321
                                e1.printStackTrace();
322
                                fail();
323 20480 jmvivo
                        }
324 20579 jmvivo
                        assertEquals(10, fc.size());
325
                        it = fc.iterator();
326 23010 jmvivo
                        count = 0;
327
                        pfeature = (Feature) it.next();
328
                        System.out.println(pfeature.getString("TIPO") + ","
329
                                        + pfeature.getString("NOMBRE"));
330 19664 jmvivo
                        count++;
331 23010 jmvivo
                        while (it.hasNext()) {
332
                                feature = (Feature) it.next();
333
                                System.out.println(feature.getString("TIPO") + ","
334
                                                + feature.getString("NOMBRE"));
335
                                v1 = ((String) pfeature.get("TIPO")).toLowerCase();
336
                                v2 = ((String) feature.get("TIPO")).toLowerCase();
337 20579 jmvivo
                                assertTrue("Short error", (v2.compareTo(v1) >= 0));
338 23010 jmvivo
                                if (v1.compareTo(v2) == 0) {
339
                                        v1 = ((String) pfeature.get("NOMBRE")).toLowerCase();
340
                                        v2 = ((String) feature.get("NOMBRE")).toLowerCase();
341 20579 jmvivo
                                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
342
                                }
343 23010 jmvivo
                                pfeature = feature;
344 19664 jmvivo
345 23010 jmvivo
                                //                                System.out.println(pfeature.getString("TIPO")+","+pfeature.getString("NOMBRE"));
346 20579 jmvivo
                                count++;
347
                        }
348 23010 jmvivo
                        assertEquals("Iteration error", 10, count);
349 19664 jmvivo
350 20579 jmvivo
                        fs.cancelEditing();
351 19468 jmvivo
352 23010 jmvivo
                        //                        try {
353
                        //                                fs.close();
354
                        //                        } catch (CloseException e) {
355
                        //                                e.printStackTrace();
356
                        //                                fail("Exception:" + e);
357
                        //                        }
358 19468 jmvivo
359 20579 jmvivo
                        System.out.println("======= /DBF ==============");
360
361
                } catch (DataException e) {
362 19658 vcaballero
                        e.printStackTrace();
363 23010 jmvivo
                        fail();
364 19658 vcaballero
                }
365 23010 jmvivo
366 19449 jmvivo
        }
367
368
        public void testSHP() {
369 19658 vcaballero
                try {
370 20579 jmvivo
                        System.out.println("======= SHP ==============");
371 22373 jmvivo
                        org.gvsig.fmap.data.feature.file.shp.Register.selfRegister();
372
                        org.gvsig.fmap.data.feature.file.dbf.Register.selfRegister();
373 19449 jmvivo
374 23754 jjdelcerro
                        DataManager dsm = DefaultDataManager.getManager();
375 19449 jmvivo
376 23010 jmvivo
                        DataStoreParameters dp = dsm
377 24081 jjdelcerro
                                        .createStoreParameters(SHPStore.DATASTORE_NAME);
378 23010 jmvivo
                        ((SHPStoreParameters) dp).setFile(shpfile);
379
                        //                        ((SHPStoreParameters)dp).setSHXFile(SHP.getShxFile(shpfile));
380
                        //                        ((SHPStoreParameters)dp).setDBFFile(SHP.getDbfFile(shpfile));
381 19449 jmvivo
382 23010 jmvivo
                        driverTest(dp, null, null, true);
383 19449 jmvivo
384 23010 jmvivo
                        FeatureStore fs = null;
385 20579 jmvivo
                        try {
386 24081 jjdelcerro
                                fs = (FeatureStore) dsm.createStore(dp);
387 20579 jmvivo
                        } catch (InitializeException e) {
388
                                e.printStackTrace();
389
                                fail("Exception:" + e);
390
                        }
391 19468 jmvivo
392 20579 jmvivo
                        assertNotNull("Can't create Feature Store", fs);
393 19480 jmvivo
394 23010 jmvivo
                        //                        fs.open();
395 19658 vcaballero
396 20579 jmvivo
                        Iterator it;
397 23842 jjdelcerro
                        FeatureSet fc;
398 23010 jmvivo
                        Comparable v1, v2;
399
                        Feature feature, pfeature;
400 20579 jmvivo
                        long count;
401 19480 jmvivo
402 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataSet();
403 19480 jmvivo
404 20579 jmvivo
                        assertEquals(9, fc.size());
405 19480 jmvivo
406 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
407 23010 jmvivo
                                        .getDefaultFeatureType(), "lower(NOMBRE) like 'b%'", null);
408 19480 jmvivo
409 20579 jmvivo
                        assertEquals(2, fc.size());
410 19480 jmvivo
411 20579 jmvivo
                        it = fc.iterator();
412 23010 jmvivo
                        count = 0;
413
                        while (it.hasNext()) {
414
                                feature = (Feature) it.next();
415
                                assertTrue("Filter error", feature.getString("NOMBRE")
416
                                                .toLowerCase().startsWith("b"));
417 20579 jmvivo
                                count++;
418
                        }
419 23010 jmvivo
                        assertEquals("Iteration error", 2, count);
420 19480 jmvivo
421 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
422 23010 jmvivo
                                        .getDefaultFeatureType(), null, "NOMBRE");
423 20579 jmvivo
                        assertEquals(9, fc.size());
424
                        it = fc.iterator();
425 23010 jmvivo
                        count = 0;
426
                        pfeature = (Feature) it.next();
427 19480 jmvivo
                        count++;
428 23010 jmvivo
                        while (it.hasNext()) {
429
                                feature = (Feature) it.next();
430
                                v1 = (Comparable) pfeature.get("NOMBRE");
431
                                v2 = (Comparable) feature.get("NOMBRE");
432
                                pfeature = feature;
433 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) <= 0));
434
                                count++;
435
                        }
436 23010 jmvivo
                        assertEquals("Iteration error", 9, count);
437 19480 jmvivo
438 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
439 23010 jmvivo
                                        .getDefaultFeatureType(), null, "NOMBRE DESC");
440 20579 jmvivo
                        assertEquals(9, fc.size());
441
                        it = fc.iterator();
442 23010 jmvivo
                        count = 0;
443
                        pfeature = (Feature) it.next();
444 19480 jmvivo
                        System.out.println(pfeature.getString("NOMBRE"));
445
                        count++;
446 23010 jmvivo
                        while (it.hasNext()) {
447
                                feature = (Feature) it.next();
448
                                v1 = (Comparable) pfeature.get("NOMBRE");
449
                                v2 = (Comparable) feature.get("NOMBRE");
450
                                pfeature = feature;
451 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) >= 0));
452
                                System.out.println(pfeature.getString("NOMBRE"));
453
                                count++;
454
                        }
455 23010 jmvivo
                        assertEquals("Iteration error", 9, count);
456 19480 jmvivo
457 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
458 23010 jmvivo
                                        .getDefaultFeatureType(), "lower(NOMBRE) like 'b%'",
459
                                        "NOMBRE ASC");
460 19480 jmvivo
461 20579 jmvivo
                        assertEquals(2, fc.size());
462 19480 jmvivo
463 20579 jmvivo
                        it = fc.iterator();
464 19480 jmvivo
465 23010 jmvivo
                        count = 0;
466
                        pfeature = (Feature) it.next();
467
                        assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith(
468
                                        "b"));
469 19480 jmvivo
                        count++;
470 23010 jmvivo
                        while (it.hasNext()) {
471
                                feature = (Feature) it.next();
472
                                assertTrue("Filter error", feature.getString("NOMBRE")
473
                                                .toLowerCase().startsWith("b"));
474
                                v1 = (Comparable) pfeature.get("NOMBRE");
475
                                v2 = (Comparable) feature.get("NOMBRE");
476
                                pfeature = feature;
477 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) <= 0));
478
                                count++;
479
                        }
480 23010 jmvivo
                        assertEquals("Iteration error", 2, count);
481 19480 jmvivo
482 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
483 23010 jmvivo
                                        .getDefaultFeatureType(), null, "lower(NOMBRE) ASC");
484 20579 jmvivo
                        assertEquals(9, fc.size());
485
                        it = fc.iterator();
486 23010 jmvivo
                        count = 0;
487
                        pfeature = (Feature) it.next();
488 19480 jmvivo
                        count++;
489 23010 jmvivo
                        while (it.hasNext()) {
490
                                feature = (Feature) it.next();
491
                                v1 = ((String) pfeature.get("NOMBRE")).toLowerCase();
492
                                v2 = ((String) feature.get("NOMBRE")).toLowerCase();
493
                                pfeature = feature;
494 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) <= 0));
495
                                count++;
496
                        }
497 23010 jmvivo
                        assertEquals("Iteration error", 9, count);
498 19480 jmvivo
499 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
500 23010 jmvivo
                                        .getDefaultFeatureType(), null, "Tipo,lower(NOMBRE) Desc");
501 20579 jmvivo
                        assertEquals(9, fc.size());
502
                        it = fc.iterator();
503 23010 jmvivo
                        count = 0;
504
                        pfeature = (Feature) it.next();
505 19480 jmvivo
                        System.out.println(pfeature.getString("NOMBRE"));
506
                        count++;
507 23010 jmvivo
                        while (it.hasNext()) {
508
                                feature = (Feature) it.next();
509
                                v1 = ((String) pfeature.get("NOMBRE")).toLowerCase();
510
                                v2 = ((String) feature.get("NOMBRE")).toLowerCase();
511
                                pfeature = feature;
512 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) >= 0));
513
                                System.out.println(pfeature.getString("NOMBRE"));
514
                                count++;
515
                        }
516 23010 jmvivo
                        assertEquals("Iteration error", 9, count);
517 19480 jmvivo
518 20579 jmvivo
                        /// CON  EDICION
519 19664 jmvivo
520 23754 jjdelcerro
                        fs.edit();
521 19664 jmvivo
522 24183 jjdelcerro
                        Feature newFeature = fs.createNewFeature(true);
523 20579 jmvivo
                        newFeature.editing();
524 24250 jjdelcerro
                        newFeature.setAttribute("NOMBRE", "BuRjaSOT");
525
                        newFeature.setAttribute("TIPO", "MUNICIPIO");
526 20579 jmvivo
                        fs.insert(newFeature);
527 19664 jmvivo
528 20579 jmvivo
                        try {
529 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataSet();
530 20579 jmvivo
                        } catch (ReadException e1) {
531
                                e1.printStackTrace();
532
                                fail();
533
                        }
534 19664 jmvivo
535 20579 jmvivo
                        assertEquals(10, fc.size());
536 19664 jmvivo
537 20579 jmvivo
                        try {
538 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
539 23010 jmvivo
                                                .getDefaultFeatureType(), "lower(NOMBRE) like 'b%'",
540
                                                null);
541 20579 jmvivo
                        } catch (ReadException e1) {
542
                                e1.printStackTrace();
543
                                fail();
544
                        }
545 19664 jmvivo
546 20579 jmvivo
                        assertEquals(3, fc.size());
547 19664 jmvivo
548 20579 jmvivo
                        it = fc.iterator();
549 23010 jmvivo
                        count = 0;
550
                        while (it.hasNext()) {
551
                                feature = (Feature) it.next();
552
                                assertTrue("Filter error", feature.getString("NOMBRE")
553
                                                .toLowerCase().startsWith("b"));
554 20579 jmvivo
                                count++;
555
                        }
556 23010 jmvivo
                        assertEquals("Iteration error", 3, count);
557 19664 jmvivo
558 20579 jmvivo
                        try {
559 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
560 23010 jmvivo
                                                .getDefaultFeatureType(), null, "NOMBRE ASC");
561 20579 jmvivo
                        } catch (ReadException e1) {
562
                                e1.printStackTrace();
563
                                fail();
564
                        }
565
                        assertEquals(10, fc.size());
566
                        it = fc.iterator();
567 23010 jmvivo
                        count = 0;
568
                        pfeature = (Feature) it.next();
569 19664 jmvivo
                        count++;
570 23010 jmvivo
                        while (it.hasNext()) {
571
                                feature = (Feature) it.next();
572
                                v1 = (Comparable) pfeature.get("NOMBRE");
573
                                v2 = (Comparable) feature.get("NOMBRE");
574
                                pfeature = feature;
575 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) <= 0));
576
                                count++;
577
                        }
578 23010 jmvivo
                        assertEquals("Iteration error", 10, count);
579 19664 jmvivo
580 20579 jmvivo
                        try {
581 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
582 23010 jmvivo
                                                .getDefaultFeatureType(), null, "NOMBRE DESC");
583 20579 jmvivo
                        } catch (ReadException e1) {
584
                                e1.printStackTrace();
585
                                fail();
586
                        }
587
                        assertEquals(10, fc.size());
588
                        it = fc.iterator();
589 19664 jmvivo
590 23010 jmvivo
                        count = 0;
591
                        pfeature = (Feature) it.next();
592 19664 jmvivo
                        count++;
593 23010 jmvivo
                        while (it.hasNext()) {
594
                                feature = (Feature) it.next();
595
                                v1 = (Comparable) pfeature.get("NOMBRE");
596
                                v2 = (Comparable) feature.get("NOMBRE");
597
                                pfeature = feature;
598 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) >= 0));
599
                                count++;
600
                        }
601 23010 jmvivo
                        assertEquals("Iteration error", 10, count);
602 19664 jmvivo
603 20579 jmvivo
                        try {
604 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
605 23010 jmvivo
                                                .getDefaultFeatureType(), "lower(NOMBRE) like 'b%'",
606
                                                "NOMBRE");
607 20579 jmvivo
                        } catch (ReadException e1) {
608
                                e1.printStackTrace();
609
                                fail();
610
                        }
611 19664 jmvivo
612 20579 jmvivo
                        assertEquals(3, fc.size());
613 19664 jmvivo
614 20579 jmvivo
                        it = fc.iterator();
615 19664 jmvivo
616 23010 jmvivo
                        count = 0;
617
                        pfeature = (Feature) it.next();
618
                        assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith(
619
                                        "b"));
620 19664 jmvivo
                        count++;
621 23010 jmvivo
                        while (it.hasNext()) {
622
                                feature = (Feature) it.next();
623
                                assertTrue("Filter error", feature.getString("NOMBRE")
624
                                                .toLowerCase().startsWith("b"));
625
                                v1 = (Comparable) pfeature.get("NOMBRE");
626
                                v2 = (Comparable) feature.get("NOMBRE");
627
                                pfeature = feature;
628 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) <= 0));
629
                                count++;
630
                        }
631 23010 jmvivo
                        assertEquals("Iteration error", 3, count);
632 19664 jmvivo
633 20579 jmvivo
                        try {
634 23842 jjdelcerro
                                fc = (FeatureSet) fs.getDataCollection(fs
635 23010 jmvivo
                                                .getDefaultFeatureType(), null,
636
                                                "Tipo,lower(NOMBRE) Desc");
637 20579 jmvivo
                        } catch (ReadException e1) {
638
                                e1.printStackTrace();
639
                                fail();
640
                        }
641
                        assertEquals(10, fc.size());
642
                        it = fc.iterator();
643 23010 jmvivo
                        count = 0;
644
                        pfeature = (Feature) it.next();
645 19664 jmvivo
                        System.out.println(pfeature.getString("NOMBRE"));
646
                        count++;
647 23010 jmvivo
                        while (it.hasNext()) {
648
                                feature = (Feature) it.next();
649
                                v1 = ((String) pfeature.get("NOMBRE")).toLowerCase();
650
                                v2 = ((String) feature.get("NOMBRE")).toLowerCase();
651
                                pfeature = feature;
652 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) >= 0));
653
                                System.out.println(pfeature.getString("NOMBRE"));
654
                                count++;
655
                        }
656 23010 jmvivo
                        assertEquals("Iteration error", 10, count);
657 19664 jmvivo
658 20579 jmvivo
                        fs.cancelEditing();
659 19664 jmvivo
660 23010 jmvivo
                        //                        try {
661
                        //                                fs.close();
662
                        //                        } catch (CloseException e) {
663
                        //                                e.printStackTrace();
664
                        //                                fail("Exception:" + e);
665
                        //                        }
666 19664 jmvivo
667 20579 jmvivo
                        System.out.println("======= /SHP ==============");
668
                } catch (DataException e) {
669 19658 vcaballero
                        // TODO Auto-generated catch block
670
                        e.printStackTrace();
671
                }
672 19449 jmvivo
        }
673
674 19603 vcaballero
        public void testDXF() {
675 19658 vcaballero
                try {
676 20579 jmvivo
                        System.out.println("======= DXF ==============");
677 22373 jmvivo
                        org.gvsig.fmap.data.feature.file.dxf.Register.selfRegister();
678 19603 vcaballero
679 23754 jjdelcerro
                        DataManager dsm = DefaultDataManager.getManager();
680 19603 vcaballero
681 23010 jmvivo
                        DataStoreParameters dp = dsm
682 24081 jjdelcerro
                                        .createStoreParameters(DXFStore.DATASTORE_NAME);
683 23010 jmvivo
                        ((DXFStoreParameters) dp).setFile(dxffile);
684 21045 jmvivo
                        IProjection proj = CRSFactory.getCRS("EPSG:23030");
685 23010 jmvivo
                        ((DXFStoreParameters) dp).setSRSID("EPSG:23030");
686
                        driverTest(dp, null, null, true);
687 19603 vcaballero
688 23010 jmvivo
                        FeatureStore fs = null;
689 20579 jmvivo
                        try {
690 24081 jjdelcerro
                                fs = (FeatureStore) dsm.createStore(dp);
691 20579 jmvivo
                        } catch (InitializeException e) {
692
                                e.printStackTrace();
693
                                fail("Exception:" + e);
694
                        }
695
                        assertNotNull("Can't create Feature Store", fs);
696 19603 vcaballero
697 23010 jmvivo
                        //                        fs.open();
698 19658 vcaballero
699 20579 jmvivo
                        Iterator it;
700 23842 jjdelcerro
                        FeatureSet fc;
701 23010 jmvivo
                        Comparable v1, v2;
702
                        Feature feature, pfeature;
703 20579 jmvivo
                        long count;
704 19603 vcaballero
705 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataSet();
706 19603 vcaballero
707 20579 jmvivo
                        assertEquals(10, fc.size());
708 19603 vcaballero
709 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
710 23010 jmvivo
                                        .getDefaultFeatureType(), "Color > '7'", null);
711 19603 vcaballero
712 20579 jmvivo
                        assertEquals(2, fc.size());
713 19603 vcaballero
714 20579 jmvivo
                        it = fc.iterator();
715 23010 jmvivo
                        count = 0;
716
                        while (it.hasNext()) {
717
                                feature = (Feature) it.next();
718
                                assertTrue("Filter error", feature.getInt("Color") > 7);
719 20579 jmvivo
                                count++;
720
                        }
721 23010 jmvivo
                        assertEquals("Iteration error", 2, count);
722 19603 vcaballero
723 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
724 23010 jmvivo
                                        .getDefaultFeatureType(), null, "Layer ASC");
725 20579 jmvivo
                        assertEquals(10, fc.size());
726
                        it = fc.iterator();
727 23010 jmvivo
                        count = 0;
728
                        pfeature = (Feature) it.next();
729 19603 vcaballero
                        count++;
730 23010 jmvivo
                        while (it.hasNext()) {
731
                                feature = (Feature) it.next();
732
                                v1 = (Comparable) pfeature.get("Layer");
733
                                v2 = (Comparable) feature.get("Layer");
734
                                pfeature = feature;
735 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) <= 0));
736
                                count++;
737
                        }
738 23010 jmvivo
                        assertEquals("Iteration error", 10, count);
739 19603 vcaballero
740 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
741 23010 jmvivo
                                        .getDefaultFeatureType(), null, "Layer DESC");
742 20579 jmvivo
                        assertEquals(10, fc.size());
743
                        it = fc.iterator();
744 19603 vcaballero
745 23010 jmvivo
                        count = 0;
746
                        pfeature = (Feature) it.next();
747 19603 vcaballero
                        count++;
748 23010 jmvivo
                        while (it.hasNext()) {
749
                                feature = (Feature) it.next();
750
                                v1 = (Comparable) pfeature.get("Layer");
751
                                v2 = (Comparable) feature.get("Layer");
752
                                pfeature = feature;
753 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v1) >= 0));
754
                                count++;
755
                        }
756 23010 jmvivo
                        assertEquals("Iteration error", 10, count);
757 19603 vcaballero
758 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
759 23010 jmvivo
                                        .getDefaultFeatureType(), "Color > '7'", "Layer ASC");
760 19603 vcaballero
761 20579 jmvivo
                        assertEquals(2, fc.size());
762 19603 vcaballero
763 20579 jmvivo
                        it = fc.iterator();
764 19603 vcaballero
765 23010 jmvivo
                        count = 0;
766
                        pfeature = (Feature) it.next();
767
                        assertTrue(pfeature.getInt("Color") > 7);
768 19603 vcaballero
                        count++;
769 23010 jmvivo
                        while (it.hasNext()) {
770
                                feature = (Feature) it.next();
771
                                assertTrue("Filter error", feature.getInt("Color") > 7);
772
                                v1 = (Comparable) pfeature.get("Color");
773
                                v2 = (Comparable) feature.get("Color");
774
                                pfeature = feature;
775
                                Integer i1 = (Integer) v1;
776
                                Integer i2 = (Integer) v2;
777
                                assertTrue("Short error", (i1.intValue() > i2.intValue()));
778 20579 jmvivo
                                count++;
779
                        }
780 23010 jmvivo
                        assertEquals("Iteration error", 2, count);
781 19603 vcaballero
782 23010 jmvivo
                        //                        fc = (FeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
783
                        //                        assertEquals(10, fc.size());
784
                        //                        it = fc.iterator();
785
                        //                        count=0;
786
                        //                        pfeature = (Feature)it.next();
787
                        //                        System.out.println(pfeature.getString("Layer"));
788
                        //                        count++;
789
                        //                        while (it.hasNext()){
790
                        //                        feature = (Feature)it.next();
791
                        //                        v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
792
                        //                        v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
793
                        //                        pfeature=feature;
794
                        //                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
795
                        //                        System.out.println(pfeature.getString("Layer"));
796
                        //                        count++;
797
                        //                        }
798
                        //                        assertEquals("Iteration error",10,count);
799 19603 vcaballero
800 23010 jmvivo
                        //                        try {
801
                        //                                fs.close();
802
                        //                        } catch (CloseException e) {
803
                        //                                e.printStackTrace();
804
                        //                                fail("Exception:" + e);
805
                        //                        }
806 19603 vcaballero
807 20579 jmvivo
                        System.out.println("======= /DXF ==============");
808 19658 vcaballero
                } catch (OpenException e1) {
809
                        e1.printStackTrace();
810
                        fail();
811
                } catch (ReadException e) {
812
                        // TODO Auto-generated catch block
813
                        e.printStackTrace();
814
                }
815 19603 vcaballero
        }
816
817 19654 vcaballero
        public void testDGN() {
818 19658 vcaballero
                try {
819 20579 jmvivo
                        System.out.println("======= DGN ==============");
820 22373 jmvivo
                        org.gvsig.fmap.data.feature.file.dgn.Register.selfRegister();
821 19603 vcaballero
822 23754 jjdelcerro
                        DataManager dsm = DefaultDataManager.getManager();
823 19603 vcaballero
824 23010 jmvivo
                        DataStoreParameters dp = dsm
825 24081 jjdelcerro
                                        .createStoreParameters(DGNStore.DATASTORE_NAME);
826 23010 jmvivo
                        ((DGNStoreParameters) dp).setFile(dgnfile);
827
                        driverTest(dp, null, null, true);
828
                        FeatureStore fs = null;
829 20579 jmvivo
                        try {
830 24081 jjdelcerro
                                fs = (FeatureStore) dsm.createStore(dp);
831 20579 jmvivo
                        } catch (InitializeException e) {
832
                                e.printStackTrace();
833
                                fail("Exception:" + e);
834
                        }
835
                        assertNotNull("Can't create Feature Store", fs);
836 19603 vcaballero
837 23010 jmvivo
                        //                        fs.open();
838 19658 vcaballero
839 20579 jmvivo
                        Iterator it;
840 23842 jjdelcerro
                        FeatureSet fc;
841 23010 jmvivo
                        Comparable v1, v2;
842
                        Feature feature, pfeature;
843 20579 jmvivo
                        long count;
844 19654 vcaballero
845 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataSet();
846 19654 vcaballero
847 20688 jmvivo
                        assertEquals(57, fc.size());
848 19654 vcaballero
849 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
850 23010 jmvivo
                                        .getDefaultFeatureType(), "Color > '7'", null);
851 19654 vcaballero
852 20688 jmvivo
                        assertEquals(45, fc.size());
853 19654 vcaballero
854 20579 jmvivo
                        it = fc.iterator();
855 23010 jmvivo
                        count = 0;
856
                        while (it.hasNext()) {
857
                                feature = (Feature) it.next();
858
                                assertTrue("Filter error", feature.getInt("Color") >= 7);
859 20579 jmvivo
                                count++;
860
                        }
861 23010 jmvivo
                        assertEquals("Iteration error", 45, count);
862 19654 vcaballero
863 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
864 23010 jmvivo
                                        .getDefaultFeatureType(), null, "Layer ASC");
865 20688 jmvivo
                        assertEquals(57, fc.size());
866 20579 jmvivo
                        it = fc.iterator();
867 23010 jmvivo
                        count = 0;
868
                        pfeature = (Feature) it.next();
869 19654 vcaballero
                        count++;
870 23010 jmvivo
                        while (it.hasNext()) {
871
                                feature = (Feature) it.next();
872
                                v1 = (Comparable) pfeature.get("Layer");
873
                                v2 = (Comparable) feature.get("Layer");
874
                                if (v2 == null) {
875 20579 jmvivo
                                        System.out.println("null");
876 23010 jmvivo
                                }
877 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) <= 0));
878 23010 jmvivo
                                pfeature = feature;
879 20579 jmvivo
                                count++;
880
                        }
881 23010 jmvivo
                        assertEquals("Iteration error", 57, count);
882 19654 vcaballero
883 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
884 23010 jmvivo
                                        .getDefaultFeatureType(), null, "Layer DESC");
885 20688 jmvivo
                        assertEquals(57, fc.size());
886 20579 jmvivo
                        it = fc.iterator();
887 19654 vcaballero
888 23010 jmvivo
                        count = 0;
889
                        pfeature = (Feature) it.next();
890 19654 vcaballero
                        count++;
891 23010 jmvivo
                        while (it.hasNext()) {
892
                                feature = (Feature) it.next();
893
                                v1 = (Comparable) pfeature.get("Layer");
894
                                v2 = (Comparable) feature.get("Layer");
895 20579 jmvivo
                                assertTrue("Short error", (v1.compareTo(v2) >= 0));
896 23010 jmvivo
                                pfeature = feature;
897 20579 jmvivo
                                count++;
898
                        }
899 23010 jmvivo
                        assertEquals("Iteration error", 57, count);
900 19654 vcaballero
901 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataCollection(fs
902 23010 jmvivo
                                        .getDefaultFeatureType(), "Color > '7'", "Layer ASC");
903 19654 vcaballero
904 20688 jmvivo
                        assertEquals(45, fc.size());
905 19654 vcaballero
906 20579 jmvivo
                        it = fc.iterator();
907 19654 vcaballero
908 23010 jmvivo
                        count = 0;
909
                        pfeature = (Feature) it.next();
910
                        assertTrue(pfeature.getInt("Color") > 7);
911 19654 vcaballero
                        count++;
912 23010 jmvivo
                        while (it.hasNext()) {
913
                                feature = (Feature) it.next();
914
                                assertTrue("Filter error", feature.getInt("Color") > 7);
915
                                v1 = (Comparable) pfeature.get("Layer");
916
                                v2 = (Comparable) feature.get("Layer");
917
                                pfeature = feature;
918
                                Integer i1 = (Integer) v1;
919
                                Integer i2 = (Integer) v2;
920
                                assertTrue("Short error", (i1.intValue() <= i2.intValue()));
921 20579 jmvivo
                                count++;
922
                        }
923 23010 jmvivo
                        assertEquals("Iteration error", 45, count);
924 19654 vcaballero
925 23010 jmvivo
                        //                        fc = (FeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
926
                        //                        assertEquals(10, fc.size());
927
                        //                        it = fc.iterator();
928
                        //                        count=0;
929
                        //                        pfeature = (Feature)it.next();
930
                        //                        System.out.println(pfeature.getString("Layer"));
931
                        //                        count++;
932
                        //                        while (it.hasNext()){
933
                        //                        feature = (Feature)it.next();
934
                        //                        v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
935
                        //                        v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
936
                        //                        pfeature=feature;
937
                        //                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
938
                        //                        System.out.println(pfeature.getString("Layer"));
939
                        //                        count++;
940
                        //                        }
941
                        //                        assertEquals("Iteration error",10,count);
942 19654 vcaballero
943 23010 jmvivo
                        //                        try {
944
                        //                                fs.close();
945
                        //                        } catch (CloseException e) {
946
                        //                                e.printStackTrace();
947
                        //                                fail("Exception:" + e);
948
                        //                        }
949 19654 vcaballero
950 20579 jmvivo
                        System.out.println("======= /DGN ==============");
951 19658 vcaballero
                } catch (OpenException e1) {
952
                        e1.printStackTrace();
953
                        fail();
954
                } catch (ReadException e) {
955
                        // TODO Auto-generated catch block
956
                        e.printStackTrace();
957
                }
958 19654 vcaballero
        }
959
960 23010 jmvivo
        //        private FeatureStore createFeatureStore(IDriverParameters dp){
961
        //        DataSourceManager dsm=DataSourceManager.getManager();
962 19654 vcaballero
963 23010 jmvivo
        //        DataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
964 19654 vcaballero
965 23010 jmvivo
        //        ((IDriverStoreParameters)dsp).setDriverParameters(dp);
966
        //        FeatureStore fs=null;
967
        //        try {
968
        //        fs = (FeatureStore)dsm.createDataStore(dsp);
969
        //        } catch (InitializeException e) {
970
        //        e.printStackTrace();
971
        //        fail("Exception:" + e);
972
        //        }
973
        //        return fs;
974 19654 vcaballero
975 23010 jmvivo
        //        }
976 19654 vcaballero
977 23010 jmvivo
        private void driverTest(DataStoreParameters dp, String filter,
978
                        String order, boolean testEdit) {
979 23754 jjdelcerro
                DataManager dsm = DefaultDataManager.getManager();
980 19654 vcaballero
981 23303 jmvivo
982 23010 jmvivo
                //                DataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
983 20579 jmvivo
984 23010 jmvivo
                //                ((IDriverStoreParameters)dsp).setDriverParameters(dp);
985
                //                FeatureStore fs=createFeatureStore(dp);
986
                FeatureStore fs = null;
987 19443 vcaballero
                try {
988 24081 jjdelcerro
                        fs = (FeatureStore) dsm.createStore(dp);
989 19443 vcaballero
                } catch (InitializeException e) {
990 19470 jmvivo
                        e.printStackTrace();
991 19468 jmvivo
                        fail("Exception:" + e);
992 19443 vcaballero
                }
993 23010 jmvivo
                //                try {
994
                //                        fs.open();
995
                //                } catch (OpenException e2) {
996
                //                        e2.printStackTrace();
997
                //                        fail();
998
                //                }
999 19401 vcaballero
1000 23754 jjdelcerro
                if (fs.allowWrite() && testEdit) {
1001 19834 jmvivo
                        try {
1002 23754 jjdelcerro
                                fs.edit();
1003 23010 jmvivo
                                if (fs.canAlterFeatureType()) {
1004
                                        FeatureType featureType = fs.getDefaultFeatureType();
1005
                                        //                                        DefaultAttributeDescriptor dad=new DefaultAttributeDescriptor();
1006
                                        //                                        dad.loading();
1007
                                        //                                        dad.setName("Prueba1");
1008
                                        //                                        dad.setDefaultValue("11p");
1009
                                        //                                        dad.setSize(10);
1010
                                        //                                        dad.setType(FeatureAttributeDescriptor.TYPE_STRING);
1011
                                        //                                        dad.stopLoading();
1012
                                        //                                        fs.insert(dad);
1013
                                        //                                        fs.delete((FeatureAttributeDescriptor)featureType.get(featureType.getFieldIndex("Prueba1")));
1014
                                        AttributeDescriptor dad2 = (AttributeDescriptor) featureType
1015 23754 jjdelcerro
                                                        .get(featureType.getIndex("TIPO"));
1016 20470 vcaballero
                                        dad2.editing();
1017 23010 jmvivo
                                        //                                        dad2.setName("TIPO");
1018 20470 vcaballero
                                        dad2.setDefaultValue("Tipop");
1019 23010 jmvivo
                                        //                                        dad2.setSize(10);
1020 23754 jjdelcerro
                                        dad2.setType(FeatureAttributeDescriptor.STRING);
1021 20470 vcaballero
                                        fs.update(dad2);
1022
                                }
1023 20850 jmvivo
                        } catch (DataException e) {
1024 23010 jmvivo
                                e.printStackTrace();
1025
                                fail();
1026 20501 vcaballero
                        }
1027 20414 vcaballero
                        try {
1028 24183 jjdelcerro
                                Feature feature1 = fs.createNewFeature(false);
1029 19449 jmvivo
1030 24183 jjdelcerro
                                Feature feature2 = fs.createNewFeature(false);
1031
                                Feature feature3 = fs.createNewFeature(false);
1032 19449 jmvivo
1033 20579 jmvivo
                                fs.insert(feature1);
1034
                                fs.insert(feature2);
1035 19449 jmvivo
1036 20579 jmvivo
                                feature1.editing();
1037 24250 jjdelcerro
                                feature1.setAttribute(1, "hola");
1038 20421 vcaballero
1039 20579 jmvivo
                                fs.update(feature1);
1040
                                fs.delete(feature3);
1041
                                fs.delete(feature2);
1042
                        } catch (DataException e) {
1043 20414 vcaballero
                                // TODO Auto-generated catch block
1044
                                e.printStackTrace();
1045
                        }
1046 19449 jmvivo
                }
1047
1048 19401 vcaballero
                //Mostrar por consola todos los registros.
1049 23010 jmvivo
                FeatureType ft = fs.getDefaultFeatureType();
1050 23842 jjdelcerro
                FeatureSet featureCollection = null;
1051 23010 jmvivo
                //                featureCollection = (FeatureCollection)fs.getDataCollection();
1052
                //                featureCollection = (FeatureCollection)fs.getDataCollection(ft,"NOMBRE = 'CALPE'",null);
1053
                //                featureCollection = (FeatureCollection)fs.getDataCollection(ft,"AREA > 3.2213163729E7 and AREA < 3.2213163749E7",null);
1054 19658 vcaballero
                try {
1055 23842 jjdelcerro
                        featureCollection = (FeatureSet) fs.getDataCollection(ft,
1056 23010 jmvivo
                                        filter, order);
1057 19658 vcaballero
                } catch (ReadException e2) {
1058
                        // TODO Auto-generated catch block
1059
                        e2.printStackTrace();
1060
                }
1061 19449 jmvivo
1062 23010 jmvivo
                PrintlnFeaturesVisitor visitor = new PrintlnFeaturesVisitor(ft);
1063 19490 jpiera
                try {
1064
                        featureCollection.accept(visitor);
1065
                } catch (BaseException e1) {
1066
                        e1.printStackTrace();
1067 23010 jmvivo
                        fail("Exception: " + e1);
1068 19490 jpiera
                }
1069 19449 jmvivo
1070 19976 jmvivo
                featureCollection.dispose();
1071
1072 23754 jjdelcerro
                if (fs.allowWrite() && testEdit) {
1073 19449 jmvivo
                        try {
1074
                                fs.finishEditing();
1075
                        } catch (WriteException e) {
1076
                                e.printStackTrace();
1077 23010 jmvivo
                                fail("Exception: " + e);
1078 19449 jmvivo
                        } catch (ReadException e) {
1079
                                e.printStackTrace();
1080 23010 jmvivo
                                fail("Exception: " + e);
1081 19449 jmvivo
                        }
1082 23543 jmvivo
                        long t1 = System.currentTimeMillis();
1083
                        while (System.currentTimeMillis() - t1 > 2000) {
1084
                                //Esperamos 2 seg para no tener problemas con
1085
                                // los lastUpdate de los ficheros
1086
                        }
1087 19449 jmvivo
                }
1088 23010 jmvivo
                //                try {
1089
                //                        fs.close();
1090
                //                } catch (CloseException e) {
1091
                //                        e.printStackTrace();
1092
                //                        fail("Exception: "+e);
1093
                //                }
1094 19443 vcaballero
                try {
1095 19736 vcaballero
                        fs.dispose();
1096
                } catch (CloseException e) {
1097
                        // TODO Auto-generated catch block
1098
                        e.printStackTrace();
1099
                }
1100 23010 jmvivo
                persistenceTest(dp);
1101 23543 jmvivo
                mapParamsBaseTest(dp);
1102
1103 19401 vcaballero
        }
1104 20660 jmvivo
1105 21045 jmvivo
        public static void doFileResourceTest(FileStoreParameters params) {
1106 23010 jmvivo
                doFileResourceTest(params, true);
1107 20661 jmvivo
        }
1108 23010 jmvivo
1109
        public static void doFileResourceTest(FileStoreParameters params,
1110
                        boolean testEdit) {
1111 23754 jjdelcerro
                DataManager manager = DefaultDataManager.getManager();
1112 20660 jmvivo
1113 23754 jjdelcerro
                ResourceManager resMan = DefaultResourceManager.getResourceManager();
1114 20660 jmvivo
1115 23010 jmvivo
                AbstractFeatureStore store = null;
1116 23754 jjdelcerro
                FeatureStore store2 = null;
1117
                FeatureStore store3 = null;
1118 20661 jmvivo
                try {
1119 24081 jjdelcerro
                        store = (AbstractFeatureStore) manager.createStore(params);
1120
                        store2 = (FeatureStore) manager.createStore(params);
1121
                        store3 = (FeatureStore) manager.createStore(params);
1122 20661 jmvivo
                } catch (InitializeException e1) {
1123 23010 jmvivo
                        e1.printStackTrace();
1124
                        fail();
1125 20661 jmvivo
                }
1126 20660 jmvivo
1127 23754 jjdelcerro
                AbstractResource res = getResource(params);
1128 20660 jmvivo
1129 23509 jmvivo
                assertNotNull(res);
1130 20660 jmvivo
1131
                assertEquals(3, res.getRefencesCount());
1132
1133 20661 jmvivo
                try {
1134
                        store.close();
1135
                } catch (CloseException e1) {
1136 23010 jmvivo
                        e1.printStackTrace();
1137
                        fail();
1138 20661 jmvivo
                }
1139 20660 jmvivo
1140
                assertEquals(false, res.isOpen());
1141
1142 23842 jjdelcerro
                DataSet coll = null;
1143 20660 jmvivo
1144 20661 jmvivo
                try {
1145 23842 jjdelcerro
                        coll = store.getDataSet();
1146 20661 jmvivo
                } catch (ReadException e1) {
1147 23010 jmvivo
                        e1.printStackTrace();
1148
                        fail();
1149 20661 jmvivo
                }
1150 20660 jmvivo
1151
                coll.iterator().next();
1152 23010 jmvivo
                //                coll.size();
1153 20660 jmvivo
1154
                assertEquals(true, res.isOpen());
1155
1156
                coll.dispose();
1157
1158 23754 jjdelcerro
                if (store.allowWrite() && testEdit) {
1159 23010 jmvivo
                        /* Test edition notification */
1160 20660 jmvivo
1161 23010 jmvivo
                        int fCountOrg = 0;
1162
                        int fCountFin = 0;
1163 20661 jmvivo
                        try {
1164 23842 jjdelcerro
                                fCountOrg = store.getDataSet().size();
1165 20688 jmvivo
                        } catch (ReadException e2) {
1166
                                // TODO Auto-generated catch block
1167 23010 jmvivo
                                e2.printStackTrace();
1168
                                fail("Exception: " + e2);
1169 20688 jmvivo
                        }
1170
                        try {
1171 23754 jjdelcerro
                                store.edit();
1172 20661 jmvivo
                        } catch (ReadException e1) {
1173 23010 jmvivo
                                e1.printStackTrace();
1174
                                fail("Exception: " + e1);
1175 20661 jmvivo
                        }
1176
1177
                        try {
1178 23842 jjdelcerro
                                coll = store2.getDataSet();
1179 20661 jmvivo
                        } catch (ReadException e1) {
1180 23010 jmvivo
                                e1.printStackTrace();
1181
                                fail("Exception: " + e1);
1182 20661 jmvivo
                        }
1183
1184
                        try {
1185
                                store.finishEditing();
1186
                        } catch (WriteException e1) {
1187 23010 jmvivo
                                e1.printStackTrace();
1188
                                fail("Exception: " + e1);
1189 20661 jmvivo
                        } catch (ReadException e1) {
1190 23010 jmvivo
                                e1.printStackTrace();
1191
                                fail("Exception: " + e1);
1192 20661 jmvivo
                        }
1193
1194 20688 jmvivo
                        try {
1195 23842 jjdelcerro
                                fCountFin = store.getDataSet().size();
1196 20688 jmvivo
                        } catch (ReadException e2) {
1197
                                // TODO Auto-generated catch block
1198 23010 jmvivo
                                e2.printStackTrace();
1199
                                fail("Exception: " + e2);
1200 20688 jmvivo
                        }
1201
1202
                        assertEquals(fCountOrg, fCountFin);
1203
1204 20661 jmvivo
                        boolean isOk = false;
1205 23010 jmvivo
                        try {
1206 20661 jmvivo
                                coll.iterator().next();
1207 23010 jmvivo
                        } catch (Exception e) {
1208
                                isOk = true;
1209 20661 jmvivo
                        }
1210 23010 jmvivo
                        assertTrue("Resource Changed Notification fails", isOk);
1211 20661 jmvivo
1212
                        coll.dispose();
1213
1214 20688 jmvivo
                        long time = System.currentTimeMillis();
1215 23010 jmvivo
                        while ((System.currentTimeMillis() - time) < 1000) {
1216 20688 jmvivo
                                //sleep
1217
                        }
1218
1219 23010 jmvivo
                        ((FileResource) res).getFile().setLastModified(
1220
                                        System.currentTimeMillis());
1221 20688 jmvivo
1222 23010 jmvivo
                        isOk = false;
1223
                        try {
1224 23842 jjdelcerro
                                store.getDataSet().iterator().next();
1225 23010 jmvivo
                        } catch (Exception e) {
1226
                                isOk = true;
1227 20661 jmvivo
                        }
1228 23010 jmvivo
                        assertTrue("Resource Changed Notification fails", isOk);
1229 20661 jmvivo
1230 23010 jmvivo
                        /* Test edition notification END */
1231 20661 jmvivo
1232
                }
1233
1234
                try {
1235
                        store3.dispose();
1236
                } catch (CloseException e1) {
1237 23010 jmvivo
                        e1.printStackTrace();
1238
                        fail();
1239 20661 jmvivo
                }
1240
1241 20660 jmvivo
                assertEquals(2, res.getRefencesCount());
1242
1243 20661 jmvivo
                try {
1244
                        store2.dispose();
1245
                } catch (CloseException e1) {
1246 23010 jmvivo
                        e1.printStackTrace();
1247
                        fail();
1248 20661 jmvivo
                }
1249 20660 jmvivo
1250
                assertEquals(1, res.getRefencesCount());
1251
1252 23551 jiyarza
                store = null;
1253
                System.gc();
1254
                System.gc();
1255
                System.gc();
1256 20660 jmvivo
1257
                assertEquals(0, res.getRefencesCount());
1258 23570 jmvivo
                try {
1259
                        resMan.collectDeadResources();
1260
                } catch (DataException e) {
1261
                        e.printStackTrace();
1262
                        fail();
1263
                        return;
1264
                }
1265 23509 jmvivo
                res = getResource(params);
1266 20660 jmvivo
1267 23509 jmvivo
                assertNull(res);
1268 20660 jmvivo
1269 20732 jmvivo
                doPrepareFileResourceTest(params);
1270 20660 jmvivo
1271 20732 jmvivo
        }
1272 20661 jmvivo
1273 23010 jmvivo
        public static void doPrepareFileResourceTest(FileStoreParameters params) {
1274 23754 jjdelcerro
                DataManager manager = DefaultDataManager.getManager();
1275 20732 jmvivo
1276 23754 jjdelcerro
                DefaultResourceManager resMan = DefaultResourceManager.getResourceManager();
1277 20732 jmvivo
1278
                File originalFile = params.getFile();
1279
                params.setFile(new File(originalFile.getName()));
1280
1281 21045 jmvivo
                Observer obs = new PrepareResourceObserver(originalFile);
1282 20732 jmvivo
1283
                resMan.addObserver(obs);
1284
1285 23010 jmvivo
                AbstractFeatureStore store = null;
1286 20732 jmvivo
                try {
1287 24081 jjdelcerro
                        store = (AbstractFeatureStore) manager.createStore(params);
1288 20732 jmvivo
                } catch (InitializeException e1) {
1289 23010 jmvivo
                        e1.printStackTrace();
1290
                        fail();
1291
                } catch (Exception e2) {
1292
                        e2.printStackTrace();
1293
                        fail();
1294 20732 jmvivo
                }
1295
1296
                try {
1297 23842 jjdelcerro
                        store.getDataSet().iterator().next();
1298 20732 jmvivo
                } catch (ReadException e) {
1299
                        // TODO Auto-generated catch block
1300 23010 jmvivo
                        e.printStackTrace();
1301
                        fail();
1302 20732 jmvivo
                }
1303
1304
                try {
1305
                        store.close();
1306
                } catch (CloseException e) {
1307
                        // TODO Auto-generated catch block
1308 23010 jmvivo
                        e.printStackTrace();
1309
                        fail();
1310 20732 jmvivo
                }
1311
                try {
1312
                        store.dispose();
1313
                } catch (CloseException e) {
1314
                        // TODO Auto-generated catch block
1315 23010 jmvivo
                        e.printStackTrace();
1316
                        fail();
1317 20732 jmvivo
                }
1318
1319 20660 jmvivo
        }
1320 20732 jmvivo
1321 23010 jmvivo
        private void persistenceTest(DataStoreParameters params) {
1322 23754 jjdelcerro
                DataManager manager = DefaultDataManager.getManager();
1323 23010 jmvivo
1324
                DataStoreParameters params2 = null;
1325
                XMLEntity paramsXML = null;
1326
                XMLEntity params2XML = null;
1327
1328
                paramsXML = params.getXMLEntity();
1329
1330
                try {
1331 24081 jjdelcerro
                        params2 = manager.createStoreParameters(paramsXML);
1332 23010 jmvivo
                } catch (InitializeException e) {
1333
                        e.printStackTrace();
1334
                        fail();
1335
                }
1336
1337
                params2XML = params2.getXMLEntity();
1338
1339
                assertEquals(paramsXML.toString(), params2XML.toString());
1340
1341
                FeatureStore store = null;
1342
                XMLEntity storeXML = null;
1343
                FeatureStore store2 = null;
1344
                XMLEntity store2XML = null;
1345
1346
                try {
1347 24081 jjdelcerro
                        store = (FeatureStore) manager.createStore(params);
1348 23010 jmvivo
                } catch (InitializeException e) {
1349
                        e.printStackTrace();
1350
                        fail();
1351
                }
1352
1353 23181 vcaballero
                try {
1354
                        storeXML = store.getXMLEntity();
1355
                } catch (XMLException e1) {
1356
                        e1.printStackTrace();
1357
                        fail();
1358
                }
1359 23010 jmvivo
1360
                assertNotNull(storeXML);
1361
1362
                try {
1363 24081 jjdelcerro
                        store2 = (FeatureStore) manager.createStore(storeXML);
1364 23010 jmvivo
                } catch (InitializeException e) {
1365
                        e.printStackTrace();
1366
                        fail();
1367
                }
1368
1369 23181 vcaballero
                try {
1370
                        store2XML = store2.getXMLEntity();
1371
                } catch (XMLException e1) {
1372
                        e1.printStackTrace();
1373
                        fail();
1374
                }
1375 23010 jmvivo
1376
                assertEquals(storeXML.toString(), store2XML.toString());
1377
1378 23842 jjdelcerro
                FeatureSet coll = null;
1379
                FeatureSet coll2 = null;
1380 23010 jmvivo
                Iterator iter = null;
1381
                Iterator iter2 = null;
1382
                Feature feature=null;
1383
                Feature feature2 = null;
1384
                Comparable v1 = null;
1385
                Comparable v2 = null;
1386
                Handler h = null;
1387
                Handler h2 = null;
1388
1389
1390
                try {
1391 23842 jjdelcerro
                        coll = (FeatureSet) store.getDataSet();
1392
                        coll2 = (FeatureSet) store2.getDataSet();
1393 23010 jmvivo
                } catch (ReadException e) {
1394
                        e.printStackTrace();
1395
                        fail();
1396
                }
1397
1398
                assertEquals(coll.size(), coll2.size());
1399
1400
                iter = coll.iterator();
1401
                iter2 = coll2.iterator();
1402
                int i;
1403
                int featureSize = store.getDefaultFeatureType().size();
1404
1405
                try {
1406
                        while (iter.hasNext()) {
1407
                                feature = (Feature) iter.next();
1408
                                feature2 = (Feature) iter2.next();
1409
                                for (i = 0; i < featureSize; i++) {
1410
                                        v1 = (Comparable) feature.get(i);
1411
                                        v2 = (Comparable) feature2.get(i);
1412
                                        if (v1 == null) {
1413
                                                assertNull(v2);
1414
                                        } else if (v1 instanceof Geometry) {
1415
                                                assertTrue(v2 instanceof Geometry);
1416
                                                assertEquals(((Geometry) v1).getType(), ((Geometry) v2)
1417
                                                                .getType());
1418
                                                assertEquals(
1419
                                                                (((Geometry) v1)
1420
                                                                                .getHandlers(Geometry.SELECTHANDLER)).length,
1421
                                                                (((Geometry) v2)
1422
                                                                                .getHandlers(Geometry.SELECTHANDLER)).length);
1423
                                                h = (((Geometry) v1)
1424
                                                                .getHandlers(Geometry.SELECTHANDLER))[0];
1425
                                                h2 = (((Geometry) v2)
1426
                                                                .getHandlers(Geometry.SELECTHANDLER))[0];
1427
1428
                                                assertEquals(0.0, h.getPoint().distance(h2.getPoint()),
1429
                                                                0.000001);
1430
1431
                                                h = (((Geometry) v1)
1432
                                                                .getHandlers(Geometry.SELECTHANDLER))[(((Geometry) v1)
1433
                                                                .getHandlers(Geometry.SELECTHANDLER)).length - 1];
1434
                                                h2 = (((Geometry) v2)
1435
                                                                .getHandlers(Geometry.SELECTHANDLER))[(((Geometry) v2)
1436
                                                                .getHandlers(Geometry.SELECTHANDLER)).length - 1];
1437
1438
                                                assertEquals(0.0, h.getPoint().distance(h2.getPoint()),
1439
                                                                0.000001);
1440
1441
                                        } else {
1442
                                                assertEquals(0, v1.compareTo(v2));
1443
                                        }
1444
                                }
1445
1446
1447
                        }
1448
                } catch (Exception e) {
1449
                        e.printStackTrace();
1450
                        fail();
1451
                }
1452
1453
                coll.dispose();
1454
                coll2.dispose();
1455
1456
                try {
1457
                        store.dispose();
1458
                        store2.dispose();
1459
                } catch (CloseException e) {
1460
                        e.printStackTrace();
1461
                        fail();
1462
                }
1463
1464
        }
1465 23303 jmvivo
1466
        public void cloneFeatureTypeTest() {
1467
1468
                org.gvsig.fmap.data.feature.file.dbf.Register.selfRegister();
1469
1470 23754 jjdelcerro
                DataManager dsm = DefaultDataManager.getManager();
1471 23303 jmvivo
1472
                DataStoreParameters dp;
1473
                try {
1474 24081 jjdelcerro
                        dp = dsm.createStoreParameters(DBFStore.DATASTORE_NAME);
1475 23303 jmvivo
                } catch (InitializeException e1) {
1476
                        e1.printStackTrace();
1477
                        fail();
1478
                        return;
1479
                }
1480
                ((DBFStoreParameters) dp).setFile(dbffile);
1481
1482
                FeatureStore fs = null;
1483
                try {
1484 24081 jjdelcerro
                        fs = (FeatureStore) dsm.createStore(dp);
1485 23303 jmvivo
                } catch (InitializeException e) {
1486
                        e.printStackTrace();
1487
                        fail("Exception:" + e);
1488
                        return;
1489
                }
1490
                assertNotNull("Can't create Feature Store", fs);
1491
1492
                compareFeatureType(fs.getDefaultFeatureType(), fs
1493
                                .getDefaultFeatureType()
1494 23754 jjdelcerro
                                .getCopy());
1495 23303 jmvivo
1496 23842 jjdelcerro
                FeatureSet fc = null;
1497 23303 jmvivo
1498
                try {
1499 23842 jjdelcerro
                        fc = (FeatureSet) fs.getDataSet();
1500 23303 jmvivo
                } catch (ReadException e1) {
1501
                        e1.printStackTrace();
1502
                        fail();
1503
                        return;
1504
                }
1505
1506
1507 23754 jjdelcerro
                compareFeatureType(fs.getDefaultFeatureType(), fc.getDefaultFeatureType());
1508 23303 jmvivo
1509
1510
1511
                fc.dispose();
1512
1513
                try {
1514
                        fs.addEvaluatedAttribute(null, "eva1",
1515 23754 jjdelcerro
                                        FeatureAttributeDescriptor.STRING, "lower(' ')", null);
1516 23303 jmvivo
                } catch (ReadException e1) {
1517
                        e1.printStackTrace();
1518
                        fail();
1519
                        return;
1520
                }
1521
1522
1523
                compareFeatureType(fs.getDefaultFeatureType(), fs
1524 23754 jjdelcerro
                                .getDefaultFeatureType().getCopy());
1525 23303 jmvivo
1526
                try {
1527
                        fs.dispose();
1528
                } catch (CloseException e) {
1529
                        e.printStackTrace();
1530
                        fail();
1531
                        return;
1532
                }
1533
        }
1534
1535
        private void compareFeatureType(FeatureType original, FeatureType copy) {
1536
                AttributeDescriptor attr1, attr2;
1537
1538
                assertEquals(original.size(), copy.size());
1539 23754 jjdelcerro
                assertEquals(original.getDefaultGeometryAttributeName(), copy.getDefaultGeometryAttributeName());
1540 23303 jmvivo
1541
                int i = 0;
1542
1543
                for (i = 0; i < original.size(); i++) {
1544
                        attr1 = (AttributeDescriptor) original.get(i);
1545
                        attr2 = (AttributeDescriptor) copy.get(i);
1546
1547
                        assertEquals(attr1.getName(), attr2.getName());
1548
                        assertEquals(attr1.getDataType(), attr2.getDataType());
1549
                        assertEquals(attr1.getDefaultValue(), attr2.getDefaultValue());
1550
                        assertEquals(attr1.ordinal(), attr2.ordinal());
1551
                        assertEquals(attr1.originalPosition(), attr2.originalPosition());
1552
                        assertEquals(attr1.isEvaluated(), attr2.isEvaluated());
1553
                        assertEquals(attr1.getGeometryType(), attr2.getGeometryType());
1554
                        assertEquals(attr1.getSize(), attr2.getSize());
1555
                        assertEquals(attr1.getSRS(), attr2.getSRS());
1556
                        assertEquals(attr1.getPrecision(), attr2.getPrecision());
1557
                        assertEquals(attr1.getExpression(), attr2.getExpression());
1558
                        assertEquals(attr1.isAllowNull(), attr2.isAllowNull());
1559
                        assertEquals(attr1.isPrimaryKey(), attr2.isPrimaryKey());
1560
                        assertEquals(attr1.isReadOnly(), attr2.isReadOnly());
1561
                }
1562
1563
        }
1564 23509 jmvivo
1565 23754 jjdelcerro
        protected static AbstractResource getResource(FileStoreParameters params) {
1566
                AbstractResource tmpRes = null;
1567 23509 jmvivo
                Object obj = null;
1568
1569 23754 jjdelcerro
                ResourceManager resMan = DefaultResourceManager.getResourceManager();
1570 23509 jmvivo
1571
                Iterator iter = resMan.iterator();
1572
                while (iter.hasNext()) {
1573
                        obj = iter.next();
1574
                        if (obj instanceof FileResource) {
1575 23754 jjdelcerro
                                tmpRes = (AbstractResource) obj;
1576 23509 jmvivo
                                if (((FileResource) tmpRes).getFile().getAbsoluteFile().equals(
1577
                                                params.getFile().getAbsoluteFile())) {
1578
                                        return tmpRes;
1579
                                }
1580
                        }
1581
                }
1582
                return null;
1583
        }
1584 23543 jmvivo
1585
        private void mapParamsBaseTest(DataParameters params) {
1586
                Exception e = null;
1587
                try {
1588
                        params.put(new Integer(0), "GEOMETRY_x");
1589
                } catch (Exception e1) {
1590
                        e = e1;
1591
                }
1592 23602 jmvivo
                assertNull(e);
1593 23543 jmvivo
1594
                e = null;
1595
                try {
1596
                        params.put("kk", "GEOMETRY_x");
1597
                } catch (IllegalArgumentException e1) {
1598
                        e = e1;
1599
                }
1600 23602 jmvivo
                assertNull(e);
1601 23543 jmvivo
1602
                e = null;
1603
                try {
1604
                        params.entrySet();
1605
                } catch (UnsupportedOperationException e1) {
1606
                        e = e1;
1607
                }
1608 23602 jmvivo
                assertNull(e);
1609 23543 jmvivo
1610
                e = null;
1611
                try {
1612
                        params.keySet().add("hola");
1613
                } catch (UnsupportedOperationException e1) {
1614
                        e = e1;
1615
                }
1616
                assertNotNull(e);
1617
1618
                e = null;
1619
                try {
1620
                        params.keySet().remove("storeSecondary");
1621
                } catch (UnsupportedOperationException e1) {
1622
                        e = e1;
1623
                }
1624
                assertNotNull(e);
1625
1626
                e = null;
1627
                try {
1628
                        params.values().remove("GEOMETRY_x");
1629
                } catch (UnsupportedOperationException e1) {
1630
                        e = e1;
1631
                }
1632
                assertNotNull(e);
1633
1634
                e = null;
1635
                try {
1636
                        params.values().add("GEOMETRY_x");
1637
                } catch (UnsupportedOperationException e1) {
1638
                        e = e1;
1639
                }
1640
                assertNotNull(e);
1641
1642
        }
1643
1644 19470 jmvivo
}