001: package org.geoserver.wfs;
002:
003: import org.geoserver.data.test.MockData;
004: import org.vfny.geoserver.global.Data;
005: import org.vfny.geoserver.global.FeatureTypeInfo;
006: import org.vfny.geoserver.global.GeoServer;
007: import org.vfny.geoserver.global.dto.GeoServerDTO;
008: import org.w3c.dom.Document;
009: import org.w3c.dom.NodeList;
010:
011: public class MaxFeaturesTest extends WFSTestSupport {
012:
013: private Data catalog;
014:
015: protected void setUp() throws Exception {
016: super .setUp();
017: // set global max to 5
018: GeoServer gs = (GeoServer) applicationContext
019: .getBean("geoServer");
020: GeoServerDTO dto = (GeoServerDTO) gs.toDTO();
021: dto.setMaxFeatures(5);
022: gs.load(dto);
023:
024: catalog = (Data) applicationContext.getBean("catalog");
025: }
026:
027: public void testGlobalMax() throws Exception {
028: // fifteen has 15 elements, but global max is 5
029: Document doc = getAsDOM("wfs?request=GetFeature&typename=cdf:Fifteen"
030: + "&version=1.0.0&service=wfs");
031: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
032: .getNodeName());
033:
034: NodeList featureMembers = doc
035: .getElementsByTagName("gml:featureMember");
036: assertEquals(5, featureMembers.getLength());
037: }
038:
039: public void testLocalMax() throws Exception {
040: // setup different max on local
041: FeatureTypeInfo info = catalog
042: .getFeatureTypeInfo(MockData.FIFTEEN);
043: info.setMaxFeatures(3);
044:
045: // fifteen has 15 elements, but global max is 5 and local is 3
046: Document doc = getAsDOM("wfs?request=GetFeature&typename=cdf:Fifteen"
047: + "&version=1.0.0&service=wfs");
048: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
049: .getNodeName());
050:
051: NodeList featureMembers = doc
052: .getElementsByTagName("gml:featureMember");
053: assertEquals(3, featureMembers.getLength());
054: }
055:
056: public void testLocalMaxBigger() throws Exception {
057: // setup different max on local
058: FeatureTypeInfo info = catalog
059: .getFeatureTypeInfo(MockData.FIFTEEN);
060: info.setMaxFeatures(10);
061:
062: // fifteen has 15 elements, but global max is 5 and local is 10
063: Document doc = getAsDOM("wfs?request=GetFeature&typename=cdf:Fifteen"
064: + "&version=1.0.0&service=wfs");
065: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
066: .getNodeName());
067:
068: NodeList featureMembers = doc
069: .getElementsByTagName("gml:featureMember");
070: assertEquals(5, featureMembers.getLength());
071: }
072:
073: public void testCombinedLocalMaxes() throws Exception {
074: // fifteen has 15 features, basic polygons 3
075: FeatureTypeInfo info = catalog
076: .getFeatureTypeInfo(MockData.FIFTEEN);
077: info.setMaxFeatures(2);
078: info = catalog.getFeatureTypeInfo(MockData.BASIC_POLYGONS);
079: info.setMaxFeatures(2);
080:
081: Document doc = getAsDOM("wfs?request=GetFeature&typename=cdf:Fifteen,cite:BasicPolygons"
082: + "&version=1.0.0&service=wfs");
083: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
084: .getNodeName());
085:
086: assertEquals(4, doc.getElementsByTagName("gml:featureMember")
087: .getLength());
088: assertEquals(2, doc.getElementsByTagName("cdf:Fifteen")
089: .getLength());
090: assertEquals(2, doc.getElementsByTagName("cite:BasicPolygons")
091: .getLength());
092: }
093:
094: public void testCombinedLocalMaxesBigger() throws Exception {
095: // fifteen has 15 features, basic polygons 3
096: FeatureTypeInfo info = catalog
097: .getFeatureTypeInfo(MockData.FIFTEEN);
098: info.setMaxFeatures(4);
099: info = catalog.getFeatureTypeInfo(MockData.BASIC_POLYGONS);
100: info.setMaxFeatures(2);
101:
102: Document doc = getAsDOM("wfs?request=GetFeature&typename=cdf:Fifteen,cite:BasicPolygons"
103: + "&version=1.0.0&service=wfs");
104: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
105: .getNodeName());
106:
107: assertEquals(5, doc.getElementsByTagName("gml:featureMember")
108: .getLength());
109: assertEquals(4, doc.getElementsByTagName("cdf:Fifteen")
110: .getLength());
111: assertEquals(1, doc.getElementsByTagName("cite:BasicPolygons")
112: .getLength());
113: }
114:
115: public void testCombinedLocalMaxesBiggerRequestOverride()
116: throws Exception {
117: // fifteen has 15 features, basic polygons 3
118: FeatureTypeInfo info = catalog
119: .getFeatureTypeInfo(MockData.FIFTEEN);
120: info.setMaxFeatures(3);
121: info = catalog.getFeatureTypeInfo(MockData.BASIC_POLYGONS);
122: info.setMaxFeatures(2);
123:
124: Document doc = getAsDOM("wfs?request=GetFeature&typename=cdf:Fifteen,cite:BasicPolygon"
125: + "s&version=1.0.0&service=wfs&maxFeatures=4");
126: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
127: .getNodeName());
128:
129: assertEquals(4, doc.getElementsByTagName("gml:featureMember")
130: .getLength());
131: assertEquals(3, doc.getElementsByTagName("cdf:Fifteen")
132: .getLength());
133: assertEquals(1, doc.getElementsByTagName("cite:BasicPolygons")
134: .getLength());
135: }
136:
137: public void testMaxFeaturesBreak() throws Exception {
138: // see http://jira.codehaus.org/browse/GEOS-1489
139: FeatureTypeInfo info = catalog
140: .getFeatureTypeInfo(MockData.FIFTEEN);
141: info.setMaxFeatures(3);
142: info = catalog.getFeatureTypeInfo(MockData.BASIC_POLYGONS);
143: info.setMaxFeatures(2);
144:
145: Document doc = getAsDOM("wfs?request=GetFeature&typename=cdf:Fifteen,cite:BasicPolygon"
146: + "s&version=1.0.0&service=wfs&maxFeatures=3");
147: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
148: .getNodeName());
149:
150: assertEquals(3, doc.getElementsByTagName("gml:featureMember")
151: .getLength());
152: assertEquals(3, doc.getElementsByTagName("cdf:Fifteen")
153: .getLength());
154: assertEquals(0, doc.getElementsByTagName("cite:BasicPolygons")
155: .getLength());
156: }
157:
158: }
|