📄 transactiontest.java
字号:
}
public void testUpdateWithGMLProperties() throws Exception {
String xml =
"<wfs:Transaction service=\"WFS\" version=\"1.1.0\"" +
" xmlns:sf=\"http://cite.opengeospatial.org/gmlsf\"" +
" xmlns:ogc=\"http://www.opengis.net/ogc\"" +
" xmlns:gml=\"http://www.opengis.net/gml\"" +
" xmlns:wfs=\"http://www.opengis.net/wfs\">" +
" <wfs:Update typeName=\"sf:WithGMLProperties\">" +
" <wfs:Property>" +
" <wfs:Name>gml:name</wfs:Name>" +
" <wfs:Value>two</wfs:Value>" +
" </wfs:Property>" +
" <wfs:Property>" +
" <wfs:Name>gml:location</wfs:Name>" +
" <wfs:Value>" +
" <gml:Point>" +
" <gml:coordinates>2,2</gml:coordinates>" +
" </gml:Point>" +
" </wfs:Value>" +
" </wfs:Property>" +
" <wfs:Property>" +
" <wfs:Name>sf:foo</wfs:Name>" +
" <wfs:Value>2</wfs:Value>" +
" </wfs:Property>" +
" <ogc:Filter>" +
" <ogc:PropertyIsEqualTo>" +
" <ogc:PropertyName>foo</ogc:PropertyName>" +
" <ogc:Literal>1</ogc:Literal>" +
" </ogc:PropertyIsEqualTo>" +
" </ogc:Filter>" +
" </wfs:Update>" +
"</wfs:Transaction>";
Document dom = postAsDOM( "wfs", xml );
assertEquals( "wfs:TransactionResponse", dom.getDocumentElement().getNodeName());
Element updated = getFirstElementByTagName(dom, "wfs:totalUpdated");
assertEquals( "1", updated.getFirstChild().getNodeValue());
dom = getAsDOM("wfs?request=getfeature&service=wfs&version=1.1.0&typename=sf:WithGMLProperties");
print( dom );
NodeList features = dom.getElementsByTagName("sf:WithGMLProperties");
assertEquals( 1, features.getLength() );
Element feature = (Element) features.item( 0 );
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:sf=\"http://cite.opengeospatial.org/gmlsf\"" +
" xmlns:ogc=\"http://www.opengis.net/ogc\"" +
" xmlns:gml=\"http://www.opengis.net/gml\"" +
" xmlns:wfs=\"http://www.opengis.net/wfs\">" +
" <wfs:Update typeName=\"sf:WithGMLProperties\">" +
" <wfs:Property>" +
" <wfs:Name>sf:name</wfs:Name>" +
" <wfs:Value>trhee</wfs:Value>" +
" </wfs:Property>" +
" <wfs:Property>" +
" <wfs:Name>sf:location</wfs:Name>" +
" <wfs:Value>" +
" <gml:Point>" +
" <gml:coordinates>3,3</gml:coordinates>" +
" </gml:Point>" +
" </wfs:Value>" +
" </wfs:Property>" +
" <wfs:Property>" +
" <wfs:Name>sf:foo</wfs:Name>" +
" <wfs:Value>3</wfs:Value>" +
" </wfs:Property>" +
" <ogc:Filter>" +
" <ogc:PropertyIsEqualTo>" +
" <ogc:PropertyName>foo</ogc:PropertyName>" +
" <ogc:Literal>2</ogc:Literal>" +
" </ogc:PropertyIsEqualTo>" +
" </ogc:Filter>" +
" </wfs:Update>" +
"</wfs:Transaction>";
dom = postAsDOM( "wfs", xml );
assertEquals( "wfs:TransactionResponse", dom.getDocumentElement().getNodeName());
updated = getFirstElementByTagName(dom, "wfs:totalUpdated");
assertEquals( "1", updated.getFirstChild().getNodeValue());
dom = getAsDOM("wfs?request=getfeature&service=wfs&version=1.1.0&typename=sf:WithGMLProperties");
features = dom.getElementsByTagName("sf:WithGMLProperties");
assertEquals( 1, features.getLength() );
feature = (Element) features.item( 0 );
assertEquals( "trhee", 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() );
}
public void testInsertWithBoundedBy() 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:cite=\"http://www.opengeospatial.org/cite\">"
+ "<wfs:Insert>"
+ " <cite:BasicPolygons>"
+ " <gml:boundedBy>"
+ " <gml:Envelope>"
+ "<gml:lowerCorner>-1.0 2.0</gml:lowerCorner>"
+ "<gml:upperCorner>2.0 5.0</gml:upperCorner>"
+ " </gml:Envelope>"
+ " </gml:boundedBy>"
+ " <cite:the_geom>"
+ " <gml:MultiPolygon>"
+ " <gml:polygonMember>"
+ " <gml:Polygon>"
+ "<gml:exterior>"
+ "<gml:LinearRing>"
+ "<gml:posList>-1.0 5.0 2.0 5.0 2.0 2.0 -1.0 2.0 -1.0 5.0</gml:posList>"
+ "</gml:LinearRing>"
+ "</gml:exterior>"
+ " </gml:Polygon>"
+ " </gml:polygonMember>"
+ " </gml:MultiPolygon>"
+ " </cite:the_geom>"
+ " <cite:ID>foo</cite:ID>"
+ " </cite:BasicPolygons>"
+ "</wfs:Insert>"
+ "</wfs:Transaction>";
Document dom = postAsDOM("wfs", xml);
assertEquals("wfs:TransactionResponse", dom.getDocumentElement().getNodeName());
assertEquals( "1", getFirstElementByTagName(dom, "wfs:totalInserted").getFirstChild().getNodeValue());
assertTrue(dom.getElementsByTagName("ogc:FeatureId").getLength() > 0);
}
public void testInsert2() 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:cite=\"http://www.opengis.net/cite\">"
+ "<wfs:Insert>"
+ " <cite:RoadSegments>"
+ " <cite:the_geom>"
+ "<gml:MultiLineString xmlns:gml=\"http://www.opengis.net/gml\""
+ " srsName=\"EPSG:4326\">"
+ " <gml:lineStringMember>"
+ " <gml:LineString>"
+ " <gml:posList>4.2582 52.0643 4.2584 52.0648</gml:posList>"
+ " </gml:LineString>"
+ " </gml:lineStringMember>"
+ " </gml:MultiLineString>"
+ " </cite:the_geom>"
+ " <cite:FID>foo</cite:FID>"
+ " <cite:NAME>bar</cite:NAME>"
+ " </cite:RoadSegments>"
+ "</wfs:Insert>"
+ "</wfs:Transaction>";
Document dom = postAsDOM( "wfs", xml );
assertEquals("wfs:TransactionResponse", dom.getDocumentElement().getNodeName());
assertEquals( "1", getFirstElementByTagName(dom, "wfs:totalInserted").getFirstChild().getNodeValue());
dom = getAsDOM( "wfs?request=getfeature&typename=cite:RoadSegments&srsName=EPSG:4326&" +
"cql_filter=FID%3D'foo'");
print(dom);
assertEquals( "wfs:FeatureCollection", dom.getDocumentElement().getNodeName() );
assertEquals( 1, dom.getElementsByTagName("cite:RoadSegments").getLength() );
Element roadSegment = getFirstElementByTagName(dom, "cite:RoadSegments" );
Element posList = getFirstElementByTagName( roadSegment, "gml:posList" );
assertEquals( "4.2582 52.0643 4.2584 52.0648", posList.getFirstChild().getNodeValue() );
}
public void testUpdateForcedSRS() throws Exception {
testUpdate("srsName=\"EPSG:4326\"");
}
public void testUpdateNoSRS() throws Exception {
testUpdate("");
}
private void testUpdate(String srs) throws Exception {
String xml =
"<wfs:Transaction service=\"WFS\" version=\"1.1.0\"" +
" xmlns:cite=\"http://www.opengis.net/cite\"" +
" xmlns:ogc=\"http://www.opengis.net/ogc\"" +
" xmlns:gml=\"http://www.opengis.net/gml\"" +
" xmlns:wfs=\"http://www.opengis.net/wfs\">" +
" <wfs:Update typeName=\"cite:RoadSegments\">" +
" <wfs:Property>" +
" <wfs:Name>cite:the_geom</wfs:Name>" +
" <wfs:Value>" +
" <gml:MultiLineString xmlns:gml=\"http://www.opengis.net/gml\" " + srs + ">" +
" <gml:lineStringMember>" +
" <gml:LineString>" +
" <gml:posList>4.2582 52.0643 4.2584 52.0648</gml:posList>" +
" </gml:LineString>" +
" </gml:lineStringMember>" +
" </gml:MultiLineString>" +
" </wfs:Value>" +
" </wfs:Property>" +
" <ogc:Filter>" +
" <ogc:PropertyIsEqualTo>" +
" <ogc:PropertyName>FID</ogc:PropertyName>" +
" <ogc:Literal>102</ogc:Literal>" +
" </ogc:PropertyIsEqualTo>" +
" </ogc:Filter>" +
" </wfs:Update>" +
"</wfs:Transaction>";
Document dom = postAsDOM( "wfs", xml );
assertEquals("wfs:TransactionResponse", dom.getDocumentElement().getNodeName());
assertEquals( "1", getFirstElementByTagName(dom, "wfs:totalUpdated").getFirstChild().getNodeValue());
String srsBlock = "".equals(srs) ? "" : "&" + srs.replaceAll("\"", "");
dom = getAsDOM( "wfs?request=getfeature&typename=cite:RoadSegments" + srsBlock + "&" +
"cql_filter=FID%3D'102'");
assertEquals( "wfs:FeatureCollection", dom.getDocumentElement().getNodeName() );
assertEquals( 1, dom.getElementsByTagName("cite:RoadSegments").getLength() );
Element roadSegment = getFirstElementByTagName(dom, "cite:RoadSegments" );
Element posList = getFirstElementByTagName( roadSegment, "gml:posList" );
assertEquals( "4.2582 52.0643 4.2584 52.0648", posList.getFirstChild().getNodeValue() );
}
public void testUpdateWithInvalidProperty() throws Exception {
String xml =
"<wfs:Transaction service=\"WFS\" version=\"1.1.0\"" +
" xmlns:cite=\"http://www.opengis.net/cite\"" +
" xmlns:ogc=\"http://www.opengis.net/ogc\"" +
" xmlns:gml=\"http://www.opengis.net/gml\"" +
" xmlns:wfs=\"http://www.opengis.net/wfs\">" +
" <wfs:Update typeName=\"cite:RoadSegments\">" +
" <wfs:Property>" +
" <wfs:Name>INVALID</wfs:Name>" +
" <wfs:Value>INVALID</wfs:Value>" +
" </wfs:Property>" +
" <ogc:Filter>" +
" <ogc:PropertyIsEqualTo>" +
" <ogc:PropertyName>FID</ogc:PropertyName>" +
" <ogc:Literal>102</ogc:Literal>" +
" </ogc:PropertyIsEqualTo>" +
" </ogc:Filter>" +
" </wfs:Update>" +
"</wfs:Transaction>";
Document dom = postAsDOM( "wfs", xml );
assertEquals("ows:ExceptionReport", dom.getDocumentElement().getNodeName());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -