01: package org.geotools.data.gml;
02:
03: import java.util.HashSet;
04: import java.util.Iterator;
05:
06: import org.geotools.data.DefaultQuery;
07: import org.geotools.factory.CommonFactoryFinder;
08: import org.geotools.feature.Feature;
09: import org.geotools.feature.FeatureCollection;
10: import org.opengis.filter.Filter;
11: import org.opengis.filter.FilterFactory;
12: import org.opengis.filter.identity.FeatureId;
13:
14: public class GMLFeatureSourceTest extends GMLDataStoreTestSupport {
15:
16: GMLFeatureSource featureSource;
17:
18: protected void setUp() throws Exception {
19: super .setUp();
20:
21: featureSource = (GMLFeatureSource) dataStore
22: .getFeatureSource("TestFeature");
23: }
24:
25: public void testGetFeatures() throws Exception {
26: FeatureCollection features = featureSource.getFeatures();
27: assertTrue(features instanceof GMLFeatureCollection);
28:
29: assertEquals(3, features.size());
30: }
31:
32: public void testGetFeaturesWithFilter() throws Exception {
33: FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
34: HashSet fids = new HashSet();
35: FeatureId id = ff.featureId("1");
36: fids.add(id);
37:
38: Filter idFilter = ff.id(fids);
39: FeatureCollection features = featureSource
40: .getFeatures(idFilter);
41: assertEquals(1, features.size());
42: }
43:
44: public void testGetFeaturesWithQuery() throws Exception {
45: FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
46: HashSet fids = new HashSet();
47: FeatureId id = ff.featureId("1");
48: fids.add(id);
49:
50: Filter idFilter = ff.id(fids);
51: DefaultQuery query = new DefaultQuery("TestFeature", idFilter,
52: new String[] { "count" });
53: FeatureCollection features = featureSource.getFeatures(query);
54: assertEquals(1, features.size());
55:
56: Iterator i = features.iterator();
57: assertTrue(i.hasNext());
58:
59: Feature f = (Feature) i.next();
60: assertNotNull(f);
61:
62: assertEquals(1, f.getFeatureType().getAttributeCount());
63: assertNull(f.getDefaultGeometry());
64: assertEquals(new Integer(1), f.getAttribute("count"));
65:
66: features.close(i);
67: }
68:
69: }
|