git-svn-id: http://svn.openlayers.org/trunk/openlayers@10703 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
334 lines
12 KiB
HTML
334 lines
12 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
function test_initialize(t) {
|
|
t.plan(2);
|
|
|
|
var protocol = new OpenLayers.Protocol.WFS({
|
|
url: "http://some.url.org",
|
|
featureNS: "http://namespace.org",
|
|
featureType: "type"
|
|
});
|
|
t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_0_0,
|
|
"initialize returns instance of default versioned protocol")
|
|
|
|
var protocol = new OpenLayers.Protocol.WFS({
|
|
url: "http://some.url.org",
|
|
featureNS: "http://namespace.org",
|
|
featureType: "type",
|
|
version: "1.1.0"
|
|
});
|
|
t.ok(protocol instanceof OpenLayers.Protocol.WFS.v1_1_0,
|
|
"initialize returns instance of custom versioned protocol")
|
|
}
|
|
|
|
function test_read(t) {
|
|
t.plan(6);
|
|
|
|
var protocol = new OpenLayers.Protocol.WFS({
|
|
url: "http://some.url.org",
|
|
featureNS: "http://namespace.org",
|
|
featureType: "type",
|
|
parseResponse: function(request) {
|
|
t.eq(request.responseText, "foo", "parseResponse called properly");
|
|
return "foo";
|
|
}
|
|
});
|
|
|
|
var _POST = OpenLayers.Request.POST;
|
|
|
|
var expected, status;
|
|
OpenLayers.Request.POST = function(obj) {
|
|
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeature request is correct");
|
|
obj.status = status;
|
|
obj.responseText = "foo";
|
|
obj.options = {};
|
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
|
return obj;
|
|
};
|
|
|
|
expected = readXML("GetFeature_1");
|
|
status = 200;
|
|
var response = protocol.read({callback: function(response) {
|
|
t.eq(response.features, "foo", "user callback properly called with features");
|
|
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly");
|
|
}});
|
|
|
|
options = {
|
|
maxFeatures: 10,
|
|
featureType: 'type2',
|
|
srsName: 'EPSG:900913',
|
|
featureNS: 'htttp://alternative.namespace.org',
|
|
callback: function(response) {
|
|
t.eq(response.code, OpenLayers.Protocol.Response.FAILURE, "failure reported properly to user callback");
|
|
}
|
|
};
|
|
expected = readXML("GetFeature_2");
|
|
status = 400;
|
|
var response = protocol.read(options);
|
|
|
|
OpenLayers.Request.POST = _POST;
|
|
}
|
|
|
|
function test_commit(t){
|
|
t.plan(4);
|
|
|
|
var url = "http://some.url.org";
|
|
var protocol = new OpenLayers.Protocol.WFS({
|
|
url: url,
|
|
featureNS: "http://namespace.org",
|
|
featureType: "type"
|
|
});
|
|
protocol.format.read = function(data) {
|
|
t.eq(data, "foo", "callback called with correct argument");
|
|
return {
|
|
insertIds: new Array(3),
|
|
success: true
|
|
}
|
|
};
|
|
|
|
var _POST = OpenLayers.Request.POST;
|
|
|
|
var expected;
|
|
OpenLayers.Request.POST = function(obj) {
|
|
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "Transaction XML with Insert, Update and Delete created correctly");
|
|
obj.responseText = "foo";
|
|
obj.options = {};
|
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
|
return obj;
|
|
};
|
|
|
|
var featureDelete = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(42, 7), {has : "cheeseburger"});
|
|
featureDelete.fid = "fid.37";
|
|
featureDelete.state = OpenLayers.State.DELETE;
|
|
featureDelete.layer = {
|
|
projection: {
|
|
getCode : function(){
|
|
return "EPSG:4326";
|
|
}
|
|
}
|
|
}
|
|
var featureInsert = featureDelete.clone();
|
|
featureInsert.state = OpenLayers.State.INSERT;
|
|
var featureModify = featureDelete.clone();
|
|
featureModify.fid = "fid.37";
|
|
featureModify.state = OpenLayers.State.UPDATE;
|
|
|
|
options = {
|
|
featureNS: "http://some.namespace.org",
|
|
featureType: "type",
|
|
callback: function(response) {
|
|
t.eq(response.insertIds.length, 3, "correct response passed to user callback");
|
|
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success properly reported to user callback");
|
|
}
|
|
}
|
|
|
|
expected = readXML("commit");
|
|
var response = protocol.commit([featureInsert, featureModify, featureDelete], options);
|
|
|
|
OpenLayers.Request.POST = _POST;
|
|
|
|
}
|
|
|
|
function test_filterDelete(t) {
|
|
t.plan(2)
|
|
|
|
var url = "http://some.url.org";
|
|
var protocol = new OpenLayers.Protocol.WFS({
|
|
url: url,
|
|
featureNS: "http://namespace.org",
|
|
featureType: "type"
|
|
});
|
|
|
|
var filter = new OpenLayers.Filter.Spatial({
|
|
type: OpenLayers.Filter.Spatial.BBOX,
|
|
value: new OpenLayers.Bounds(-5, -5, 5, 5)
|
|
});
|
|
|
|
var _POST = OpenLayers.Request.POST;
|
|
|
|
var expected = readXML("filter_delete");
|
|
OpenLayers.Request.POST = function(obj) {
|
|
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "request data correct");
|
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
|
return obj;
|
|
};
|
|
|
|
var response = protocol.filterDelete(filter, {
|
|
callback: function() {
|
|
t.ok("user callback function called");
|
|
}
|
|
});
|
|
|
|
OpenLayers.Request.POST = _POST;
|
|
}
|
|
|
|
function test_abort(t) {
|
|
t.plan(1);
|
|
var protocol = new OpenLayers.Protocol.WFS({
|
|
url: "http://example.com",
|
|
featureNS: "http://example.com#namespace",
|
|
featureType: "type"
|
|
});
|
|
|
|
var response = {
|
|
priv: {
|
|
abort: function() {
|
|
aborted = true;
|
|
}
|
|
}
|
|
};
|
|
|
|
// call abort with mocked response
|
|
var aborted = false;
|
|
protocol.abort(response);
|
|
t.eq(aborted, true, "abort called on response.priv");
|
|
|
|
}
|
|
|
|
function test_fromWMSLayer(t) {
|
|
t.plan(8);
|
|
var map = new OpenLayers.Map("map", {
|
|
projection: "EPSG:1234"
|
|
});
|
|
var layer = new OpenLayers.Layer.WMS("foo", "htttp://foo/ows",
|
|
{layers: "topp:states"}
|
|
);
|
|
map.addLayer(layer);
|
|
var protocol = OpenLayers.Protocol.WFS.fromWMSLayer(layer);
|
|
t.eq(protocol.url, "htttp://foo/ows", "url taken from wms layer");
|
|
t.eq(protocol.featurePrefix, "topp", "feature prefix correctly extracted");
|
|
t.eq(protocol.featureType, "states", "typeName correctly extracted");
|
|
t.eq(protocol.srsName, "EPSG:1234", "srsName set correctly");
|
|
t.eq(protocol.version, "1.1.0", "version set correctly");
|
|
|
|
layer.params["LAYERS"] = ["topp:street_centerline", "topp:states"];
|
|
layer.projection = new OpenLayers.Projection("EPSG:900913");
|
|
protocol = OpenLayers.Protocol.WFS.fromWMSLayer(layer);
|
|
t.eq(protocol.featurePrefix, "topp", "featurePrefix from layer param array");
|
|
t.eq(protocol.featureType, "street_centerline", "first layer from layer param array as featureType");
|
|
t.eq(protocol.srsName, "EPSG:900913", "projection from layer preferred");
|
|
}
|
|
|
|
function test_readFormat(t) {
|
|
t.plan(1);
|
|
|
|
var protocol = new OpenLayers.Protocol.WFS({
|
|
url: "http://some.url.org",
|
|
featureNS: "http://namespace.org",
|
|
featureType: "type",
|
|
formatOptions: {outputFormat: 'json'},
|
|
readFormat: new OpenLayers.Format.GeoJSON()
|
|
});
|
|
|
|
var request = {};
|
|
request.responseText = '{"type":"FeatureCollection","features":[{"type":"Feature","id":"V_HECTOPUNTEN.108411","geometry":{"type":"MultiPoint","coordinates":[[190659.467,349576.19]]},"geometry_name":"ORA_GEOMETRY","properties":{"WEGNUMMER":"002","HECTOMTRNG_ORG":2200,"HECTOMTRNG":"220.00","bbox":[190659.467,349576.19,190659.467,349576.19]}}]}';
|
|
var features = protocol.parseResponse(request);
|
|
t.eq(features.length, 1, "the right format is used to read the request (GeoJSON)");
|
|
}
|
|
|
|
function test_readOptions(t) {
|
|
t.plan(1);
|
|
|
|
var protocol = new OpenLayers.Protocol.WFS({
|
|
url: "http://some.url.org",
|
|
version: "1.1.0",
|
|
featureNS: "http://namespace.org",
|
|
featureType: "type",
|
|
readOptions: {'output': 'object'},
|
|
parseResponse: function(request, options) {
|
|
t.eq(options.output, "object", "Options object correctly set to pass on to Format's read");
|
|
}
|
|
});
|
|
|
|
var _POST = OpenLayers.Request.POST;
|
|
|
|
OpenLayers.Request.POST = function(obj) {
|
|
obj.status = 200;
|
|
obj.responseText = "foo";
|
|
obj.options = {};
|
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
|
return obj;
|
|
};
|
|
|
|
protocol.read({
|
|
callback: function() {}
|
|
});
|
|
|
|
OpenLayers.Request.POST = _POST;
|
|
}
|
|
|
|
function readXML(id) {
|
|
var xml = document.getElementById(id).firstChild.nodeValue;
|
|
return new OpenLayers.Format.XML().read(xml).documentElement;
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width:512px; height:256px"> </div>
|
|
<div id="GetFeature_1"><!--
|
|
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
<wfs:Query typeName="feature:type" xmlns:feature="http://namespace.org"/>
|
|
</wfs:GetFeature>
|
|
--></div>
|
|
<div id="GetFeature_2"><!--
|
|
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" maxFeatures="10" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
<wfs:Query typeName="feature:type2" xmlns:feature="htttp://alternative.namespace.org"/>
|
|
</wfs:GetFeature>
|
|
--></div>
|
|
<div id="commit"><!--
|
|
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
<wfs:Insert>
|
|
<feature:type xmlns:feature="http://namespace.org">
|
|
<feature:the_geom>
|
|
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
|
<gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates>
|
|
</gml:Point>
|
|
</feature:the_geom>
|
|
<feature:has>cheeseburger</feature:has>
|
|
</feature:type>
|
|
</wfs:Insert>
|
|
<wfs:Update typeName="feature:type" xmlns:feature="http://namespace.org">
|
|
<wfs:Property>
|
|
<wfs:Name>the_geom</wfs:Name>
|
|
<wfs:Value>
|
|
<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
|
<gml:coordinates decimal="." cs="," ts=" ">42,7</gml:coordinates>
|
|
</gml:Point>
|
|
</wfs:Value>
|
|
</wfs:Property>
|
|
<wfs:Property>
|
|
<wfs:Name>has</wfs:Name>
|
|
<wfs:Value>cheeseburger</wfs:Value>
|
|
</wfs:Property>
|
|
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
|
<ogc:FeatureId fid="fid.37"/>
|
|
</ogc:Filter>
|
|
</wfs:Update>
|
|
<wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org">
|
|
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
|
<ogc:FeatureId fid="fid.37"/>
|
|
</ogc:Filter>
|
|
</wfs:Delete>
|
|
</wfs:Transaction>
|
|
--></div>
|
|
<div id="filter_delete"><!--
|
|
<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0">
|
|
<wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org">
|
|
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
|
<ogc:BBOX>
|
|
<ogc:PropertyName/>
|
|
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
|
<gml:coordinates decimal="." cs="," ts=" ">-5,-5 5,5</gml:coordinates>
|
|
</gml:Box>
|
|
</ogc:BBOX>
|
|
</ogc:Filter>
|
|
</wfs:Delete>
|
|
</wfs:Transaction>
|
|
--></div>
|
|
</body>
|
|
</html>
|