starting to add tests for WFS 1.1.0

make sure we don't override the wfs:FeatureCollection reader with the one from GML
This commit is contained in:
Bart van den Eijnden
2013-10-22 20:34:55 +02:00
parent 0581a49378
commit d2ac206ca3
6 changed files with 104 additions and 22 deletions

View File

@@ -57,6 +57,40 @@ ol.parser.ogc.WFS_v1 = function(opt_options) {
goog.inherits(ol.parser.ogc.WFS_v1, ol.parser.XML);
/**
* @param {ol.parser.ogc.Filter_v1_0_0|ol.parser.ogc.Filter_v1_1_0} filter The
* Filter parser to use.
* @protected
*/
ol.parser.ogc.WFS_v1.prototype.setFilterParser = function(filter) {
this.filter_ = filter;
for (var uri in this.filter_.readers) {
for (var key in this.filter_.readers[uri]) {
if (!goog.isDef(this.readers[uri])) {
this.readers[uri] = {};
}
// do not overwrite any readers
if (!goog.isDef(this.readers[uri][key])) {
this.readers[uri][key] = goog.bind(this.filter_.readers[uri][key],
this.filter_);
}
}
}
for (uri in this.filter_.writers) {
for (key in this.filter_.writers[uri]) {
if (!goog.isDef(this.writers[uri])) {
this.writers[uri] = {};
}
// do not overwrite any writers
if (!goog.isDef(this.writers[uri][key])) {
this.writers[uri][key] = goog.bind(this.filter_.writers[uri][key],
this.filter_);
}
}
}
};
/**
* @param {string|Document|Element} data Data to read.
* @return {Object} An object representing the document.

View File

@@ -74,25 +74,7 @@ ol.parser.ogc.WFS_v1_0_0 = function(opt_options) {
return node;
}
});
this.filter_ = new ol.parser.ogc.Filter_v1_0_0();
for (var uri in this.filter_.readers) {
for (var key in this.filter_.readers[uri]) {
if (!goog.isDef(this.readers[uri])) {
this.readers[uri] = {};
}
this.readers[uri][key] = goog.bind(this.filter_.readers[uri][key],
this.filter_);
}
}
for (uri in this.filter_.writers) {
for (key in this.filter_.writers[uri]) {
if (!goog.isDef(this.writers[uri])) {
this.writers[uri] = {};
}
this.writers[uri][key] = goog.bind(this.filter_.writers[uri][key],
this.filter_);
}
}
this.setFilterParser(new ol.parser.ogc.Filter_v1_0_0());
};
goog.inherits(ol.parser.ogc.WFS_v1_0_0,
ol.parser.ogc.WFS_v1);

View File

@@ -2,6 +2,7 @@ goog.provide('ol.parser.ogc.WFS_v1_1_0');
goog.require('goog.functions');
goog.require('goog.object');
goog.require('ol.parser.ogc.Filter_v1_1_0');
goog.require('ol.parser.ogc.WFS_v1');
@@ -36,9 +37,11 @@ ol.parser.ogc.WFS_v1_1_0 = function() {
this.readChildNodes(node, obj);
},
'Feature': function(node, container) {
var obj = {fids: []};
var obj = {};
this.readChildNodes(node, obj);
container.insertIds.push(obj.fids[0]);
for (var key in obj.fids) {
container.insertIds.push(key);
}
}
});
goog.object.extend(this.writers[this.defaultNamespaceURI], {
@@ -88,7 +91,7 @@ ol.parser.ogc.WFS_v1_1_0 = function() {
return node;
}
});
// TODO ogc and gml namespaces
this.setFilterParser(new ol.parser.ogc.Filter_v1_1_0());
};
goog.inherits(ol.parser.ogc.WFS_v1_1_0,
ol.parser.ogc.WFS_v1);

View File

@@ -0,0 +1,38 @@
goog.provide('ol.test.parser.ogc.WFS_v1_1_0');
describe('ol.parser.ogc.WFS_v1_1_0', function() {
var parser = new ol.parser.ogc.WFS();
describe('reading and writing', function() {
it('handles read of transaction response', function(done) {
var url = 'spec/ol/parser/ogc/xml/wfs_v1_1_0/TransactionResponse.xml';
afterLoadXml(url, function(xml) {
var obj = parser.read(xml);
expect(obj.insertIds.length).to.equal(2);
expect(obj.insertIds[0]).to.equal('parcelle.40');
expect(obj.insertIds[1]).to.equal('parcelle.41');
expect(obj.version).to.equal('1.1.0');
expect(obj.success).to.be(true);
done();
});
});
it('handles read of number of features', function(done) {
var url = 'spec/ol/parser/ogc/xml/wfs_v1_1_0/NumberOfFeatures.xml';
afterLoadXml(url, function(xml) {
// the XML does not contain a version attribute on the root node
var p = new ol.parser.ogc.WFS_v1_1_0();
var obj = p.read(xml);
expect(obj.numberOfFeatures).to.equal(625);
done();
});
});
});
});
goog.require('goog.dom.xml');
goog.require('ol.parser.ogc.WFS');
goog.require('ol.parser.ogc.WFS_v1_1_0');

View File

@@ -0,0 +1,9 @@
<?xml version='1.0' encoding="ISO-8859-1" ?>
<wfs:FeatureCollection
xmlns:rws="http://mapserver.gis.umn.edu/mapserver"
xmlns:gml="http://www.opengis.net/gml"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://mapserver.gis.umn.edu/mapserver http://intranet.rijkswaterstaat.nl/services/geoservices/nwb_wegen?SERVICE=WFS&amp;VERSION=1.1.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=feature:AAA64&amp;OUTPUTFORMAT=text/xml; subtype=gml/3.1.1 http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" numberOfFeatures="625">
</wfs:FeatureCollection>

View File

@@ -0,0 +1,16 @@
<wfs:TransactionResponse version="1.1.0" xmlns:ogc="http://www.opengis.net/ogc" xmlns:tiger="http://www.census.gov" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink">
<wfs:TransactionSummary>
<wfs:totalInserted>0</wfs:totalInserted>
<wfs:totalUpdated>1</wfs:totalUpdated>
<wfs:totalDeleted>0</wfs:totalDeleted>
</wfs:TransactionSummary>
<wfs:TransactionResults/>
<wfs:InsertResults>
<wfs:Feature>
<ogc:FeatureId fid="parcelle.40"/>
</wfs:Feature>
<wfs:Feature>
<ogc:FeatureId fid="parcelle.41"/>
</wfs:Feature>
</wfs:InsertResults>
</wfs:TransactionResponse>