📄 transactiontest.java
字号:
package org.geoserver.wfs.v1_1;
import javax.xml.namespace.QName;
import org.geoserver.data.test.MockData;
import org.geoserver.wfs.WFSTestSupport;
import org.geoserver.wfs.kvp.SrsNameKvpParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class TransactionTest extends WFSTestSupport {
protected void setUp() throws Exception {
super.setUp();
dataDirectory.addFeatureType(
new QName( MockData.SF_URI, "WithGMLProperties", MockData.SF_PREFIX ),
getClass().getResourceAsStream("WithGMLProperties.properties")
);
applicationContext.refresh();
}
public void testInsert1() throws Exception {
String xml = "<wfs:Transaction service=\"WFS\" version=\"1.1.0\" "
+ " xmlns:wfs=\"http://www.opengis.net/wfs\" "
+ " xmlns:gml=\"http://www.opengis.net/gml\" "
+ " xmlns:sf=\"http://cite.opengeospatial.org/gmlsf\">"
+ "<wfs:Insert handle=\"insert-1\">"
+ " <sf:PrimitiveGeoFeature gml:id=\"cite.gmlsf0-f01\">"
+ " <gml:description>"
+ "Fusce tellus ante, tempus nonummy, ornare sed, accumsan nec, leo."
+ "Vivamus pulvinar molestie nisl."
+ "</gml:description>"
+ "<gml:name>Aliquam condimentum felis sit amet est.</gml:name>"
//+ "<gml:name codeSpace=\"http://cite.opengeospatial.org/gmlsf\">cite.gmlsf0-f01</gml:name>"
+ "<sf:curveProperty>"
+ " <gml:LineString gml:id=\"cite.gmlsf0-g01\" srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\">"
+ " <gml:posList>47.608284 19.034142 51.286873 16.7836 49.849854 15.764992</gml:posList>"
+ " </gml:LineString>"
+ "</sf:curveProperty>"
+ "<sf:intProperty>1025</sf:intProperty>"
+ "<sf:measurand>7.405E2</sf:measurand>"
+ "<sf:dateTimeProperty>2006-06-23T12:43:12+01:00</sf:dateTimeProperty>"
+ "<sf:decimalProperty>90.62</sf:decimalProperty>"
+ "</sf:PrimitiveGeoFeature>"
+ "</wfs:Insert>"
+ "<wfs:Insert handle=\"insert-2\">"
+ "<sf:AggregateGeoFeature gml:id=\"cite.gmlsf0-f02\">"
+ " <gml:description>"
+ "Duis nulla nisi, molestie vel, rhoncus a, ullamcorper eu, justo. Sed bibendum."
+ " Ut sem. Mauris nec nunc a eros aliquet pharetra. Mauris nonummy, pede et"
+ " tincidunt ultrices, mauris lectus fermentum massa, in ullamcorper lectus"
+ "felis vitae metus. Sed imperdiet sollicitudin dolor."
+ " </gml:description>"
+ " <gml:name codeSpace=\"http://cite.opengeospatial.org/gmlsf\">cite.gmlsf0-f02</gml:name>"
+ " <gml:name>Quisqué viverra</gml:name>"
+ " <gml:boundedBy>"
+ " <gml:Envelope srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\">"
+ " <gml:lowerCorner>36.1 8.0</gml:lowerCorner>"
+ " <gml:upperCorner>52.0 21.1</gml:upperCorner>"
+ " </gml:Envelope>"
+ " </gml:boundedBy>"
+ " <sf:multiPointProperty>"
+ "<gml:MultiPoint srsName=\"urn:x-ogc:def:crs:EPSG:6.11.2:4326\">"
+ "<gml:pointMember>"
+ " <gml:Point><gml:pos>49.325176 21.036873</gml:pos></gml:Point>"
+ "</gml:pointMember>"
+ "<gml:pointMember>"
+ " <gml:Point><gml:pos>36.142586 13.56189</gml:pos></gml:Point>"
+ "</gml:pointMember>"
+ "<gml:pointMember>"
+ " <gml:Point><gml:pos>51.920937 8.014193</gml:pos></gml:Point>"
+ "</gml:pointMember>"
+ "</gml:MultiPoint>"
+ "</sf:multiPointProperty>"
+
"<sf:doubleProperty>2012.78</sf:doubleProperty>"
+ " <sf:intRangeProperty>43</sf:intRangeProperty>"
+ " <sf:strProperty>"
+ "Donec ligulä pede, sodales iń, vehicula eu, sodales et, lêo."
+ "</sf:strProperty>"
+ "<sf:featureCode>AK121</sf:featureCode>"
+ "</sf:AggregateGeoFeature>"
+ "</wfs:Insert>"
+ "</wfs:Transaction>";
Document dom = postAsDOM("wfs", xml);
assertEquals("wfs:TransactionResponse", dom.getDocumentElement()
.getNodeName());
assertTrue(dom.getElementsByTagName("ogc:FeatureId").getLength() > 0);
}
public void testInsertWithNoSRS() throws Exception {
// 1. do a getFeature
String getFeature = "<wfs:GetFeature " + "service=\"WFS\" " + "version=\"1.1.0\" "
+ "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
+ "xmlns:ogc=\"http://www.opengis.net/ogc\" "
+ "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
+ "<wfs:Query typeName=\"cgf:Points\"> "
+ "<wfs:PropertyName>cite:id</wfs:PropertyName> " + "</wfs:Query> "
+ "</wfs:GetFeature>";
Document dom = postAsDOM("wfs", getFeature);
int n = dom.getElementsByTagName("cgf:Points").getLength();
// perform an insert
String insert = "<wfs:Transaction service=\"WFS\" version=\"1.1.0\" "
+ "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
+ "xmlns:ogc=\"http://www.opengis.net/ogc\" "
+ "xmlns:wfs=\"http://www.opengis.net/wfs\" "
+ "xmlns:gml=\"http://www.opengis.net/gml\"> " + "<wfs:Insert > " + "<cgf:Points>"
+ "<cgf:pointProperty>" + "<gml:Point>" + "<gml:pos>20 40</gml:pos>"
+ "</gml:Point>" + "</cgf:pointProperty>" + "<cgf:id>t0002</cgf:id>"
+ "</cgf:Points>" + "</wfs:Insert>" + "</wfs:Transaction>";
dom = postAsDOM("wfs", insert);
NodeList numberInserteds = dom.getElementsByTagName("wfs:totalInserted");
Element numberInserted = (Element) numberInserteds.item(0);
assertNotNull(numberInserted);
assertEquals("1", numberInserted.getFirstChild().getNodeValue());
String fid = getFirstElementByTagName(dom, "ogc:FeatureId").getAttribute("fid");
// check insertion occurred
dom = postAsDOM("wfs", getFeature);
assertEquals(n + 1, dom.getElementsByTagName("cgf:Points").getLength());
// check coordinate order is preserved
getFeature = "<wfs:GetFeature " + "service=\"WFS\" " + "version=\"1.1.0\" "
+ "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
+ "xmlns:ogc=\"http://www.opengis.net/ogc\" "
+ "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
+ "<wfs:Query typeName=\"cgf:Points\"> "
+ "<ogc:Filter>"
+ "<ogc:PropertyIsEqualTo>"
+ "<ogc:PropertyName>cgf:id</ogc:PropertyName>"
+ "<ogc:Literal>t0002</ogc:Literal>"
+ "</ogc:PropertyIsEqualTo>"
+ "</ogc:Filter></wfs:Query> "
+ "</wfs:GetFeature>";
dom = postAsDOM("wfs", getFeature);
print(dom);
assertEquals("20.0 40.0", getFirstElementByTagName(dom, "gml:pos").getFirstChild().getNodeValue());
}
public void testInsertWithSRS() throws Exception {
// 1. do a getFeature
String getFeature = "<wfs:GetFeature " + "service=\"WFS\" " + "version=\"1.1.0\" "
+ "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
+ "xmlns:ogc=\"http://www.opengis.net/ogc\" "
+ "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
+ "<wfs:Query typeName=\"cgf:Points\"/> "
+ "</wfs:GetFeature>";
Document dom = postAsDOM("wfs", getFeature);
print(dom);
int n = dom.getElementsByTagName("cgf:Points").getLength();
// perform an insert
String insert = "<wfs:Transaction service=\"WFS\" version=\"1.1.0\" "
+ "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
+ "xmlns:ogc=\"http://www.opengis.net/ogc\" "
+ "xmlns:wfs=\"http://www.opengis.net/wfs\" "
+ "xmlns:gml=\"http://www.opengis.net/gml\"> "
+ "<wfs:Insert srsName=\"EPSG:32615\"> " + "<cgf:Points>" + "<cgf:pointProperty>"
+ "<gml:Point>" + "<gml:pos>1 1</gml:pos>" + "</gml:Point>"
+ "</cgf:pointProperty>" + "<cgf:id>t0003</cgf:id>" + "</cgf:Points>"
+ "</wfs:Insert>" + "</wfs:Transaction>";
dom = postAsDOM("wfs", insert);
NodeList numberInserteds = dom.getElementsByTagName("wfs:totalInserted");
Element numberInserted = (Element) numberInserteds.item(0);
assertNotNull(numberInserted);
assertEquals("1", numberInserted.getFirstChild().getNodeValue());
// do another get feature
getFeature = "<wfs:GetFeature " + "service=\"WFS\" version=\"1.1.0\" "
+ "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
+ "xmlns:ogc=\"http://www.opengis.net/ogc\" "
+ "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
+ "<wfs:Query typeName=\"cgf:Points\"> "
+ "</wfs:Query> "
+ "</wfs:GetFeature>";
dom = postAsDOM("wfs", getFeature);
print(dom);
NodeList pointsList = dom.getElementsByTagName("cgf:Points");
assertEquals(n + 1, pointsList.getLength());
}
public void testInsertWithGMLProperties() throws Exception {
String xml = "<wfs:Transaction service=\"WFS\" version=\"1.1.0\" " +
"xmlns:wfs=\"http://www.opengis.net/wfs\" " +
"xmlns:sf=\"http://cite.opengeospatial.org/gmlsf\" " +
"xmlns:gml=\"http://www.opengis.net/gml\">" +
"<wfs:Insert>" +
"<sf:WithGMLProperties>" +
"<gml:location>" +
"<gml:Point>" +
"<gml:coordinates>2,2</gml:coordinates>" +
"</gml:Point>" +
"</gml:location>" +
"<gml:name>two</gml:name>" +
"<sf:foo>2</sf:foo>" +
"</sf:WithGMLProperties>" +
"</wfs:Insert>" +
"</wfs:Transaction>";
Document dom = postAsDOM("wfs", xml);
assertEquals( "wfs:TransactionResponse", dom.getDocumentElement().getNodeName());
Element inserted = getFirstElementByTagName(dom, "wfs:totalInserted");
assertEquals( "1", inserted.getFirstChild().getNodeValue());
dom = getAsDOM("wfs?request=getfeature&service=wfs&version=1.1.0&typename=sf:WithGMLProperties");
NodeList features = dom.getElementsByTagName("sf:WithGMLProperties");
assertEquals( 2, features.getLength() );
Element feature = (Element) features.item( 1 );
assertEquals( "two", getFirstElementByTagName(feature, "gml:name" ).getFirstChild().getNodeValue());
assertEquals( "2", getFirstElementByTagName(feature, "sf:foo" ).getFirstChild().getNodeValue());
Element location = getFirstElementByTagName( feature, "gml:location" );
Element pos = getFirstElementByTagName(location, "gml:pos");
assertEquals( "2.0 2.0", pos.getFirstChild().getNodeValue() );
xml = "<wfs:Transaction service=\"WFS\" version=\"1.1.0\" " +
"xmlns:wfs=\"http://www.opengis.net/wfs\" " +
"xmlns:sf=\"http://cite.opengeospatial.org/gmlsf\" " +
"xmlns:gml=\"http://www.opengis.net/gml\">" +
"<wfs:Insert>" +
"<sf:WithGMLProperties>" +
"<sf:location>" +
"<gml:Point>" +
"<gml:coordinates>3,3</gml:coordinates>" +
"</gml:Point>" +
"</sf:location>" +
"<sf:name>three</sf:name>" +
"<sf:foo>3</sf:foo>" +
"</sf:WithGMLProperties>" +
"</wfs:Insert>" +
"</wfs:Transaction>";
dom = postAsDOM("wfs", xml);
assertEquals( "wfs:TransactionResponse", dom.getDocumentElement().getNodeName());
dom = getAsDOM("wfs?request=getfeature&service=wfs&version=1.1.0&typename=sf:WithGMLProperties");
features = dom.getElementsByTagName("sf:WithGMLProperties");
assertEquals( 3, features.getLength() );
feature = (Element) features.item( 2 );
assertEquals( "three", getFirstElementByTagName(feature, "gml:name" ).getFirstChild().getNodeValue());
assertEquals( "3", getFirstElementByTagName(feature, "sf:foo" ).getFirstChild().getNodeValue());
location = getFirstElementByTagName( feature, "gml:location" );
pos = getFirstElementByTagName(location, "gml:pos");
assertEquals( "3.0 3.0", pos.getFirstChild().getNodeValue() );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -