From d2ac206ca3bf617a339bfd7a57177ec4533faae4 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 22 Oct 2013 20:34:55 +0200 Subject: [PATCH] starting to add tests for WFS 1.1.0 make sure we don't override the wfs:FeatureCollection reader with the one from GML --- src/ol/parser/ogc/wfsparser_v1.js | 34 +++++++++++++++++ src/ol/parser/ogc/wfsparser_v1_0_0.js | 20 +--------- src/ol/parser/ogc/wfsparser_v1_1_0.js | 9 +++-- test/spec/ol/parser/ogc/wfs_v1_1_0.test.js | 38 +++++++++++++++++++ .../ogc/xml/wfs_v1_1_0/NumberOfFeatures.xml | 9 +++++ .../xml/wfs_v1_1_0/TransactionResponse.xml | 16 ++++++++ 6 files changed, 104 insertions(+), 22 deletions(-) create mode 100644 test/spec/ol/parser/ogc/wfs_v1_1_0.test.js create mode 100644 test/spec/ol/parser/ogc/xml/wfs_v1_1_0/NumberOfFeatures.xml create mode 100644 test/spec/ol/parser/ogc/xml/wfs_v1_1_0/TransactionResponse.xml diff --git a/src/ol/parser/ogc/wfsparser_v1.js b/src/ol/parser/ogc/wfsparser_v1.js index dd1acc1f9e..531287c5ab 100644 --- a/src/ol/parser/ogc/wfsparser_v1.js +++ b/src/ol/parser/ogc/wfsparser_v1.js @@ -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. diff --git a/src/ol/parser/ogc/wfsparser_v1_0_0.js b/src/ol/parser/ogc/wfsparser_v1_0_0.js index f2b55fe5ac..df2e93f691 100644 --- a/src/ol/parser/ogc/wfsparser_v1_0_0.js +++ b/src/ol/parser/ogc/wfsparser_v1_0_0.js @@ -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); diff --git a/src/ol/parser/ogc/wfsparser_v1_1_0.js b/src/ol/parser/ogc/wfsparser_v1_1_0.js index d44ec90dc8..016fd10a7d 100644 --- a/src/ol/parser/ogc/wfsparser_v1_1_0.js +++ b/src/ol/parser/ogc/wfsparser_v1_1_0.js @@ -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); diff --git a/test/spec/ol/parser/ogc/wfs_v1_1_0.test.js b/test/spec/ol/parser/ogc/wfs_v1_1_0.test.js new file mode 100644 index 0000000000..2af072d81a --- /dev/null +++ b/test/spec/ol/parser/ogc/wfs_v1_1_0.test.js @@ -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'); diff --git a/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/NumberOfFeatures.xml b/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/NumberOfFeatures.xml new file mode 100644 index 0000000000..dcc67c37d7 --- /dev/null +++ b/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/NumberOfFeatures.xml @@ -0,0 +1,9 @@ + + + diff --git a/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/TransactionResponse.xml b/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/TransactionResponse.xml new file mode 100644 index 0000000000..6a64bddeca --- /dev/null +++ b/test/spec/ol/parser/ogc/xml/wfs_v1_1_0/TransactionResponse.xml @@ -0,0 +1,16 @@ + + + 0 + 1 + 0 + + + + + + + + + + +