svn-gvsig-desktop / trunk / libraries / libFMap_dataFile / src-test / org / gvsig / data / datastores / vectorial / file / DataStoreTest.java @ 20744
History | View | Annotate | Download (35 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.IDataCollection; |
11 |
import org.gvsig.data.IDataStoreParameters; |
12 |
import org.gvsig.data.Resource; |
13 |
import org.gvsig.data.ResourceManager; |
14 |
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStore; |
15 |
import org.gvsig.data.datastores.vectorial.file.dbf.DBFStoreParameters; |
16 |
import org.gvsig.data.datastores.vectorial.file.dgn.DGNStore; |
17 |
import org.gvsig.data.datastores.vectorial.file.dgn.DGNStoreParameters; |
18 |
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStore; |
19 |
import org.gvsig.data.datastores.vectorial.file.dxf.DXFStoreParameters; |
20 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStore; |
21 |
import org.gvsig.data.datastores.vectorial.file.shp.SHPStoreParameters; |
22 |
import org.gvsig.data.exception.CloseException; |
23 |
import org.gvsig.data.exception.DataException; |
24 |
import org.gvsig.data.exception.InitializeException; |
25 |
import org.gvsig.data.exception.OpenException; |
26 |
import org.gvsig.data.exception.ReadException; |
27 |
import org.gvsig.data.exception.WriteException; |
28 |
import org.gvsig.data.vectorial.AttributeDescriptor; |
29 |
import org.gvsig.data.vectorial.FeatureStore; |
30 |
import org.gvsig.data.vectorial.IFeature; |
31 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
32 |
import org.gvsig.data.vectorial.IFeatureCollection; |
33 |
import org.gvsig.data.vectorial.IFeatureStore; |
34 |
import org.gvsig.data.vectorial.IFeatureType; |
35 |
import org.gvsig.data.vectorial.IsNotAttributeSettingException; |
36 |
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor; |
37 |
import org.gvsig.exceptions.BaseException; |
38 |
import org.gvsig.util.observer.IObserver; |
39 |
|
40 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
41 |
|
42 |
public class DataStoreTest extends TestCase { |
43 |
|
44 |
private File dbffile = new File(DataStoreTest.class.getResource("data/prueba.dbf").getFile()); |
45 |
private File shpfile = new File(DataStoreTest.class.getResource("data/prueba.shp").getFile()); |
46 |
private File dxffile = new File(DataStoreTest.class.getResource("data/prueba.dxf").getFile()); |
47 |
private File dgnfile = new File(DataStoreTest.class.getResource("data/prueba.dgn").getFile()); |
48 |
|
49 |
public static void main(String[] args) { |
50 |
junit.textui.TestRunner.run(DataStoreTest.class); |
51 |
} |
52 |
|
53 |
protected void setUp() throws Exception { |
54 |
super.setUp();
|
55 |
|
56 |
} |
57 |
|
58 |
public void testDBF() { |
59 |
try {
|
60 |
System.out.println("======= DBF =============="); |
61 |
org.gvsig.data.datastores.vectorial.file.dbf.Register.selfRegister(); |
62 |
|
63 |
DataManager dsm=DataManager.getManager(); |
64 |
|
65 |
|
66 |
IDataStoreParameters dp=dsm.createDataStoreParameters(DBFStore.DATASTORE_NAME); |
67 |
((DBFStoreParameters)dp).setFile(dbffile); |
68 |
|
69 |
driverTest(dp,null,null,true); |
70 |
IFeatureStore fs=null;
|
71 |
try {
|
72 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
73 |
} catch (InitializeException e) {
|
74 |
e.printStackTrace(); |
75 |
fail("Exception:" + e);
|
76 |
} |
77 |
assertNotNull("Can't create Feature Store", fs);
|
78 |
|
79 |
|
80 |
fs.open(); |
81 |
|
82 |
|
83 |
Iterator it;
|
84 |
IFeatureCollection fc; |
85 |
Comparable v1,v2;
|
86 |
IFeature feature,pfeature; |
87 |
long count;
|
88 |
|
89 |
|
90 |
fc = (IFeatureCollection)fs.getDataCollection(); |
91 |
|
92 |
assertEquals(9, fc.size());
|
93 |
|
94 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
95 |
|
96 |
assertEquals(2, fc.size());
|
97 |
|
98 |
it = fc.iterator(); |
99 |
count=0;
|
100 |
while (it.hasNext()){
|
101 |
feature = (IFeature)it.next(); |
102 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
103 |
count++; |
104 |
} |
105 |
assertEquals("Iteration error",2,count); |
106 |
|
107 |
|
108 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
109 |
assertEquals(9, fc.size());
|
110 |
it = fc.iterator(); |
111 |
count=0;
|
112 |
pfeature = (IFeature)it.next(); |
113 |
count++; |
114 |
while (it.hasNext()){
|
115 |
feature = (IFeature)it.next(); |
116 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
117 |
v2 = (Comparable)feature.get("NOMBRE"); |
118 |
pfeature=feature; |
119 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
120 |
count++; |
121 |
} |
122 |
assertEquals("Iteration error",9,count); |
123 |
|
124 |
|
125 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
126 |
assertEquals(9, fc.size());
|
127 |
it = fc.iterator(); |
128 |
|
129 |
count=0;
|
130 |
pfeature = (IFeature)it.next(); |
131 |
count++; |
132 |
while (it.hasNext()){
|
133 |
feature = (IFeature)it.next(); |
134 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
135 |
v2 = (Comparable)feature.get("NOMBRE"); |
136 |
pfeature=feature; |
137 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
138 |
count++; |
139 |
} |
140 |
assertEquals("Iteration error",9,count); |
141 |
|
142 |
|
143 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
144 |
|
145 |
assertEquals(2, fc.size());
|
146 |
|
147 |
it = fc.iterator(); |
148 |
|
149 |
count=0;
|
150 |
pfeature = (IFeature)it.next(); |
151 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
152 |
count++; |
153 |
while (it.hasNext()){
|
154 |
feature = (IFeature)it.next(); |
155 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
156 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
157 |
v2 = (Comparable)feature.get("NOMBRE"); |
158 |
pfeature=feature; |
159 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
160 |
count++; |
161 |
} |
162 |
assertEquals("Iteration error",2,count); |
163 |
|
164 |
|
165 |
|
166 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
167 |
assertEquals(9, fc.size());
|
168 |
it = fc.iterator(); |
169 |
count=0;
|
170 |
pfeature = (IFeature)it.next(); |
171 |
System.out.println(pfeature.getString("NOMBRE")); |
172 |
count++; |
173 |
while (it.hasNext()){
|
174 |
feature = (IFeature)it.next(); |
175 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
176 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
177 |
pfeature=feature; |
178 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
179 |
System.out.println(pfeature.getString("NOMBRE")); |
180 |
count++; |
181 |
} |
182 |
assertEquals("Iteration error",9,count); |
183 |
|
184 |
|
185 |
/// CON EDICION
|
186 |
|
187 |
fs.startEditing(); |
188 |
|
189 |
IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType()); |
190 |
newFeature.editing(); |
191 |
newFeature.set("NOMBRE","BuRjaSOT"); |
192 |
newFeature.set("TIPO","MUNICIPIO"); |
193 |
fs.insert(newFeature); |
194 |
|
195 |
try {
|
196 |
fc = (IFeatureCollection)fs.getDataCollection(); |
197 |
} catch (ReadException e1) {
|
198 |
e1.printStackTrace(); |
199 |
fail(); |
200 |
} |
201 |
|
202 |
assertEquals(10, fc.size());
|
203 |
|
204 |
try {
|
205 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
206 |
} catch (ReadException e1) {
|
207 |
e1.printStackTrace(); |
208 |
fail(); |
209 |
} |
210 |
|
211 |
assertEquals(3, fc.size());
|
212 |
|
213 |
it = fc.iterator(); |
214 |
count=0;
|
215 |
while (it.hasNext()){
|
216 |
feature = (IFeature)it.next(); |
217 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
218 |
count++; |
219 |
} |
220 |
assertEquals("Iteration error",3,count); |
221 |
|
222 |
|
223 |
try {
|
224 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
225 |
} catch (ReadException e1) {
|
226 |
e1.printStackTrace(); |
227 |
fail(); |
228 |
} |
229 |
assertEquals(10, fc.size());
|
230 |
it = fc.iterator(); |
231 |
count=0;
|
232 |
pfeature = (IFeature)it.next(); |
233 |
count++; |
234 |
while (it.hasNext()){
|
235 |
feature = (IFeature)it.next(); |
236 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
237 |
v2 = (Comparable)feature.get("NOMBRE"); |
238 |
pfeature=feature; |
239 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
240 |
count++; |
241 |
} |
242 |
assertEquals("Iteration error",10,count); |
243 |
|
244 |
|
245 |
try {
|
246 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
247 |
} catch (ReadException e1) {
|
248 |
e1.printStackTrace(); |
249 |
fail(); |
250 |
} |
251 |
assertEquals(10, fc.size());
|
252 |
it = fc.iterator(); |
253 |
|
254 |
count=0;
|
255 |
pfeature = (IFeature)it.next(); |
256 |
count++; |
257 |
while (it.hasNext()){
|
258 |
feature = (IFeature)it.next(); |
259 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
260 |
v2 = (Comparable)feature.get("NOMBRE"); |
261 |
pfeature=feature; |
262 |
if (v1!=null && v2!=null) |
263 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
264 |
count++; |
265 |
} |
266 |
assertEquals("Iteration error",10,count); |
267 |
|
268 |
|
269 |
try {
|
270 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
271 |
} catch (ReadException e1) {
|
272 |
e1.printStackTrace(); |
273 |
fail(); |
274 |
} |
275 |
|
276 |
assertEquals(3, fc.size());
|
277 |
|
278 |
it = fc.iterator(); |
279 |
|
280 |
count=0;
|
281 |
pfeature = (IFeature)it.next(); |
282 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
283 |
count++; |
284 |
while (it.hasNext()){
|
285 |
feature = (IFeature)it.next(); |
286 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
287 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
288 |
v2 = (Comparable)feature.get("NOMBRE"); |
289 |
pfeature=feature; |
290 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
291 |
count++; |
292 |
} |
293 |
assertEquals("Iteration error",3,count); |
294 |
|
295 |
|
296 |
|
297 |
try {
|
298 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
299 |
} catch (ReadException e1) {
|
300 |
e1.printStackTrace(); |
301 |
fail(); |
302 |
} |
303 |
assertEquals(10, fc.size());
|
304 |
it = fc.iterator(); |
305 |
count=0;
|
306 |
pfeature = (IFeature)it.next(); |
307 |
System.out.println(pfeature.getString("TIPO")+","+pfeature.getString("NOMBRE")); |
308 |
count++; |
309 |
while (it.hasNext()){
|
310 |
feature = (IFeature)it.next(); |
311 |
System.out.println(feature.getString("TIPO")+","+feature.getString("NOMBRE")); |
312 |
v1 = (Comparable)((String)pfeature.get("TIPO")).toLowerCase(); |
313 |
v2 = (Comparable)((String)feature.get("TIPO")).toLowerCase(); |
314 |
assertTrue("Short error", (v2.compareTo(v1) >= 0)); |
315 |
if (v1.compareTo(v2) == 0){ |
316 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
317 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
318 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
319 |
} |
320 |
pfeature=feature; |
321 |
|
322 |
// System.out.println(pfeature.getString("TIPO")+","+pfeature.getString("NOMBRE"));
|
323 |
count++; |
324 |
} |
325 |
assertEquals("Iteration error",10,count); |
326 |
|
327 |
fs.cancelEditing(); |
328 |
|
329 |
try {
|
330 |
fs.close(); |
331 |
} catch (CloseException e) {
|
332 |
e.printStackTrace(); |
333 |
fail("Exception:" + e);
|
334 |
} |
335 |
|
336 |
|
337 |
System.out.println("======= /DBF =============="); |
338 |
|
339 |
} catch (DataException e) {
|
340 |
// TODO Auto-generated catch block
|
341 |
e.printStackTrace(); |
342 |
} |
343 |
} |
344 |
|
345 |
public void testSHP() { |
346 |
try {
|
347 |
System.out.println("======= SHP =============="); |
348 |
org.gvsig.data.datastores.vectorial.file.shp.Register.selfRegister(); |
349 |
org.gvsig.data.datastores.vectorial.file.dbf.Register.selfRegister(); |
350 |
|
351 |
DataManager dsm=DataManager.getManager(); |
352 |
|
353 |
|
354 |
IDataStoreParameters dp=dsm.createDataStoreParameters(SHPStore.DATASTORE_NAME); |
355 |
((SHPStoreParameters)dp).setFile(shpfile); |
356 |
// ((SHPStoreParameters)dp).setSHXFile(SHP.getShxFile(shpfile));
|
357 |
// ((SHPStoreParameters)dp).setDBFFile(SHP.getDbfFile(shpfile));
|
358 |
|
359 |
|
360 |
driverTest(dp,null,null,true); |
361 |
|
362 |
IFeatureStore fs=null;
|
363 |
try {
|
364 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
365 |
} catch (InitializeException e) {
|
366 |
e.printStackTrace(); |
367 |
fail("Exception:" + e);
|
368 |
} |
369 |
|
370 |
assertNotNull("Can't create Feature Store", fs);
|
371 |
|
372 |
|
373 |
fs.open(); |
374 |
|
375 |
|
376 |
Iterator it;
|
377 |
IFeatureCollection fc; |
378 |
Comparable v1,v2;
|
379 |
IFeature feature,pfeature; |
380 |
long count;
|
381 |
|
382 |
|
383 |
fc = (IFeatureCollection)fs.getDataCollection(); |
384 |
|
385 |
assertEquals(9, fc.size());
|
386 |
|
387 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
388 |
|
389 |
assertEquals(2, fc.size());
|
390 |
|
391 |
it = fc.iterator(); |
392 |
count=0;
|
393 |
while (it.hasNext()){
|
394 |
feature = (IFeature)it.next(); |
395 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
396 |
count++; |
397 |
} |
398 |
assertEquals("Iteration error",2,count); |
399 |
|
400 |
|
401 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE"); |
402 |
assertEquals(9, fc.size());
|
403 |
it = fc.iterator(); |
404 |
count=0;
|
405 |
pfeature = (IFeature)it.next(); |
406 |
count++; |
407 |
while (it.hasNext()){
|
408 |
feature = (IFeature)it.next(); |
409 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
410 |
v2 = (Comparable)feature.get("NOMBRE"); |
411 |
pfeature=feature; |
412 |
assertTrue("Short error", (v1.compareTo(v2) <= 0)); |
413 |
count++; |
414 |
} |
415 |
assertEquals("Iteration error",9,count); |
416 |
|
417 |
|
418 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
419 |
assertEquals(9, fc.size());
|
420 |
it = fc.iterator(); |
421 |
count=0;
|
422 |
pfeature = (IFeature)it.next(); |
423 |
System.out.println(pfeature.getString("NOMBRE")); |
424 |
count++; |
425 |
while (it.hasNext()){
|
426 |
feature = (IFeature)it.next(); |
427 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
428 |
v2 = (Comparable)feature.get("NOMBRE"); |
429 |
pfeature=feature; |
430 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
431 |
System.out.println(pfeature.getString("NOMBRE")); |
432 |
count++; |
433 |
} |
434 |
assertEquals("Iteration error",9,count); |
435 |
|
436 |
|
437 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE ASC"); |
438 |
|
439 |
assertEquals(2, fc.size());
|
440 |
|
441 |
it = fc.iterator(); |
442 |
|
443 |
count=0;
|
444 |
pfeature = (IFeature)it.next(); |
445 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
446 |
count++; |
447 |
while (it.hasNext()){
|
448 |
feature = (IFeature)it.next(); |
449 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
450 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
451 |
v2 = (Comparable)feature.get("NOMBRE"); |
452 |
pfeature=feature; |
453 |
assertTrue("Short error", (v1.compareTo(v2) <= 0)); |
454 |
count++; |
455 |
} |
456 |
assertEquals("Iteration error",2,count); |
457 |
|
458 |
|
459 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"lower(NOMBRE) ASC"); |
460 |
assertEquals(9, fc.size());
|
461 |
it = fc.iterator(); |
462 |
count=0;
|
463 |
pfeature = (IFeature)it.next(); |
464 |
count++; |
465 |
while (it.hasNext()){
|
466 |
feature = (IFeature)it.next(); |
467 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
468 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
469 |
pfeature=feature; |
470 |
assertTrue("Short error", (v1.compareTo(v2) <= 0)); |
471 |
count++; |
472 |
} |
473 |
assertEquals("Iteration error",9,count); |
474 |
|
475 |
|
476 |
|
477 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
478 |
assertEquals(9, fc.size());
|
479 |
it = fc.iterator(); |
480 |
count=0;
|
481 |
pfeature = (IFeature)it.next(); |
482 |
System.out.println(pfeature.getString("NOMBRE")); |
483 |
count++; |
484 |
while (it.hasNext()){
|
485 |
feature = (IFeature)it.next(); |
486 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
487 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
488 |
pfeature=feature; |
489 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
490 |
System.out.println(pfeature.getString("NOMBRE")); |
491 |
count++; |
492 |
} |
493 |
assertEquals("Iteration error",9,count); |
494 |
|
495 |
|
496 |
|
497 |
/// CON EDICION
|
498 |
|
499 |
fs.startEditing(); |
500 |
|
501 |
IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType()); |
502 |
newFeature.editing(); |
503 |
newFeature.set("NOMBRE","BuRjaSOT"); |
504 |
newFeature.set("TIPO","MUNICIPIO"); |
505 |
fs.insert(newFeature); |
506 |
|
507 |
|
508 |
|
509 |
try {
|
510 |
fc = (IFeatureCollection)fs.getDataCollection(); |
511 |
} catch (ReadException e1) {
|
512 |
e1.printStackTrace(); |
513 |
fail(); |
514 |
} |
515 |
|
516 |
assertEquals(10, fc.size());
|
517 |
|
518 |
try {
|
519 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
520 |
} catch (ReadException e1) {
|
521 |
e1.printStackTrace(); |
522 |
fail(); |
523 |
} |
524 |
|
525 |
assertEquals(3, fc.size());
|
526 |
|
527 |
it = fc.iterator(); |
528 |
count=0;
|
529 |
while (it.hasNext()){
|
530 |
feature = (IFeature)it.next(); |
531 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
532 |
count++; |
533 |
} |
534 |
assertEquals("Iteration error",3,count); |
535 |
|
536 |
|
537 |
try {
|
538 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
539 |
} catch (ReadException e1) {
|
540 |
e1.printStackTrace(); |
541 |
fail(); |
542 |
} |
543 |
assertEquals(10, fc.size());
|
544 |
it = fc.iterator(); |
545 |
count=0;
|
546 |
pfeature = (IFeature)it.next(); |
547 |
count++; |
548 |
while (it.hasNext()){
|
549 |
feature = (IFeature)it.next(); |
550 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
551 |
v2 = (Comparable)feature.get("NOMBRE"); |
552 |
pfeature=feature; |
553 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
554 |
count++; |
555 |
} |
556 |
assertEquals("Iteration error",10,count); |
557 |
|
558 |
|
559 |
try {
|
560 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
561 |
} catch (ReadException e1) {
|
562 |
e1.printStackTrace(); |
563 |
fail(); |
564 |
} |
565 |
assertEquals(10, fc.size());
|
566 |
it = fc.iterator(); |
567 |
|
568 |
count=0;
|
569 |
pfeature = (IFeature)it.next(); |
570 |
count++; |
571 |
while (it.hasNext()){
|
572 |
feature = (IFeature)it.next(); |
573 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
574 |
v2 = (Comparable)feature.get("NOMBRE"); |
575 |
pfeature=feature; |
576 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
577 |
count++; |
578 |
} |
579 |
assertEquals("Iteration error",10,count); |
580 |
|
581 |
|
582 |
try {
|
583 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
584 |
} catch (ReadException e1) {
|
585 |
e1.printStackTrace(); |
586 |
fail(); |
587 |
} |
588 |
|
589 |
assertEquals(3, fc.size());
|
590 |
|
591 |
it = fc.iterator(); |
592 |
|
593 |
count=0;
|
594 |
pfeature = (IFeature)it.next(); |
595 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
596 |
count++; |
597 |
while (it.hasNext()){
|
598 |
feature = (IFeature)it.next(); |
599 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
600 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
601 |
v2 = (Comparable)feature.get("NOMBRE"); |
602 |
pfeature=feature; |
603 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
604 |
count++; |
605 |
} |
606 |
assertEquals("Iteration error",3,count); |
607 |
|
608 |
|
609 |
|
610 |
try {
|
611 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
612 |
} catch (ReadException e1) {
|
613 |
e1.printStackTrace(); |
614 |
fail(); |
615 |
} |
616 |
assertEquals(10, fc.size());
|
617 |
it = fc.iterator(); |
618 |
count=0;
|
619 |
pfeature = (IFeature)it.next(); |
620 |
System.out.println(pfeature.getString("NOMBRE")); |
621 |
count++; |
622 |
while (it.hasNext()){
|
623 |
feature = (IFeature)it.next(); |
624 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
625 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
626 |
pfeature=feature; |
627 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
628 |
System.out.println(pfeature.getString("NOMBRE")); |
629 |
count++; |
630 |
} |
631 |
assertEquals("Iteration error",10,count); |
632 |
|
633 |
|
634 |
|
635 |
|
636 |
fs.cancelEditing(); |
637 |
|
638 |
|
639 |
|
640 |
try {
|
641 |
fs.close(); |
642 |
} catch (CloseException e) {
|
643 |
e.printStackTrace(); |
644 |
fail("Exception:" + e);
|
645 |
} |
646 |
|
647 |
|
648 |
|
649 |
System.out.println("======= /SHP =============="); |
650 |
} catch (DataException e) {
|
651 |
// TODO Auto-generated catch block
|
652 |
e.printStackTrace(); |
653 |
} |
654 |
} |
655 |
|
656 |
public void testDXF() { |
657 |
try {
|
658 |
System.out.println("======= DXF =============="); |
659 |
org.gvsig.data.datastores.vectorial.file.dxf.Register.selfRegister(); |
660 |
|
661 |
DataManager dsm=DataManager.getManager(); |
662 |
|
663 |
|
664 |
IDataStoreParameters dp=dsm.createDataStoreParameters(DXFStore.DATASTORE_NAME); |
665 |
((DXFStoreParameters)dp).setFile(dxffile); |
666 |
IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
667 |
((DXFStoreParameters)dp).setProjection(proj); |
668 |
driverTest(dp,null,null,true); |
669 |
|
670 |
IFeatureStore fs=null;
|
671 |
try {
|
672 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
673 |
} catch (InitializeException e) {
|
674 |
e.printStackTrace(); |
675 |
fail("Exception:" + e);
|
676 |
} |
677 |
assertNotNull("Can't create Feature Store", fs);
|
678 |
|
679 |
|
680 |
fs.open(); |
681 |
|
682 |
|
683 |
Iterator it;
|
684 |
IFeatureCollection fc; |
685 |
Comparable v1,v2;
|
686 |
IFeature feature,pfeature; |
687 |
long count;
|
688 |
|
689 |
|
690 |
fc = (IFeatureCollection)fs.getDataCollection(); |
691 |
|
692 |
assertEquals(10, fc.size());
|
693 |
|
694 |
fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null); |
695 |
|
696 |
assertEquals(2, fc.size());
|
697 |
|
698 |
it = fc.iterator(); |
699 |
count=0;
|
700 |
while (it.hasNext()){
|
701 |
feature = (IFeature)it.next(); |
702 |
assertTrue("Filter error",feature.getInt("Color")>7); |
703 |
count++; |
704 |
} |
705 |
assertEquals("Iteration error",2,count); |
706 |
|
707 |
|
708 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC"); |
709 |
assertEquals(10, fc.size());
|
710 |
it = fc.iterator(); |
711 |
count=0;
|
712 |
pfeature = (IFeature)it.next(); |
713 |
count++; |
714 |
while (it.hasNext()){
|
715 |
feature = (IFeature)it.next(); |
716 |
v1 = (Comparable)pfeature.get("Layer"); |
717 |
v2 = (Comparable)feature.get("Layer"); |
718 |
pfeature=feature; |
719 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
720 |
count++; |
721 |
} |
722 |
assertEquals("Iteration error",10,count); |
723 |
|
724 |
|
725 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC"); |
726 |
assertEquals(10, fc.size());
|
727 |
it = fc.iterator(); |
728 |
|
729 |
count=0;
|
730 |
pfeature = (IFeature)it.next(); |
731 |
count++; |
732 |
while (it.hasNext()){
|
733 |
feature = (IFeature)it.next(); |
734 |
v1 = (Comparable)pfeature.get("Layer"); |
735 |
v2 = (Comparable)feature.get("Layer"); |
736 |
pfeature=feature; |
737 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
738 |
count++; |
739 |
} |
740 |
assertEquals("Iteration error",10,count); |
741 |
|
742 |
|
743 |
fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC"); |
744 |
|
745 |
assertEquals(2, fc.size());
|
746 |
|
747 |
it = fc.iterator(); |
748 |
|
749 |
count=0;
|
750 |
pfeature = (IFeature)it.next(); |
751 |
assertTrue(pfeature.getInt("Color")>7); |
752 |
count++; |
753 |
while (it.hasNext()){
|
754 |
feature = (IFeature)it.next(); |
755 |
assertTrue("Filter error",feature.getInt("Color")>7); |
756 |
v1 = (Comparable)pfeature.get("Color"); |
757 |
v2 = (Comparable)feature.get("Color"); |
758 |
pfeature=feature; |
759 |
Integer i1=(Integer)v1; |
760 |
Integer i2=(Integer)v2; |
761 |
assertTrue("Short error", (i1.intValue()>i2.intValue()));
|
762 |
count++; |
763 |
} |
764 |
assertEquals("Iteration error",2,count); |
765 |
|
766 |
|
767 |
|
768 |
// fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
|
769 |
// assertEquals(10, fc.size());
|
770 |
// it = fc.iterator();
|
771 |
// count=0;
|
772 |
// pfeature = (IFeature)it.next();
|
773 |
// System.out.println(pfeature.getString("Layer"));
|
774 |
// count++;
|
775 |
// while (it.hasNext()){
|
776 |
// feature = (IFeature)it.next();
|
777 |
// v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
|
778 |
// v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
|
779 |
// pfeature=feature;
|
780 |
// assertTrue("Short error", (v1.compareTo(v2) >= 0));
|
781 |
// System.out.println(pfeature.getString("Layer"));
|
782 |
// count++;
|
783 |
// }
|
784 |
// assertEquals("Iteration error",10,count);
|
785 |
|
786 |
|
787 |
try {
|
788 |
fs.close(); |
789 |
} catch (CloseException e) {
|
790 |
e.printStackTrace(); |
791 |
fail("Exception:" + e);
|
792 |
} |
793 |
|
794 |
|
795 |
System.out.println("======= /DXF =============="); |
796 |
} catch (OpenException e1) {
|
797 |
e1.printStackTrace(); |
798 |
fail(); |
799 |
} catch (ReadException e) {
|
800 |
// TODO Auto-generated catch block
|
801 |
e.printStackTrace(); |
802 |
} |
803 |
} |
804 |
|
805 |
public void testDGN() { |
806 |
try {
|
807 |
System.out.println("======= DGN =============="); |
808 |
org.gvsig.data.datastores.vectorial.file.dgn.Register.selfRegister(); |
809 |
|
810 |
DataManager dsm=DataManager.getManager(); |
811 |
|
812 |
|
813 |
IDataStoreParameters dp=dsm.createDataStoreParameters(DGNStore.DATASTORE_NAME); |
814 |
((DGNStoreParameters)dp).setFile(dgnfile); |
815 |
driverTest(dp,null,null,true); |
816 |
IFeatureStore fs=null;
|
817 |
try {
|
818 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
819 |
} catch (InitializeException e) {
|
820 |
e.printStackTrace(); |
821 |
fail("Exception:" + e);
|
822 |
} |
823 |
assertNotNull("Can't create Feature Store", fs);
|
824 |
|
825 |
|
826 |
fs.open(); |
827 |
|
828 |
|
829 |
Iterator it;
|
830 |
IFeatureCollection fc; |
831 |
Comparable v1,v2;
|
832 |
IFeature feature,pfeature; |
833 |
long count;
|
834 |
|
835 |
|
836 |
fc = (IFeatureCollection)fs.getDataCollection(); |
837 |
|
838 |
assertEquals(57, fc.size());
|
839 |
|
840 |
fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'",null); |
841 |
|
842 |
assertEquals(45, fc.size());
|
843 |
|
844 |
it = fc.iterator(); |
845 |
count=0;
|
846 |
while (it.hasNext()){
|
847 |
feature = (IFeature)it.next(); |
848 |
assertTrue("Filter error",feature.getInt("Color")>=7); |
849 |
count++; |
850 |
} |
851 |
assertEquals("Iteration error",45,count); |
852 |
|
853 |
|
854 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer ASC"); |
855 |
assertEquals(57, fc.size());
|
856 |
it = fc.iterator(); |
857 |
count=0;
|
858 |
pfeature = (IFeature)it.next(); |
859 |
count++; |
860 |
while (it.hasNext()){
|
861 |
feature = (IFeature)it.next(); |
862 |
v1 = (Comparable)pfeature.get("Layer"); |
863 |
v2 = (Comparable)feature.get("Layer"); |
864 |
if (v2==null) |
865 |
System.out.println("null"); |
866 |
assertTrue("Short error", (v1.compareTo(v2) <= 0)); |
867 |
pfeature=feature; |
868 |
count++; |
869 |
} |
870 |
assertEquals("Iteration error",57,count); |
871 |
|
872 |
|
873 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Layer DESC"); |
874 |
assertEquals(57, fc.size());
|
875 |
it = fc.iterator(); |
876 |
|
877 |
count=0;
|
878 |
pfeature = (IFeature)it.next(); |
879 |
count++; |
880 |
while (it.hasNext()){
|
881 |
feature = (IFeature)it.next(); |
882 |
v1 = (Comparable)pfeature.get("Layer"); |
883 |
v2 = (Comparable)feature.get("Layer"); |
884 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
885 |
pfeature=feature; |
886 |
count++; |
887 |
} |
888 |
assertEquals("Iteration error",57,count); |
889 |
|
890 |
|
891 |
fc = (IFeatureCollection)fs.getDataCollection(null,"Color > '7'","Layer ASC"); |
892 |
|
893 |
assertEquals(45, fc.size());
|
894 |
|
895 |
it = fc.iterator(); |
896 |
|
897 |
count=0;
|
898 |
pfeature = (IFeature)it.next(); |
899 |
assertTrue(pfeature.getInt("Color")>7); |
900 |
count++; |
901 |
while (it.hasNext()){
|
902 |
feature = (IFeature)it.next(); |
903 |
assertTrue("Filter error",feature.getInt("Color")>7); |
904 |
v1 = (Comparable)pfeature.get("Layer"); |
905 |
v2 = (Comparable)feature.get("Layer"); |
906 |
pfeature=feature; |
907 |
Integer i1=(Integer)v1; |
908 |
Integer i2=(Integer)v2; |
909 |
assertTrue("Short error", (i1.intValue()<=i2.intValue()));
|
910 |
count++; |
911 |
} |
912 |
assertEquals("Iteration error",45,count); |
913 |
|
914 |
|
915 |
|
916 |
// fc = (IFeatureCollection)fs.getDataCollection(null,null,"Color,Layer Desc");
|
917 |
// assertEquals(10, fc.size());
|
918 |
// it = fc.iterator();
|
919 |
// count=0;
|
920 |
// pfeature = (IFeature)it.next();
|
921 |
// System.out.println(pfeature.getString("Layer"));
|
922 |
// count++;
|
923 |
// while (it.hasNext()){
|
924 |
// feature = (IFeature)it.next();
|
925 |
// v1 = (Comparable)((String)pfeature.get("Layer")).toLowerCase();
|
926 |
// v2 = (Comparable)((String)feature.get("Layer")).toLowerCase();
|
927 |
// pfeature=feature;
|
928 |
// assertTrue("Short error", (v1.compareTo(v2) >= 0));
|
929 |
// System.out.println(pfeature.getString("Layer"));
|
930 |
// count++;
|
931 |
// }
|
932 |
// assertEquals("Iteration error",10,count);
|
933 |
|
934 |
|
935 |
try {
|
936 |
fs.close(); |
937 |
} catch (CloseException e) {
|
938 |
e.printStackTrace(); |
939 |
fail("Exception:" + e);
|
940 |
} |
941 |
|
942 |
|
943 |
System.out.println("======= /DGN =============="); |
944 |
} catch (OpenException e1) {
|
945 |
e1.printStackTrace(); |
946 |
fail(); |
947 |
} catch (ReadException e) {
|
948 |
// TODO Auto-generated catch block
|
949 |
e.printStackTrace(); |
950 |
} |
951 |
} |
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
// private IFeatureStore createFeatureStore(IDriverParameters dp){
|
959 |
// DataSourceManager dsm=DataSourceManager.getManager();
|
960 |
|
961 |
// IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
|
962 |
|
963 |
// ((IDriverStoreParameters)dsp).setDriverParameters(dp);
|
964 |
// IFeatureStore fs=null;
|
965 |
// try {
|
966 |
// fs = (IFeatureStore)dsm.createDataStore(dsp);
|
967 |
// } catch (InitializeException e) {
|
968 |
// e.printStackTrace();
|
969 |
// fail("Exception:" + e);
|
970 |
// }
|
971 |
// return fs;
|
972 |
|
973 |
// }
|
974 |
|
975 |
|
976 |
private void driverTest(IDataStoreParameters dp,String filter, String order,boolean testEdit){ |
977 |
DataManager dsm=DataManager.getManager(); |
978 |
|
979 |
// IDataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME);
|
980 |
|
981 |
// ((IDriverStoreParameters)dsp).setDriverParameters(dp);
|
982 |
// IFeatureStore fs=createFeatureStore(dp);
|
983 |
IFeatureStore fs=null;
|
984 |
try {
|
985 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
986 |
} catch (InitializeException e) {
|
987 |
e.printStackTrace(); |
988 |
fail("Exception:" + e);
|
989 |
} |
990 |
try {
|
991 |
fs.open(); |
992 |
} catch (OpenException e2) {
|
993 |
e2.printStackTrace(); |
994 |
fail(); |
995 |
} |
996 |
|
997 |
if (fs.isEditable() && testEdit) {
|
998 |
try {
|
999 |
fs.startEditing(); |
1000 |
if (fs.canAlterFeatureType()){
|
1001 |
IFeatureType featureType=fs.getDefaultFeatureType(); |
1002 |
// DefaultAttributeDescriptor dad=new DefaultAttributeDescriptor();
|
1003 |
// dad.loading();
|
1004 |
// dad.setName("Prueba1");
|
1005 |
// dad.setDefaultValue("11p");
|
1006 |
// dad.setSize(10);
|
1007 |
// dad.setType(IFeatureAttributeDescriptor.TYPE_STRING);
|
1008 |
// dad.stopLoading();
|
1009 |
// fs.insert(dad);
|
1010 |
// fs.delete((IFeatureAttributeDescriptor)featureType.get(featureType.getFieldIndex("Prueba1")));
|
1011 |
AttributeDescriptor dad2=(AttributeDescriptor)featureType.get(featureType.getFieldIndex("TIPO"));
|
1012 |
dad2.editing(); |
1013 |
// dad2.setName("TIPO");
|
1014 |
dad2.setDefaultValue("Tipop");
|
1015 |
// dad2.setSize(10);
|
1016 |
dad2.setType(IFeatureAttributeDescriptor.TYPE_STRING); |
1017 |
fs.update(dad2); |
1018 |
} |
1019 |
} catch (ReadException e) {
|
1020 |
e.printStackTrace(); |
1021 |
fail(); |
1022 |
} |
1023 |
catch (IsNotAttributeSettingException e) {
|
1024 |
// TODO Auto-generated catch block
|
1025 |
e.printStackTrace(); |
1026 |
} |
1027 |
try {
|
1028 |
IFeature feature1 = fs.createDefaultFeature(false);
|
1029 |
|
1030 |
IFeature feature2 = fs.createDefaultFeature(false);
|
1031 |
IFeature feature3 = fs.createDefaultFeature(false);
|
1032 |
|
1033 |
fs.insert(feature1); |
1034 |
fs.insert(feature2); |
1035 |
|
1036 |
feature1.editing(); |
1037 |
feature1.set(1,"hola"); |
1038 |
|
1039 |
fs.update(feature1); |
1040 |
fs.delete(feature3); |
1041 |
fs.delete(feature2); |
1042 |
} catch (DataException e) {
|
1043 |
// TODO Auto-generated catch block
|
1044 |
e.printStackTrace(); |
1045 |
} |
1046 |
} |
1047 |
|
1048 |
//Mostrar por consola todos los registros.
|
1049 |
IFeatureType ft= fs.getDefaultFeatureType(); |
1050 |
IFeatureCollection featureCollection=null;
|
1051 |
// featureCollection = (IFeatureCollection)fs.getDataCollection();
|
1052 |
// featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"NOMBRE = 'CALPE'",null);
|
1053 |
// featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"AREA > 3.2213163729E7 and AREA < 3.2213163749E7",null);
|
1054 |
try {
|
1055 |
featureCollection = (IFeatureCollection)fs.getDataCollection(ft,filter,order); |
1056 |
} catch (ReadException e2) {
|
1057 |
// TODO Auto-generated catch block
|
1058 |
e2.printStackTrace(); |
1059 |
} |
1060 |
|
1061 |
PrintlnFeaturesVisitor visitor=new PrintlnFeaturesVisitor(ft);
|
1062 |
try {
|
1063 |
featureCollection.accept(visitor); |
1064 |
} catch (BaseException e1) {
|
1065 |
e1.printStackTrace(); |
1066 |
fail("Exception: "+e1);
|
1067 |
} |
1068 |
|
1069 |
featureCollection.dispose(); |
1070 |
|
1071 |
if (fs.isEditable() && testEdit){
|
1072 |
try {
|
1073 |
fs.finishEditing(); |
1074 |
} catch (WriteException e) {
|
1075 |
e.printStackTrace(); |
1076 |
fail("Exception: "+e);
|
1077 |
} catch (ReadException e) {
|
1078 |
e.printStackTrace(); |
1079 |
fail("Exception: "+e);
|
1080 |
} |
1081 |
} |
1082 |
try {
|
1083 |
fs.close(); |
1084 |
} catch (CloseException e) {
|
1085 |
e.printStackTrace(); |
1086 |
fail("Exception: "+e);
|
1087 |
} |
1088 |
try {
|
1089 |
fs.dispose(); |
1090 |
} catch (CloseException e) {
|
1091 |
// TODO Auto-generated catch block
|
1092 |
e.printStackTrace(); |
1093 |
} |
1094 |
} |
1095 |
|
1096 |
public static void doFileResourceTest(IFileStoreParameters params) { |
1097 |
doFileResourceTest(params,true);
|
1098 |
} |
1099 |
public static void doFileResourceTest(IFileStoreParameters params,boolean testEdit){ |
1100 |
DataManager manager = DataManager.getManager(); |
1101 |
|
1102 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
1103 |
|
1104 |
FeatureStore store=null;
|
1105 |
FeatureStore store2=null;
|
1106 |
FeatureStore store3=null;
|
1107 |
try {
|
1108 |
store = (FeatureStore)manager.createDataStore(params); |
1109 |
store2 = (FeatureStore)manager.createDataStore(params); |
1110 |
store3 = (FeatureStore)manager.createDataStore(params); |
1111 |
} catch (InitializeException e1) {
|
1112 |
e1.printStackTrace();fail(); |
1113 |
} |
1114 |
|
1115 |
int i=0; |
1116 |
Resource res = null;
|
1117 |
Resource tmpRes = null;
|
1118 |
Object obj = null; |
1119 |
|
1120 |
Iterator iter = resMan.iterator();
|
1121 |
while (iter.hasNext()){
|
1122 |
obj = iter.next(); |
1123 |
if (obj instanceof FileResource){ |
1124 |
tmpRes = (Resource)obj; |
1125 |
if (((FileResource)tmpRes).getFile().getAbsoluteFile().equals(params.getFile().getAbsoluteFile())){
|
1126 |
i++; |
1127 |
res=tmpRes; |
1128 |
} |
1129 |
} |
1130 |
} |
1131 |
|
1132 |
assertEquals(1, i);
|
1133 |
|
1134 |
assertEquals(3, res.getRefencesCount());
|
1135 |
|
1136 |
try {
|
1137 |
store.close(); |
1138 |
} catch (CloseException e1) {
|
1139 |
e1.printStackTrace();fail(); |
1140 |
} |
1141 |
|
1142 |
assertEquals(false, res.isOpen());
|
1143 |
|
1144 |
IDataCollection coll = null;
|
1145 |
|
1146 |
try {
|
1147 |
coll =store.getDataCollection(); |
1148 |
} catch (ReadException e1) {
|
1149 |
e1.printStackTrace();fail(); |
1150 |
} |
1151 |
|
1152 |
coll.iterator().next(); |
1153 |
|
1154 |
assertEquals(true, res.isOpen());
|
1155 |
|
1156 |
coll.dispose(); |
1157 |
|
1158 |
|
1159 |
|
1160 |
if (store.isEditable() && testEdit){
|
1161 |
/*Test edition notification*/
|
1162 |
|
1163 |
int fCountOrg=0; |
1164 |
int fCountFin=0; |
1165 |
try {
|
1166 |
fCountOrg = store.getDataCollection().size(); |
1167 |
} catch (ReadException e2) {
|
1168 |
// TODO Auto-generated catch block
|
1169 |
e2.printStackTrace();fail(); |
1170 |
} |
1171 |
try {
|
1172 |
store.startEditing(); |
1173 |
} catch (ReadException e1) {
|
1174 |
e1.printStackTrace();fail(); |
1175 |
} |
1176 |
|
1177 |
try {
|
1178 |
coll = store2.getDataCollection(); |
1179 |
} catch (ReadException e1) {
|
1180 |
e1.printStackTrace();fail(); |
1181 |
} |
1182 |
|
1183 |
try {
|
1184 |
store.finishEditing(); |
1185 |
} catch (WriteException e1) {
|
1186 |
e1.printStackTrace();fail(); |
1187 |
} catch (ReadException e1) {
|
1188 |
// TODO Auto-generated catch block
|
1189 |
e1.printStackTrace();fail(); |
1190 |
} |
1191 |
|
1192 |
try {
|
1193 |
fCountFin = store.getDataCollection().size(); |
1194 |
} catch (ReadException e2) {
|
1195 |
// TODO Auto-generated catch block
|
1196 |
e2.printStackTrace();fail(); |
1197 |
} |
1198 |
|
1199 |
assertEquals(fCountOrg, fCountFin); |
1200 |
|
1201 |
|
1202 |
boolean isOk = false; |
1203 |
try{
|
1204 |
coll.iterator().next(); |
1205 |
} catch (Exception e){ |
1206 |
isOk=true;
|
1207 |
} |
1208 |
assertTrue("Resource Changed Notification fails",isOk);
|
1209 |
|
1210 |
coll.dispose(); |
1211 |
|
1212 |
|
1213 |
|
1214 |
long time = System.currentTimeMillis(); |
1215 |
while ((System.currentTimeMillis()-time) < 1000){ |
1216 |
//sleep
|
1217 |
} |
1218 |
|
1219 |
|
1220 |
((FileResource)res).getFile().setLastModified(System.currentTimeMillis());
|
1221 |
|
1222 |
isOk=false;
|
1223 |
try{
|
1224 |
store.getDataCollection().iterator().next(); |
1225 |
} catch (Exception e){ |
1226 |
isOk=true;
|
1227 |
} |
1228 |
assertTrue("Resource Changed Notification fails",isOk);
|
1229 |
|
1230 |
/*Test edition notification END*/
|
1231 |
|
1232 |
} |
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
try {
|
1238 |
store3.dispose(); |
1239 |
} catch (CloseException e1) {
|
1240 |
e1.printStackTrace();fail(); |
1241 |
} |
1242 |
|
1243 |
assertEquals(2, res.getRefencesCount());
|
1244 |
|
1245 |
try {
|
1246 |
store2.dispose(); |
1247 |
} catch (CloseException e1) {
|
1248 |
e1.printStackTrace();fail(); |
1249 |
} |
1250 |
|
1251 |
assertEquals(1, res.getRefencesCount());
|
1252 |
|
1253 |
try {
|
1254 |
store.dispose(); |
1255 |
} catch (CloseException e1) {
|
1256 |
e1.printStackTrace();fail(); |
1257 |
} |
1258 |
|
1259 |
assertEquals(0, res.getRefencesCount());
|
1260 |
res = null;
|
1261 |
|
1262 |
i=0;
|
1263 |
iter = resMan.iterator(); |
1264 |
while (iter.hasNext()){
|
1265 |
obj = iter.next(); |
1266 |
if (obj instanceof FileResource){ |
1267 |
tmpRes = (Resource)obj; |
1268 |
if (((FileResource)tmpRes).getFile().getAbsoluteFile().equals(params.getFile().getAbsoluteFile())){
|
1269 |
i++; |
1270 |
res=tmpRes; |
1271 |
} |
1272 |
} |
1273 |
} |
1274 |
|
1275 |
assertEquals(0, i);
|
1276 |
|
1277 |
doPrepareFileResourceTest(params); |
1278 |
|
1279 |
} |
1280 |
|
1281 |
public static void doPrepareFileResourceTest(IFileStoreParameters params){ |
1282 |
DataManager manager = DataManager.getManager(); |
1283 |
|
1284 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
1285 |
|
1286 |
File originalFile = params.getFile();
|
1287 |
params.setFile(new File(originalFile.getName())); |
1288 |
|
1289 |
IObserver obs = new PrepareResourceObserver(originalFile);
|
1290 |
|
1291 |
|
1292 |
resMan.addObserver(obs); |
1293 |
|
1294 |
FeatureStore store=null;
|
1295 |
try {
|
1296 |
store = (FeatureStore)manager.createDataStore(params); |
1297 |
} catch (InitializeException e1) {
|
1298 |
e1.printStackTrace();fail(); |
1299 |
} catch (Exception e2){ |
1300 |
e2.printStackTrace();fail(); |
1301 |
} |
1302 |
|
1303 |
try {
|
1304 |
store.getDataCollection().iterator().next(); |
1305 |
} catch (ReadException e) {
|
1306 |
// TODO Auto-generated catch block
|
1307 |
e.printStackTrace();fail(); |
1308 |
} |
1309 |
|
1310 |
try {
|
1311 |
store.close(); |
1312 |
} catch (CloseException e) {
|
1313 |
// TODO Auto-generated catch block
|
1314 |
e.printStackTrace();fail(); |
1315 |
} |
1316 |
try {
|
1317 |
store.dispose(); |
1318 |
} catch (CloseException e) {
|
1319 |
// TODO Auto-generated catch block
|
1320 |
e.printStackTrace();fail(); |
1321 |
} |
1322 |
|
1323 |
} |
1324 |
|
1325 |
} |