01: package org.geotools.data.wfs;
02:
03: import java.net.URL;
04:
05: import junit.framework.TestCase;
06:
07: import org.geotools.data.DefaultQuery;
08: import org.geotools.data.FeatureReader;
09: import org.geotools.data.FeatureSource;
10: import org.geotools.data.Query;
11: import org.geotools.data.Transaction;
12: import org.geotools.feature.FeatureCollection;
13: import org.geotools.feature.FeatureIterator;
14: import org.geotools.filter.Filter;
15: import org.geotools.filter.FilterFactory;
16: import org.geotools.filter.FilterFactoryFinder;
17: import org.geotools.filter.FilterType;
18: import org.geotools.filter.GeometryFilter;
19:
20: public class MapServerWFSStrategyOnlineTest extends TestCase {
21: private static final String TYPE_NAME = "hospitals"; //$NON-NLS-1$
22:
23: private WFSDataStore ds;
24:
25: private int totalFeatures;
26:
27: protected void setUp() throws Exception {
28: URL host = new URL(
29: "http://mapserver.refractions.net/cgi-bin/mapserv48?map=/home/www/mapserv/maps/victoria-wms.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetCapabilities");
30: ds = new WFSDataStore(host, null, null, null, 10000, 100, true,
31: true);
32: assertTrue(ds.strategy instanceof MapServerWFSStrategy);
33: FilterFactory fac = FilterFactoryFinder.createFilterFactory();
34:
35: GeometryFilter filter = fac
36: .createGeometryFilter(FilterType.GEOMETRY_BBOX);
37:
38: String attName = ds.getSchema(TYPE_NAME).getDefaultGeometry()
39: .getName();
40: filter.addLeftGeometry(fac.createAttributeExpression(attName));
41:
42: filter.addRightGeometry(fac.createBBoxExpression(ds
43: .getBounds(new DefaultQuery(TYPE_NAME))));
44:
45: Query query = new DefaultQuery(TYPE_NAME, filter);
46:
47: FeatureCollection features = ds.getFeatureSource(TYPE_NAME)
48: .getFeatures(query);
49:
50: FeatureIterator iter = features.features();
51: try {
52: int count = 0;
53: while (iter.hasNext()) {
54: iter.next();
55: count++;
56: }
57: this .totalFeatures = count;
58: } finally {
59: iter.close();
60: }
61: }
62:
63: public void testFilterNONE() throws Exception {
64: FeatureSource source = ds.getFeatureSource(TYPE_NAME);
65:
66: FeatureCollection reader = source.getFeatures(Query.ALL);
67: assertCorrectSize(reader);
68:
69: reader = source.getFeatures(Filter.NONE);
70: assertCorrectSize(reader);
71:
72: reader = source.getFeatures(new DefaultQuery(TYPE_NAME,
73: Filter.NONE));
74: assertCorrectSize(reader);
75: }
76:
77: private void assertCorrectSize(FeatureCollection collection)
78: throws Exception {
79: FeatureIterator iter = collection.features();
80:
81: try {
82: int count = 0;
83: while (iter.hasNext()) {
84: count++;
85: iter.next();
86: }
87: assertEquals(this.totalFeatures, count);
88:
89: } finally {
90: iter.close();
91: }
92: }
93:
94: }
|