001: package org.geoserver.wfs;
002:
003: import org.geoserver.data.test.MockData;
004: import org.w3c.dom.Document;
005: import org.w3c.dom.NodeList;
006:
007: public class GetFeatureTest extends WFSTestSupport {
008:
009: public void testGet() throws Exception {
010: testGetFifteenAll("wfs?request=GetFeature&typename=cdf:Fifteen&version=1.0.0&service=wfs");
011: }
012:
013: public void testGetPropertyNameEmpty() throws Exception {
014: testGetFifteenAll("wfs?request=GetFeature&typename=cdf:Fifteen&version=1.0.0&service=wfs&propertyname=");
015: }
016:
017: public void testGetPropertyNameStar() throws Exception {
018: testGetFifteenAll("wfs?request=GetFeature&typename=cdf:Fifteen&version=1.0.0&service=wfs&propertyname=*");
019: }
020:
021: private void testGetFifteenAll(String request) throws Exception {
022: Document doc = getAsDOM(request);
023: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
024: .getNodeName());
025:
026: NodeList featureMembers = doc
027: .getElementsByTagName("gml:featureMember");
028: assertFalse(featureMembers.getLength() == 0);
029: }
030:
031: public void testAlienNamespace() throws Exception {
032: // if the namespace is not known, complain with a service exception
033: Document doc = getAsDOM("wfs?request=GetFeature&typename=youdontknowme:Fifteen&version=1.0.0&service=wfs");
034: assertEquals("ServiceExceptionReport", doc.getDocumentElement()
035: .getNodeName());
036: }
037:
038: public void testPost() throws Exception {
039:
040: String xml = "<wfs:GetFeature " + "service=\"WFS\" "
041: + "version=\"1.0.0\" "
042: + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
043: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
044: + "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
045: + "<wfs:Query typeName=\"cdf:Other\"> "
046: + "<ogc:PropertyName>cdf:string2</ogc:PropertyName> "
047: + "</wfs:Query> " + "</wfs:GetFeature>";
048:
049: Document doc = postAsDOM("wfs", xml);
050:
051: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
052: .getNodeName());
053:
054: NodeList featureMembers = doc
055: .getElementsByTagName("gml:featureMember");
056: assertFalse(featureMembers.getLength() == 0);
057:
058: }
059:
060: public void testPostWithFilter() throws Exception {
061:
062: String xml = "<wfs:GetFeature " + "service=\"WFS\" "
063: + "version=\"1.0.0\" " + "outputFormat=\"GML2\" "
064: + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
065: + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
066: + "xmlns:ogc=\"http://www.opengis.net/ogc\" > "
067: + "<wfs:Query typeName=\"cdf:Other\"> "
068: + "<ogc:PropertyName>cdf:string2</ogc:PropertyName> "
069: + "<ogc:Filter> " + "<ogc:PropertyIsEqualTo> "
070: + "<ogc:PropertyName>cdf:integers</ogc:PropertyName> "
071: + "<ogc:Add> " + "<ogc:Literal>4</ogc:Literal> "
072: + "<ogc:Literal>3</ogc:Literal> " + "</ogc:Add> "
073: + "</ogc:PropertyIsEqualTo> " + "</ogc:Filter> "
074: + "</wfs:Query> " + "</wfs:GetFeature>";
075:
076: Document doc = postAsDOM("wfs", xml);
077:
078: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
079: .getNodeName());
080:
081: NodeList featureMembers = doc
082: .getElementsByTagName("gml:featureMember");
083: assertFalse(featureMembers.getLength() == 0);
084: }
085:
086: public void testLax() throws Exception {
087: String xml = "<GetFeature xmlns:gml=\"http://www.opengis.net/gml\">"
088: + " <Query typeName=\""
089: + MockData.BUILDINGS.getLocalPart()
090: + "\">"
091: + " <PropertyName>ADDRESS</PropertyName>"
092: + " <Filter>"
093: + " <PropertyIsEqualTo>"
094: + " <PropertyName>ADDRESS</PropertyName>"
095: + " <Literal>123 Main Street</Literal>"
096: + " </PropertyIsEqualTo>"
097: + " </Filter>"
098: + " </Query>" + "</GetFeature>";
099:
100: Document doc = postAsDOM("wfs", xml);
101: //print( doc );
102: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
103: .getNodeName());
104:
105: NodeList featureMembers = doc
106: .getElementsByTagName("cite:Buildings");
107: assertEquals(1, featureMembers.getLength());
108: }
109:
110: }
|