Statistics
| Revision:

root / trunk / libraries / libDataSourceBaseDrivers / src-test / org / gvsig / data / datastores / vectorial / file / DataStoreTest.java @ 20501

History | View | Annotate | Download (29.8 KB)

1
package org.gvsig.data.datastores.vectorial.file;
2

    
3
import java.io.File;
4
import java.util.Iterator;
5

    
6
import junit.framework.TestCase;
7

    
8
import org.cresques.cts.IProjection;
9
import org.gvsig.data.DataManager;
10
import org.gvsig.data.IDataStoreParameters;
11
import org.gvsig.data.commands.ICommandsRecord;
12
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStore;
13
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStoreParameters;
14
import org.gvsig.data.datastores.vectorial.file.dgn.DGNStore;
15
import org.gvsig.data.datastores.vectorial.file.dgn.DGNStoreParameters;
16
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStore;
17
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStoreParameters;
18
import org.gvsig.data.datastores.vectorial.file.shp.SHPStore;
19
import org.gvsig.data.datastores.vectorial.file.shp.SHPStoreParameters;
20
import org.gvsig.data.datastores.vectorial.file.shp.utils.SHP;
21
import org.gvsig.data.exception.CloseException;
22
import org.gvsig.data.exception.InitializeException;
23
import org.gvsig.data.exception.OpenException;
24
import org.gvsig.data.exception.ReadException;
25
import org.gvsig.data.exception.WriteException;
26
import org.gvsig.data.vectorial.DefaultAttributeDescriptor;
27
import org.gvsig.data.vectorial.DefaultFeatureType;
28
import org.gvsig.data.vectorial.IFeature;
29
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor;
30
import org.gvsig.data.vectorial.IFeatureCollection;
31
import org.gvsig.data.vectorial.IFeatureStore;
32
import org.gvsig.data.vectorial.IFeatureType;
33
import org.gvsig.data.vectorial.IsNotAttributeSettingException;
34
import org.gvsig.data.vectorial.IsNotFeatureSettingException;
35
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor;
36
import org.gvsig.exceptions.BaseException;
37

    
38
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
39

    
40
public class DataStoreTest extends TestCase {
41

    
42
        private File dbffile = new File(DataStoreTest.class.getResource("data/prueba.dbf").getFile());
43
        private File shpfile = new File(DataStoreTest.class.getResource("data/prueba.shp").getFile());
44
        private File dxffile = new File(DataStoreTest.class.getResource("data/prueba.dxf").getFile());
45
        private File dgnfile = new File(DataStoreTest.class.getResource("data/cv_300_todo.dgn").getFile());
46

    
47
        public static void main(String[] args) {
48
                junit.textui.TestRunner.run(DataStoreTest.class);
49
        }
50

    
51
        protected void setUp() throws Exception {
52
                super.setUp();
53

    
54
        }
55

    
56
        public void testDBF() {
57
                try {
58
                System.out.println("======= DBF ==============");
59
                org.gvsig.data.datastores.vectorial.file.dbf.Register.selfRegister();
60

    
61
                DataManager dsm=DataManager.getManager();
62

    
63

    
64
                IDataStoreParameters dp=dsm.createDataStoreParameters(DBFStore.DATASTORE_NAME);
65
                ((DBFStoreParameters)dp).setFile(dbffile);
66

    
67
                driverTest(dp,null,null,true);
68
                IFeatureStore fs=null;
69
                try {
70
                        fs = (IFeatureStore)dsm.createDataStore(dp);
71
                } catch (InitializeException e) {
72
                        e.printStackTrace();
73
                        fail("Exception:" + e);
74
                }
75
                assertNotNull("Can't create Feature Store", fs);
76

    
77

    
78
                        fs.open();
79

    
80

    
81
                Iterator it;
82
                IFeatureCollection fc;
83
                Comparable v1,v2;
84
                IFeature feature,pfeature;
85
                long count;
86

    
87

    
88
                fc = (IFeatureCollection)fs.getDataCollection();
89

    
90
                assertEquals(9, fc.size());
91

    
92
                fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null);
93

    
94
                assertEquals(2, fc.size());
95

    
96
                it = fc.iterator();
97
                count=0;
98
                while (it.hasNext()){
99
                        feature = (IFeature)it.next();
100
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
101
                        count++;
102
                }
103
                assertEquals("Iteration error",2,count);
104

    
105

    
106
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC");
107
                assertEquals(9, fc.size());
108
                it = fc.iterator();
109
                count=0;
110
                pfeature = (IFeature)it.next();
111
                count++;
112
                while (it.hasNext()){
113
                        feature = (IFeature)it.next();
114
                        v1 = (Comparable)pfeature.get("NOMBRE");
115
                        v2 = (Comparable)feature.get("NOMBRE");
116
                        pfeature=feature;
117
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
118
                        count++;
119
                }
120
                assertEquals("Iteration error",9,count);
121

    
122

    
123
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC");
124
                assertEquals(9, fc.size());
125
                it = fc.iterator();
126

    
127
                count=0;
128
                pfeature = (IFeature)it.next();
129
                count++;
130
                while (it.hasNext()){
131
                        feature = (IFeature)it.next();
132
                        v1 = (Comparable)pfeature.get("NOMBRE");
133
                        v2 = (Comparable)feature.get("NOMBRE");
134
                        pfeature=feature;
135
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
136
                        count++;
137
                }
138
                assertEquals("Iteration error",9,count);
139

    
140

    
141
                fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE");
142

    
143
                assertEquals(2, fc.size());
144

    
145
                it = fc.iterator();
146

    
147
                count=0;
148
                pfeature = (IFeature)it.next();
149
                assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b"));
150
                count++;
151
                while (it.hasNext()){
152
                        feature = (IFeature)it.next();
153
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
154
                        v1 = (Comparable)pfeature.get("NOMBRE");
155
                        v2 = (Comparable)feature.get("NOMBRE");
156
                        pfeature=feature;
157
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
158
                        count++;
159
                }
160
                assertEquals("Iteration error",2,count);
161

    
162

    
163

    
164
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc");
165
                assertEquals(9, fc.size());
166
                it = fc.iterator();
167
                count=0;
168
                pfeature = (IFeature)it.next();
169
                System.out.println(pfeature.getString("NOMBRE"));
170
                count++;
171
                while (it.hasNext()){
172
                        feature = (IFeature)it.next();
173
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
174
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
175
                        pfeature=feature;
176
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
177
                        System.out.println(pfeature.getString("NOMBRE"));
178
                        count++;
179
                }
180
                assertEquals("Iteration error",9,count);
181

    
182

    
183
                /// CON  EDICION
184

    
185
                fs.startEditing();
186

    
187
                IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType());
188
                newFeature.editing();
189
                newFeature.set("NOMBRE","BuRjaSOT");
190
                newFeature.set("TIPO","MUNICIPIO");
191
                fs.insert(newFeature);
192

    
193
                try {
194
                        fc = (IFeatureCollection)fs.getDataCollection();
195
                } catch (ReadException e1) {
196
                        e1.printStackTrace();
197
                        fail();
198
                }
199

    
200
                assertEquals(10, fc.size());
201

    
202
                try {
203
                        fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null);
204
                } catch (ReadException e1) {
205
                        e1.printStackTrace();
206
                        fail();
207
                }
208

    
209
                assertEquals(3, fc.size());
210

    
211
                it = fc.iterator();
212
                count=0;
213
                while (it.hasNext()){
214
                        feature = (IFeature)it.next();
215
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
216
                        count++;
217
                }
218
                assertEquals("Iteration error",3,count);
219

    
220

    
221
                try {
222
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC");
223
                } catch (ReadException e1) {
224
                        e1.printStackTrace();
225
                        fail();
226
                }
227
                assertEquals(10, fc.size());
228
                it = fc.iterator();
229
                count=0;
230
                pfeature = (IFeature)it.next();
231
                count++;
232
                while (it.hasNext()){
233
                        feature = (IFeature)it.next();
234
                        v1 = (Comparable)pfeature.get("NOMBRE");
235
                        v2 = (Comparable)feature.get("NOMBRE");
236
                        pfeature=feature;
237
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
238
                        count++;
239
                }
240
                assertEquals("Iteration error",10,count);
241

    
242

    
243
                try {
244
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC");
245
                } catch (ReadException e1) {
246
                        e1.printStackTrace();
247
                        fail();
248
                }
249
                assertEquals(10, fc.size());
250
                it = fc.iterator();
251

    
252
                count=0;
253
                pfeature = (IFeature)it.next();
254
                count++;
255
                while (it.hasNext()){
256
                        feature = (IFeature)it.next();
257
                        v1 = (Comparable)pfeature.get("NOMBRE");
258
                        v2 = (Comparable)feature.get("NOMBRE");
259
                        pfeature=feature;
260
                        if (v1!=null && v2!=null)
261
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
262
                        count++;
263
                }
264
                assertEquals("Iteration error",10,count);
265

    
266

    
267
                try {
268
                        fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE");
269
                } catch (ReadException e1) {
270
                        e1.printStackTrace();
271
                        fail();
272
                }
273

    
274
                assertEquals(3, fc.size());
275

    
276
                it = fc.iterator();
277

    
278
                count=0;
279
                pfeature = (IFeature)it.next();
280
                assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b"));
281
                count++;
282
                while (it.hasNext()){
283
                        feature = (IFeature)it.next();
284
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
285
                        v1 = (Comparable)pfeature.get("NOMBRE");
286
                        v2 = (Comparable)feature.get("NOMBRE");
287
                        pfeature=feature;
288
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
289
                        count++;
290
                }
291
                assertEquals("Iteration error",3,count);
292

    
293

    
294

    
295
                try {
296
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc");
297
                } catch (ReadException e1) {
298
                        e1.printStackTrace();
299
                        fail();
300
                }
301
                assertEquals(10, fc.size());
302
                it = fc.iterator();
303
                count=0;
304
                pfeature = (IFeature)it.next();
305
                System.out.println(pfeature.getString("TIPO")+","+pfeature.getString("NOMBRE"));
306
                count++;
307
                while (it.hasNext()){
308
                        feature = (IFeature)it.next();
309
                        System.out.println(feature.getString("TIPO")+","+feature.getString("NOMBRE"));
310
                        v1 = (Comparable)((String)pfeature.get("TIPO")).toLowerCase();
311
                        v2 = (Comparable)((String)feature.get("TIPO")).toLowerCase();
312
                        assertTrue("Short error", (v2.compareTo(v1) >= 0));
313
                        if (v1.compareTo(v2) == 0){
314
                                v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
315
                                v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
316
                                assertTrue("Short error", (v1.compareTo(v2) >= 0));
317
                        }
318
                        pfeature=feature;
319

    
320
//                        System.out.println(pfeature.getString("TIPO")+","+pfeature.getString("NOMBRE"));
321
                        count++;
322
                }
323
                assertEquals("Iteration error",10,count);
324

    
325
                fs.cancelEditing();
326

    
327
                try {
328
                        fs.close();
329
                } catch (CloseException e) {
330
                        e.printStackTrace();
331
                        fail("Exception:" + e);
332
                }
333

    
334

    
335
                System.out.println("======= /DBF ==============");
336
                } catch (OpenException e1) {
337
                        e1.printStackTrace();
338
                        fail();
339
                } catch (ReadException e) {
340
                        // TODO Auto-generated catch block
341
                        e.printStackTrace();
342
                } catch (IsNotFeatureSettingException e) {
343
                        // TODO Auto-generated catch block
344
                        e.printStackTrace();
345
                }
346
        }
347

    
348
        public void testSHP() {
349
                try {
350
                System.out.println("======= SHP ==============");
351
                org.gvsig.data.datastores.vectorial.file.shp.Register.selfRegister();
352
                org.gvsig.data.datastores.vectorial.file.dbf.Register.selfRegister();
353

    
354
                DataManager dsm=DataManager.getManager();
355

    
356

    
357
                IDataStoreParameters dp=dsm.createDataStoreParameters(SHPStore.DATASTORE_NAME);
358
                ((SHPStoreParameters)dp).setFile(shpfile);
359
//                ((SHPStoreParameters)dp).setSHXFile(SHP.getShxFile(shpfile));
360
//                ((SHPStoreParameters)dp).setDBFFile(SHP.getDbfFile(shpfile));
361

    
362

    
363
                driverTest(dp,null,null,true);
364

    
365
                IFeatureStore fs=null;
366
                try {
367
                        fs = (IFeatureStore)dsm.createDataStore(dp);
368
                } catch (InitializeException e) {
369
                        e.printStackTrace();
370
                        fail("Exception:" + e);
371
                }
372

    
373
                assertNotNull("Can't create Feature Store", fs);
374

    
375

    
376
                        fs.open();
377

    
378

    
379
                Iterator it;
380
                IFeatureCollection fc;
381
                Comparable v1,v2;
382
                IFeature feature,pfeature;
383
                long count;
384

    
385

    
386
                fc = (IFeatureCollection)fs.getDataCollection();
387

    
388
                assertEquals(9, fc.size());
389

    
390
                fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null);
391

    
392
                assertEquals(2, fc.size());
393

    
394
                it = fc.iterator();
395
                count=0;
396
                while (it.hasNext()){
397
                        feature = (IFeature)it.next();
398
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
399
                        count++;
400
                }
401
                assertEquals("Iteration error",2,count);
402

    
403

    
404
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE");
405
                assertEquals(9, fc.size());
406
                it = fc.iterator();
407
                count=0;
408
                pfeature = (IFeature)it.next();
409
                count++;
410
                while (it.hasNext()){
411
                        feature = (IFeature)it.next();
412
                        v1 = (Comparable)pfeature.get("NOMBRE");
413
                        v2 = (Comparable)feature.get("NOMBRE");
414
                        pfeature=feature;
415
                        assertTrue("Short error", (v1.compareTo(v2) <= 0));
416
                        count++;
417
                }
418
                assertEquals("Iteration error",9,count);
419

    
420

    
421
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC");
422
                assertEquals(9, fc.size());
423
                it = fc.iterator();
424
                count=0;
425
                pfeature = (IFeature)it.next();
426
                System.out.println(pfeature.getString("NOMBRE"));
427
                count++;
428
                while (it.hasNext()){
429
                        feature = (IFeature)it.next();
430
                        v1 = (Comparable)pfeature.get("NOMBRE");
431
                        v2 = (Comparable)feature.get("NOMBRE");
432
                        pfeature=feature;
433
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
434
                        System.out.println(pfeature.getString("NOMBRE"));
435
                        count++;
436
                }
437
                assertEquals("Iteration error",9,count);
438

    
439

    
440
                fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE ASC");
441

    
442
                assertEquals(2, fc.size());
443

    
444
                it = fc.iterator();
445

    
446
                count=0;
447
                pfeature = (IFeature)it.next();
448
                assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b"));
449
                count++;
450
                while (it.hasNext()){
451
                        feature = (IFeature)it.next();
452
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
453
                        v1 = (Comparable)pfeature.get("NOMBRE");
454
                        v2 = (Comparable)feature.get("NOMBRE");
455
                        pfeature=feature;
456
                        assertTrue("Short error", (v1.compareTo(v2) <= 0));
457
                        count++;
458
                }
459
                assertEquals("Iteration error",2,count);
460

    
461

    
462
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"lower(NOMBRE) ASC");
463
                assertEquals(9, fc.size());
464
                it = fc.iterator();
465
                count=0;
466
                pfeature = (IFeature)it.next();
467
                count++;
468
                while (it.hasNext()){
469
                        feature = (IFeature)it.next();
470
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
471
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
472
                        pfeature=feature;
473
                        assertTrue("Short error", (v1.compareTo(v2) <= 0));
474
                        count++;
475
                }
476
                assertEquals("Iteration error",9,count);
477

    
478

    
479

    
480
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc");
481
                assertEquals(9, fc.size());
482
                it = fc.iterator();
483
                count=0;
484
                pfeature = (IFeature)it.next();
485
                System.out.println(pfeature.getString("NOMBRE"));
486
                count++;
487
                while (it.hasNext()){
488
                        feature = (IFeature)it.next();
489
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
490
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
491
                        pfeature=feature;
492
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
493
                        System.out.println(pfeature.getString("NOMBRE"));
494
                        count++;
495
                }
496
                assertEquals("Iteration error",9,count);
497

    
498

    
499

    
500
                /// CON  EDICION
501

    
502
                fs.startEditing();
503

    
504
                IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType());
505
                newFeature.editing();
506
                newFeature.set("NOMBRE","BuRjaSOT");
507
                newFeature.set("TIPO","MUNICIPIO");
508
                fs.insert(newFeature);
509

    
510

    
511

    
512
                try {
513
                        fc = (IFeatureCollection)fs.getDataCollection();
514
                } catch (ReadException e1) {
515
                        e1.printStackTrace();
516
                        fail();
517
                }
518

    
519
                assertEquals(10, fc.size());
520

    
521
                try {
522
                        fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null);
523
                } catch (ReadException e1) {
524
                        e1.printStackTrace();
525
                        fail();
526
                }
527

    
528
                assertEquals(3, fc.size());
529

    
530
                it = fc.iterator();
531
                count=0;
532
                while (it.hasNext()){
533
                        feature = (IFeature)it.next();
534
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
535
                        count++;
536
                }
537
                assertEquals("Iteration error",3,count);
538

    
539

    
540
                try {
541
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC");
542
                } catch (ReadException e1) {
543
                        e1.printStackTrace();
544
                        fail();
545
                }
546
                assertEquals(10, fc.size());
547
                it = fc.iterator();
548
                count=0;
549
                pfeature = (IFeature)it.next();
550
                count++;
551
                while (it.hasNext()){
552
                        feature = (IFeature)it.next();
553
                        v1 = (Comparable)pfeature.get("NOMBRE");
554
                        v2 = (Comparable)feature.get("NOMBRE");
555
                        pfeature=feature;
556
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
557
                        count++;
558
                }
559
                assertEquals("Iteration error",10,count);
560

    
561

    
562
                try {
563
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC");
564
                } catch (ReadException e1) {
565
                        e1.printStackTrace();
566
                        fail();
567
                }
568
                assertEquals(10, fc.size());
569
                it = fc.iterator();
570

    
571
                count=0;
572
                pfeature = (IFeature)it.next();
573
                count++;
574
                while (it.hasNext()){
575
                        feature = (IFeature)it.next();
576
                        v1 = (Comparable)pfeature.get("NOMBRE");
577
                        v2 = (Comparable)feature.get("NOMBRE");
578
                        pfeature=feature;
579
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
580
                        count++;
581
                }
582
                assertEquals("Iteration error",10,count);
583

    
584

    
585
                try {
586
                        fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE");
587
                } catch (ReadException e1) {
588
                        e1.printStackTrace();
589
                        fail();
590
                }
591

    
592
                assertEquals(3, fc.size());
593

    
594
                it = fc.iterator();
595

    
596
                count=0;
597
                pfeature = (IFeature)it.next();
598
                assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b"));
599
                count++;
600
                while (it.hasNext()){
601
                        feature = (IFeature)it.next();
602
                        assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b"));
603
                        v1 = (Comparable)pfeature.get("NOMBRE");
604
                        v2 = (Comparable)feature.get("NOMBRE");
605
                        pfeature=feature;
606
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
607
                        count++;
608
                }
609
                assertEquals("Iteration error",3,count);
610

    
611

    
612

    
613
                try {
614
                        fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc");
615
                } catch (ReadException e1) {
616
                        e1.printStackTrace();
617
                        fail();
618
                }
619
                assertEquals(10, fc.size());
620
                it = fc.iterator();
621
                count=0;
622
                pfeature = (IFeature)it.next();
623
                System.out.println(pfeature.getString("NOMBRE"));
624
                count++;
625
                while (it.hasNext()){
626
                        feature = (IFeature)it.next();
627
                        v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase();
628
                        v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase();
629
                        pfeature=feature;
630
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
631
                        System.out.println(pfeature.getString("NOMBRE"));
632
                        count++;
633
                }
634
                assertEquals("Iteration error",10,count);
635

    
636

    
637

    
638

    
639
                fs.cancelEditing();
640

    
641

    
642

    
643
                try {
644
                        fs.close();
645
                } catch (CloseException e) {
646
                        e.printStackTrace();
647
                        fail("Exception:" + e);
648
                }
649

    
650

    
651

    
652
                System.out.println("======= /SHP ==============");
653
                } catch (OpenException e1) {
654
                        e1.printStackTrace();
655
                        fail();
656
                } catch (ReadException e) {
657
                        // TODO Auto-generated catch block
658
                        e.printStackTrace();
659
                } catch (IsNotFeatureSettingException e) {
660
                        // TODO Auto-generated catch block
661
                        e.printStackTrace();
662
                }
663
        }
664

    
665
        public void testDXF() {
666
                try {
667
                System.out.println("======= DXF ==============");
668
                org.gvsig.data.datastores.vectorial.file.dxf.Register.selfRegister();
669

    
670
                DataManager dsm=DataManager.getManager();
671

    
672

    
673
                IDataStoreParameters dp=dsm.createDataStoreParameters(DXFStore.DATASTORE_NAME);
674
                ((DXFStoreParameters)dp).setFile(dxffile);
675
                IProjection proj = CRSFactory.getCRS("EPSG:23030");
676
                ((DXFStoreParameters)dp).setProjection(proj);
677
                driverTest(dp,null,null,true);
678

    
679
                IFeatureStore fs=null;
680
                try {
681
                        fs = (IFeatureStore)dsm.createDataStore(dp);
682
                } catch (InitializeException e) {
683
                        e.printStackTrace();
684
                        fail("Exception:" + e);
685
                }
686
                assertNotNull("Can't create Feature Store", fs);
687

    
688

    
689
                        fs.open();
690

    
691

    
692
                Iterator it;
693
                IFeatureCollection fc;
694
                Comparable v1,v2;
695
                IFeature feature,pfeature;
696
                long count;
697

    
698

    
699
                fc = (IFeatureCollection)fs.getDataCollection();
700

    
701
                assertEquals(10, fc.size());
702

    
703
                fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null);
704

    
705
                assertEquals(2, fc.size());
706

    
707
                it = fc.iterator();
708
                count=0;
709
                while (it.hasNext()){
710
                        feature = (IFeature)it.next();
711
                        assertTrue("Filter error",feature.getInt("Color")>7);
712
                        count++;
713
                }
714
                assertEquals("Iteration error",2,count);
715

    
716

    
717
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC");
718
                assertEquals(10, fc.size());
719
                it = fc.iterator();
720
                count=0;
721
                pfeature = (IFeature)it.next();
722
                count++;
723
                while (it.hasNext()){
724
                        feature = (IFeature)it.next();
725
                        v1 = (Comparable)pfeature.get("Layer");
726
                        v2 = (Comparable)feature.get("Layer");
727
                        pfeature=feature;
728
                        assertTrue("Short error", (v1.compareTo(v1) <= 0));
729
                        count++;
730
                }
731
                assertEquals("Iteration error",10,count);
732

    
733

    
734
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC");
735
                assertEquals(10, fc.size());
736
                it = fc.iterator();
737

    
738
                count=0;
739
                pfeature = (IFeature)it.next();
740
                count++;
741
                while (it.hasNext()){
742
                        feature = (IFeature)it.next();
743
                        v1 = (Comparable)pfeature.get("Layer");
744
                        v2 = (Comparable)feature.get("Layer");
745
                        pfeature=feature;
746
                        assertTrue("Short error", (v1.compareTo(v1) >= 0));
747
                        count++;
748
                }
749
                assertEquals("Iteration error",10,count);
750

    
751

    
752
                fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC");
753

    
754
                assertEquals(2, fc.size());
755

    
756
                it = fc.iterator();
757

    
758
                count=0;
759
                pfeature = (IFeature)it.next();
760
                assertTrue(pfeature.getInt("Color")>7);
761
                count++;
762
                while (it.hasNext()){
763
                        feature = (IFeature)it.next();
764
                        assertTrue("Filter error",feature.getInt("Color")>7);
765
                        v1 = (Comparable)pfeature.get("Color");
766
                        v2 = (Comparable)feature.get("Color");
767
                        pfeature=feature;
768
                        Integer i1=(Integer)v1;
769
                        Integer i2=(Integer)v2;
770
                        assertTrue("Short error", (i1.intValue()>i2.intValue()));
771
                        count++;
772
                }
773
                assertEquals("Iteration error",2,count);
774

    
775

    
776

    
777
//                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
778
//                assertEquals(10, fc.size());
779
//                it = fc.iterator();
780
//                count=0;
781
//                pfeature = (IFeature)it.next();
782
//                System.out.println(pfeature.getString("Layer"));
783
//                count++;
784
//                while (it.hasNext()){
785
//                        feature = (IFeature)it.next();
786
//                        v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
787
//                        v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
788
//                        pfeature=feature;
789
//                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
790
//                        System.out.println(pfeature.getString("Layer"));
791
//                        count++;
792
//                }
793
//                assertEquals("Iteration error",10,count);
794

    
795

    
796
                try {
797
                        fs.close();
798
                } catch (CloseException e) {
799
                        e.printStackTrace();
800
                        fail("Exception:" + e);
801
                }
802

    
803

    
804
                System.out.println("======= /DXF ==============");
805
                } catch (OpenException e1) {
806
                        e1.printStackTrace();
807
                        fail();
808
                } catch (ReadException e) {
809
                        // TODO Auto-generated catch block
810
                        e.printStackTrace();
811
                }
812
        }
813

    
814
        public void testDGN() {
815
                try {
816
                System.out.println("======= DGN ==============");
817
                org.gvsig.data.datastores.vectorial.file.dgn.Register.selfRegister();
818

    
819
                DataManager dsm=DataManager.getManager();
820

    
821

    
822
                IDataStoreParameters dp=dsm.createDataStoreParameters(DGNStore.DATASTORE_NAME);
823
                ((DGNStoreParameters)dp).setFile(dgnfile);
824
                driverTest(dp,null,null,true);
825
                IFeatureStore fs=null;
826
                try {
827
                        fs = (IFeatureStore)dsm.createDataStore(dp);
828
                } catch (InitializeException e) {
829
                        e.printStackTrace();
830
                        fail("Exception:" + e);
831
                }
832
                assertNotNull("Can't create Feature Store", fs);
833

    
834

    
835
                        fs.open();
836

    
837

    
838
                Iterator it;
839
                IFeatureCollection fc;
840
                Comparable v1,v2;
841
                IFeature feature,pfeature;
842
                long count;
843

    
844

    
845
                fc = (IFeatureCollection)fs.getDataCollection();
846

    
847
                assertEquals(14646, fc.size());
848

    
849
                fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null);
850

    
851
                assertEquals(7352, fc.size());
852

    
853
                it = fc.iterator();
854
                count=0;
855
                while (it.hasNext()){
856
                        feature = (IFeature)it.next();
857
                        assertTrue("Filter error",feature.getInt("Color")>=7);
858
                        count++;
859
                }
860
                assertEquals("Iteration error",7352,count);
861

    
862

    
863
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC");
864
                assertEquals(14646, fc.size());
865
                it = fc.iterator();
866
                count=0;
867
                pfeature = (IFeature)it.next();
868
                count++;
869
                while (it.hasNext()){
870
                        feature = (IFeature)it.next();
871
                        v1 = (Comparable)pfeature.get("Layer");
872
                        v2 = (Comparable)feature.get("Layer");
873
                        if (v2==null)
874
                                System.out.println("null");
875
                        assertTrue("Short error", (v1.compareTo(v2) <= 0));
876
                        pfeature=feature;
877
                        count++;
878
                }
879
                assertEquals("Iteration error",14646,count);
880

    
881

    
882
                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC");
883
                assertEquals(14646, fc.size());
884
                it = fc.iterator();
885

    
886
                count=0;
887
                pfeature = (IFeature)it.next();
888
                count++;
889
                while (it.hasNext()){
890
                        feature = (IFeature)it.next();
891
                        v1 = (Comparable)pfeature.get("Layer");
892
                        v2 = (Comparable)feature.get("Layer");
893
                        assertTrue("Short error", (v1.compareTo(v2) >= 0));
894
                        pfeature=feature;
895
                        count++;
896
                }
897
                assertEquals("Iteration error",14646,count);
898

    
899

    
900
                fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC");
901

    
902
                assertEquals(7352, fc.size());
903

    
904
                it = fc.iterator();
905

    
906
                count=0;
907
                pfeature = (IFeature)it.next();
908
                assertTrue(pfeature.getInt("Color")>7);
909
                count++;
910
                while (it.hasNext()){
911
                        feature = (IFeature)it.next();
912
                        assertTrue("Filter error",feature.getInt("Color")>7);
913
                        v1 = (Comparable)pfeature.get("Layer");
914
                        v2 = (Comparable)feature.get("Layer");
915
                        pfeature=feature;
916
                        Integer i1=(Integer)v1;
917
                        Integer i2=(Integer)v2;
918
                        assertTrue("Short error", (i1.intValue()<=i2.intValue()));
919
                        count++;
920
                }
921
                assertEquals("Iteration error",7352,count);
922

    
923

    
924

    
925
//                fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
926
//                assertEquals(10, fc.size());
927
//                it = fc.iterator();
928
//                count=0;
929
//                pfeature = (IFeature)it.next();
930
//                System.out.println(pfeature.getString("Layer"));
931
//                count++;
932
//                while (it.hasNext()){
933
//                        feature = (IFeature)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

    
943

    
944
                try {
945
                        fs.close();
946
                } catch (CloseException e) {
947
                        e.printStackTrace();
948
                        fail("Exception:" + e);
949
                }
950

    
951

    
952
                System.out.println("======= /DGN ==============");
953
                } catch (OpenException e1) {
954
                        e1.printStackTrace();
955
                        fail();
956
                } catch (ReadException e) {
957
                        // TODO Auto-generated catch block
958
                        e.printStackTrace();
959
                }
960
        }
961

    
962

    
963

    
964

    
965

    
966

    
967
//        private IFeatureStore createFeatureStore(IDriverParameters dp){
968
//                DataSourceManager dsm=DataSourceManager.getManager();
969
//
970
//                IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
971
//
972
//                ((IDriverStoreParameters)dsp).setDriverParameters(dp);
973
//                IFeatureStore fs=null;
974
//                try {
975
//                        fs = (IFeatureStore)dsm.createDataStore(dsp);
976
//                } catch (InitializeException e) {
977
//                        e.printStackTrace();
978
//                        fail("Exception:" + e);
979
//                }
980
//                return fs;
981
//
982
//        }
983

    
984

    
985
        private void driverTest(IDataStoreParameters dp,String filter, String order,boolean testEdit){
986
                DataManager dsm=DataManager.getManager();
987

    
988
//                IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
989

    
990
//                ((IDriverStoreParameters)dsp).setDriverParameters(dp);
991
//                IFeatureStore fs=createFeatureStore(dp);
992
                IFeatureStore fs=null;
993
                try {
994
                        fs = (IFeatureStore)dsm.createDataStore(dp);
995
                } catch (InitializeException e) {
996
                        e.printStackTrace();
997
                        fail("Exception:" + e);
998
                }
999
                try {
1000
                        fs.open();
1001
                } catch (OpenException e2) {
1002
                        e2.printStackTrace();
1003
                        fail();
1004
                }
1005

    
1006
                if (fs.isEditable() && testEdit) {
1007
                        try {
1008
                                fs.startEditing();
1009
                                if (fs.canAlterFeatureType()){
1010
                                        IFeatureType featureType=fs.getDefaultFeatureType();
1011
//                                        DefaultAttributeDescriptor dad=new DefaultAttributeDescriptor();
1012
//                                        dad.loading();
1013
//                                        dad.setName("Prueba1");
1014
//                                        dad.setDefaultValue("11p");
1015
//                                        dad.setSize(10);
1016
//                                        dad.setType(IFeatureAttributeDescriptor.TYPE_STRING);
1017
//                                        dad.stopLoading();
1018
//                                        fs.insert(dad);
1019
//                                        fs.delete((IFeatureAttributeDescriptor)featureType.get(featureType.getFieldIndex("Prueba1")));
1020
                                        DefaultAttributeDescriptor dad2=(DefaultAttributeDescriptor)featureType.get(featureType.getFieldIndex("TIPO"));
1021
                                        dad2.editing();
1022
//                                        dad2.setName("TIPO");
1023
                                        dad2.setDefaultValue("Tipop");
1024
//                                        dad2.setSize(10);
1025
                                        dad2.setType(IFeatureAttributeDescriptor.TYPE_STRING);
1026
                                        fs.update(dad2);
1027
                                }
1028
                        } catch (ReadException e) {
1029
                                e.printStackTrace();
1030
                                fail();
1031
                        }
1032
                        catch (IsNotAttributeSettingException e) {
1033
                                // TODO Auto-generated catch block
1034
                                e.printStackTrace();
1035
                        }
1036
                        try {
1037
                        IFeature feature1 = fs.createDefaultFeature(false);
1038

    
1039
                        IFeature feature2 = fs.createDefaultFeature(false);
1040
                        IFeature feature3 = fs.createDefaultFeature(false);
1041

    
1042
                        fs.insert(feature1);
1043
                        fs.insert(feature2);
1044

    
1045
                        feature1.editing();
1046
                        feature1.set(1,"hola");
1047

    
1048
                        fs.update(feature1);
1049
                        fs.delete(feature3);
1050
                        fs.delete(feature2);
1051
                        } catch (IsNotFeatureSettingException e) {
1052
                                // TODO Auto-generated catch block
1053
                                e.printStackTrace();
1054
                        }
1055
                }
1056

    
1057
                //Mostrar por consola todos los registros.
1058
                IFeatureType ft= fs.getDefaultFeatureType();
1059
                IFeatureCollection featureCollection=null;
1060
//                featureCollection = (IFeatureCollection)fs.getDataCollection();
1061
//                featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"NOMBRE = 'CALPE'",null);
1062
//                featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"AREA > 3.2213163729E7 and AREA < 3.2213163749E7",null);
1063
                try {
1064
                        featureCollection = (IFeatureCollection)fs.getDataCollection(ft,filter,order);
1065
                } catch (ReadException e2) {
1066
                        // TODO Auto-generated catch block
1067
                        e2.printStackTrace();
1068
                }
1069

    
1070
                PrintlnFeaturesVisitor visitor=new PrintlnFeaturesVisitor(ft);
1071
                try {
1072
                        featureCollection.accept(visitor);
1073
                } catch (BaseException e1) {
1074
                        e1.printStackTrace();
1075
                        fail("Exception: "+e1);
1076
                }
1077

    
1078
                featureCollection.dispose();
1079

    
1080
                if (fs.isEditable() && testEdit){
1081
                        try {
1082
                                fs.finishEditing();
1083
                        } catch (WriteException e) {
1084
                                e.printStackTrace();
1085
                                fail("Exception: "+e);
1086
                        } catch (ReadException e) {
1087
                                e.printStackTrace();
1088
                                fail("Exception: "+e);
1089
                        }
1090
                }
1091
                try {
1092
                        fs.close();
1093
                } catch (CloseException e) {
1094
                        e.printStackTrace();
1095
                        fail("Exception: "+e);
1096
                }
1097
                try {
1098
                        fs.dispose();
1099
                } catch (CloseException e) {
1100
                        // TODO Auto-generated catch block
1101
                        e.printStackTrace();
1102
                }
1103
        }
1104
}