rcap 0.4 → 1.0.0.rc.1

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.
Files changed (63) hide show
  1. data/.gitignore +7 -0
  2. data/CHANGELOG.rdoc +6 -0
  3. data/Gemfile +4 -0
  4. data/README.rdoc +104 -85
  5. data/Rakefile +35 -0
  6. data/lib/rcap.rb +21 -14
  7. data/lib/rcap/alert.rb +26 -325
  8. data/lib/rcap/cap_1_1/alert.rb +363 -0
  9. data/lib/rcap/cap_1_1/area.rb +180 -0
  10. data/lib/rcap/cap_1_1/circle.rb +81 -0
  11. data/lib/rcap/cap_1_1/event_code.rb +22 -0
  12. data/lib/rcap/cap_1_1/geocode.rb +22 -0
  13. data/lib/rcap/cap_1_1/info.rb +470 -0
  14. data/lib/rcap/cap_1_1/parameter.rb +68 -0
  15. data/lib/rcap/cap_1_1/point.rb +55 -0
  16. data/lib/rcap/cap_1_1/polygon.rb +89 -0
  17. data/lib/rcap/cap_1_1/resource.rb +145 -0
  18. data/lib/rcap/cap_1_2/alert.rb +363 -0
  19. data/lib/rcap/cap_1_2/area.rb +180 -0
  20. data/lib/rcap/cap_1_2/circle.rb +81 -0
  21. data/lib/rcap/cap_1_2/event_code.rb +22 -0
  22. data/lib/rcap/cap_1_2/geocode.rb +22 -0
  23. data/lib/rcap/cap_1_2/info.rb +472 -0
  24. data/lib/rcap/cap_1_2/parameter.rb +68 -0
  25. data/lib/rcap/cap_1_2/point.rb +55 -0
  26. data/lib/rcap/cap_1_2/polygon.rb +90 -0
  27. data/lib/rcap/cap_1_2/resource.rb +147 -0
  28. data/lib/rcap/utilities.rb +14 -9
  29. data/lib/rcap/validations.rb +39 -7
  30. data/lib/rcap/version.rb +3 -0
  31. data/rcap.gemspec +30 -0
  32. data/spec/alert_spec.rb +109 -172
  33. data/spec/cap_1_1/alert_spec.rb +222 -0
  34. data/spec/cap_1_1/area_spec.rb +247 -0
  35. data/spec/cap_1_1/circle_spec.rb +88 -0
  36. data/spec/{geocode_spec.rb → cap_1_1/geocode_spec.rb} +8 -8
  37. data/spec/{info_spec.rb → cap_1_1/info_spec.rb} +143 -75
  38. data/spec/{point_spec.rb → cap_1_1/point_spec.rb} +8 -8
  39. data/spec/cap_1_1/polygon_spec.rb +97 -0
  40. data/spec/{resource_spec.rb → cap_1_1/resource_spec.rb} +24 -24
  41. data/spec/cap_1_2/alert_spec.rb +233 -0
  42. data/spec/cap_1_2/area_spec.rb +248 -0
  43. data/spec/cap_1_2/circle_spec.rb +95 -0
  44. data/spec/cap_1_2/geocode_spec.rb +38 -0
  45. data/spec/cap_1_2/info_spec.rb +338 -0
  46. data/spec/cap_1_2/point_spec.rb +46 -0
  47. data/spec/cap_1_2/polygon_spec.rb +102 -0
  48. data/spec/cap_1_2/resource_spec.rb +161 -0
  49. data/spec/spec.opts +2 -0
  50. data/spec/validations_spec.rb +80 -7
  51. metadata +122 -37
  52. data/lib/rcap/area.rb +0 -156
  53. data/lib/rcap/circle.rb +0 -78
  54. data/lib/rcap/event_code.rb +0 -20
  55. data/lib/rcap/geocode.rb +0 -20
  56. data/lib/rcap/info.rb +0 -437
  57. data/lib/rcap/parameter.rb +0 -66
  58. data/lib/rcap/point.rb +0 -53
  59. data/lib/rcap/polygon.rb +0 -77
  60. data/lib/rcap/resource.rb +0 -143
  61. data/spec/area_spec.rb +0 -179
  62. data/spec/circle_spec.rb +0 -88
  63. data/spec/polygon_spec.rb +0 -68
@@ -0,0 +1,3 @@
1
+ module RCAP
2
+ VERSION = '1.0.0.rc.1'
3
+ end
data/rcap.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'rcap/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'rcap'
7
+ s.version = RCAP::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Farrel Lifson']
10
+ s.email = ['farrel.lifson@aimred.com']
11
+ s.homepage = 'http://www.aimred.com/projects/rcap'
12
+ s.summary = 'CAP(Common Alerting Protocol) API'
13
+ s.description = 'A Ruby API providing parsing, generation and validation of CAP(Common Alerting Protocol) messages.'
14
+
15
+ s.rubyforge_project = 'rcap'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
+
22
+ s.has_rdoc = true
23
+ s.extra_rdoc_files = ['README.rdoc','CHANGELOG.rdoc']
24
+ s.add_dependency('assistance', '>= 0.1.5')
25
+ s.add_dependency('json', '>= 1.5.1')
26
+ s.add_dependency('uuidtools', '>= 2.1.2')
27
+
28
+ s.add_development_dependency('rspec', '>= 2.5.0')
29
+ s.add_development_dependency('hanna', '>= 0.1.12')
30
+ end
data/spec/alert_spec.rb CHANGED
@@ -1,194 +1,131 @@
1
- require 'spec_helper'
2
-
3
1
  describe( RCAP::Alert ) do
4
- context( 'on initialisation' ) do
5
- before( :each ) do
6
- @alert = RCAP::Alert.new
7
- end
2
+ describe( 'initialising' ) do
3
+
4
+ context( 'a CAP 1.1 alert' ) do
5
+ before( :each ) do
6
+ @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
7
+ :sent => DateTime.now,
8
+ :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
9
+ :scope => RCAP::CAP_1_1::Alert::SCOPE_PUBLIC,
10
+ :source => 'Source',
11
+ :restriction => 'No Restriction',
12
+ :addresses => [ 'Address 1', 'Address 2'],
13
+ :code => ['Code1', 'Code2'],
14
+ :note => 'Note',
15
+ :references => [ "1,1,1", "1,1,2" ],
16
+ :incidents => [ 'Incident1', 'Incident2' ],
17
+ :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
18
+ end
8
19
 
9
- it( 'should have a default identifier' ){ @alert.identifier.should_not( be_nil )}
10
- it( 'should not have a sender' ){ @alert.sender.should( be_nil )}
11
- it( 'should have a default sent time' ){ @alert.sent.should_not( be_nil )}
12
- it( 'should not have a status' ){ @alert.status.should( be_nil )}
13
- it( 'should not have a scope' ){ @alert.scope.should( be_nil )}
14
- it( 'should not have a source'){ @alert.source.should( be_nil )}
15
- it( 'should not have a restriction'){ @alert.restriction.should( be_nil )}
16
- it( 'should not have any addresses' ){ @alert.addresses.should( be_empty )}
17
- it( 'should not have a code' ){ @alert.code.should( be_nil )}
18
- it( 'should not have a note' ){ @alert.note.should( be_nil )}
19
- it( 'should not have any references' ){ @alert.references.should( be_empty )}
20
- it( 'should not have any incidents' ){ @alert.incidents.should( be_empty )}
21
- it( 'should not have any infos' ){ @alert.infos.should( be_empty )}
22
-
23
- shared_examples_for( "a successfully parsed alert" ) do
24
- it( 'should parse identifier correctly' ) { @alert.identifier.should == @original_alert.identifier }
25
- it( 'should parse sender correctly' ) { @alert.sender.should == @original_alert.sender }
26
- it( 'should parse sent correctly' ) { @alert.sent.should( be_close( @original_alert.sent, Rational( 1, 86400 )))}
27
- it( 'should parse status correctly' ) { @alert.status.should == @original_alert.status }
28
- it( 'should parse msg_type correctly' ) { @alert.msg_type.should == @original_alert.msg_type }
29
- it( 'should parse source correctly' ) { @alert.source.should == @original_alert.source }
30
- it( 'should parse scope correctly' ) { @alert.scope.should == @original_alert.scope }
31
- it( 'should parse restriction correctly' ){ @alert.restriction.should == @original_alert.restriction }
32
- it( 'should parse addresses correctly' ) { @alert.addresses.should == @original_alert.addresses }
33
- it( 'should parse code correctly' ) { @alert.code.should == @original_alert.code }
34
- it( 'should parse note correctly' ) { @alert.note.should == @original_alert.note }
35
- it( 'should parse references correctly' ) { @alert.references.should == @original_alert.references }
36
- it( 'should parse incidents correctly' ) { @alert.incidents.should == @original_alert.incidents }
37
- it( 'should parse infos correctly' ) do
38
- @alert.infos.size.should == @original_alert.infos.size
39
- @alert.infos.each{ |info| info.class.should == RCAP::Info }
40
- end
41
- end
42
-
43
- context( 'from XML' ) do
44
- before( :each ) do
45
- @original_alert = RCAP::Alert.new( :sender => 'Sender',
46
- :status => RCAP::Alert::STATUS_TEST,
47
- :scope => RCAP::Alert::SCOPE_PUBLIC,
48
- :source => 'Source',
49
- :restriction => 'No Restriction',
50
- :addresses => [ 'Address 1', 'Address 2'],
51
- :code => 'Code',
52
- :note => 'Note',
53
- :references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
54
- :incidents => [ 'Incident1', 'Incident2' ],
55
- :infos => [ RCAP::Info.new, RCAP::Info.new ])
56
- @xml_string = @original_alert.to_xml
57
- @xml_document = REXML::Document.new( @xml_string )
58
- @alert_element = @xml_document.root
59
- @alert = RCAP::Alert.from_xml_element( @alert_element )
60
- end
61
-
62
- it_should_behave_like( "a successfully parsed alert" )
63
20
 
64
- end
65
21
 
66
- context( 'from YAML' ) do
67
- before( :each ) do
68
- @original_alert = RCAP::Alert.new( :sender => 'Sender',
69
- :status => RCAP::Alert::STATUS_TEST,
70
- :scope => RCAP::Alert::SCOPE_PUBLIC,
71
- :source => 'Source',
72
- :restriction => 'No Restriction',
73
- :addresses => [ 'Address 1', 'Address 2'],
74
- :code => 'Code',
75
- :note => 'Note',
76
- :references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
77
- :incidents => [ 'Incident1', 'Incident2' ],
78
- :infos => [ RCAP::Info.new, RCAP::Info.new ])
79
- @yaml_string = @original_alert.to_yaml
80
- @alert = RCAP::Alert.from_yaml( @yaml_string )
81
- end
82
-
83
- it_should_behave_like( "a successfully parsed alert" )
84
- end
85
-
86
- context( 'from a hash' ) do
87
- before( :each ) do
88
- @original_alert = RCAP::Alert.new( :sender => 'Sender',
89
- :status => RCAP::Alert::STATUS_TEST,
90
- :scope => RCAP::Alert::SCOPE_PUBLIC,
91
- :source => 'Source',
92
- :restriction => 'No Restriction',
93
- :addresses => [ 'Address 1', 'Address 2'],
94
- :code => 'Code',
95
- :note => 'Note',
96
- :references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
97
- :incidents => [ 'Incident1', 'Incident2' ],
98
- :infos => [ RCAP::Info.new, RCAP::Info.new ])
99
- @alert = RCAP::Alert.from_h( @original_alert.to_h )
100
- end
101
-
102
- it_should_behave_like( "a successfully parsed alert" )
103
- end
22
+ shared_examples_for( 'it has parsed a CAP 1.1 alert correctly' ) do
23
+ it( 'should use the correct CAP Version' ){ @alert.class.should == RCAP::CAP_1_1::Alert }
24
+ it( 'should parse identifier correctly' ) { @alert.identifier.should == @original_alert.identifier }
25
+ it( 'should parse sender correctly' ) { @alert.sender.should == @original_alert.sender }
26
+ it( 'should parse sent correctly' ) { @alert.sent.should( be_within( 1 ).of( @original_alert.sent ))}
27
+ it( 'should parse status correctly' ) { @alert.status.should == @original_alert.status }
28
+ it( 'should parse msg_type correctly' ) { @alert.msg_type.should == @original_alert.msg_type }
29
+ it( 'should parse source correctly' ) { @alert.source.should == @original_alert.source }
30
+ it( 'should parse scope correctly' ) { @alert.scope.should == @original_alert.scope }
31
+ it( 'should parse restriction correctly' ){ @alert.restriction.should == @original_alert.restriction }
32
+ it( 'should parse addresses correctly' ) { @alert.addresses.should == @original_alert.addresses }
33
+ it( 'should parse code correctly' ) { @alert.codes.should == @original_alert.codes }
34
+ it( 'should parse note correctly' ) { @alert.note.should == @original_alert.note }
35
+ it( 'should parse references correctly' ) { @alert.references.should == @original_alert.references }
36
+ it( 'should parse incidents correctly' ) { @alert.incidents.should == @original_alert.incidents }
37
+ it( 'should parse infos correctly' ) do
38
+ @alert.infos.size.should == @original_alert.infos.size
39
+ @alert.infos.each{ |info| info.class.should == RCAP::CAP_1_1::Info }
40
+ end
41
+ end
104
42
 
105
- context( 'from JSON' ) do
106
- before( :each ) do
107
- @original_alert = RCAP::Alert.new( :sender => 'Sender',
108
- :status => RCAP::Alert::STATUS_TEST,
109
- :scope => RCAP::Alert::SCOPE_PUBLIC,
110
- :source => 'Source',
111
- :restriction => 'No Restriction',
112
- :addresses => [ 'Address 1', 'Address 2'],
113
- :code => 'Code',
114
- :note => 'Note',
115
- :references => [ RCAP::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::Alert.new( :sender => 'Sender2' ).to_reference ],
116
- :incidents => [ 'Incident1', 'Incident2' ],
117
- :infos => [ RCAP::Info.new, RCAP::Info.new ])
118
- @alert = RCAP::Alert.from_json( @original_alert.to_json )
119
- end
120
-
121
- it_should_behave_like( "a successfully parsed alert" )
122
- end
123
- end
43
+ context( 'from XML' ) do
44
+ before( :each ) do
45
+ @alert = RCAP::Alert.from_xml( @original_alert.to_xml )
46
+ end
124
47
 
125
- describe( 'is not valid if it' ) do
126
- before( :each ) do
127
- @alert = RCAP::Alert.new( :sender => "cap@tempuri.org",
128
- :status => RCAP::Alert::STATUS_TEST,
129
- :msg_type => RCAP::Alert::MSG_TYPE_ALERT,
130
- :scope => RCAP::Alert::SCOPE_PUBLIC )
131
- @alert.should( be_valid )
132
- end
48
+ it_should_behave_like( 'it has parsed a CAP 1.1 alert correctly' )
49
+ end
133
50
 
134
- it( 'does not have a identifier' ) do
135
- @alert.identifier = nil
136
- @alert.should_not( be_valid )
137
- end
51
+ context( 'from YAML' ) do
52
+ before( :each ) do
53
+ @alert = RCAP::Alert.from_yaml( @original_alert.to_yaml )
54
+ end
138
55
 
139
- it( 'does not have a sender' ) do
140
- @alert.sender = nil
141
- @alert.should_not( be_valid )
142
- end
56
+ it_should_behave_like( 'it has parsed a CAP 1.1 alert correctly' )
57
+ end
143
58
 
144
- it( 'does not have a sent time (sent)' ) do
145
- @alert.sent = nil
146
- @alert.should_not( be_valid )
147
- end
59
+ context( 'from JSON' ) do
60
+ before( :each ) do
61
+ @alert = RCAP::Alert.from_json( @original_alert.to_json )
62
+ end
148
63
 
149
- it( 'does not have a status' ) do
150
- @alert.status = nil
151
- @alert.should_not( be_valid )
64
+ it_should_behave_like( 'it has parsed a CAP 1.1 alert correctly' )
65
+ end
152
66
  end
153
67
 
154
- it( 'does not have a message type (msg_type)' ) do
155
- @alert.msg_type = nil
156
- @alert.should_not( be_valid )
157
- end
68
+ context( 'a CAP 1.2 alert' ) do
69
+ before( :each ) do
70
+ @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
71
+ :sent => DateTime.now,
72
+ :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
73
+ :scope => RCAP::CAP_1_2::Alert::SCOPE_PUBLIC,
74
+ :source => 'Source',
75
+ :restriction => 'No Restriction',
76
+ :addresses => [ 'Address 1', 'Address 2'],
77
+ :codes => [ 'Code1', 'Code2'],
78
+ :note => 'Note',
79
+ :references => [ "1,1,1", "1,1,2" ],
80
+ :incidents => [ 'Incident1', 'Incident2' ],
81
+ :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
82
+ end
158
83
 
159
- it( 'does not have a scope' ) do
160
- @alert.scope = nil
161
- @alert.should_not( be_valid )
162
- end
163
84
 
164
85
 
165
- it( 'does not have a valid status' ) do
166
- @alert.status = 'incorrect value'
167
- @alert.should_not( be_valid )
168
- end
86
+ shared_examples_for( 'it has parsed a CAP 1.2 alert correctly' ) do
87
+ it( 'should use the correct CAP Version' ){ @alert.class.should == RCAP::CAP_1_2::Alert }
88
+ it( 'should parse identifier correctly' ) { @alert.identifier.should == @original_alert.identifier }
89
+ it( 'should parse sender correctly' ) { @alert.sender.should == @original_alert.sender }
90
+ it( 'should parse sent correctly' ) { @alert.sent.should( be_within( 1 ).of( @original_alert.sent ))}
91
+ it( 'should parse status correctly' ) { @alert.status.should == @original_alert.status }
92
+ it( 'should parse msg_type correctly' ) { @alert.msg_type.should == @original_alert.msg_type }
93
+ it( 'should parse source correctly' ) { @alert.source.should == @original_alert.source }
94
+ it( 'should parse scope correctly' ) { @alert.scope.should == @original_alert.scope }
95
+ it( 'should parse restriction correctly' ){ @alert.restriction.should == @original_alert.restriction }
96
+ it( 'should parse addresses correctly' ) { @alert.addresses.should == @original_alert.addresses }
97
+ it( 'should parse codes correctly' ) { @alert.codes.should == @original_alert.codes }
98
+ it( 'should parse note correctly' ) { @alert.note.should == @original_alert.note }
99
+ it( 'should parse references correctly' ) { @alert.references.should == @original_alert.references }
100
+ it( 'should parse incidents correctly' ) { @alert.incidents.should == @original_alert.incidents }
101
+ it( 'should parse infos correctly' ) do
102
+ @alert.infos.size.should == @original_alert.infos.size
103
+ @alert.infos.each{ |info| info.class.should == RCAP::CAP_1_2::Info }
104
+ end
105
+ end
169
106
 
170
- it( 'does not have a valid message type msg_type' ) do
171
- @alert.msg_type = 'incorrect value'
172
- @alert.should_not( be_valid )
173
- end
107
+ context( 'from XML' ) do
108
+ before( :each ) do
109
+ @alert = RCAP::Alert.from_xml( @original_alert.to_xml )
110
+ end
174
111
 
175
- it( 'does not have a valid scope' ) do
176
- @alert.scope = 'incorrect value'
177
- @alert.should_not( be_valid )
178
- end
112
+ it_should_behave_like( 'it has parsed a CAP 1.2 alert correctly' )
113
+ end
114
+
115
+ context( 'from YAML' ) do
116
+ before( :each ) do
117
+ @alert = RCAP::Alert.from_yaml( @original_alert.to_yaml )
118
+ end
119
+
120
+ it_should_behave_like( 'it has parsed a CAP 1.2 alert correctly' )
121
+ end
179
122
 
123
+ context( 'from JSON' ) do
124
+ before( :each ) do
125
+ @alert = RCAP::Alert.from_json( @original_alert.to_json )
126
+ end
180
127
 
181
- context( 'has an info element and it' ) do
182
- it( 'is not valid' ) do
183
- @info = RCAP::Info.new( :event => 'Info Event',
184
- :categories => RCAP::Info::CATEGORY_GEO,
185
- :urgency => RCAP::Info::URGENCY_IMMEDIATE,
186
- :severity => RCAP::Info::SEVERITY_EXTREME,
187
- :certainty => RCAP::Info::CERTAINTY_OBSERVED )
188
- @info.event = nil
189
- @alert.infos << @info
190
- @info.should_not( be_valid )
191
- @alert.should_not( be_valid )
128
+ it_should_behave_like( 'it has parsed a CAP 1.2 alert correctly' )
192
129
  end
193
130
  end
194
131
  end
@@ -0,0 +1,222 @@
1
+ require 'spec_helper'
2
+
3
+ describe( RCAP::CAP_1_1::Alert ) do
4
+ context( 'on initialisation' ) do
5
+ before( :each ) do
6
+ @alert = RCAP::CAP_1_1::Alert.new
7
+ end
8
+
9
+ it( 'should not have a identifier' ){ @alert.identifier.should( be_nil )}
10
+ it( 'should not have a sender' ){ @alert.sender.should( be_nil )}
11
+ it( 'should not have a sent time' ){ @alert.sent.should( be_nil )}
12
+ it( 'should not have a status' ){ @alert.status.should( be_nil )}
13
+ it( 'should not have a scope' ){ @alert.scope.should( be_nil )}
14
+ it( 'should not have a source'){ @alert.source.should( be_nil )}
15
+ it( 'should not have a restriction'){ @alert.restriction.should( be_nil )}
16
+ it( 'should not have any addresses' ){ @alert.addresses.should( be_empty )}
17
+ it( 'should not have any codes' ){ @alert.codes.should( be_empty )}
18
+ it( 'should not have a note' ){ @alert.note.should( be_nil )}
19
+ it( 'should not have any references' ){ @alert.references.should( be_empty )}
20
+ it( 'should not have any incidents' ){ @alert.incidents.should( be_empty )}
21
+ it( 'should not have any infos' ){ @alert.infos.should( be_empty )}
22
+
23
+ shared_examples_for( "a successfully parsed CAP 1.1 alert" ) do
24
+ it( 'should parse identifier correctly' ) { @alert.identifier.should == @original_alert.identifier }
25
+ it( 'should parse sender correctly' ) { @alert.sender.should == @original_alert.sender }
26
+ it( 'should parse sent correctly' ) { @alert.sent.should( be_within( 1 ).of( @original_alert.sent ))}
27
+ it( 'should parse status correctly' ) { @alert.status.should == @original_alert.status }
28
+ it( 'should parse msg_type correctly' ) { @alert.msg_type.should == @original_alert.msg_type }
29
+ it( 'should parse source correctly' ) { @alert.source.should == @original_alert.source }
30
+ it( 'should parse scope correctly' ) { @alert.scope.should == @original_alert.scope }
31
+ it( 'should parse restriction correctly' ){ @alert.restriction.should == @original_alert.restriction }
32
+ it( 'should parse addresses correctly' ) { @alert.addresses.should == @original_alert.addresses }
33
+ it( 'should parse code correctly' ) { @alert.codes.should == @original_alert.codes }
34
+ it( 'should parse note correctly' ) { @alert.note.should == @original_alert.note }
35
+ it( 'should parse references correctly' ) { @alert.references.should == @original_alert.references }
36
+ it( 'should parse incidents correctly' ) { @alert.incidents.should == @original_alert.incidents }
37
+ it( 'should parse infos correctly' ) do
38
+ @alert.infos.size.should == @original_alert.infos.size
39
+ @alert.infos.each{ |info| info.class.should == RCAP::CAP_1_1::Info }
40
+ end
41
+ end
42
+
43
+ context( 'from XML' ) do
44
+ before( :each ) do
45
+ @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
46
+ :sent => DateTime.now,
47
+ :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
48
+ :scope => RCAP::CAP_1_1::Alert::SCOPE_PUBLIC,
49
+ :source => 'Source',
50
+ :restriction => 'No Restriction',
51
+ :addresses => [ 'Address 1', 'Address 2'],
52
+ :codes => [ 'Code1', 'Code2' ],
53
+ :note => 'Note',
54
+ :references => [ RCAP::CAP_1_1::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_1::Alert.new( :sender => 'Sender2' ).to_reference ],
55
+ :incidents => [ 'Incident1', 'Incident2' ],
56
+ :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
57
+ @xml_string = @original_alert.to_xml
58
+ @xml_document = REXML::Document.new( @xml_string )
59
+ @alert_element = @xml_document.root
60
+ @alert = RCAP::CAP_1_1::Alert.from_xml_element( @alert_element )
61
+ end
62
+
63
+ it_should_behave_like( "a successfully parsed CAP 1.1 alert" )
64
+
65
+ end
66
+
67
+ context( 'from YAML' ) do
68
+ before( :each ) do
69
+ @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
70
+ :sent => DateTime.now,
71
+ :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
72
+ :scope => RCAP::CAP_1_1::Alert::SCOPE_PUBLIC,
73
+ :source => 'Source',
74
+ :restriction => 'No Restriction',
75
+ :addresses => [ 'Address 1', 'Address 2'],
76
+ :codes => [ 'Code1', 'Code2' ],
77
+ :note => 'Note',
78
+ :references => [ RCAP::CAP_1_1::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_1::Alert.new( :sender => 'Sender2' ).to_reference ],
79
+ :incidents => [ 'Incident1', 'Incident2' ],
80
+ :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
81
+ @yaml_string = @original_alert.to_yaml
82
+ @alert = RCAP::CAP_1_1::Alert.from_yaml( @yaml_string )
83
+ end
84
+
85
+ it_should_behave_like( "a successfully parsed CAP 1.1 alert" )
86
+ end
87
+
88
+ context( 'from a hash' ) do
89
+ before( :each ) do
90
+ @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
91
+ :sent => DateTime.now,
92
+ :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
93
+ :scope => RCAP::CAP_1_1::Alert::SCOPE_PUBLIC,
94
+ :source => 'Source',
95
+ :restriction => 'No Restriction',
96
+ :addresses => [ 'Address 1', 'Address 2'],
97
+ :codes => [ 'Code1', 'Code2' ],
98
+ :note => 'Note',
99
+ :references => [ RCAP::CAP_1_1::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_1::Alert.new( :sender => 'Sender2' ).to_reference ],
100
+ :incidents => [ 'Incident1', 'Incident2' ],
101
+ :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
102
+ @alert = RCAP::CAP_1_1::Alert.from_h( @original_alert.to_h )
103
+ end
104
+
105
+ it_should_behave_like( "a successfully parsed CAP 1.1 alert" )
106
+ end
107
+
108
+ context( 'from JSON' ) do
109
+ before( :each ) do
110
+ @original_alert = RCAP::CAP_1_1::Alert.new( :sender => 'Sender',
111
+ :sent => DateTime.now,
112
+ :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
113
+ :scope => RCAP::CAP_1_1::Alert::SCOPE_PUBLIC,
114
+ :source => 'Source',
115
+ :restriction => 'No Restriction',
116
+ :addresses => [ 'Address 1', 'Address 2'],
117
+ :codes => [ 'Code1', 'Code2' ],
118
+ :note => 'Note',
119
+ :references => [ RCAP::CAP_1_1::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_1::Alert.new( :sender => 'Sender2' ).to_reference ],
120
+ :incidents => [ 'Incident1', 'Incident2' ],
121
+ :infos => [ RCAP::CAP_1_1::Info.new, RCAP::CAP_1_1::Info.new ])
122
+ @alert = RCAP::CAP_1_1::Alert.from_json( @original_alert.to_json )
123
+ end
124
+
125
+ it_should_behave_like( "a successfully parsed CAP 1.1 alert" )
126
+ end
127
+ end
128
+
129
+ describe( 'is not valid if it' ) do
130
+ before( :each ) do
131
+ @alert = RCAP::CAP_1_1::Alert.new( :identifier => 'Identifier',
132
+ :sender => "cap@tempuri.org",
133
+ :sent => DateTime.now,
134
+ :status => RCAP::CAP_1_1::Alert::STATUS_TEST,
135
+ :msg_type => RCAP::CAP_1_1::Alert::MSG_TYPE_ALERT,
136
+ :scope => RCAP::CAP_1_1::Alert::SCOPE_PUBLIC )
137
+ @alert.should( be_valid )
138
+ end
139
+
140
+ it( 'does not have a identifier' ) do
141
+ @alert.identifier = nil
142
+ @alert.should_not( be_valid )
143
+ end
144
+
145
+ it( 'does not have a sender' ) do
146
+ @alert.sender = nil
147
+ @alert.should_not( be_valid )
148
+ end
149
+
150
+ it( 'does not have a sent time (sent)' ) do
151
+ @alert.sent = nil
152
+ @alert.should_not( be_valid )
153
+ end
154
+
155
+ it( 'does not have a status' ) do
156
+ @alert.status = nil
157
+ @alert.should_not( be_valid )
158
+ end
159
+
160
+ it( 'does not have a message type (msg_type)' ) do
161
+ @alert.msg_type = nil
162
+ @alert.should_not( be_valid )
163
+ end
164
+
165
+ it( 'does not have a scope' ) do
166
+ @alert.scope = nil
167
+ @alert.should_not( be_valid )
168
+ end
169
+
170
+
171
+ it( 'does not have a valid status' ) do
172
+ @alert.status = 'incorrect value'
173
+ @alert.should_not( be_valid )
174
+ end
175
+
176
+ it( 'does not have a valid message type msg_type' ) do
177
+ @alert.msg_type = 'incorrect value'
178
+ @alert.should_not( be_valid )
179
+ end
180
+
181
+ it( 'does not have a valid scope' ) do
182
+ @alert.scope = 'incorrect value'
183
+ @alert.should_not( be_valid )
184
+ end
185
+
186
+
187
+ context( 'has an info element and it' ) do
188
+ it( 'is not valid' ) do
189
+ @info = RCAP::CAP_1_1::Info.new( :event => 'Info Event',
190
+ :categories => RCAP::CAP_1_1::Info::CATEGORY_GEO,
191
+ :urgency => RCAP::CAP_1_1::Info::URGENCY_IMMEDIATE,
192
+ :severity => RCAP::CAP_1_1::Info::SEVERITY_EXTREME,
193
+ :certainty => RCAP::CAP_1_1::Info::CERTAINTY_OBSERVED )
194
+ @info.event = nil
195
+ @alert.infos << @info
196
+ @info.should_not( be_valid )
197
+ @alert.should_not( be_valid )
198
+ end
199
+ end
200
+ end
201
+
202
+ describe( 'instance methods' ) do
203
+ before( :each ) do
204
+ @alert = RCAP::CAP_1_1::Alert.new
205
+ end
206
+
207
+ describe( '#add_info' ) do
208
+ before( :each ) do
209
+ @info = @alert.add_info( :urgency => 'urgent' )
210
+ @info.urgency.should == 'urgent'
211
+ end
212
+
213
+ it( 'should return a CAP 1.1 Info object' ) do
214
+ @info.class.should == RCAP::CAP_1_1::Info
215
+ end
216
+
217
+ it( 'should add an Info object to the infos array' ) do
218
+ @alert.infos.size.should == 1
219
+ end
220
+ end
221
+ end
222
+ end