Revision 22940
branches/v2_0_0_prep/libraries/libFMap_dataFile/src-test/org/gvsig/fmap/data/feature/joinstore/JoinStoreTest.java | ||
---|---|---|
28 | 28 |
package org.gvsig.fmap.data.feature.joinstore; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.util.Iterator; |
|
31 | 32 |
|
32 | 33 |
import junit.framework.TestCase; |
33 | 34 |
|
... | ... | |
36 | 37 |
import org.gvsig.fmap.data.InitializeException; |
37 | 38 |
import org.gvsig.fmap.data.ReadException; |
38 | 39 |
import org.gvsig.fmap.data.feature.AttributeDescriptor; |
40 |
import org.gvsig.fmap.data.feature.Feature; |
|
39 | 41 |
import org.gvsig.fmap.data.feature.FeatureCollection; |
40 | 42 |
import org.gvsig.fmap.data.feature.FeatureStore; |
41 | 43 |
import org.gvsig.fmap.data.feature.FeatureType; |
... | ... | |
58 | 60 |
org.gvsig.fmap.data.feature.file.shp.Register.selfRegister(); |
59 | 61 |
} |
60 | 62 |
|
61 |
public void testShp_Dbf_carrilbici() { |
|
63 |
protected JoinFeatureStoreParameters getDefaultParameters() { |
|
64 |
|
|
62 | 65 |
DataManager dm = DataManager.getManager(); |
63 | 66 |
|
64 | 67 |
DBFStoreParameters dbf_params = null; |
65 | 68 |
SHPStoreParameters shp_params = null; |
66 | 69 |
JoinFeatureStoreParameters join_params = null; |
67 |
FeatureStore join = null; |
|
68 | 70 |
|
69 | 71 |
try { |
70 | 72 |
dbf_params = (DBFStoreParameters) dm |
... | ... | |
78 | 80 |
e.printStackTrace(); |
79 | 81 |
fail(); |
80 | 82 |
} |
81 |
|
|
82 | 83 |
shp_params.setFile(shp_carrilbici); |
83 | 84 |
dbf_params.setFile(dbf_carrilbici); |
84 | 85 |
|
... | ... | |
89 | 90 |
join_params.setFieldNamePrefix("l_"); |
90 | 91 |
join_params.setDefaultGeometry("GEOMETRY"); |
91 | 92 |
|
93 |
return join_params; |
|
94 |
} |
|
92 | 95 |
|
96 |
|
|
97 |
public void testShp_Dbf_carrilbici_base() { |
|
98 |
DataManager dm = DataManager.getManager(); |
|
99 |
JoinFeatureStoreParameters join_params = this.getDefaultParameters(); |
|
100 |
FeatureStore join = null; |
|
101 |
|
|
93 | 102 |
try { |
94 | 103 |
join = (FeatureStore) dm.createDataStore(join_params); |
95 | 104 |
} catch (InitializeException e) { |
... | ... | |
159 | 168 |
fail(); |
160 | 169 |
} |
161 | 170 |
|
162 |
|
|
163 | 171 |
fColl.dispose(); |
164 | 172 |
fColl = null; |
165 | 173 |
|
166 |
|
|
167 | 174 |
//Comprobar los coleccion de "subtipo" |
168 | 175 |
try { |
169 |
fColl = (FeatureCollection) join.getDataCollection( |
|
170 |
new String[] {"CODIGO", join_params.getFieldNamePrefix() + "CALLE" }, |
|
171 |
null, |
|
172 |
null); |
|
176 |
fColl = (FeatureCollection) join.getDataCollection(new String[] { |
|
177 |
"CODIGO", join_params.getFieldNamePrefix() + "CALLE" }, |
|
178 |
null, null); |
|
173 | 179 |
} catch (ReadException e) { |
174 | 180 |
e.printStackTrace(); |
175 | 181 |
fail(); |
... | ... | |
180 | 186 |
|
181 | 187 |
assertEquals(2, fColl.getFeatureType().size()); |
182 | 188 |
|
183 |
|
|
184 | 189 |
// numero de elementos: shp 43 |
185 | 190 |
assertEquals(43, fColl.size()); |
186 | 191 |
try { |
... | ... | |
195 | 200 |
|
196 | 201 |
} |
197 | 202 |
|
203 |
public void testShp_Dbf_carrilbici_order() { |
|
204 |
DataManager dm = DataManager.getManager(); |
|
205 |
JoinFeatureStoreParameters join_params = this.getDefaultParameters(); |
|
206 |
FeatureStore join = null; |
|
207 |
|
|
208 |
|
|
209 |
FeatureCollection fColl = null; |
|
210 |
|
|
211 |
|
|
212 |
try { |
|
213 |
join = (FeatureStore) dm.createDataStore(join_params); |
|
214 |
} catch (InitializeException e) { |
|
215 |
e.printStackTrace(); |
|
216 |
fail(); |
|
217 |
} |
|
218 |
|
|
219 |
//Comprobar los coleccion con orden |
|
220 |
try { |
|
221 |
fColl = (FeatureCollection) join.getDataCollection(join |
|
222 |
.getDefaultFeatureType(), null, "CODIGO"); |
|
223 |
} catch (ReadException e) { |
|
224 |
e.printStackTrace(); |
|
225 |
fail(); |
|
226 |
} |
|
227 |
|
|
228 |
// numero de elementos: shp 43 |
|
229 |
assertEquals(43, fColl.size()); |
|
230 |
Comparable v1 = null; |
|
231 |
Comparable v2 = null; |
|
232 |
Iterator iter; |
|
233 |
boolean elPrimero; |
|
234 |
Feature feature; |
|
235 |
|
|
236 |
iter = fColl.iterator(); |
|
237 |
elPrimero = true; |
|
238 |
|
|
239 |
while (iter.hasNext()) { |
|
240 |
feature = (Feature) iter.next(); |
|
241 |
if (elPrimero) { |
|
242 |
v1 = (Comparable) feature.get("CODIGO"); |
|
243 |
elPrimero = false; |
|
244 |
} else { |
|
245 |
v2 = (Comparable) feature.get("CODIGO"); |
|
246 |
if (v1.compareTo(v2) > 0) { |
|
247 |
fail(); |
|
248 |
} |
|
249 |
v1 = v2; |
|
250 |
} |
|
251 |
} |
|
252 |
|
|
253 |
fColl.dispose(); |
|
254 |
fColl = null; |
|
255 |
|
|
256 |
//Comprobar los coleccion con orden de la segunda tabla |
|
257 |
try { |
|
258 |
fColl = (FeatureCollection) join.getDataCollection(join |
|
259 |
.getDefaultFeatureType(), null, join_params |
|
260 |
.getFieldNamePrefix() |
|
261 |
+ "CALLE"); |
|
262 |
} catch (ReadException e) { |
|
263 |
e.printStackTrace(); |
|
264 |
fail(); |
|
265 |
} |
|
266 |
|
|
267 |
// numero de elementos: shp 43 |
|
268 |
assertEquals(43, fColl.size()); |
|
269 |
iter = fColl.iterator(); |
|
270 |
elPrimero = true; |
|
271 |
|
|
272 |
while (iter.hasNext()) { |
|
273 |
feature = (Feature) iter.next(); |
|
274 |
if (elPrimero) { |
|
275 |
v1 = (Comparable) feature.get(join_params.getFieldNamePrefix() |
|
276 |
+ "CALLE"); |
|
277 |
elPrimero = false; |
|
278 |
System.out.println(v1); |
|
279 |
} else { |
|
280 |
v2 = (Comparable) feature.get(join_params.getFieldNamePrefix() |
|
281 |
+ "CALLE"); |
|
282 |
System.out.println(v2); |
|
283 |
if (v1 == null || v2 == null) { |
|
284 |
continue; |
|
285 |
} |
|
286 |
if (v1.compareTo(v2) > 0) { |
|
287 |
fail(); |
|
288 |
} |
|
289 |
v1 = v2; |
|
290 |
} |
|
291 |
} |
|
292 |
|
|
293 |
//Comprobar los coleccion con orden de la segunda tabla y subtipo |
|
294 |
try { |
|
295 |
fColl = (FeatureCollection) join.getDataCollection(new String[] { |
|
296 |
"CODIGO", join_params.getFieldNamePrefix() + "CALLE" }, |
|
297 |
null, join_params.getFieldNamePrefix() + "CALLE"); |
|
298 |
} catch (ReadException e) { |
|
299 |
e.printStackTrace(); |
|
300 |
fail(); |
|
301 |
} |
|
302 |
|
|
303 |
// numero de elementos: shp 43 |
|
304 |
assertEquals(43, fColl.size()); |
|
305 |
iter = fColl.iterator(); |
|
306 |
elPrimero = true; |
|
307 |
|
|
308 |
while (iter.hasNext()) { |
|
309 |
feature = (Feature) iter.next(); |
|
310 |
if (elPrimero) { |
|
311 |
v1 = (Comparable) feature.get(join_params.getFieldNamePrefix() |
|
312 |
+ "CALLE"); |
|
313 |
elPrimero = false; |
|
314 |
System.out.println(v1); |
|
315 |
} else { |
|
316 |
v2 = (Comparable) feature.get(join_params.getFieldNamePrefix() |
|
317 |
+ "CALLE"); |
|
318 |
System.out.println(v2); |
|
319 |
if (v1 == null || v2 == null) { |
|
320 |
continue; |
|
321 |
} |
|
322 |
if (v1.compareTo(v2) > 0) { |
|
323 |
fail(); |
|
324 |
} |
|
325 |
v1 = v2; |
|
326 |
} |
|
327 |
} |
|
328 |
|
|
329 |
fColl.dispose(); |
|
330 |
fColl = null; |
|
331 |
|
|
332 |
} |
|
333 |
|
|
334 |
|
|
335 |
public void testShp_Dbf_carrilbici_filter() { |
|
336 |
DataManager dm = DataManager.getManager(); |
|
337 |
JoinFeatureStoreParameters join_params = this.getDefaultParameters(); |
|
338 |
FeatureStore join = null; |
|
339 |
|
|
340 |
|
|
341 |
FeatureCollection fColl = null; |
|
342 |
|
|
343 |
|
|
344 |
try { |
|
345 |
join = (FeatureStore) dm.createDataStore(join_params); |
|
346 |
} catch (InitializeException e) { |
|
347 |
e.printStackTrace(); |
|
348 |
fail(); |
|
349 |
} |
|
350 |
|
|
351 |
//Filtro simple |
|
352 |
try { |
|
353 |
fColl = (FeatureCollection) join.getDataCollection(join |
|
354 |
.getDefaultFeatureType(), "CODIGO < 10", null); |
|
355 |
} catch (ReadException e) { |
|
356 |
e.printStackTrace(); |
|
357 |
fail(); |
|
358 |
} |
|
359 |
|
|
360 |
// numero de elementos: shp 13 (codigo < 10) |
|
361 |
assertEquals(13, fColl.size()); |
|
362 |
Iterator iter; |
|
363 |
Feature feature; |
|
364 |
|
|
365 |
iter = fColl.iterator(); |
|
366 |
|
|
367 |
while (iter.hasNext()) { |
|
368 |
feature = (Feature) iter.next(); |
|
369 |
if (feature.getInt("CODIGO") >= 10) { |
|
370 |
fail(); |
|
371 |
} |
|
372 |
} |
|
373 |
|
|
374 |
fColl.dispose(); |
|
375 |
fColl = null; |
|
376 |
|
|
377 |
//Filtro de campo de segunda tabla |
|
378 |
try { |
|
379 |
fColl = (FeatureCollection) join.getDataCollection(join |
|
380 |
.getDefaultFeatureType(), "lower(" |
|
381 |
+ join_params |
|
382 |
.getFieldNamePrefix() |
|
383 |
+ "CALLE) like 'a%'", |
|
384 |
null); |
|
385 |
} catch (ReadException e) { |
|
386 |
e.printStackTrace(); |
|
387 |
fail(); |
|
388 |
} |
|
389 |
|
|
390 |
// numero de elementos: shp 9 (lower(l_CALLE) like 'a%') |
|
391 |
assertEquals(9, fColl.size()); |
|
392 |
iter = fColl.iterator(); |
|
393 |
|
|
394 |
while (iter.hasNext()) { |
|
395 |
feature = (Feature) iter.next(); |
|
396 |
if (!feature.getString(join_params.getFieldNamePrefix() + "CALLE") |
|
397 |
.toLowerCase().startsWith("a")) { |
|
398 |
fail(); |
|
399 |
} |
|
400 |
} |
|
401 |
|
|
402 |
|
|
403 |
//Filtro de campo de segunda tabla con subtipo |
|
404 |
try { |
|
405 |
fColl = (FeatureCollection) join.getDataCollection(new String[] { |
|
406 |
"CODIGO", join_params.getFieldNamePrefix() + "CALLE" }, |
|
407 |
"lower(" + join_params.getFieldNamePrefix() |
|
408 |
+ "CALLE) like 'a%'", null); |
|
409 |
} catch (ReadException e) { |
|
410 |
e.printStackTrace(); |
|
411 |
fail(); |
|
412 |
} |
|
413 |
|
|
414 |
// numero de elementos: shp 9 (lower(l_CALLE) like 'a%') |
|
415 |
assertEquals(9, fColl.size()); |
|
416 |
iter = fColl.iterator(); |
|
417 |
|
|
418 |
while (iter.hasNext()) { |
|
419 |
feature = (Feature) iter.next(); |
|
420 |
if (!feature.getString(join_params.getFieldNamePrefix() + "CALLE") |
|
421 |
.toLowerCase().startsWith("a")) { |
|
422 |
fail(); |
|
423 |
} |
|
424 |
} |
|
425 |
|
|
426 |
fColl.dispose(); |
|
427 |
fColl = null; |
|
428 |
|
|
429 |
} |
|
430 |
|
|
431 |
|
|
198 | 432 |
} |
Also available in: Unified diff