01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.shapefile.indexed;
17:
18: import org.geotools.data.FeatureSource;
19: import org.geotools.data.Query;
20: import org.geotools.data.shapefile.indexed.FidIndexer;
21: import org.geotools.data.shapefile.indexed.IndexedFidReader;
22: import org.geotools.data.shapefile.indexed.IndexedShapefileDataStore;
23: import java.net.URL;
24:
25: public class FidIndexerTest extends FIDTestCase {
26: protected void tearDown() throws Exception {
27: super .tearDown();
28: }
29:
30: /*
31: * Test method for 'org.geotools.index.fid.FidIndexer.generate(URL)'
32: */
33: public void testGenerate() throws Exception {
34: URL url = FidIndexer.generate(backshp.toURL());
35:
36: IndexedShapefileDataStore ds = new IndexedShapefileDataStore(
37: backshp.toURL(), null, false, false, (byte) 0);
38:
39: FeatureSource fs = ds.getFeatureSource();
40: int features = fs.getCount(Query.ALL);
41:
42: IndexedFidReader reader = new IndexedFidReader(TYPE_NAME,
43: FidIndexer.getReadChannel(url));
44:
45: try {
46: assertEquals(features, reader.getCount());
47:
48: int i = 1;
49:
50: while (reader.hasNext()) {
51: assertEquals(TYPE_NAME + "." + i, reader.next());
52: assertEquals(TYPE_NAME + "." + i, i - 1, reader
53: .currentIndex());
54: i++;
55: }
56:
57: assertEquals(features, i - 1);
58: } finally {
59: reader.close();
60: }
61: }
62: }
|