rcap 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/lib/rcap.rb +10 -0
- data/lib/rcap/alert.rb +7 -1
- data/lib/rcap/cap_1_0/alert.rb +383 -0
- data/lib/rcap/cap_1_0/area.rb +178 -0
- data/lib/rcap/cap_1_0/circle.rb +81 -0
- data/lib/rcap/cap_1_0/event_code.rb +8 -0
- data/lib/rcap/cap_1_0/geocode.rb +8 -0
- data/lib/rcap/cap_1_0/info.rb +435 -0
- data/lib/rcap/cap_1_0/parameter.rb +71 -0
- data/lib/rcap/cap_1_0/point.rb +55 -0
- data/lib/rcap/cap_1_0/polygon.rb +89 -0
- data/lib/rcap/cap_1_0/resource.rb +132 -0
- data/lib/rcap/cap_1_1/event_code.rb +0 -14
- data/lib/rcap/cap_1_1/geocode.rb +0 -14
- data/lib/rcap/cap_1_1/parameter.rb +5 -5
- data/lib/rcap/cap_1_1/resource.rb +5 -5
- data/lib/rcap/cap_1_2/event_code.rb +0 -14
- data/lib/rcap/cap_1_2/geocode.rb +0 -14
- data/lib/rcap/cap_1_2/parameter.rb +2 -3
- data/lib/rcap/cap_1_2/resource.rb +5 -5
- data/lib/rcap/version.rb +1 -1
- data/rcap.gemspec +0 -1
- data/spec/alert_spec.rb +64 -0
- data/spec/cap_1_0/alert_spec.rb +222 -0
- data/spec/cap_1_0/area_spec.rb +247 -0
- data/spec/cap_1_0/circle_spec.rb +88 -0
- data/spec/cap_1_0/event_code_spec.rb +37 -0
- data/spec/cap_1_0/geocode_spec.rb +38 -0
- data/spec/cap_1_0/info_spec.rb +324 -0
- data/spec/cap_1_0/parameter_spec.rb +65 -0
- data/spec/cap_1_0/point_spec.rb +46 -0
- data/spec/cap_1_0/polygon_spec.rb +97 -0
- data/spec/cap_1_0/resource_spec.rb +140 -0
- data/spec/cap_1_1/event_code_spec.rb +38 -0
- data/spec/cap_1_1/parameter_spec.rb +37 -0
- data/spec/cap_1_2/event_code_spec.rb +38 -0
- data/spec/cap_1_2/parameter_spec.rb +37 -0
- metadata +49 -34
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_0::Parameter ) do
|
4
|
+
context( 'when initialised' ) do
|
5
|
+
context( 'from XML' ) do
|
6
|
+
before( :each ) do
|
7
|
+
@original_parameter = RCAP::CAP_1_0::Parameter.new( :name => 'name', :value => 'value' )
|
8
|
+
@alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :parameters => @original_parameter ))
|
9
|
+
@xml_string = @alert.to_xml
|
10
|
+
@xml_document = REXML::Document.new( @xml_string )
|
11
|
+
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
|
12
|
+
@parameter_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_0::Parameter::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
|
13
|
+
@parameter = RCAP::CAP_1_0::Parameter.from_xml_element( @parameter_xml_element )
|
14
|
+
end
|
15
|
+
|
16
|
+
it( 'should parse the name correctly' ) do
|
17
|
+
@parameter.name.should == @original_parameter.name
|
18
|
+
end
|
19
|
+
|
20
|
+
it( 'should parse the value correctly' ) do
|
21
|
+
@parameter.value.should == @original_parameter.value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context( 'when exported' ) do
|
27
|
+
before( :each ) do
|
28
|
+
@parameter = RCAP::CAP_1_0::Parameter.new( :name => 'name', :value => 'value' )
|
29
|
+
end
|
30
|
+
|
31
|
+
context( 'to a hash' ) do
|
32
|
+
it( 'should export correctly' ) do
|
33
|
+
@parameter.to_h.should == { 'name' => 'value' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe( '.parse_parameter' ) do
|
39
|
+
it( 'should parse the content correctly' ) do
|
40
|
+
RCAP::CAP_1_0::Parameter.parse_parameter( "name=value" ).should == { :name => 'name', :value => 'value' }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe( '.to_xml_element' ) do
|
45
|
+
before( :each ) do
|
46
|
+
@parameter = RCAP::CAP_1_0::Parameter.new( :name => 'name', :value => 'value' )
|
47
|
+
end
|
48
|
+
|
49
|
+
it( 'should generate an XML element correctly' ) do
|
50
|
+
@parameter.to_xml_element.text.should == 'name=value'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe( '.from_xml_element' ) do
|
55
|
+
before( :each ) do
|
56
|
+
@parameter = RCAP::CAP_1_0::Parameter.new( :name => 'name', :value => 'value' )
|
57
|
+
end
|
58
|
+
|
59
|
+
it( 'should initialise correctly' ) do
|
60
|
+
parameter = RCAP::CAP_1_0::Parameter.from_xml_element( @parameter.to_xml_element )
|
61
|
+
parameter.name.should == @parameter.name
|
62
|
+
parameter.value.should == @parameter.value
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_0::Point ) do
|
4
|
+
describe( 'is not valid if' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@point = RCAP::CAP_1_0::Point.new( :lattitude => 0, :longitude => 0 )
|
7
|
+
@point.should( be_valid )
|
8
|
+
end
|
9
|
+
|
10
|
+
it( 'does not have a longitude defined' ) do
|
11
|
+
@point.longitude = nil
|
12
|
+
@point.should_not( be_valid )
|
13
|
+
end
|
14
|
+
|
15
|
+
it( 'does not have a valid longitude' ) do
|
16
|
+
@point.longitude = RCAP::CAP_1_0::Point::MAX_LONGITUDE + 1
|
17
|
+
@point.should_not( be_valid )
|
18
|
+
@point.longitude = RCAP::CAP_1_0::Point::MIN_LONGITUDE - 1
|
19
|
+
@point.should_not( be_valid )
|
20
|
+
end
|
21
|
+
|
22
|
+
it( 'does not have a lattitude defined' ) do
|
23
|
+
@point.lattitude = nil
|
24
|
+
@point.should_not( be_valid )
|
25
|
+
end
|
26
|
+
|
27
|
+
it( 'does not have a valid lattitude' ) do
|
28
|
+
@point.lattitude = RCAP::CAP_1_0::Point::MAX_LATTITUDE + 1
|
29
|
+
@point.should_not( be_valid )
|
30
|
+
@point.lattitude = RCAP::CAP_1_0::Point::MIN_LATTITUDE - 1
|
31
|
+
@point.should_not( be_valid )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context( 'when exported' ) do
|
36
|
+
before( :each ) do
|
37
|
+
@point = RCAP::CAP_1_0::Point.new( :lattitude => 1, :longitude => 1 )
|
38
|
+
end
|
39
|
+
|
40
|
+
context( 'to hash' ) do
|
41
|
+
it( 'should export correctly' ) do
|
42
|
+
@point.to_h.should == { RCAP::CAP_1_0::Point::LATTITUDE_KEY => 1, RCAP::CAP_1_0::Point::LONGITUDE_KEY => 1 }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_0::Polygon ) do
|
4
|
+
describe( 'is not valid if it' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@polygon = RCAP::CAP_1_0::Polygon.new
|
7
|
+
3.times do
|
8
|
+
@polygon.points << RCAP::CAP_1_0::Point.new( :lattitude => 0, :longitude => 0 )
|
9
|
+
end
|
10
|
+
@polygon.should( be_valid )
|
11
|
+
end
|
12
|
+
|
13
|
+
it( 'does not have any points' ) do
|
14
|
+
@polygon.points.clear
|
15
|
+
@polygon.should_not( be_valid )
|
16
|
+
end
|
17
|
+
|
18
|
+
it( 'does not have a valid collection of points' ) do
|
19
|
+
@polygon.points.first.lattitude = nil
|
20
|
+
@polygon.should_not( be_valid )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context( 'on initialization' ) do
|
25
|
+
context( 'from XML' ) do
|
26
|
+
before( :each ) do
|
27
|
+
@original_polygon = RCAP::CAP_1_0::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_0::Point.new( :lattitude => i, :longitude => i )})
|
28
|
+
@empty_original_polygon = RCAP::CAP_1_0::Polygon.new()
|
29
|
+
@alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :areas => RCAP::CAP_1_0::Area.new( :polygons => [@original_polygon, @empty_original_polygon] )))
|
30
|
+
@xml_string = @alert.to_xml
|
31
|
+
@xml_document = REXML::Document.new( @xml_string )
|
32
|
+
@info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
|
33
|
+
@area_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_0::Area::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
|
34
|
+
@polygon_element = RCAP.xpath_first( @area_element, RCAP::CAP_1_0::Polygon::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
|
35
|
+
@polygon = RCAP::CAP_1_0::Polygon.from_xml_element( @polygon_element )
|
36
|
+
end
|
37
|
+
|
38
|
+
it( 'should parse all the points' ) do
|
39
|
+
@polygon.points.zip( @original_polygon.points ).each do |point, original_point|
|
40
|
+
point.lattitude.should == original_point.lattitude
|
41
|
+
point.longitude.should == original_point.longitude
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should allow empty polygon xml elements' do
|
46
|
+
empty_polygon_element = RCAP.xpath_match( @area_element, RCAP::CAP_1_0::Polygon::XPATH, RCAP::CAP_1_0::Alert::XMLNS )[1]
|
47
|
+
empty_polygon = RCAP::CAP_1_0::Polygon.from_xml_element( empty_polygon_element )
|
48
|
+
empty_polygon.should == @empty_original_polygon
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context( 'from a hash' ) do
|
53
|
+
before( :each ) do
|
54
|
+
@polygon = RCAP::CAP_1_0::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_0::Point.new( :lattitude => i, :longitude => i )})
|
55
|
+
end
|
56
|
+
|
57
|
+
it( 'should load all the points' ) do
|
58
|
+
@new_polygon = RCAP::CAP_1_0::Polygon.from_h( @polygon.to_h )
|
59
|
+
@new_polygon.points.should == @polygon.points
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context( 'when exported' ) do
|
65
|
+
before( :each ) do
|
66
|
+
@polygon = RCAP::CAP_1_0::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_0::Point.new( :lattitude => i, :longitude => i )})
|
67
|
+
end
|
68
|
+
|
69
|
+
context( 'to a hash' ) do
|
70
|
+
it( 'should export correctly' ) do
|
71
|
+
@polygon.to_h.should == { RCAP::CAP_1_0::Polygon::POINTS_KEY => @polygon.points.map{ |point| point.to_h }}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe( 'instance methods' ) do
|
77
|
+
before( :each ) do
|
78
|
+
@polygon = RCAP::CAP_1_0::Polygon.new
|
79
|
+
end
|
80
|
+
|
81
|
+
describe( '#add_point' ) do
|
82
|
+
before( :each ) do
|
83
|
+
@point = @polygon.add_point( lattitude: 1, longitude: 1 )
|
84
|
+
end
|
85
|
+
|
86
|
+
it( 'should return a 1.0 Point' ) do
|
87
|
+
@point.class.should == RCAP::CAP_1_0::Point
|
88
|
+
@point.lattitude.should == 1
|
89
|
+
@point.longitude.should == 1
|
90
|
+
end
|
91
|
+
|
92
|
+
it( 'should add a Point to the points attribute' ) do
|
93
|
+
@polygon.points.size.should == 1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_0::Resource ) do
|
4
|
+
context( 'on initialisation' ) do
|
5
|
+
before( :each ) do
|
6
|
+
@resource = RCAP::CAP_1_0::Resource.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it( 'should have no mime_type' ){ @resource.mime_type.should( be_nil )}
|
10
|
+
it( 'should have no size' ){ @resource.size.should( be_nil )}
|
11
|
+
it( 'should have no uri' ){ @resource.uri.should( be_nil )}
|
12
|
+
it( 'should have no digest' ){ @resource.digest.should( be_nil )}
|
13
|
+
it( 'should have no resource_desc' ){ @resource.resource_desc.should( be_nil )}
|
14
|
+
|
15
|
+
context( 'from XML' ) do
|
16
|
+
before( :each ) do
|
17
|
+
@original_resource = RCAP::CAP_1_0::Resource.new
|
18
|
+
@original_resource.resource_desc = "Image of incident"
|
19
|
+
@original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
20
|
+
@original_resource.mime_type = 'image/png'
|
21
|
+
@original_resource.size = "20480"
|
22
|
+
@original_resource.digest = "2048"
|
23
|
+
|
24
|
+
@alert = RCAP::CAP_1_0::Alert.new( :infos => RCAP::CAP_1_0::Info.new( :resources => @original_resource ))
|
25
|
+
@xml_string = @alert.to_xml
|
26
|
+
@xml_document = REXML::Document.new( @xml_string )
|
27
|
+
@info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_0::Info::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
|
28
|
+
@resource_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_0::Resource::XPATH, RCAP::CAP_1_0::Alert::XMLNS )
|
29
|
+
@resource_element.should_not( be_nil )
|
30
|
+
@resource = RCAP::CAP_1_0::Resource.from_xml_element( @resource_element )
|
31
|
+
end
|
32
|
+
|
33
|
+
it( 'should parse resource_desc correctly' ) do
|
34
|
+
@resource.resource_desc.should == @original_resource.resource_desc
|
35
|
+
end
|
36
|
+
|
37
|
+
it( 'should parse uri correctly' ) do
|
38
|
+
@resource.uri.should == @original_resource.uri
|
39
|
+
end
|
40
|
+
|
41
|
+
it( 'should parse mime_type correctly' ) do
|
42
|
+
@resource.mime_type.should == @original_resource.mime_type
|
43
|
+
end
|
44
|
+
|
45
|
+
it( 'should parse size correctly' ) do
|
46
|
+
@resource.size.should == @original_resource.size
|
47
|
+
end
|
48
|
+
|
49
|
+
it( 'should parse digest correctly' ) do
|
50
|
+
@resource.digest.should == @original_resource.digest
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
context( 'from a hash' ) do
|
56
|
+
before( :each ) do
|
57
|
+
@original_resource = RCAP::CAP_1_0::Resource.new
|
58
|
+
@original_resource.resource_desc = "Image of incident"
|
59
|
+
@original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
60
|
+
@original_resource.mime_type = 'image/png'
|
61
|
+
@original_resource.size = "20480"
|
62
|
+
@original_resource.digest = "2048"
|
63
|
+
|
64
|
+
@resource = RCAP::CAP_1_0::Resource.from_h( @original_resource.to_h )
|
65
|
+
end
|
66
|
+
|
67
|
+
it( 'should parse resource_desc correctly' ) do
|
68
|
+
@resource.resource_desc.should == @original_resource.resource_desc
|
69
|
+
end
|
70
|
+
|
71
|
+
it( 'should parse uri correctly' ) do
|
72
|
+
@resource.uri.should == @original_resource.uri
|
73
|
+
end
|
74
|
+
|
75
|
+
it( 'should parse mime_type correctly' ) do
|
76
|
+
@resource.mime_type.should == @original_resource.mime_type
|
77
|
+
end
|
78
|
+
|
79
|
+
it( 'should parse size correctly' ) do
|
80
|
+
@resource.size.should == @original_resource.size
|
81
|
+
end
|
82
|
+
|
83
|
+
it( 'should parse digest correctly' ) do
|
84
|
+
@resource.digest.should == @original_resource.digest
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
context( 'when exported' ) do
|
91
|
+
before( :each ) do
|
92
|
+
@resource = RCAP::CAP_1_0::Resource.new
|
93
|
+
@resource.resource_desc = "Image of incident"
|
94
|
+
@resource.uri = "http://capetown.gov.za/cap/resources/image.png"
|
95
|
+
@resource.mime_type = 'image/png'
|
96
|
+
@resource.size = "20480"
|
97
|
+
@resource.digest = "2048"
|
98
|
+
end
|
99
|
+
|
100
|
+
context( 'to a hash' ) do
|
101
|
+
before( :each ) do
|
102
|
+
@resource_hash = @resource.to_h
|
103
|
+
end
|
104
|
+
|
105
|
+
it( 'should set the resource description' ) do
|
106
|
+
@resource_hash[ RCAP::CAP_1_0::Resource::RESOURCE_DESC_KEY ].should == @resource.resource_desc
|
107
|
+
end
|
108
|
+
|
109
|
+
it( 'should set the mime type' ) do
|
110
|
+
@resource_hash[ RCAP::CAP_1_0::Resource::MIME_TYPE_KEY ].should == @resource.mime_type
|
111
|
+
end
|
112
|
+
|
113
|
+
it( 'should set the size' ) do
|
114
|
+
@resource_hash[ RCAP::CAP_1_0::Resource::SIZE_KEY ].should == @resource.size
|
115
|
+
end
|
116
|
+
|
117
|
+
it( 'should set the URI' ) do
|
118
|
+
@resource_hash[ RCAP::CAP_1_0::Resource::URI_KEY ].should == @resource.uri
|
119
|
+
end
|
120
|
+
|
121
|
+
it( 'should set the digest' ) do
|
122
|
+
@resource_hash[ RCAP::CAP_1_0::Resource::DIGEST_KEY ].should == @resource.digest
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context( 'which is valid' ) do
|
128
|
+
before( :each ) do
|
129
|
+
@resource = RCAP::CAP_1_0::Resource.new( :resource_desc => 'Resource Description' )
|
130
|
+
@resource.should( be_valid )
|
131
|
+
end
|
132
|
+
|
133
|
+
describe( 'should not be valid if it' ) do
|
134
|
+
it( 'does not have a resource description (resource_desc)' ) do
|
135
|
+
@resource.resource_desc = nil
|
136
|
+
@resource.should_not( be_valid )
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_1::EventCode ) do
|
4
|
+
context( 'when initialised' ) do
|
5
|
+
context( 'from XML' ) do
|
6
|
+
before( :each ) do
|
7
|
+
@original_event_code = RCAP::CAP_1_1::EventCode.new( :name => 'name', :value => 'value' )
|
8
|
+
@alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :event_codes => @original_event_code ))
|
9
|
+
@xml_string = @alert.to_xml
|
10
|
+
@xml_document = REXML::Document.new( @xml_string )
|
11
|
+
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
|
12
|
+
@event_code_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_1::EventCode::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
|
13
|
+
@event_code = RCAP::CAP_1_1::EventCode.from_xml_element( @event_code_xml_element )
|
14
|
+
end
|
15
|
+
|
16
|
+
it( 'should parse the name correctly' ) do
|
17
|
+
@event_code.name.should == @original_event_code.name
|
18
|
+
end
|
19
|
+
|
20
|
+
it( 'should parse the value correctly' ) do
|
21
|
+
@event_code.value.should == @original_event_code.value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context( 'when exported' ) do
|
27
|
+
before( :each ) do
|
28
|
+
@event_code = RCAP::CAP_1_1::EventCode.new( :name => 'name', :value => 'value' )
|
29
|
+
end
|
30
|
+
|
31
|
+
context( 'to a hash' ) do
|
32
|
+
it( 'should export correctly' ) do
|
33
|
+
@event_code.to_h.should == { 'name' => 'value' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_1::Parameter ) do
|
4
|
+
context( 'when initialised' ) do
|
5
|
+
context( 'from XML' ) do
|
6
|
+
before( :each ) do
|
7
|
+
@original_parameter = RCAP::CAP_1_1::Parameter.new( :name => 'name', :value => 'value' )
|
8
|
+
@alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :parameters => @original_parameter ))
|
9
|
+
@xml_string = @alert.to_xml
|
10
|
+
@xml_document = REXML::Document.new( @xml_string )
|
11
|
+
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
|
12
|
+
@parameter_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_1::Parameter::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
|
13
|
+
@parameter = RCAP::CAP_1_1::Parameter.from_xml_element( @parameter_xml_element )
|
14
|
+
end
|
15
|
+
|
16
|
+
it( 'should parse the name correctly' ) do
|
17
|
+
@parameter.name.should == @original_parameter.name
|
18
|
+
end
|
19
|
+
|
20
|
+
it( 'should parse the value correctly' ) do
|
21
|
+
@parameter.value.should == @original_parameter.value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context( 'when exported' ) do
|
27
|
+
before( :each ) do
|
28
|
+
@parameter = RCAP::CAP_1_1::Parameter.new( :name => 'name', :value => 'value' )
|
29
|
+
end
|
30
|
+
|
31
|
+
context( 'to a hash' ) do
|
32
|
+
it( 'should export correctly' ) do
|
33
|
+
@parameter.to_h.should == { 'name' => 'value' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe( RCAP::CAP_1_2::EventCode ) do
|
4
|
+
context( 'when initialised' ) do
|
5
|
+
context( 'from XML' ) do
|
6
|
+
before( :each ) do
|
7
|
+
@original_event_code = RCAP::CAP_1_2::EventCode.new( :name => 'name', :value => 'value' )
|
8
|
+
@alert = RCAP::CAP_1_2::Alert.new( :infos => RCAP::CAP_1_2::Info.new( :event_codes => @original_event_code ))
|
9
|
+
@xml_string = @alert.to_xml
|
10
|
+
@xml_document = REXML::Document.new( @xml_string )
|
11
|
+
@info_xml_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_2::Info::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
|
12
|
+
@event_code_xml_element = RCAP.xpath_first( @info_xml_element, RCAP::CAP_1_2::EventCode::XPATH, RCAP::CAP_1_2::Alert::XMLNS )
|
13
|
+
@event_code = RCAP::CAP_1_2::EventCode.from_xml_element( @event_code_xml_element )
|
14
|
+
end
|
15
|
+
|
16
|
+
it( 'should parse the name correctly' ) do
|
17
|
+
@event_code.name.should == @original_event_code.name
|
18
|
+
end
|
19
|
+
|
20
|
+
it( 'should parse the value correctly' ) do
|
21
|
+
@event_code.value.should == @original_event_code.value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context( 'when exported' ) do
|
27
|
+
before( :each ) do
|
28
|
+
@event_code = RCAP::CAP_1_2::EventCode.new( :name => 'name', :value => 'value' )
|
29
|
+
end
|
30
|
+
|
31
|
+
context( 'to a hash' ) do
|
32
|
+
it( 'should export correctly' ) do
|
33
|
+
@event_code.to_h.should == { 'name' => 'value' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|