]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Format/ArcXML/Features.html
initial commit
[syp.git] / openlayers / tests / Format / ArcXML / Features.html
1 <html> 
2 <head> 
3     <script src="../../../lib/OpenLayers.js"></script>
4     <script type="text/javascript">
5     
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>';
7     
8     //
9     // creating a new arcxml features format creates an object that has a read and write function
10     //
11     function test_initialize(t) { 
12         t.plan(3); 
13          
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" ); 
17                                                  
18         t.eq(typeof format.read, "function", "format has a read function"); 
19         t.eq(typeof format.write, "function", "format has a write function"); 
20     }
21     
22     //
23     // read in a known good axl feature response
24     //
25     function test_read1(t) {
26         t.plan(8);
27         var f = new OpenLayers.Format.ArcXML.Features();
28         var features = f.read(axl_feature_response);
29         
30         t.ok(features !== null, "features are not null" );
31         t.eq(features.length, 2, "feature count is 2" );
32         
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" );
48     }
49     
50     //
51     // cause an error by parsing bad axl
52     //
53     function test_parseerror(t) {
54         t.plan(1);
55         var f = new OpenLayers.Format.ArcXML.Features();
56         
57         try {
58             f.read( '<?xml version="1.0" encoding="Cp1252"?><ARCXML version="1.1"><NO END TAG>' );
59             t.fail("reading didn't fail");
60         }  catch (ex) {
61             t.eq( ex.message, "Error parsing the ArcXML request", "Exception message indicates parsing error." );
62         }
63     }
64     
65     </script> 
66 </head> 
67 <body> 
68 </body> 
69 </html>