001: package org.geoserver.wfs;
002:
003: import org.w3c.dom.Document;
004:
005: /**
006: * This test must be run with the server configured with the wfs 1.0 cite
007: * configuration, with data initialized.
008: *
009: * @author Justin Deoliveira, The Open Planning Project
010: *
011: */
012: public class TransactionTest extends WFSTestSupport {
013:
014: public void testDelete() throws Exception {
015:
016: // 1. do a getFeature
017: String getFeature = "<wfs:GetFeature " + "service=\"WFS\" "
018: + "version=\"1.0.0\" "
019: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
020: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
021: + "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
022: + "<wfs:Query typeName=\"cgf:Points\"> "
023: + "<ogc:PropertyName>cite:id</ogc:PropertyName> "
024: + "</wfs:Query> " + "</wfs:GetFeature>";
025:
026: Document dom = postAsDOM("wfs", getFeature);
027: assertEquals(1, dom.getElementsByTagName("gml:featureMember")
028: .getLength());
029:
030: // perform a delete
031: String delete = "<wfs:Transaction service=\"WFS\" version=\"1.0.0\" "
032: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
033: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
034: + "xmlns:wfs=\"http://www.opengis.net/wfs\"> "
035: + "<wfs:Delete typeName=\"cgf:Points\"> "
036: + "<ogc:Filter> "
037: + "<ogc:PropertyIsEqualTo> "
038: + "<ogc:PropertyName>cgf:id</ogc:PropertyName> "
039: + "<ogc:Literal>t0000</ogc:Literal> "
040: + "</ogc:PropertyIsEqualTo> "
041: + "</ogc:Filter> "
042: + "</wfs:Delete> " + "</wfs:Transaction>";
043:
044: dom = postAsDOM("wfs", delete);
045: assertEquals("WFS_TransactionResponse", dom
046: .getDocumentElement().getLocalName());
047: assertEquals(1, dom.getElementsByTagName("wfs:SUCCESS")
048: .getLength());
049:
050: // do another get feature
051: dom = postAsDOM("wfs", getFeature);
052:
053: assertEquals(0, dom.getElementsByTagName("gml:featureMember")
054: .getLength());
055:
056: }
057:
058: public void testInsert() throws Exception {
059:
060: // 1. do a getFeature
061: String getFeature = "<wfs:GetFeature " + "service=\"WFS\" "
062: + "version=\"1.0.0\" "
063: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
064: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
065: + "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
066: + "<wfs:Query typeName=\"cgf:Lines\"> "
067: + "<ogc:PropertyName>cite:id</ogc:PropertyName> "
068: + "</wfs:Query> " + "</wfs:GetFeature>";
069:
070: Document dom = postAsDOM("wfs", getFeature);
071: assertEquals(1, dom.getElementsByTagName("gml:featureMember")
072: .getLength());
073:
074: // perform an insert
075: String insert = "<wfs:Transaction service=\"WFS\" version=\"1.0.0\" "
076: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
077: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
078: + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
079: + "xmlns:gml=\"http://www.opengis.net/gml\"> "
080: + "<wfs:Insert > "
081: + "<cgf:Lines>"
082: + "<cgf:lineStringProperty>"
083: + "<gml:LineString>"
084: + "<gml:coordinates decimal=\".\" cs=\",\" ts=\" \">"
085: + "494475.71056415,5433016.8189323 494982.70115662,5435041.95096618"
086: + "</gml:coordinates>"
087: + "</gml:LineString>"
088: + "</cgf:lineStringProperty>"
089: + "<cgf:id>t0002</cgf:id>"
090: + "</cgf:Lines>"
091: + "</wfs:Insert>" + "</wfs:Transaction>";
092:
093: dom = postAsDOM("wfs", insert);
094: assertTrue(dom.getElementsByTagName("wfs:SUCCESS").getLength() != 0);
095: assertTrue(dom.getElementsByTagName("wfs:InsertResult")
096: .getLength() != 0);
097:
098: // do another get feature
099: dom = postAsDOM("wfs", getFeature);
100: assertEquals(2, dom.getElementsByTagName("gml:featureMember")
101: .getLength());
102: }
103:
104: public void testUpdate() throws Exception {
105:
106: // 1. do a getFeature
107: String getFeature = "<wfs:GetFeature " + "service=\"WFS\" "
108: + "version=\"1.0.0\" "
109: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
110: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
111: + "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
112: + "<wfs:Query typeName=\"cgf:Polygons\"> "
113: + "<ogc:PropertyName>cite:id</ogc:PropertyName> "
114: + "</wfs:Query> " + "</wfs:GetFeature>";
115:
116: Document dom = postAsDOM("wfs", getFeature);
117: assertEquals(1, dom.getElementsByTagName("gml:featureMember")
118: .getLength());
119: assertEquals("t0002", dom.getElementsByTagName("cgf:id")
120: .item(0).getFirstChild().getNodeValue());
121:
122: // perform an update
123: String insert = "<wfs:Transaction service=\"WFS\" version=\"1.0.0\" "
124: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
125: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
126: + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
127: + "xmlns:gml=\"http://www.opengis.net/gml\"> "
128: + "<wfs:Update typeName=\"cgf:Polygons\" > "
129: + "<wfs:Property>"
130: + "<wfs:Name>id</wfs:Name>"
131: + "<wfs:Value>t0003</wfs:Value>"
132: + "</wfs:Property>"
133: + "<ogc:Filter>"
134: + "<ogc:PropertyIsEqualTo>"
135: + "<ogc:PropertyName>id</ogc:PropertyName>"
136: + "<ogc:Literal>t0002</ogc:Literal>"
137: + "</ogc:PropertyIsEqualTo>"
138: + "</ogc:Filter>"
139: + "</wfs:Update>" + "</wfs:Transaction>";
140:
141: dom = postAsDOM("wfs", insert);
142:
143: // do another get feature
144: dom = postAsDOM("wfs", getFeature);
145: assertEquals("t0003", dom.getElementsByTagName("cgf:id")
146: .item(0).getFirstChild().getNodeValue());
147: }
148:
149: public void testInsertWithBoundedBy() throws Exception {
150: String xml = "<wfs:Transaction service=\"WFS\" version=\"1.0.0\" "
151: + " xmlns:wfs=\"http://www.opengis.net/wfs\" "
152: + " xmlns:gml=\"http://www.opengis.net/gml\" "
153: + " xmlns:cite=\"http://www.opengeospatial.org/cite\">"
154: + "<wfs:Insert>"
155: + " <cite:BasicPolygons>"
156: + "<gml:boundedBy>"
157: + "<gml:Box>"
158: + "<gml:coordinates cs=\",\" decimal=\".\" ts=\" \">-2,-1 2,6</gml:coordinates>"
159: + "</gml:Box>"
160: + "</gml:boundedBy>"
161: + " <cite:the_geom>"
162: + "<gml:MultiPolygon>"
163: + "<gml:polygonMember>"
164: + "<gml:Polygon>"
165: + "<gml:outerBoundaryIs>"
166: + "<gml:LinearRing>"
167: + "<gml:coordinates cs=\",\" decimal=\".\" ts=\" \">-1,0 0,1 1,0 0,-1 -1,0</gml:coordinates>"
168: + "</gml:LinearRing>"
169: + "</gml:outerBoundaryIs>"
170: + "</gml:Polygon>"
171: + "</gml:polygonMember>"
172: + "</gml:MultiPolygon>"
173: + " </cite:the_geom>"
174: + " <cite:ID>foo</cite:ID>"
175: + " </cite:BasicPolygons>"
176: + "</wfs:Insert>" + "</wfs:Transaction>";
177:
178: Document dom = postAsDOM("wfs", xml);
179:
180: assertEquals("wfs:WFS_TransactionResponse", dom
181: .getDocumentElement().getNodeName());
182: assertTrue(dom.getElementsByTagName("ogc:FeatureId")
183: .getLength() > 0);
184: assertTrue(dom.getElementsByTagName("wfs:SUCCESS").getLength() > 0);
185: }
186: }
|