3 <script src="../../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 var axl_feature_response = '<?xml version="1.0" encoding="Cp1252"?><ARCXML version="1.1"><RESPONSE><FEATURES><FEATURE><FIELDS><FIELD name="UNIQUE_ID" value="514504b5-0458-461d-b540-8e18a454f619" /><FIELD name="LABEL" value="LIBRARY" /><FIELD name="Y_COORD" value="39.57" /><FIELD name="X_COORD" value="-104.24" /><FIELD name="#SHAPE#" value="[Geometry]" /><FIELD name="OBJECTID" value="1" /><FIELD name="shape.area" value="0" /><FIELD name="shape.len" value="0" /></FIELDS></FEATURE><FEATURE><FIELDS><FIELD name="UNIQUE_ID" value="514504b5-0458-461d-b540-8e81a454f619" /><FIELD name="LABEL" value="LIBRARY2" /><FIELD name="Y_COORD" value="39.75" /><FIELD name="X_COORD" value="-104.42" /><FIELD name="#SHAPE#" value="[Geometry]" /><FIELD name="OBJECTID" value="2" /><FIELD name="shape.area" value="0" /><FIELD name="shape.len" value="0" /></FIELDS></FEATURE><FEATURECOUNT count="2" hasmore="false" /><ENVELOPE minx="-678853.220047791" miny="1810.22081371862" maxx="-678853.220047791" maxy="1810.22081371862"/></FEATURES></RESPONSE></ARCXML>';
9 // creating a new arcxml features format creates an object that has a read and write function
11 function test_initialize(t) {
14 var format = new OpenLayers.Format.ArcXML.Features();
15 t.ok(format instanceof OpenLayers.Format.ArcXML.Features,
16 "new OpenLayers.Format.ArcXML.Features returns object" );
18 t.eq(typeof format.read, "function", "format has a read function");
19 t.eq(typeof format.write, "function", "format has a write function");
23 // read in a known good axl feature response
25 function test_read1(t) {
27 var f = new OpenLayers.Format.ArcXML.Features();
28 var features = f.read(axl_feature_response);
30 t.ok(features !== null, "features are not null" );
31 t.eq(features.length, 2, "feature count is 2" );
33 // test the second feature parsed
34 // <FIELD name="UNIQUE_ID" value="514504b5-0458-461d-b540-8e81a454f619" />
35 // <FIELD name="LABEL" value="LIBRARY2" />
36 // <FIELD name="Y_COORD" value="39.75" />
37 // <FIELD name="X_COORD" value="-104.42" />
38 // <FIELD name="#SHAPE#" value="[Geometry]" />
39 // <FIELD name="OBJECTID" value="2" />
40 // <FIELD name="shape.area" value="0" />
41 // <FIELD name="shape.len" value="0" />
42 t.eq( features[1].attributes['UNIQUE_ID'], "514504b5-0458-461d-b540-8e81a454f619", "field 1 for feature 2 is correct" );
43 t.eq( features[1].attributes['LABEL'], "LIBRARY2", "field 2 for feature 2 is correct" );
44 t.eq( features[1].attributes['Y_COORD'], "39.75", "field 3 for feature 2 is correct" );
45 t.eq( features[1].attributes['X_COORD'], "-104.42", "field 4 for feature 2 is correct" );
46 t.eq( features[1].attributes['#SHAPE#'], "[Geometry]", "field 5 for feature 2 is correct" );
47 t.eq( features[1].attributes['OBJECTID'], "2", "field 6 for feature 2 is correct" );
51 // cause an error by parsing bad axl
53 function test_parseerror(t) {
55 var f = new OpenLayers.Format.ArcXML.Features();
58 f.read( '<?xml version="1.0" encoding="Cp1252"?><ARCXML version="1.1"><NO END TAG>' );
59 t.fail("reading didn't fail");
61 t.eq( ex.message, "Error parsing the ArcXML request", "Exception message indicates parsing error." );