3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_read_WFSDescribeFeatureType(t) {
9 var parser = new OpenLayers.Format.WFSDescribeFeatureType();
11 // single typeName from UMN Mapserver
13 '<?xml version="1.0" encoding="ISO-8859-1" ?>' +
15 ' targetNamespace="http://mapserver.gis.umn.edu/mapserver" ' +
16 ' xmlns:rws="http://mapserver.gis.umn.edu/mapserver" ' +
17 ' xmlns:ogc="http://www.opengis.net/ogc"' +
18 ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
19 ' xmlns="http://www.w3.org/2001/XMLSchema"' +
20 ' xmlns:gml="http://www.opengis.net/gml"' +
21 ' elementFormDefault="qualified" version="0.1" >' +
22 ' <import namespace="http://www.opengis.net/gml"' +
23 ' schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd" />' +
24 ' <element name="AAA64" ' +
25 ' type="rws:AAA64Type" ' +
26 ' substitutionGroup="gml:_Feature" />' +
27 ' <complexType name="AAA64Type">' +
29 ' <extension base="gml:AbstractFeatureType">' +
31 ' <element name="geometry" type="gml:MultiLineStringPropertyType" minOccurs="0" maxOccurs="1"/>' +
32 ' <element name="OBJECTID" type="string"/>' +
33 ' <element name="ROUTE" type="string"/>' +
34 ' <element name="ROUTE_CH" type="string"/>' +
35 ' <element name="COUNT" type="string"/>' +
36 ' <element name="BEHEERDER" type="string"/>' +
37 ' <element name="LENGTH" type="string"/>' +
38 ' <element name="SHAPE" type="string"/>' +
39 ' <element name="SE_ANNO_CAD_DATA" type="string"/>' +
42 ' </complexContent>' +
45 var res = parser.read(text);
47 t.eq(res.featureTypes.length, 1,
48 "There is only 1 typename, so length should be 1");
50 t.eq(res.featureTypes[0].properties[0].type, 'gml:MultiLineStringPropertyType',
51 "The first attribute is of type multi line string");
53 t.eq(res.featureTypes[0].properties[2].name, 'ROUTE',
54 "The third attribute is named ROUTE");
56 t.eq(res.featureTypes[0].properties[2].type, 'string',
57 "The third attribute is of type string");
59 // three typeNames in one response from UMN Mapserver
61 '<?xml version="1.0" encoding="ISO-8859-1" ?>' +
63 ' targetNamespace="http://mapserver.gis.umn.edu/mapserver" ' +
64 ' xmlns:rws="http://mapserver.gis.umn.edu/mapserver" ' +
65 ' xmlns:ogc="http://www.opengis.net/ogc"' +
66 ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
67 ' xmlns="http://www.w3.org/2001/XMLSchema"' +
68 ' xmlns:gml="http://www.opengis.net/gml"' +
69 ' elementFormDefault="qualified" version="0.1" >' +
70 ' <import namespace="http://www.opengis.net/gml"' +
71 ' schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd" />' +
72 ' <element name="KGNAT.VKUNSTWERK" ' +
73 ' type="rws:KGNAT.VKUNSTWERKType" ' +
74 ' substitutionGroup="gml:_Feature" />' +
75 ' <complexType name="KGNAT.VKUNSTWERKType">' +
77 ' <extension base="gml:AbstractFeatureType">' +
79 ' <element name="geometry" type="gml:MultiPolygonPropertyType" minOccurs="0" maxOccurs="1"/>' +
80 ' <element name="OBJECTID" type="string"/>' +
81 ' <element name="OBJECTSUBCATEGORIE" type="string"/>' +
82 ' <element name="DIENSTCODE" type="string"/>' +
83 ' <element name="DISTRICTNAAM" type="string"/>' +
84 ' <element name="CODEBPN" type="string"/>' +
85 ' <element name="WSD" type="string"/>' +
86 ' <element name="SUBCAT" type="string"/>' +
87 ' <element name="ZIJDE" type="string"/>' +
88 ' <element name="KM" type="string"/>' +
89 ' <element name="ELEMENTCODE" type="string"/>' +
90 ' <element name="COMPLEXCODE" type="string"/>' +
91 ' <element name="BEHEEROBJECTCODE" type="string"/>' +
92 ' <element name="BEGINDATUM" type="string"/>' +
93 ' <element name="NAAMCONTACTPERSOON" type="string"/>' +
94 ' <element name="KMTOT" type="string"/>' +
95 ' <element name="HOOFDWATERSYSTEEM" type="string"/>' +
96 ' <element name="WATERSYSTEEMNAAM" type="string"/>' +
97 ' <element name="OBJECTNAAM" type="string"/>' +
98 ' <element name="HERKOMST" type="string"/>' +
99 ' <element name="BEHEERSREGIME" type="string"/>' +
100 ' <element name="VERSIE" type="string"/>' +
101 ' <element name="KWALITEITSNIVEAU" type="string"/>' +
102 ' <element name="STICHTINGSJAAR" type="string"/>' +
103 ' <element name="OBJECTTYPE" type="string"/>' +
104 ' <element name="OPMERKING" type="string"/>' +
105 ' <element name="OPPERVLAKTE" type="string"/>' +
106 ' <element name="SE_ANNO_CAD_DATA" type="string"/>' +
107 ' <element name="SHAPE" type="string"/>' +
110 ' </complexContent>' +
112 ' <element name="KGNAT.LKUNSTWERK" ' +
113 ' type="rws:KGNAT.LKUNSTWERKType" ' +
114 ' substitutionGroup="gml:_Feature" />' +
115 ' <complexType name="KGNAT.LKUNSTWERKType">' +
116 ' <complexContent>' +
117 ' <extension base="gml:AbstractFeatureType">' +
119 ' <element name="geometry" type="gml:MultiLineStringPropertyType" minOccurs="0" maxOccurs="1"/>' +
120 ' <element name="OBJECTID" type="string"/>' +
121 ' <element name="OBJECTSUBCATEGORIE" type="string"/>' +
122 ' <element name="DIENSTCODE" type="string"/>' +
123 ' <element name="DISTRICTNAAM" type="string"/>' +
124 ' <element name="CODEBPN" type="string"/>' +
125 ' <element name="WSD" type="string"/>' +
126 ' <element name="SUBCAT" type="string"/>' +
127 ' <element name="ZIJDE" type="string"/>' +
128 ' <element name="KM" type="string"/>' +
129 ' <element name="ELEMENTCODE" type="string"/>' +
130 ' <element name="COMPLEXCODE" type="string"/>' +
131 ' <element name="BEHEEROBJECTCODE" type="string"/>' +
132 ' <element name="BEGINDATUM" type="string"/>' +
133 ' <element name="NAAMCONTACTPERSOON" type="string"/>' +
134 ' <element name="KMTOT" type="string"/>' +
135 ' <element name="HOOFDWATERSYSTEEM" type="string"/>' +
136 ' <element name="WATERSYSTEEMNAAM" type="string"/>' +
137 ' <element name="OBJECTNAAM" type="string"/>' +
138 ' <element name="HERKOMST" type="string"/>' +
139 ' <element name="BEHEERSREGIME" type="string"/>' +
140 ' <element name="VERSIE" type="string"/>' +
141 ' <element name="KWALITEITSNIVEAU" type="string"/>' +
142 ' <element name="STICHTINGSJAAR" type="string"/>' +
143 ' <element name="OBJECTTYPE" type="string"/>' +
144 ' <element name="OPMERKING" type="string"/>' +
145 ' <element name="LENGTE" type="string"/>' +
146 ' <element name="SE_ANNO_CAD_DATA" type="string"/>' +
147 ' <element name="SHAPE" type="string"/>' +
150 ' </complexContent>' +
152 ' <element name="KGNAT.PKUNSTWERK" ' +
153 ' type="rws:KGNAT.PKUNSTWERKType" ' +
154 ' substitutionGroup="gml:_Feature" />' +
155 ' <complexType name="KGNAT.PKUNSTWERKType">' +
156 ' <complexContent>' +
157 ' <extension base="gml:AbstractFeatureType">' +
159 ' <element name="geometry" type="gml:MultiPointPropertyType" minOccurs="0" maxOccurs="1"/>' +
160 ' <element name="OBJECTID" type="string"/>' +
161 ' <element name="OBJECTSUBCATEGORIE" type="string"/>' +
162 ' <element name="DIENSTCODE" type="string"/>' +
163 ' <element name="DISTRICTNAAM" type="string"/>' +
164 ' <element name="CODEBPN" type="string"/>' +
165 ' <element name="WSD" type="string"/>' +
166 ' <element name="SUBCAT" type="string"/>' +
167 ' <element name="ZIJDE" type="string"/>' +
168 ' <element name="KM" type="string"/>' +
169 ' <element name="ELEMENTCODE" type="string"/>' +
170 ' <element name="COMPLEXCODE" type="string"/>' +
171 ' <element name="BEHEEROBJECTCODE" type="string"/>' +
172 ' <element name="BEGINDATUM" type="string"/>' +
173 ' <element name="NAAMCONTACTPERSOON" type="string"/>' +
174 ' <element name="KMTOT" type="string"/>' +
175 ' <element name="HOOFDWATERSYSTEEM" type="string"/>' +
176 ' <element name="WATERSYSTEEMNAAM" type="string"/>' +
177 ' <element name="OBJECTNAAM" type="string"/>' +
178 ' <element name="HERKOMST" type="string"/>' +
179 ' <element name="BEHEERSREGIME" type="string"/>' +
180 ' <element name="VERSIE" type="string"/>' +
181 ' <element name="KWALITEITSNIVEAU" type="string"/>' +
182 ' <element name="STICHTINGSJAAR" type="string"/>' +
183 ' <element name="OBJECTTYPE" type="string"/>' +
184 ' <element name="OPMERKING" type="string"/>' +
185 ' <element name="X" type="string"/>' +
186 ' <element name="Y" type="string"/>' +
187 ' <element name="SE_ANNO_CAD_DATA" type="string"/>' +
188 ' <element name="SHAPE" type="string"/>' +
191 ' </complexContent>' +
195 parser = new OpenLayers.Format.WFSDescribeFeatureType();
196 res = parser.read(text);
198 t.eq(res.featureTypes.length, 3,
199 "There are 3 typenames, so length should be 3");
201 t.eq(res.featureTypes[0].typeName, 'KGNAT.VKUNSTWERK',
202 "There name of the first typename is KGNAT.VKUNSTWERK");
204 t.eq(res.featureTypes[2].properties.length, 30,
205 "We expect 30 attributes in the third typename");
207 t.eq(res.featureTypes[2].properties[1].name, 'OBJECTID',
208 "The second attribute has name OBJECTID");
210 t.eq(res.featureTypes[2].properties[1].type, 'string',
211 "The second attribute has type string");
213 t.eq(res.targetNamespace, 'http://mapserver.gis.umn.edu/mapserver',
214 "The targetNamespace should be http://mapserver.gis.umn.edu/mapserver");
216 t.eq(res.targetPrefix, 'rws', "the targetPrefix should be rws");
218 // response from Ionic WFS, taken from:
219 // http://webservices.ionicsoft.com/ionicweb/wfs/BOSTON_ORA?service=WFS&request=DescribeFeatureType&version=1.0.0&typename=wfs:highways
221 "<?xml version='1.0' encoding='utf-8' ?>" +
222 ' <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.ionicsoft.com/wfs" targetNamespace="http://www.ionicsoft.com/wfs" xmlns:xlink="http://www.w3.org/1999/xlink" elementFormDefault="qualified" version="0.1">' +
223 ' <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>' +
224 ' <xsd:element name="highways" substitutionGroup="gml:_Feature" type="wfs:highways"/>' +
225 ' <xsd:complexType name="highways">' +
226 ' <xsd:complexContent>' +
227 ' <xsd:extension base="gml:AbstractFeatureType">' +
229 ' <xsd:element name="ROUTE_" minOccurs="0" nillable="true" type="xsd:int"/>' +
230 ' <xsd:element name="ROUTE_ID" minOccurs="0" nillable="true" type="xsd:int"/>' +
231 ' <xsd:element name="RT_NUMBER" minOccurs="0" nillable="true" type="xsd:string"/>' +
232 ' <xsd:element name="GEOMETRY" minOccurs="0" nillable="true" type="gml:GeometryAssociationType"/>' +
234 ' </xsd:extension>' +
235 ' </xsd:complexContent>' +
236 ' </xsd:complexType>' +
239 parser = new OpenLayers.Format.WFSDescribeFeatureType();
240 res = parser.read(text);
242 t.eq(res.featureTypes.length, 1,
243 "There is 1 typename, so length should be 1");
245 t.eq(res.featureTypes[0].typeName, "highways",
246 "The name of the typename is highways");
248 t.eq(res.featureTypes[0].properties.length, 4,
249 "We expect 4 attributes in the first typename");
251 t.eq(res.featureTypes[0].properties[1].name, 'ROUTE_ID',
252 "The second attribute has name ROUTE_ID");
254 t.eq(res.featureTypes[0].properties[1].type, 'xsd:int',
255 "The second attribute has type integer");
257 t.eq(parseInt(res.featureTypes[0].properties[1].minOccurs), 0,
258 "The second attribute has minOccurs 0");
260 t.eq(res.targetNamespace, 'http://www.ionicsoft.com/wfs',
261 "The targetNamespace should be http://www.ionicsoft.com/wfs");
263 t.eq(res.targetPrefix, 'wfs', "the targetPrefix should be wfs");
268 function geoServerTests(text) {
269 parser = new OpenLayers.Format.WFSDescribeFeatureType();
270 res = parser.read(text);
272 t.eq(res.featureTypes.length, 1,
273 "There is 1 typename, so length should be 1");
275 t.eq(res.featureTypes[0].typeName, "railroads",
276 "The name of the typeName is railroads");
278 t.eq(res.featureTypes[0].properties.length, 2,
279 "We expect 2 attributes in the typename");
281 t.eq(res.featureTypes[0].properties[0].name, 'cat',
282 "The first attribute has name cat");
284 t.eq(res.featureTypes[0].properties[0].type.split(":")[1], 'long',
285 "The first attribute has type long with a prefix");
287 t.eq(res.featureTypes[0].properties[0].localType, 'long',
288 "The first attribute has localType long");
290 t.eq(res.targetNamespace, 'http://opengeo.org',
291 "The targetNamespace should be http://opengeo.org");
293 t.eq(res.targetPrefix, 'opengeo', "the targetPrefix should be opengeo");
297 // Read Geoserver WFS 1.0.0 response
298 // Taken from: http://demo.opengeo.org/geoserver/wfs?service=WFS&request=DescribeFeatureType&typename=opengeo:railroads&version=1.0.0
300 '<?xml version="1.0" encoding="UTF-8"?>' +
301 '<xs:schema targetNamespace="http://opengeo.org" xmlns:opengeo="http://opengeo.org" xmlns:gml="http://www.opengis.net/gml" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">' +
302 ' <xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://demo.opengeo.org:80/geoserver/schemas/gml/2.1.2.1/feature.xsd"/>' +
303 ' <xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" name="railroads_Type">' +
304 ' <xs:complexContent>' +
305 ' <xs:extension base="gml:AbstractFeatureType">' +
307 ' <xs:element name="cat" minOccurs="0" nillable="true" type="xs:long"/>' +
308 ' <xs:element name="the_geom" minOccurs="0" nillable="true" type="gml:MultiLineStringPropertyType"/>' +
311 ' </xs:complexContent>' +
312 ' </xs:complexType>' +
313 ' <xs:element name="railroads" type="opengeo:railroads_Type" substitutionGroup="gml:_Feature"/>' +
316 geoServerTests(text);
319 // Read GeoServer WFS 1.1.0 response
320 // taken from http://demo.opengeo.org/geoserver/wfs?service=WFS&request=DescribeFeatureType&typename=opengeo:railroads&version=1.1.0
322 '<?xml version="1.0" encoding="UTF-8"?>' +
323 ' <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:opengeo="http://opengeo.org" elementFormDefault="qualified" targetNamespace="http://opengeo.org">' +
324 ' <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://demo.opengeo.org:80/geoserver/wfs/schemas/gml/3.1.1/base/gml.xsd"/>' +
325 ' <xsd:complexType name="railroadsType">' +
326 ' <xsd:complexContent>' +
327 ' <xsd:extension base="gml:AbstractFeatureType">' +
329 ' <xsd:element maxOccurs="1" minOccurs="0" name="cat" nillable="true" type="xsd:long"/>' +
330 ' <xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiLineStringPropertyType"/>' +
332 ' </xsd:extension>' +
333 ' </xsd:complexContent>' +
334 ' </xsd:complexType>' +
335 ' <xsd:element name="railroads" substitutionGroup="gml:_Feature" type="opengeo:railroadsType"/>' +
338 geoServerTests(text);
340 // Another GeoServer response with type restrictions
341 // taken from http://sigma.openplans.org/geoserver/wfs?service=WFS&request=DescribeFeatureType&typename=topp:states&version=1.0.0
342 text = '<?xml version="1.0" encoding="UTF-8"?><xs:schema targetNamespace="http://www.openplans.org/topp" xmlns:topp="http://www.openplans.org/topp" xmlns:gml="http://www.opengis.net/gml" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0"><xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://sigma.openplans.org:80/geoserver/schemas/gml/2.1.2.1/feature.xsd"/><xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" name="states_Type"><xs:complexContent><xs:extension base="gml:AbstractFeatureType"><xs:sequence><xs:element name="the_geom" minOccurs="0" nillable="true" type="gml:MultiPolygonPropertyType"/><xs:element name="STATE_NAME" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="25"/></xs:restriction></xs:simpleType></xs:element><xs:element name="STATE_FIPS" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="2"/></xs:restriction></xs:simpleType></xs:element><xs:element name="SUB_REGION" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="7"/></xs:restriction></xs:simpleType></xs:element><xs:element name="STATE_ABBR" minOccurs="0" nillable="true"><xs:simpleType><xs:restriction base="xs:string"><xs:maxLength value="2"/></xs:restriction></xs:simpleType></xs:element><xs:element name="LAND_KM" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="WATER_KM" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="PERSONS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="FAMILIES" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="HOUSHOLD" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="MALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="FEMALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="WORKERS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="DRVALONE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="CARPOOL" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="PUBTRANS" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="EMPLOYED" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="UNEMPLOY" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="SERVICE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="MANUAL" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="P_MALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="P_FEMALE" minOccurs="0" nillable="true" type="xs:double"/><xs:element name="SAMP_POP" minOccurs="0" nillable="true" type="xs:double"/></xs:sequence></xs:extension></xs:complexContent></xs:complexType><xs:element name="states" type="topp:states_Type" substitutionGroup="gml:_Feature"/></xs:schema>';
344 parser = new OpenLayers.Format.WFSDescribeFeatureType();
345 res = parser.read(text);
347 t.eq(res.featureTypes[0].properties[1].name, "STATE_NAME",
348 "name of 2nd property of 1st featureType should be 'STATE_NAME'");
350 t.eq(res.featureTypes[0].properties[1].type, "xs:string",
351 "type of 2nd property of 1st featureType should be 'xs:string'");
353 t.eq(res.featureTypes[0].properties[1].localType, "string",
354 "localType of 2nd property of 1st featureType should be 'string'");
356 t.eq(res.featureTypes[0].properties[1].restriction.maxLength, "25",
357 "the maxLength restriction should be 25");
360 function test_readRestriction(t) {
363 '<restriction xmlns="http://www.w3.org/2001/XMLSchema" base="xs:string">' +
364 ' <enumeration value="One"/>' +
365 ' <enumeration value="Two"/>' +
367 var doc = OpenLayers.Format.XML.prototype.read(text).documentElement;
369 new OpenLayers.Format.WFSDescribeFeatureType().readRestriction(doc, obj);
371 t.eq(obj.enumeration.length, 2, "enumeration has a length of 2");
372 t.eq(obj.enumeration[1], "Two", "2nd enumeration value is 'Two'");
373 // other functionality of readRestriction already tested in the last
374 // GeoServer example above