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 |
package org.gvsig.data.datastores.vectorial.driver; |
---|---|
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.DataSourceManager; |
10 |
import org.gvsig.data.IDataStoreParameters; |
11 |
import org.gvsig.data.datastores.vectorial.driver.dbf.DBFDriverParameters; |
12 |
import org.gvsig.data.datastores.vectorial.driver.dgn.DGNDriverParameters; |
13 |
import org.gvsig.data.datastores.vectorial.driver.dxf.DXFDriverParameters; |
14 |
import org.gvsig.data.datastores.vectorial.driver.shp.ShpDriverParameters; |
15 |
import org.gvsig.data.datastores.vectorial.driver.shp.fileshp.SHP; |
16 |
import org.gvsig.data.exception.CloseException; |
17 |
import org.gvsig.data.exception.InitializeException; |
18 |
import org.gvsig.data.exception.OpenException; |
19 |
import org.gvsig.data.exception.ReadException; |
20 |
import org.gvsig.data.exception.WriteException; |
21 |
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 |
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor; |
26 |
import org.gvsig.exceptions.BaseException; |
27 |
|
28 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
29 |
|
30 |
public class DataStoreTest extends TestCase { |
31 |
|
32 |
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 |
private File dxffile = new File(DataStoreTest.class.getResource("data/prueba.dxf").getFile()); |
35 |
private File dgnfile = new File(DataStoreTest.class.getResource("data/cv_300_todo.dgn").getFile()); |
36 |
|
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 |
try {
|
48 |
System.out.println("======= DBF =============="); |
49 |
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 |
driverTest(dp,null,null,true); |
59 |
|
60 |
IFeatureStore fs = createFeatureStore(dp); |
61 |
assertNotNull("Can't create Feature Store", fs);
|
62 |
|
63 |
|
64 |
fs.open(); |
65 |
|
66 |
|
67 |
Iterator it;
|
68 |
IFeatureCollection fc; |
69 |
Comparable v1,v2;
|
70 |
IFeature feature,pfeature; |
71 |
long count;
|
72 |
|
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 |
assertEquals(2, fc.size());
|
81 |
|
82 |
it = fc.iterator(); |
83 |
count=0;
|
84 |
while (it.hasNext()){
|
85 |
feature = (IFeature)it.next(); |
86 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
87 |
count++; |
88 |
} |
89 |
assertEquals("Iteration error",2,count); |
90 |
|
91 |
|
92 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
93 |
assertEquals(9, fc.size());
|
94 |
it = fc.iterator(); |
95 |
count=0;
|
96 |
pfeature = (IFeature)it.next(); |
97 |
count++; |
98 |
while (it.hasNext()){
|
99 |
feature = (IFeature)it.next(); |
100 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
101 |
v2 = (Comparable)feature.get("NOMBRE"); |
102 |
pfeature=feature; |
103 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
104 |
count++; |
105 |
} |
106 |
assertEquals("Iteration error",9,count); |
107 |
|
108 |
|
109 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
110 |
assertEquals(9, fc.size());
|
111 |
it = fc.iterator(); |
112 |
|
113 |
count=0;
|
114 |
pfeature = (IFeature)it.next(); |
115 |
count++; |
116 |
while (it.hasNext()){
|
117 |
feature = (IFeature)it.next(); |
118 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
119 |
v2 = (Comparable)feature.get("NOMBRE"); |
120 |
pfeature=feature; |
121 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
122 |
count++; |
123 |
} |
124 |
assertEquals("Iteration error",9,count); |
125 |
|
126 |
|
127 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
128 |
|
129 |
assertEquals(2, fc.size());
|
130 |
|
131 |
it = fc.iterator(); |
132 |
|
133 |
count=0;
|
134 |
pfeature = (IFeature)it.next(); |
135 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
136 |
count++; |
137 |
while (it.hasNext()){
|
138 |
feature = (IFeature)it.next(); |
139 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
140 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
141 |
v2 = (Comparable)feature.get("NOMBRE"); |
142 |
pfeature=feature; |
143 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
144 |
count++; |
145 |
} |
146 |
assertEquals("Iteration error",2,count); |
147 |
|
148 |
|
149 |
|
150 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
151 |
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 |
/// 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 |
try {
|
181 |
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 |
fs.close(); |
315 |
} catch (CloseException e) {
|
316 |
e.printStackTrace(); |
317 |
fail("Exception:" + e);
|
318 |
} |
319 |
|
320 |
|
321 |
System.out.println("======= /DBF =============="); |
322 |
} catch (OpenException e1) {
|
323 |
e1.printStackTrace(); |
324 |
fail(); |
325 |
} catch (ReadException e) {
|
326 |
// TODO Auto-generated catch block
|
327 |
e.printStackTrace(); |
328 |
} |
329 |
} |
330 |
|
331 |
public void testSHP() { |
332 |
try {
|
333 |
System.out.println("======= SHP =============="); |
334 |
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 |
((ShpDriverParameters)dp).setSHXFile(SHP.getShxFile(shpfile)); |
344 |
((ShpDriverParameters)dp).setDBFFile(SHP.getDbfFile(shpfile)); |
345 |
|
346 |
|
347 |
driverTest(dp,null,null,true); |
348 |
|
349 |
|
350 |
|
351 |
|
352 |
IFeatureStore fs = createFeatureStore(dp); |
353 |
assertNotNull("Can't create Feature Store", fs);
|
354 |
|
355 |
|
356 |
fs.open(); |
357 |
|
358 |
|
359 |
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 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE"); |
385 |
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 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
402 |
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 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE ASC"); |
421 |
|
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 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"lower(NOMBRE) ASC"); |
443 |
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 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
461 |
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 |
|
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 |
try {
|
492 |
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 |
fs.close(); |
624 |
} catch (CloseException e) {
|
625 |
e.printStackTrace(); |
626 |
fail("Exception:" + e);
|
627 |
} |
628 |
|
629 |
|
630 |
|
631 |
System.out.println("======= /SHP =============="); |
632 |
} catch (OpenException e1) {
|
633 |
e1.printStackTrace(); |
634 |
fail(); |
635 |
} catch (ReadException e) {
|
636 |
// TODO Auto-generated catch block
|
637 |
e.printStackTrace(); |
638 |
} |
639 |
} |
640 |
|
641 |
public void testDXF() { |
642 |
try {
|
643 |
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 |
|
660 |
fs.open(); |
661 |
|
662 |
|
663 |
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 |
} catch (OpenException e1) {
|
777 |
e1.printStackTrace(); |
778 |
fail(); |
779 |
} catch (ReadException e) {
|
780 |
// TODO Auto-generated catch block
|
781 |
e.printStackTrace(); |
782 |
} |
783 |
} |
784 |
|
785 |
public void testDGN() { |
786 |
try {
|
787 |
System.out.println("======= DGN =============="); |
788 |
org.gvsig.data.datastores.vectorial.driver.dgn.Register.selfRegister(); |
789 |
org.gvsig.data.datastores.vectorial.driver.Register.selfRegister(); |
790 |
|
791 |
DataSourceManager dsm=DataSourceManager.getManager(); |
792 |
|
793 |
|
794 |
IDriverParameters dp=dsm.createDriverParameters("dgn");
|
795 |
((DGNDriverParameters)dp).setDGNFile(dgnfile); |
796 |
driverTest(dp,null,null,true); |
797 |
|
798 |
IFeatureStore fs = createFeatureStore(dp); |
799 |
assertNotNull("Can't create Feature Store", fs);
|
800 |
|
801 |
|
802 |
fs.open(); |
803 |
|
804 |
|
805 |
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 |
} catch (OpenException e1) {
|
919 |
e1.printStackTrace(); |
920 |
fail(); |
921 |
} catch (ReadException e) {
|
922 |
// TODO Auto-generated catch block
|
923 |
e.printStackTrace(); |
924 |
} |
925 |
} |
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
private IFeatureStore createFeatureStore(IDriverParameters dp){
|
933 |
DataSourceManager dsm=DataSourceManager.getManager(); |
934 |
|
935 |
IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME); |
936 |
|
937 |
((IDriverStoreParameters)dsp).setDriverParameters(dp); |
938 |
IFeatureStore fs=null;
|
939 |
try {
|
940 |
fs = (IFeatureStore)dsm.createDataStore(dsp); |
941 |
} catch (InitializeException e) {
|
942 |
e.printStackTrace(); |
943 |
fail("Exception:" + e);
|
944 |
} |
945 |
return fs;
|
946 |
|
947 |
} |
948 |
|
949 |
|
950 |
private void driverTest(IDriverParameters dp,String filter, String order,boolean testEdit){ |
951 |
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 |
try {
|
959 |
fs.open(); |
960 |
} catch (OpenException e2) {
|
961 |
e2.printStackTrace(); |
962 |
fail(); |
963 |
} |
964 |
|
965 |
if (fs.isEditable() && testEdit) {
|
966 |
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 |
//Mostrar por consola todos los registros.
|
981 |
IFeatureType ft= fs.getDefaultFeatureType(); |
982 |
IFeatureCollection featureCollection=null;
|
983 |
// 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 |
try {
|
987 |
featureCollection = (IFeatureCollection)fs.getDataCollection(ft,filter,order); |
988 |
} catch (ReadException e2) {
|
989 |
// TODO Auto-generated catch block
|
990 |
e2.printStackTrace(); |
991 |
} |
992 |
|
993 |
PrintlnFeaturesVisitor visitor=new PrintlnFeaturesVisitor(ft);
|
994 |
try {
|
995 |
featureCollection.accept(visitor); |
996 |
} catch (BaseException e1) {
|
997 |
e1.printStackTrace(); |
998 |
fail("Exception: "+e1);
|
999 |
} |
1000 |
|
1001 |
if (fs.isEditable() && testEdit){
|
1002 |
try {
|
1003 |
fs.finishEditing(); |
1004 |
} catch (WriteException e) {
|
1005 |
e.printStackTrace(); |
1006 |
fail("Exception: "+e);
|
1007 |
} catch (ReadException e) {
|
1008 |
e.printStackTrace(); |
1009 |
fail("Exception: "+e);
|
1010 |
} |
1011 |
} |
1012 |
try {
|
1013 |
fs.close(); |
1014 |
} catch (CloseException e) {
|
1015 |
e.printStackTrace(); |
1016 |
fail("Exception: "+e);
|
1017 |
} |
1018 |
fs.dispose(); |
1019 |
} |
1020 |
} |