Source Code Cross Referenced for GetFeatureTest.java in  » GIS » GeoServer » org » geoserver » wfs » v1_1 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoServer » org.geoserver.wfs.v1_1 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.geoserver.wfs.v1_1;
002:
003:        import javax.xml.namespace.QName;
004:
005:        import junit.textui.TestRunner;
006:
007:        import org.geoserver.data.test.MockData;
008:        import org.geoserver.wfs.WFSTestSupport;
009:        import org.geotools.gml3.bindings.GML;
010:        import org.geotools.referencing.CRS;
011:        import org.w3c.dom.Document;
012:        import org.w3c.dom.Element;
013:        import org.w3c.dom.NodeList;
014:
015:        public class GetFeatureTest extends WFSTestSupport {
016:
017:            public void testGet() throws Exception {
018:                testGetFifteenAll("wfs?request=GetFeature&typename=cdf:Fifteen&version=1.1.0&service=wfs");
019:            }
020:
021:            public void testGetPropertyNameEmpty() throws Exception {
022:                testGetFifteenAll("wfs?request=GetFeature&typename=cdf:Fifteen&version=1.1.0&service=wfs&propertyname=");
023:            }
024:
025:            public void testGetPropertyNameStar() throws Exception {
026:                testGetFifteenAll("wfs?request=GetFeature&typename=cdf:Fifteen&version=1.1.0&service=wfs&propertyname=*");
027:            }
028:
029:            private void testGetFifteenAll(String request) throws Exception {
030:                Document doc = getAsDOM(request);
031:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
032:                        .getNodeName());
033:
034:                NodeList features = doc.getElementsByTagName("cdf:Fifteen");
035:                assertFalse(features.getLength() == 0);
036:
037:                for (int i = 0; i < features.getLength(); i++) {
038:                    Element feature = (Element) features.item(i);
039:                    assertTrue(feature.hasAttribute("gml:id"));
040:                }
041:            }
042:
043:            public void testPost() throws Exception {
044:
045:                String xml = "<wfs:GetFeature " + "service=\"WFS\" "
046:                        + "version=\"1.1.0\" "
047:                        + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
048:                        + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
049:                        + "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
050:                        + "<wfs:Query typeName=\"cdf:Other\"> "
051:                        + "<wfs:PropertyName>cdf:string2</wfs:PropertyName> "
052:                        + "</wfs:Query> " + "</wfs:GetFeature>";
053:
054:                Document doc = postAsDOM("wfs", xml);
055:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
056:                        .getNodeName());
057:
058:                NodeList features = doc.getElementsByTagName("cdf:Other");
059:                assertFalse(features.getLength() == 0);
060:
061:                for (int i = 0; i < features.getLength(); i++) {
062:                    Element feature = (Element) features.item(i);
063:                    assertTrue(feature.hasAttribute("gml:id"));
064:                }
065:
066:            }
067:
068:            public void testPostFormEncoded() throws Exception {
069:                String request = "wfs?service=WFS&version=1.1.0&request=GetFeature&typename=sf:PrimitiveGeoFeature"
070:                        + "&namespace=xmlns(sf=http://cite.opengeospatial.org/gmlsf)";
071:
072:                Document doc = postAsDOM(request);
073:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
074:                        .getNodeName());
075:
076:                assertEquals(5, doc.getElementsByTagName(
077:                        "sf:PrimitiveGeoFeature").getLength());
078:            }
079:
080:            public void testPostWithFilter() throws Exception {
081:                String xml = "<wfs:GetFeature " + "service=\"WFS\" "
082:                        + "version=\"1.1.0\" "
083:                        + "outputFormat=\"text/xml; subtype=gml/3.1.1\" "
084:                        + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
085:                        + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
086:                        + "xmlns:ogc=\"http://www.opengis.net/ogc\" > "
087:                        + "<wfs:Query typeName=\"cdf:Other\"> "
088:                        + "<ogc:Filter> " + "<ogc:PropertyIsEqualTo> "
089:                        + "<ogc:PropertyName>cdf:integers</ogc:PropertyName> "
090:                        + "<ogc:Add> " + "<ogc:Literal>4</ogc:Literal> "
091:                        + "<ogc:Literal>3</ogc:Literal> " + "</ogc:Add> "
092:                        + "</ogc:PropertyIsEqualTo> " + "</ogc:Filter> "
093:                        + "</wfs:Query> " + "</wfs:GetFeature>";
094:
095:                Document doc = postAsDOM("wfs", xml);
096:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
097:                        .getNodeName());
098:
099:                NodeList features = doc.getElementsByTagName("cdf:Other");
100:                assertFalse(features.getLength() == 0);
101:
102:                for (int i = 0; i < features.getLength(); i++) {
103:                    Element feature = (Element) features.item(i);
104:                    assertTrue(feature.hasAttribute("gml:id"));
105:                }
106:            }
107:
108:            public void testPostWithBboxFilter() throws Exception {
109:                String xml = "<wfs:GetFeature "
110:                        + "service=\"WFS\" "
111:                        + "version=\"1.1.0\" "
112:                        + "outputFormat=\"text/xml; subtype=gml/3.1.1\" "
113:                        + "xmlns:gml=\"http://www.opengis.net/gml\" "
114:                        + "xmlns:sf=\"http://www.opengis.net/cite/data\" "
115:                        + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
116:                        + "xmlns:ogc=\"http://www.opengis.net/ogc\" > "
117:                        + "<wfs:Query typeName=\"sf:PrimitiveGeoFeature\">"
118:                        + "<ogc:Filter>"
119:                        + "<ogc:BBOX>"
120:                        + "   <ogc:PropertyName>pointProperty</ogc:PropertyName>"
121:                        + "   <gml:Envelope srsName=\"EPSG:4326\">"
122:                        + "      <gml:lowerCorner>57.0 -4.5</gml:lowerCorner>"
123:                        + "      <gml:upperCorner>62.0 1.0</gml:upperCorner>"
124:                        + "   </gml:Envelope>" + "</ogc:BBOX>"
125:                        + "</ogc:Filter>" + "</wfs:Query>"
126:                        + "</wfs:GetFeature>";
127:
128:                Document doc = postAsDOM("wfs", xml);
129:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
130:                        .getNodeName());
131:
132:                NodeList features = doc
133:                        .getElementsByTagName("sf:PrimitiveGeoFeature");
134:                assertEquals(1, features.getLength());
135:            }
136:
137:            public void testPostWithFailingUrnBboxFilter() throws Exception {
138:                String xml = "<wfs:GetFeature "
139:                        + "service=\"WFS\" "
140:                        + "version=\"1.1.0\" "
141:                        + "outputFormat=\"text/xml; subtype=gml/3.1.1\" "
142:                        + "xmlns:gml=\"http://www.opengis.net/gml\" "
143:                        + "xmlns:sf=\"http://www.opengis.net/cite/data\" "
144:                        + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
145:                        + "xmlns:ogc=\"http://www.opengis.net/ogc\" > "
146:                        + "<wfs:Query typeName=\"sf:PrimitiveGeoFeature\">"
147:                        + "<ogc:Filter>"
148:                        + "<ogc:BBOX>"
149:                        + "   <ogc:PropertyName>pointProperty</ogc:PropertyName>"
150:                        + "   <gml:Envelope srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\">"
151:                        + "      <gml:lowerCorner>57.0 -4.5</gml:lowerCorner>"
152:                        + "      <gml:upperCorner>62.0 1.0</gml:upperCorner>"
153:                        + "   </gml:Envelope>" + "</ogc:BBOX>"
154:                        + "</ogc:Filter>" + "</wfs:Query>"
155:                        + "</wfs:GetFeature>";
156:
157:                Document doc = postAsDOM("wfs", xml);
158:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
159:                        .getNodeName());
160:                NodeList features = doc
161:                        .getElementsByTagName("sf:PrimitiveGeoFeature");
162:                assertEquals(0, features.getLength());
163:            }
164:
165:            public void testPostWithMatchingUrnBboxFilter() throws Exception {
166:                String xml = "<wfs:GetFeature "
167:                        + "service=\"WFS\" "
168:                        + "version=\"1.1.0\" "
169:                        + "outputFormat=\"text/xml; subtype=gml/3.1.1\" "
170:                        + "xmlns:gml=\"http://www.opengis.net/gml\" "
171:                        + "xmlns:sf=\"http://www.opengis.net/cite/data\" "
172:                        + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
173:                        + "xmlns:ogc=\"http://www.opengis.net/ogc\" > "
174:                        + "<wfs:Query typeName=\"sf:PrimitiveGeoFeature\">"
175:                        + "<ogc:Filter>"
176:                        + "<ogc:BBOX>"
177:                        + "   <ogc:PropertyName>pointProperty</ogc:PropertyName>"
178:                        + "   <gml:Envelope srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\">"
179:                        + "      <gml:lowerCorner>-4.5 57.0</gml:lowerCorner>"
180:                        + "      <gml:upperCorner>1.0 62.0</gml:upperCorner>"
181:                        + "   </gml:Envelope>" + "</ogc:BBOX>"
182:                        + "</ogc:Filter>" + "</wfs:Query>"
183:                        + "</wfs:GetFeature>";
184:
185:                Document doc = postAsDOM("wfs", xml);
186:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
187:                        .getNodeName());
188:                NodeList features = doc
189:                        .getElementsByTagName("sf:PrimitiveGeoFeature");
190:                assertEquals(1, features.getLength());
191:            }
192:
193:            public void testResultTypeHitsGet() throws Exception {
194:                Document doc = getAsDOM("wfs?request=GetFeature&typename=cdf:Fifteen&version=1.1.0&resultType=hits&service=wfs");
195:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
196:                        .getNodeName());
197:
198:                NodeList features = doc.getElementsByTagName("cdf:Fifteen");
199:                assertEquals(0, features.getLength());
200:
201:                assertEquals("15", doc.getDocumentElement().getAttribute(
202:                        "numberOfFeatures"));
203:            }
204:
205:            public void testResultTypeHitsPost() throws Exception {
206:                String xml = "<wfs:GetFeature " + "service=\"WFS\" "
207:                        + "version=\"1.1.0\" "
208:                        + "outputFormat=\"text/xml; subtype=gml/3.1.1\" "
209:                        + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
210:                        + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
211:                        + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
212:                        + "resultType=\"hits\"> "
213:                        + "<wfs:Query typeName=\"cdf:Seven\"/> "
214:                        + "</wfs:GetFeature>";
215:
216:                Document doc = postAsDOM("wfs", xml);
217:                assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
218:                        .getNodeName());
219:
220:                NodeList features = doc.getElementsByTagName("cdf:Fifteen");
221:                assertEquals(0, features.getLength());
222:
223:                assertEquals("7", doc.getDocumentElement().getAttribute(
224:                        "numberOfFeatures"));
225:            }
226:
227:            public void testWithSRS() throws Exception {
228:                String xml = "<wfs:GetFeature xmlns:wfs=\"http://www.opengis.net/wfs\" version=\"1.1.0\" service=\"WFS\">"
229:                        + "<wfs:Query xmlns:cdf=\"http://www.opengis.net/cite/data\" typeName=\"cdf:Other\" srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\"/>"
230:                        + "</wfs:GetFeature>";
231:
232:                Document dom = postAsDOM("wfs", xml);
233:                assertEquals(1, dom.getElementsByTagName("cdf:Other")
234:                        .getLength());
235:            }
236:
237:            public void testWithSillyLiteral() throws Exception {
238:                String xml = "<wfs:GetFeature xmlns:cdf=\"http://www.opengis.net/cite/data\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" version=\"1.1.0\" service=\"WFS\">"
239:                        + "<wfs:Query  typeName=\"cdf:Other\" srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\">"
240:                        + "<ogc:Filter>"
241:                        + "  <ogc:PropertyIsEqualTo>"
242:                        + "   <ogc:PropertyName>description</ogc:PropertyName>"
243:                        + "   <ogc:Literal>"
244:                        + "       <wfs:Native vendorId=\"foo\" safeToIgnore=\"true\"/>"
245:                        + "   </ogc:Literal>"
246:                        + "   </ogc:PropertyIsEqualTo>"
247:                        + " </ogc:Filter>"
248:                        + "</wfs:Query>"
249:                        + "</wfs:GetFeature>";
250:
251:                Document dom = postAsDOM("wfs", xml);
252:                assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
253:                        .getNodeName());
254:                assertEquals(0, dom.getElementsByTagName("cdf:Other")
255:                        .getLength());
256:            }
257:
258:            public void testWithGmlObjectId() throws Exception {
259:                String xml = "<wfs:GetFeature xmlns:cdf=\"http://www.opengis.net/cite/data\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" version=\"1.1.0\" service=\"WFS\">"
260:                        + "<wfs:Query  typeName=\"cdf:Seven\" srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\">"
261:                        + "</wfs:Query>" + "</wfs:GetFeature>";
262:
263:                Document dom = postAsDOM("wfs", xml);
264:                assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
265:                        .getNodeName());
266:                assertEquals(7, dom.getElementsByTagName("cdf:Seven")
267:                        .getLength());
268:
269:                NodeList others = dom.getElementsByTagName("cdf:Seven");
270:                String id = ((Element) others.item(0)).getAttributeNS(
271:                        GML.NAMESPACE, "id");
272:                assertNotNull(id);
273:
274:                xml = "<wfs:GetFeature xmlns:cdf=\"http://www.opengis.net/cite/data\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" version=\"1.1.0\" service=\"WFS\">"
275:                        + "<wfs:Query  typeName=\"cdf:Seven\" srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\">"
276:                        + "<ogc:Filter>"
277:                        + "<ogc:GmlObjectId gml:id=\""
278:                        + id
279:                        + "\"/>"
280:                        + "</ogc:Filter>"
281:                        + "</wfs:Query>"
282:                        + "</wfs:GetFeature>";
283:                dom = postAsDOM("wfs", xml);
284:
285:                assertEquals(1, dom.getElementsByTagName("cdf:Seven")
286:                        .getLength());
287:            }
288:
289:            public void testPostWithBoundsEnabled() throws Exception {
290:                // enable feature bounds computation
291:                boolean oldFeatureBounding = getWFS().isFeatureBounding();
292:                getWFS().setFeatureBounding(true);
293:                try {
294:                    String xml = "<wfs:GetFeature "
295:                            + "service=\"WFS\" "
296:                            + "version=\"1.1.0\" "
297:                            + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
298:                            + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
299:                            + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
300:                            + "> "
301:                            + "<wfs:Query typeName=\"cdf:Other\"> "
302:                            + "<wfs:PropertyName>cdf:string2</wfs:PropertyName> "
303:                            + "</wfs:Query> " + "</wfs:GetFeature>";
304:
305:                    Document doc = postAsDOM("wfs", xml);
306:                    assertEquals("wfs:FeatureCollection", doc
307:                            .getDocumentElement().getNodeName());
308:
309:                    NodeList features = doc.getElementsByTagName("cdf:Other");
310:                    assertFalse(features.getLength() == 0);
311:
312:                    for (int i = 0; i < features.getLength(); i++) {
313:                        Element feature = (Element) features.item(i);
314:                        assertTrue(feature.hasAttribute("gml:id"));
315:                        NodeList boundList = feature
316:                                .getElementsByTagName("gml:boundedBy");
317:                        assertEquals(1, boundList.getLength());
318:                        Element boundedBy = (Element) boundList.item(0);
319:                        NodeList boxList = boundedBy
320:                                .getElementsByTagName("gml:Envelope");
321:                        assertEquals(1, boxList.getLength());
322:                        Element box = (Element) boxList.item(0);
323:                        assertTrue(box.hasAttribute("srsName"));
324:                    }
325:                } finally {
326:                    getWFS().setFeatureBounding(oldFeatureBounding);
327:                }
328:            }
329:
330:            public void testAfterFeatureTypeAdded() throws Exception {
331:                Document dom = getAsDOM("wfs?request=getfeature&service=wfs&version=1.1.0&typename=sf:new");
332:                assertEquals("ExceptionReport", dom.getDocumentElement()
333:                        .getLocalName());
334:
335:                //add a feature type
336:                dataDirectory.addFeatureType(new QName(MockData.SF_URI, "new",
337:                        MockData.SF_PREFIX), getClass().getResourceAsStream(
338:                        "new.properties"));
339:                applicationContext.refresh();
340:
341:                dom = getAsDOM("wfs?request=getfeature&service=wfs&version=1.1.0&typename=sf:new");
342:                assertEquals("FeatureCollection", dom.getDocumentElement()
343:                        .getLocalName());
344:            }
345:
346:            public void testWithGMLProperties() throws Exception {
347:
348:                dataDirectory.addFeatureType(new QName(MockData.SF_URI,
349:                        "WithGMLProperties", MockData.SF_PREFIX), getClass()
350:                        .getResourceAsStream("WithGMLProperties.properties"));
351:                applicationContext.refresh();
352:
353:                Document dom = getAsDOM("wfs?request=getfeature&service=wfs&version=1.1.0&typename=sf:WithGMLProperties");
354:
355:                assertEquals("FeatureCollection", dom.getDocumentElement()
356:                        .getLocalName());
357:
358:                NodeList features = dom
359:                        .getElementsByTagName("sf:WithGMLProperties");
360:                assertEquals(1, features.getLength());
361:
362:                for (int i = 0; i < features.getLength(); i++) {
363:                    Element feature = (Element) features.item(i);
364:                    assertEquals("one", getFirstElementByTagName(feature,
365:                            "gml:name").getFirstChild().getNodeValue());
366:                    assertEquals("1", getFirstElementByTagName(feature,
367:                            "sf:foo").getFirstChild().getNodeValue());
368:
369:                    Element location = getFirstElementByTagName(feature,
370:                            "gml:location");
371:                    assertNotNull(getFirstElementByTagName(location,
372:                            "gml:Point"));
373:                }
374:            }
375:
376:            public static void main(String[] args) {
377:                TestRunner runner = new TestRunner();
378:                runner.run(GetFeatureTest.class);
379:            }
380:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.