forked from geoserver/geoserver
/
GetFeaturePagingTest.java
252 lines (204 loc) · 11.4 KB
/
GetFeaturePagingTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package org.geoserver.wfs;
import java.util.Map;
import org.custommonkey.xmlunit.XMLAssert;
import org.geoserver.catalog.Catalog;
import org.geoserver.catalog.CatalogBuilder;
import org.geoserver.catalog.DataStoreInfo;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.data.test.SystemTestData;
import org.geotools.data.DataStore;
import org.geotools.data.FeatureSource;
import org.geotools.data.FeatureStore;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.junit.Test;
import org.opengis.feature.simple.SimpleFeatureType;
import org.w3c.dom.Document;
public class GetFeaturePagingTest extends WFSTestSupport {
@Override
protected void setUpInternal(SystemTestData testData) throws Exception {
//run all the tests against a store that can do native paging (h2) and one that
// can't (property)
Catalog cat = getCatalog();
DataStoreInfo ds = cat.getFactory().createDataStore();
ds.setName("foo");
ds.setWorkspace(cat.getDefaultWorkspace());
Map params = ds.getConnectionParameters();
params.put("dbtype", "h2");
params.put("database", getTestData().getDataDirectoryRoot().getAbsolutePath());
cat.add(ds);
FeatureSource fs1 = getFeatureSource(SystemTestData.FIFTEEN);
FeatureSource fs2 = getFeatureSource(SystemTestData.SEVEN);
DataStore store = (DataStore) ds.getDataStore(null);
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.init((SimpleFeatureType) fs1.getSchema());
tb.remove("boundedBy");
store.createSchema(tb.buildFeatureType());
tb.init((SimpleFeatureType) fs2.getSchema());
tb.remove("boundedBy");
store.createSchema(tb.buildFeatureType());
CatalogBuilder cb = new CatalogBuilder(cat);
cb.setStore(ds);
FeatureStore fs = (FeatureStore) store.getFeatureSource("Fifteen");
fs.addFeatures(fs1.getFeatures());
FeatureTypeInfo ft = cb.buildFeatureType(fs);
cat.add(ft);
fs = (FeatureStore) store.getFeatureSource("Seven");
fs.addFeatures(fs2.getFeatures());
ft = cb.buildFeatureType(fs);
cat.add(ft);
}
@Test
public void testSingleType() throws Exception {
doTestSingleType("gs:Fifteen");
doTestSingleType("cdf:Fifteen");
}
void doTestSingleType(String typeName) throws Exception {
Document doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeName + "&startIndex=10");
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + typeName + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeName + "&startIndex=16");
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + typeName + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeName + "&startIndex=0");
XMLAssert.assertXpathEvaluatesTo("15", "count(//" + typeName + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeName + "&startIndex=1&maxFeatures=1");
XMLAssert.assertXpathEvaluatesTo("1", "count(//" + typeName + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeName + "&startIndex=16&maxFeatures=1");
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + typeName + ")", doc);
}
@Test
public void testStartIndexSimplePOST() throws Exception {
doTestStartIndexSimplePOST("gs:Fifteen");
doTestStartIndexSimplePOST("cdf:Fifteen");
}
void doTestStartIndexSimplePOST(String typeName) throws Exception {
Document doc = postAsDOM("wfs", startIndexSimpleXML(typeName, 10,-1));
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + typeName + ")", doc);
doc = postAsDOM("wfs", startIndexSimpleXML(typeName, 16,-1));
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + typeName + ")", doc);
doc = postAsDOM("wfs", startIndexSimpleXML(typeName, 0,-1));
XMLAssert.assertXpathEvaluatesTo("15", "count(//" + typeName + ")", doc);
doc = postAsDOM("wfs", startIndexSimpleXML(typeName, 1,1));
XMLAssert.assertXpathEvaluatesTo("1", "count(//" + typeName + ")", doc);
doc = postAsDOM("wfs", startIndexSimpleXML(typeName, 16, 1));
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + typeName + ")", doc);
}
String startIndexSimpleXML(String typeName, int startIndex, int maxFeatures) {
String xml =
"<GetFeature version='1.0.0' xmlns:gml=\"http://www.opengis.net/gml\" startIndex='"+startIndex+"'";
if (maxFeatures > -1) {
xml += " maxFeatures='" + maxFeatures + "'";
}
xml += ">" +
" <Query typeName='" + typeName + "'>" +
" </Query>" +
"</GetFeature>";
return xml;
}
@Test
public void testStartIndexMultipleTypes() throws Exception {
doTestStartIndexMultipleTypes("gs:Fifteen", "gs:Seven");
doTestStartIndexMultipleTypes("cdf:Fifteen", "cdf:Seven");
doTestStartIndexMultipleTypes("gs:Fifteen", "cdf:Seven");
doTestStartIndexMultipleTypes("cdf:Fifteen", "gs:Seven");
}
public void doTestStartIndexMultipleTypes(String fifteen, String seven) throws Exception {
String typeNames = fifteen+","+seven;
Document doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeNames + "&startIndex=10");
print(doc);
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("7", "count(//" + seven + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeNames + "&startIndex=16");
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("6", "count(//" + seven + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeNames + "&startIndex=10&maxfeatures=5");
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + seven + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeNames + "&startIndex=10&maxfeatures=6");
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("1", "count(//" + seven + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.0.0&service=wfs&" +
"typename=" + typeNames + "&startIndex=25");
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + seven + ")", doc);
}
@Test
public void testStartIndexMultipleTypesPOST() throws Exception {
doTestStartIndexMultipleTypesPOST("gs:Fifteen", "gs:Seven");
doTestStartIndexMultipleTypesPOST("cdf:Fifteen", "cdf:Seven");
doTestStartIndexMultipleTypesPOST("gs:Fifteen", "cdf:Seven");
doTestStartIndexMultipleTypesPOST("cdf:Fifteen", "gs:Seven");
}
public void doTestStartIndexMultipleTypesPOST(String fifteen, String seven) throws Exception {
Document doc = postAsDOM("wfs", startIndexMultiXML(fifteen, seven, 10, -1));
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("7", "count(//" + seven + ")", doc);
doc = postAsDOM("wfs", startIndexMultiXML(fifteen, seven, 16, -1));
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("6", "count(//" + seven + ")", doc);
doc = postAsDOM("wfs", startIndexMultiXML(fifteen, seven, 10, 5));
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + seven + ")", doc);
doc = postAsDOM("wfs", startIndexMultiXML(fifteen, seven, 10, 6));
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("1", "count(//" + seven + ")", doc);
doc = postAsDOM("wfs", startIndexMultiXML(fifteen, seven, 25, -1));
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + fifteen + ")", doc);
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + seven + ")", doc);
}
String startIndexMultiXML(String fifteen, String seven, int startIndex, int maxFeatures) {
String xml =
"<GetFeature version=\"1.0.0\" xmlns:gml=\"http://www.opengis.net/gml\" startIndex='"+startIndex+"'";
if (maxFeatures > -1) {
xml += " maxFeatures='" + maxFeatures + "'";
}
xml += ">" +
" <Query typeName='" + fifteen + "'>" +
" </Query>" +
" <Query typeName='" + seven + "'>" +
" </Query>" +
"</GetFeature>";
return xml;
}
@Test
public void testWithFilter() throws Exception {
doTestWithFilter("gs:Fifteen");
doTestWithFilter("cdf:Fifteen");
}
public void doTestWithFilter(String typeName) throws Exception {
Document doc = getAsDOM("/wfs?request=GetFeature&version=1.1.0&service=wfs&" +
"typename=" + typeName + "&startIndex=10");
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + typeName + ")", doc);
doc = getAsDOM("/wfs?request=GetFeature&version=1.1.0&service=wfs&" +
"typename=" + typeName + "&startIndex=10&maxfeatures=4");
XMLAssert.assertXpathEvaluatesTo("4", "count(//" + typeName + ")", doc);
String xml = String.format("<GetFeature version='1.1.0' xmlns:gml='http://www.opengis.net/gml' " +
"startIndex='%d' maxFeatures='%d'>" +
"<Query typeName = '%s'/>" +
"</GetFeature>", 10, 100, typeName);
doc = postAsDOM("wfs", xml);
XMLAssert.assertXpathEvaluatesTo("5", "count(//" + typeName + ")", doc);
xml = String.format("<GetFeature version='1.1.0' xmlns:gml='http://www.opengis.net/gml' " +
"xmlns:ogc='http://www.opengis.net/ogc' startIndex='%d' maxFeatures='%d'>" +
"<Query typeName = '%s'>" +
" <ogc:Filter>" +
" <ogc:FeatureId fid='%s'></ogc:FeatureId>" +
" <ogc:FeatureId fid='%s'></ogc:FeatureId>" +
" <ogc:FeatureId fid='%s'></ogc:FeatureId>" +
" </ogc:Filter>" +
"</Query>"+
"</GetFeature>", 1, 100, typeName, "Fifteen.3", "Fifteen.4", "Fifteen.5");
doc = postAsDOM("wfs", xml);
XMLAssert.assertXpathEvaluatesTo("2", "count(//" + typeName + ")", doc);
XMLAssert.assertXpathEvaluatesTo("0", "count(//" + typeName + "[@gml:id='Fifteen.3'])", doc);
XMLAssert.assertXpathEvaluatesTo("1", "count(//" + typeName + "[@gml:id='Fifteen.4'])", doc);
XMLAssert.assertXpathEvaluatesTo("1", "count(//" + typeName + "[@gml:id='Fifteen.5'])", doc);
}
}