Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libDataSourceBaseDrivers / src-test / org / gvsig / data / datastores / vectorial / driver / DataStoreTest.java @ 19664

History | View | Annotate | Download (26.8 KB)

1 19401 vcaballero
package org.gvsig.data.datastores.vectorial.driver;
2
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 19401 vcaballero
import org.gvsig.data.DataSourceManager;
10
import org.gvsig.data.IDataStoreParameters;
11
import org.gvsig.data.datastores.vectorial.driver.dbf.DBFDriverParameters;
12 19654 vcaballero
import org.gvsig.data.datastores.vectorial.driver.dgn.DGNDriverParameters;
13 19603 vcaballero
import org.gvsig.data.datastores.vectorial.driver.dxf.DXFDriverParameters;
14 19449 jmvivo
import org.gvsig.data.datastores.vectorial.driver.shp.ShpDriverParameters;
15
import org.gvsig.data.datastores.vectorial.driver.shp.fileshp.SHP;
16 19443 vcaballero
import org.gvsig.data.exception.CloseException;
17
import org.gvsig.data.exception.InitializeException;
18 19609 jmvivo
import org.gvsig.data.exception.OpenException;
19 19449 jmvivo
import org.gvsig.data.exception.ReadException;
20
import org.gvsig.data.exception.WriteException;
21 19401 vcaballero
import org.gvsig.data.vectorial.IFeature;
22
import org.gvsig.data.vectorial.IFeatureCollection;
23
import org.gvsig.data.vectorial.IFeatureStore;
24
import org.gvsig.data.vectorial.IFeatureType;
25 19490 jpiera
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor;
26
import org.gvsig.exceptions.BaseException;
27 19401 vcaballero
28 19603 vcaballero
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
29 19490 jpiera
30 19401 vcaballero
public class DataStoreTest extends TestCase {
31
32 19402 vcaballero
        private File dbffile = new File(DataStoreTest.class.getResource("data/prueba.dbf").getFile());
33
        private File shpfile = new File(DataStoreTest.class.getResource("data/prueba.shp").getFile());
34 19603 vcaballero
        private File dxffile = new File(DataStoreTest.class.getResource("data/prueba.dxf").getFile());
35 19654 vcaballero
        private File dgnfile = new File(DataStoreTest.class.getResource("data/cv_300_todo.dgn").getFile());
36 19401 vcaballero
37
        public static void main(String[] args) {
38
                junit.textui.TestRunner.run(DataStoreTest.class);
39
        }
40
41
        protected void setUp() throws Exception {
42
                super.setUp();
43
44
        }
45
46
        public void testDBF() {
47 19658 vcaballero
                try {
48 19468 jmvivo
                System.out.println("======= DBF ==============");
49 19401 vcaballero
                org.gvsig.data.datastores.vectorial.driver.dbf.Register.selfRegister();
50
                org.gvsig.data.datastores.vectorial.driver.Register.selfRegister();
51
52
                DataSourceManager dsm=DataSourceManager.getManager();
53
54
55
                IDriverParameters dp=dsm.createDriverParameters("dbf");
56
                ((DBFDriverParameters)dp).setDBFFile(dbffile);
57
58 19481 jmvivo
                driverTest(dp,null,null,true);
59 19449 jmvivo
60 19468 jmvivo
                IFeatureStore fs = createFeatureStore(dp);
61
                assertNotNull("Can't create Feature Store", fs);
62
63 19658 vcaballero
64 19609 jmvivo
                        fs.open();
65 19468 jmvivo
66 19658 vcaballero
67 19468 jmvivo
                Iterator it;
68
                IFeatureCollection fc;
69
                Comparable v1,v2;
70
                IFeature feature,pfeature;
71 19470 jmvivo
                long count;
72 19468 jmvivo
73
74
                fc = (IFeatureCollection)fs.getDataCollection();
75
76
                assertEquals(9, fc.size());
77
78
                fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null);
79
80 19480 jmvivo
                assertEquals(2, fc.size());
81 19468 jmvivo
82
                it = fc.iterator();
83 19470 jmvivo
                count=0;
84 19468 jmvivo
                while (it.hasNext()){
85
                        feature = (IFeature)it.next();
86 19470 jmvivo
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
87
                        count++;
88 19468 jmvivo
                }
89 19470 jmvivo
                assertEquals("Iteration error",2,count);
90 19468 jmvivo
91 19470 jmvivo
92 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC");
93 19468 jmvivo
                assertEquals(9, fc.size());
94
                it = fc.iterator();
95 19470 jmvivo
                count=0;
96 19468 jmvivo
                pfeature = (IFeature)it.next();
97 19470 jmvivo
                count++;
98 19468 jmvivo
                while (it.hasNext()){
99
                        feature = (IFeature)it.next();
100
                        v1 = (Comparable)pfeature.get("NOMBRE");
101
                        v2 = (Comparable)feature.get("NOMBRE");
102
                        pfeature=feature;
103 19480 jmvivo
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
104 19470 jmvivo
                        count++;
105 19468 jmvivo
                }
106 19470 jmvivo
                assertEquals("Iteration error",9,count);
107 19468 jmvivo
108
109 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC");
110 19468 jmvivo
                assertEquals(9, fc.size());
111
                it = fc.iterator();
112
113 19470 jmvivo
                count=0;
114 19468 jmvivo
                pfeature = (IFeature)it.next();
115 19470 jmvivo
                count++;
116 19468 jmvivo
                while (it.hasNext()){
117
                        feature = (IFeature)it.next();
118
                        v1 = (Comparable)pfeature.get("NOMBRE");
119
                        v2 = (Comparable)feature.get("NOMBRE");
120
                        pfeature=feature;
121 19480 jmvivo
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
122 19470 jmvivo
                        count++;
123 19468 jmvivo
                }
124 19470 jmvivo
                assertEquals("Iteration error",9,count);
125 19468 jmvivo
126
127 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE");
128 19468 jmvivo
129
                assertEquals(2, fc.size());
130
131
                it = fc.iterator();
132
133 19470 jmvivo
                count=0;
134 19468 jmvivo
                pfeature = (IFeature)it.next();
135
                assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b"));
136 19470 jmvivo
                count++;
137 19468 jmvivo
                while (it.hasNext()){
138
                        feature = (IFeature)it.next();
139 19470 jmvivo
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
140 19468 jmvivo
                        v1 = (Comparable)pfeature.get("NOMBRE");
141
                        v2 = (Comparable)feature.get("NOMBRE");
142
                        pfeature=feature;
143 19480 jmvivo
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
144 19470 jmvivo
                        count++;
145 19468 jmvivo
                }
146 19470 jmvivo
                assertEquals("Iteration error",2,count);
147 19468 jmvivo
148 19480 jmvivo
149
150 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc");
151 19480 jmvivo
                assertEquals(9, fc.size());
152
                it = fc.iterator();
153
                count=0;
154
                pfeature = (IFeature)it.next();
155
                System.out.println(pfeature.getString("NOMBRE"));
156
                count++;
157
                while (it.hasNext()){
158
                        feature = (IFeature)it.next();
159
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
160
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
161
                        pfeature=feature;
162
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
163
                        System.out.println(pfeature.getString("NOMBRE"));
164
                        count++;
165
                }
166
                assertEquals("Iteration error",9,count);
167
168
169 19664 jmvivo
                /// CON  EDICION
170
171
                fs.startEditing();
172
173
                IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType());
174
                newFeature.set("NOMBRE","BuRjaSOT");
175
                newFeature.set("TIPO","MUNICIPIO");
176
                fs.insert(newFeature);
177
178
179
180 19468 jmvivo
                try {
181 19664 jmvivo
                        fc = (IFeatureCollection)fs.getDataCollection();
182
                } catch (ReadException e1) {
183
                        e1.printStackTrace();
184
                        fail();
185
                }
186
187
                assertEquals(10, fc.size());
188
189
                try {
190
                        fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null);
191
                } catch (ReadException e1) {
192
                        e1.printStackTrace();
193
                        fail();
194
                }
195
196
                assertEquals(3, fc.size());
197
198
                it = fc.iterator();
199
                count=0;
200
                while (it.hasNext()){
201
                        feature = (IFeature)it.next();
202
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
203
                        count++;
204
                }
205
                assertEquals("Iteration error",3,count);
206
207
208
                try {
209
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC");
210
                } catch (ReadException e1) {
211
                        e1.printStackTrace();
212
                        fail();
213
                }
214
                assertEquals(10, fc.size());
215
                it = fc.iterator();
216
                count=0;
217
                pfeature = (IFeature)it.next();
218
                count++;
219
                while (it.hasNext()){
220
                        feature = (IFeature)it.next();
221
                        v1 = (Comparable)pfeature.get("NOMBRE");
222
                        v2 = (Comparable)feature.get("NOMBRE");
223
                        pfeature=feature;
224
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
225
                        count++;
226
                }
227
                assertEquals("Iteration error",10,count);
228
229
230
                try {
231
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC");
232
                } catch (ReadException e1) {
233
                        e1.printStackTrace();
234
                        fail();
235
                }
236
                assertEquals(10, fc.size());
237
                it = fc.iterator();
238
239
                count=0;
240
                pfeature = (IFeature)it.next();
241
                count++;
242
                while (it.hasNext()){
243
                        feature = (IFeature)it.next();
244
                        v1 = (Comparable)pfeature.get("NOMBRE");
245
                        v2 = (Comparable)feature.get("NOMBRE");
246
                        pfeature=feature;
247
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
248
                        count++;
249
                }
250
                assertEquals("Iteration error",10,count);
251
252
253
                try {
254
                        fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE");
255
                } catch (ReadException e1) {
256
                        e1.printStackTrace();
257
                        fail();
258
                }
259
260
                assertEquals(3, fc.size());
261
262
                it = fc.iterator();
263
264
                count=0;
265
                pfeature = (IFeature)it.next();
266
                assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b"));
267
                count++;
268
                while (it.hasNext()){
269
                        feature = (IFeature)it.next();
270
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
271
                        v1 = (Comparable)pfeature.get("NOMBRE");
272
                        v2 = (Comparable)feature.get("NOMBRE");
273
                        pfeature=feature;
274
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
275
                        count++;
276
                }
277
                assertEquals("Iteration error",3,count);
278
279
280
281
                try {
282
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc");
283
                } catch (ReadException e1) {
284
                        e1.printStackTrace();
285
                        fail();
286
                }
287
                assertEquals(10, fc.size());
288
                it = fc.iterator();
289
                count=0;
290
                pfeature = (IFeature)it.next();
291
                System.out.println(pfeature.getString("NOMBRE"));
292
                count++;
293
                while (it.hasNext()){
294
                        feature = (IFeature)it.next();
295
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
296
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
297
                        pfeature=feature;
298
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
299
                        System.out.println(pfeature.getString("NOMBRE"));
300
                        count++;
301
                }
302
                assertEquals("Iteration error",10,count);
303
304
305
306
307
308
309
310
                fs.cancelEditing();
311
312
313
                try {
314 19468 jmvivo
                        fs.close();
315
                } catch (CloseException e) {
316 19470 jmvivo
                        e.printStackTrace();
317 19468 jmvivo
                        fail("Exception:" + e);
318
                }
319
320
321
                System.out.println("======= /DBF ==============");
322 19658 vcaballero
                } catch (OpenException e1) {
323
                        e1.printStackTrace();
324
                        fail();
325
                } catch (ReadException e) {
326
                        // TODO Auto-generated catch block
327
                        e.printStackTrace();
328
                }
329 19449 jmvivo
        }
330
331
        public void testSHP() {
332 19658 vcaballero
                try {
333 19468 jmvivo
                System.out.println("======= SHP ==============");
334 19449 jmvivo
                org.gvsig.data.datastores.vectorial.driver.shp.Register.selfRegister();
335
                org.gvsig.data.datastores.vectorial.driver.dbf.Register.selfRegister();
336
                org.gvsig.data.datastores.vectorial.driver.Register.selfRegister();
337
338
                DataSourceManager dsm=DataSourceManager.getManager();
339
340
341
                IDriverParameters dp=dsm.createDriverParameters("shp");
342
                ((ShpDriverParameters)dp).setSHPFile(shpfile);
343 19459 vcaballero
                ((ShpDriverParameters)dp).setSHXFile(SHP.getShxFile(shpfile));
344
                ((ShpDriverParameters)dp).setDBFFile(SHP.getDbfFile(shpfile));
345 19449 jmvivo
346
347 19483 jmvivo
                driverTest(dp,null,null,true);
348 19449 jmvivo
349 19468 jmvivo
350
351
352 19480 jmvivo
                IFeatureStore fs = createFeatureStore(dp);
353
                assertNotNull("Can't create Feature Store", fs);
354
355 19658 vcaballero
356 19609 jmvivo
                        fs.open();
357 19480 jmvivo
358 19658 vcaballero
359 19480 jmvivo
                Iterator it;
360
                IFeatureCollection fc;
361
                Comparable v1,v2;
362
                IFeature feature,pfeature;
363
                long count;
364
365
366
                fc = (IFeatureCollection)fs.getDataCollection();
367
368
                assertEquals(9, fc.size());
369
370
                fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null);
371
372
                assertEquals(2, fc.size());
373
374
                it = fc.iterator();
375
                count=0;
376
                while (it.hasNext()){
377
                        feature = (IFeature)it.next();
378
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
379
                        count++;
380
                }
381
                assertEquals("Iteration error",2,count);
382
383
384 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE");
385 19480 jmvivo
                assertEquals(9, fc.size());
386
                it = fc.iterator();
387
                count=0;
388
                pfeature = (IFeature)it.next();
389
                count++;
390
                while (it.hasNext()){
391
                        feature = (IFeature)it.next();
392
                        v1 = (Comparable)pfeature.get("NOMBRE");
393
                        v2 = (Comparable)feature.get("NOMBRE");
394
                        pfeature=feature;
395
                        assertTrue("Short error", (v1.compareTo(v2) <= 0));
396
                        count++;
397
                }
398
                assertEquals("Iteration error",9,count);
399
400
401 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC");
402 19480 jmvivo
                assertEquals(9, fc.size());
403
                it = fc.iterator();
404
                count=0;
405
                pfeature = (IFeature)it.next();
406
                System.out.println(pfeature.getString("NOMBRE"));
407
                count++;
408
                while (it.hasNext()){
409
                        feature = (IFeature)it.next();
410
                        v1 = (Comparable)pfeature.get("NOMBRE");
411
                        v2 = (Comparable)feature.get("NOMBRE");
412
                        pfeature=feature;
413
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
414
                        System.out.println(pfeature.getString("NOMBRE"));
415
                        count++;
416
                }
417
                assertEquals("Iteration error",9,count);
418
419
420 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE ASC");
421 19480 jmvivo
422
                assertEquals(2, fc.size());
423
424
                it = fc.iterator();
425
426
                count=0;
427
                pfeature = (IFeature)it.next();
428
                assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b"));
429
                count++;
430
                while (it.hasNext()){
431
                        feature = (IFeature)it.next();
432
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
433
                        v1 = (Comparable)pfeature.get("NOMBRE");
434
                        v2 = (Comparable)feature.get("NOMBRE");
435
                        pfeature=feature;
436
                        assertTrue("Short error", (v1.compareTo(v2) <= 0));
437
                        count++;
438
                }
439
                assertEquals("Iteration error",2,count);
440
441
442 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"lower(NOMBRE) ASC");
443 19480 jmvivo
                assertEquals(9, fc.size());
444
                it = fc.iterator();
445
                count=0;
446
                pfeature = (IFeature)it.next();
447
                count++;
448
                while (it.hasNext()){
449
                        feature = (IFeature)it.next();
450
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
451
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
452
                        pfeature=feature;
453
                        assertTrue("Short error", (v1.compareTo(v2) <= 0));
454
                        count++;
455
                }
456
                assertEquals("Iteration error",9,count);
457
458
459
460 19484 jmvivo
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc");
461 19480 jmvivo
                assertEquals(9, fc.size());
462
                it = fc.iterator();
463
                count=0;
464
                pfeature = (IFeature)it.next();
465
                System.out.println(pfeature.getString("NOMBRE"));
466
                count++;
467
                while (it.hasNext()){
468
                        feature = (IFeature)it.next();
469
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
470
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
471
                        pfeature=feature;
472
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
473
                        System.out.println(pfeature.getString("NOMBRE"));
474
                        count++;
475
                }
476
                assertEquals("Iteration error",9,count);
477
478 19664 jmvivo
479
480
                /// CON  EDICION
481
482
                fs.startEditing();
483
484
                IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType());
485
                newFeature.set("NOMBRE","BuRjaSOT");
486
                newFeature.set("TIPO","MUNICIPIO");
487
                fs.insert(newFeature);
488
489
490
491 19480 jmvivo
                try {
492 19664 jmvivo
                        fc = (IFeatureCollection)fs.getDataCollection();
493
                } catch (ReadException e1) {
494
                        e1.printStackTrace();
495
                        fail();
496
                }
497
498
                assertEquals(10, fc.size());
499
500
                try {
501
                        fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null);
502
                } catch (ReadException e1) {
503
                        e1.printStackTrace();
504
                        fail();
505
                }
506
507
                assertEquals(3, fc.size());
508
509
                it = fc.iterator();
510
                count=0;
511
                while (it.hasNext()){
512
                        feature = (IFeature)it.next();
513
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
514
                        count++;
515
                }
516
                assertEquals("Iteration error",3,count);
517
518
519
                try {
520
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC");
521
                } catch (ReadException e1) {
522
                        e1.printStackTrace();
523
                        fail();
524
                }
525
                assertEquals(10, fc.size());
526
                it = fc.iterator();
527
                count=0;
528
                pfeature = (IFeature)it.next();
529
                count++;
530
                while (it.hasNext()){
531
                        feature = (IFeature)it.next();
532
                        v1 = (Comparable)pfeature.get("NOMBRE");
533
                        v2 = (Comparable)feature.get("NOMBRE");
534
                        pfeature=feature;
535
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
536
                        count++;
537
                }
538
                assertEquals("Iteration error",10,count);
539
540
541
                try {
542
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC");
543
                } catch (ReadException e1) {
544
                        e1.printStackTrace();
545
                        fail();
546
                }
547
                assertEquals(10, fc.size());
548
                it = fc.iterator();
549
550
                count=0;
551
                pfeature = (IFeature)it.next();
552
                count++;
553
                while (it.hasNext()){
554
                        feature = (IFeature)it.next();
555
                        v1 = (Comparable)pfeature.get("NOMBRE");
556
                        v2 = (Comparable)feature.get("NOMBRE");
557
                        pfeature=feature;
558
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
559
                        count++;
560
                }
561
                assertEquals("Iteration error",10,count);
562
563
564
                try {
565
                        fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE");
566
                } catch (ReadException e1) {
567
                        e1.printStackTrace();
568
                        fail();
569
                }
570
571
                assertEquals(3, fc.size());
572
573
                it = fc.iterator();
574
575
                count=0;
576
                pfeature = (IFeature)it.next();
577
                assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b"));
578
                count++;
579
                while (it.hasNext()){
580
                        feature = (IFeature)it.next();
581
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
582
                        v1 = (Comparable)pfeature.get("NOMBRE");
583
                        v2 = (Comparable)feature.get("NOMBRE");
584
                        pfeature=feature;
585
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
586
                        count++;
587
                }
588
                assertEquals("Iteration error",3,count);
589
590
591
592
                try {
593
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc");
594
                } catch (ReadException e1) {
595
                        e1.printStackTrace();
596
                        fail();
597
                }
598
                assertEquals(10, fc.size());
599
                it = fc.iterator();
600
                count=0;
601
                pfeature = (IFeature)it.next();
602
                System.out.println(pfeature.getString("NOMBRE"));
603
                count++;
604
                while (it.hasNext()){
605
                        feature = (IFeature)it.next();
606
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
607
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
608
                        pfeature=feature;
609
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
610
                        System.out.println(pfeature.getString("NOMBRE"));
611
                        count++;
612
                }
613
                assertEquals("Iteration error",10,count);
614
615
616
617
618
                fs.cancelEditing();
619
620
621
622
                try {
623 19480 jmvivo
                        fs.close();
624
                } catch (CloseException e) {
625
                        e.printStackTrace();
626
                        fail("Exception:" + e);
627
                }
628
629
630
631 19468 jmvivo
                System.out.println("======= /SHP ==============");
632 19658 vcaballero
                } catch (OpenException e1) {
633
                        e1.printStackTrace();
634
                        fail();
635
                } catch (ReadException e) {
636
                        // TODO Auto-generated catch block
637
                        e.printStackTrace();
638
                }
639 19449 jmvivo
        }
640
641 19603 vcaballero
        public void testDXF() {
642 19658 vcaballero
                try {
643 19603 vcaballero
                System.out.println("======= DXF ==============");
644
                org.gvsig.data.datastores.vectorial.driver.dxf.Register.selfRegister();
645
                org.gvsig.data.datastores.vectorial.driver.Register.selfRegister();
646
647
                DataSourceManager dsm=DataSourceManager.getManager();
648
649
650
                IDriverParameters dp=dsm.createDriverParameters("dxf");
651
                ((DXFDriverParameters)dp).setDXFFile(dxffile);
652
                IProjection proj = CRSFactory.getCRS("EPSG:23030");
653
                ((DXFDriverParameters)dp).setProjection(proj);
654
                driverTest(dp,null,null,true);
655
656
                IFeatureStore fs = createFeatureStore(dp);
657
                assertNotNull("Can't create Feature Store", fs);
658
659 19658 vcaballero
660 19609 jmvivo
                        fs.open();
661 19603 vcaballero
662 19658 vcaballero
663 19603 vcaballero
                Iterator it;
664
                IFeatureCollection fc;
665
                Comparable v1,v2;
666
                IFeature feature,pfeature;
667
                long count;
668
669
670
                fc = (IFeatureCollection)fs.getDataCollection();
671
672
                assertEquals(10, fc.size());
673
674
                fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null);
675
676
                assertEquals(2, fc.size());
677
678
                it = fc.iterator();
679
                count=0;
680
                while (it.hasNext()){
681
                        feature = (IFeature)it.next();
682
                        assertTrue("Filter error",feature.getInt("Color")>7);
683
                        count++;
684
                }
685
                assertEquals("Iteration error",2,count);
686
687
688
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC");
689
                assertEquals(10, fc.size());
690
                it = fc.iterator();
691
                count=0;
692
                pfeature = (IFeature)it.next();
693
                count++;
694
                while (it.hasNext()){
695
                        feature = (IFeature)it.next();
696
                        v1 = (Comparable)pfeature.get("Layer");
697
                        v2 = (Comparable)feature.get("Layer");
698
                        pfeature=feature;
699
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
700
                        count++;
701
                }
702
                assertEquals("Iteration error",10,count);
703
704
705
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC");
706
                assertEquals(10, fc.size());
707
                it = fc.iterator();
708
709
                count=0;
710
                pfeature = (IFeature)it.next();
711
                count++;
712
                while (it.hasNext()){
713
                        feature = (IFeature)it.next();
714
                        v1 = (Comparable)pfeature.get("Layer");
715
                        v2 = (Comparable)feature.get("Layer");
716
                        pfeature=feature;
717
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
718
                        count++;
719
                }
720
                assertEquals("Iteration error",10,count);
721
722
723
                fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC");
724
725
                assertEquals(2, fc.size());
726
727
                it = fc.iterator();
728
729
                count=0;
730
                pfeature = (IFeature)it.next();
731
                assertTrue(pfeature.getInt("Color")>7);
732
                count++;
733
                while (it.hasNext()){
734
                        feature = (IFeature)it.next();
735
                        assertTrue("Filter error",feature.getInt("Color")>7);
736
                        v1 = (Comparable)pfeature.get("Color");
737
                        v2 = (Comparable)feature.get("Color");
738
                        pfeature=feature;
739
                        Integer i1=(Integer)v1;
740
                        Integer i2=(Integer)v2;
741
                        assertTrue("Short error", (i1.intValue()>i2.intValue()));
742
                        count++;
743
                }
744
                assertEquals("Iteration error",2,count);
745
746
747
748
//                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
749
//                assertEquals(10, fc.size());
750
//                it = fc.iterator();
751
//                count=0;
752
//                pfeature = (IFeature)it.next();
753
//                System.out.println(pfeature.getString("Layer"));
754
//                count++;
755
//                while (it.hasNext()){
756
//                        feature = (IFeature)it.next();
757
//                        v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
758
//                        v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
759
//                        pfeature=feature;
760
//                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
761
//                        System.out.println(pfeature.getString("Layer"));
762
//                        count++;
763
//                }
764
//                assertEquals("Iteration error",10,count);
765
766
767
                try {
768
                        fs.close();
769
                } catch (CloseException e) {
770
                        e.printStackTrace();
771
                        fail("Exception:" + e);
772
                }
773
774
775
                System.out.println("======= /DXF ==============");
776 19658 vcaballero
                } catch (OpenException e1) {
777
                        e1.printStackTrace();
778
                        fail();
779
                } catch (ReadException e) {
780
                        // TODO Auto-generated catch block
781
                        e.printStackTrace();
782
                }
783 19603 vcaballero
        }
784
785 19654 vcaballero
        public void testDGN() {
786 19658 vcaballero
                try {
787 19654 vcaballero
                System.out.println("======= DGN ==============");
788
                org.gvsig.data.datastores.vectorial.driver.dgn.Register.selfRegister();
789
                org.gvsig.data.datastores.vectorial.driver.Register.selfRegister();
790 19603 vcaballero
791 19654 vcaballero
                DataSourceManager dsm=DataSourceManager.getManager();
792 19603 vcaballero
793
794 19654 vcaballero
                IDriverParameters dp=dsm.createDriverParameters("dgn");
795
                ((DGNDriverParameters)dp).setDGNFile(dgnfile);
796
                driverTest(dp,null,null,true);
797 19603 vcaballero
798 19654 vcaballero
                IFeatureStore fs = createFeatureStore(dp);
799
                assertNotNull("Can't create Feature Store", fs);
800 19603 vcaballero
801 19658 vcaballero
802 19654 vcaballero
                        fs.open();
803
804 19658 vcaballero
805 19654 vcaballero
                Iterator it;
806
                IFeatureCollection fc;
807
                Comparable v1,v2;
808
                IFeature feature,pfeature;
809
                long count;
810
811
812
                fc = (IFeatureCollection)fs.getDataCollection();
813
814
                assertEquals(14646, fc.size());
815
816
                fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null);
817
818
                assertEquals(14614, fc.size());
819
820
                it = fc.iterator();
821
                count=0;
822
                while (it.hasNext()){
823
                        feature = (IFeature)it.next();
824
                        assertTrue("Filter error",feature.getInt("Color")>7);
825
                        count++;
826
                }
827
                assertEquals("Iteration error",14614,count);
828
829
830
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC");
831
                assertEquals(14646, fc.size());
832
                it = fc.iterator();
833
                count=0;
834
                pfeature = (IFeature)it.next();
835
                count++;
836
                while (it.hasNext()){
837
                        feature = (IFeature)it.next();
838
                        v1 = (Comparable)pfeature.get("Layer");
839
                        v2 = (Comparable)feature.get("Layer");
840
                        pfeature=feature;
841
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
842
                        count++;
843
                }
844
                assertEquals("Iteration error",10,count);
845
846
847
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC");
848
                assertEquals(14646, fc.size());
849
                it = fc.iterator();
850
851
                count=0;
852
                pfeature = (IFeature)it.next();
853
                count++;
854
                while (it.hasNext()){
855
                        feature = (IFeature)it.next();
856
                        v1 = (Comparable)pfeature.get("Layer");
857
                        v2 = (Comparable)feature.get("Layer");
858
                        pfeature=feature;
859
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
860
                        count++;
861
                }
862
                assertEquals("Iteration error",14646,count);
863
864
865
                fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC");
866
867
                assertEquals(2, fc.size());
868
869
                it = fc.iterator();
870
871
                count=0;
872
                pfeature = (IFeature)it.next();
873
                assertTrue(pfeature.getInt("Color")>7);
874
                count++;
875
                while (it.hasNext()){
876
                        feature = (IFeature)it.next();
877
                        assertTrue("Filter error",feature.getInt("Color")>7);
878
                        v1 = (Comparable)pfeature.get("Color");
879
                        v2 = (Comparable)feature.get("Color");
880
                        pfeature=feature;
881
                        Integer i1=(Integer)v1;
882
                        Integer i2=(Integer)v2;
883
                        assertTrue("Short error", (i1.intValue()>i2.intValue()));
884
                        count++;
885
                }
886
                assertEquals("Iteration error",14614,count);
887
888
889
890
//                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
891
//                assertEquals(10, fc.size());
892
//                it = fc.iterator();
893
//                count=0;
894
//                pfeature = (IFeature)it.next();
895
//                System.out.println(pfeature.getString("Layer"));
896
//                count++;
897
//                while (it.hasNext()){
898
//                        feature = (IFeature)it.next();
899
//                        v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
900
//                        v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
901
//                        pfeature=feature;
902
//                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
903
//                        System.out.println(pfeature.getString("Layer"));
904
//                        count++;
905
//                }
906
//                assertEquals("Iteration error",10,count);
907
908
909
                try {
910
                        fs.close();
911
                } catch (CloseException e) {
912
                        e.printStackTrace();
913
                        fail("Exception:" + e);
914
                }
915
916
917
                System.out.println("======= /DGN ==============");
918 19658 vcaballero
                } catch (OpenException e1) {
919
                        e1.printStackTrace();
920
                        fail();
921
                } catch (ReadException e) {
922
                        // TODO Auto-generated catch block
923
                        e.printStackTrace();
924
                }
925 19654 vcaballero
        }
926
927
928
929
930
931
932 19468 jmvivo
        private IFeatureStore createFeatureStore(IDriverParameters dp){
933 19449 jmvivo
                DataSourceManager dsm=DataSourceManager.getManager();
934
935
                IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
936
937 19401 vcaballero
                ((IDriverStoreParameters)dsp).setDriverParameters(dp);
938 19443 vcaballero
                IFeatureStore fs=null;
939
                try {
940
                        fs = (IFeatureStore)dsm.createDataStore(dsp);
941
                } catch (InitializeException e) {
942 19470 jmvivo
                        e.printStackTrace();
943 19468 jmvivo
                        fail("Exception:" + e);
944 19443 vcaballero
                }
945 19468 jmvivo
                return fs;
946 19401 vcaballero
947 19468 jmvivo
        }
948
949
950 19470 jmvivo
        private void driverTest(IDriverParameters dp,String filter, String order,boolean testEdit){
951 19468 jmvivo
                DataSourceManager dsm=DataSourceManager.getManager();
952
953
                IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
954
955
                ((IDriverStoreParameters)dsp).setDriverParameters(dp);
956
                IFeatureStore fs=createFeatureStore(dp);
957
958 19609 jmvivo
                try {
959
                        fs.open();
960
                } catch (OpenException e2) {
961
                        e2.printStackTrace();
962
                        fail();
963
                }
964 19401 vcaballero
965 19472 jmvivo
                if (fs.isEditable() && testEdit) {
966 19449 jmvivo
                        fs.startEditing();
967
968
                        IFeature feature1 = fs.createDefaultFeature(false);
969
                        IFeature feature2 = fs.createDefaultFeature(false);
970
                        IFeature feature3 = fs.createDefaultFeature(false);
971
972
                        fs.insert(feature1);
973
                        fs.insert(feature2);
974
975
                        fs.update(feature3,feature1);
976
                        fs.delete(feature3);
977
                        fs.delete(feature2);
978
                }
979
980 19401 vcaballero
                //Mostrar por consola todos los registros.
981
                IFeatureType ft= fs.getDefaultFeatureType();
982 19658 vcaballero
                IFeatureCollection featureCollection=null;
983 19449 jmvivo
//                featureCollection = (IFeatureCollection)fs.getDataCollection();
984
//                featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"NOMBRE = 'CALPE'",null);
985
//                featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"AREA > 3.2213163729E7 and AREA < 3.2213163749E7",null);
986 19658 vcaballero
                try {
987
                        featureCollection = (IFeatureCollection)fs.getDataCollection(ft,filter,order);
988
                } catch (ReadException e2) {
989
                        // TODO Auto-generated catch block
990
                        e2.printStackTrace();
991
                }
992 19449 jmvivo
993 19490 jpiera
                PrintlnFeaturesVisitor visitor=new PrintlnFeaturesVisitor(ft);
994
                try {
995
                        featureCollection.accept(visitor);
996
                } catch (BaseException e1) {
997
                        e1.printStackTrace();
998
                        fail("Exception: "+e1);
999
                }
1000 19449 jmvivo
1001 19472 jmvivo
                if (fs.isEditable() && testEdit){
1002 19449 jmvivo
                        try {
1003
                                fs.finishEditing();
1004
                        } catch (WriteException e) {
1005
                                e.printStackTrace();
1006 19470 jmvivo
                                fail("Exception: "+e);
1007 19449 jmvivo
                        } catch (ReadException e) {
1008
                                e.printStackTrace();
1009 19470 jmvivo
                                fail("Exception: "+e);
1010 19449 jmvivo
                        }
1011
                }
1012 19443 vcaballero
                try {
1013
                        fs.close();
1014
                } catch (CloseException e) {
1015
                        e.printStackTrace();
1016 19470 jmvivo
                        fail("Exception: "+e);
1017 19443 vcaballero
                }
1018 19401 vcaballero
                fs.dispose();
1019
        }
1020 19470 jmvivo
}