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
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::Point ) do
3
+ describe( RCAP::CAP_1_1::Point ) do
4
4
  describe( 'is not valid if' ) do
5
5
  before( :each ) do
6
- @point = RCAP::Point.new( :lattitude => 0, :longitude => 0 )
6
+ @point = RCAP::CAP_1_1::Point.new( :lattitude => 0, :longitude => 0 )
7
7
  @point.should( be_valid )
8
8
  end
9
9
 
@@ -13,9 +13,9 @@ describe( RCAP::Point ) do
13
13
  end
14
14
 
15
15
  it( 'does not have a valid longitude' ) do
16
- @point.longitude = RCAP::Point::MAX_LONGITUDE + 1
16
+ @point.longitude = RCAP::CAP_1_1::Point::MAX_LONGITUDE + 1
17
17
  @point.should_not( be_valid )
18
- @point.longitude = RCAP::Point::MIN_LONGITUDE - 1
18
+ @point.longitude = RCAP::CAP_1_1::Point::MIN_LONGITUDE - 1
19
19
  @point.should_not( be_valid )
20
20
  end
21
21
 
@@ -25,21 +25,21 @@ describe( RCAP::Point ) do
25
25
  end
26
26
 
27
27
  it( 'does not have a valid lattitude' ) do
28
- @point.lattitude = RCAP::Point::MAX_LATTITUDE + 1
28
+ @point.lattitude = RCAP::CAP_1_1::Point::MAX_LATTITUDE + 1
29
29
  @point.should_not( be_valid )
30
- @point.lattitude = RCAP::Point::MIN_LATTITUDE - 1
30
+ @point.lattitude = RCAP::CAP_1_1::Point::MIN_LATTITUDE - 1
31
31
  @point.should_not( be_valid )
32
32
  end
33
33
  end
34
34
 
35
35
  context( 'when exported' ) do
36
36
  before( :each ) do
37
- @point = RCAP::Point.new( :lattitude => 1, :longitude => 1 )
37
+ @point = RCAP::CAP_1_1::Point.new( :lattitude => 1, :longitude => 1 )
38
38
  end
39
39
 
40
40
  context( 'to hash' ) do
41
41
  it( 'should export correctly' ) do
42
- @point.to_h.should == { RCAP::Point::LATTITUDE_KEY => 1, RCAP::Point::LONGITUDE_KEY => 1 }
42
+ @point.to_h.should == { RCAP::CAP_1_1::Point::LATTITUDE_KEY => 1, RCAP::CAP_1_1::Point::LONGITUDE_KEY => 1 }
43
43
  end
44
44
  end
45
45
  end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe( RCAP::CAP_1_1::Polygon ) do
4
+ describe( 'is not valid if it' ) do
5
+ before( :each ) do
6
+ @polygon = RCAP::CAP_1_1::Polygon.new
7
+ 3.times do
8
+ @polygon.points << RCAP::CAP_1_1::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_1::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_1::Point.new( :lattitude => i, :longitude => i )})
28
+ @empty_original_polygon = RCAP::CAP_1_1::Polygon.new()
29
+ @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :areas => RCAP::CAP_1_1::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_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
33
+ @area_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_1::Area::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
34
+ @polygon_element = RCAP.xpath_first( @area_element, RCAP::CAP_1_1::Polygon::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
35
+ @polygon = RCAP::CAP_1_1::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_1::Polygon::XPATH, RCAP::CAP_1_1::Alert::XMLNS )[1]
47
+ empty_polygon = RCAP::CAP_1_1::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_1::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_1::Point.new( :lattitude => i, :longitude => i )})
55
+ end
56
+
57
+ it( 'should load all the points' ) do
58
+ @new_polygon = RCAP::CAP_1_1::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_1::Polygon.new( :points => Array.new(3){|i| RCAP::CAP_1_1::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_1::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_1::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.1 Point' ) do
87
+ @point.class.should == RCAP::CAP_1_1::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
@@ -1,21 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe( RCAP::Resource ) do
3
+ describe( RCAP::CAP_1_1::Resource ) do
4
4
  context( 'on initialisation' ) do
5
5
  before( :each ) do
6
- @resource = RCAP::Resource.new
6
+ @resource = RCAP::CAP_1_1::Resource.new
7
7
  end
8
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 deref_uri' ){ @resource.deref_uri.should( be_nil )}
13
- it( 'should have no digest' ){ @resource.digest.should( be_nil )}
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 deref_uri' ){ @resource.deref_uri.should( be_nil )}
13
+ it( 'should have no digest' ){ @resource.digest.should( be_nil )}
14
14
  it( 'should have no resource_desc' ){ @resource.resource_desc.should( be_nil )}
15
15
 
16
16
  context( 'from XML' ) do
17
17
  before( :each ) do
18
- @original_resource = RCAP::Resource.new
18
+ @original_resource = RCAP::CAP_1_1::Resource.new
19
19
  @original_resource.resource_desc = "Image of incident"
20
20
  @original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
21
21
  @original_resource.mime_type = 'image/png'
@@ -23,13 +23,13 @@ describe( RCAP::Resource ) do
23
23
  @original_resource.size = "20480"
24
24
  @original_resource.digest = "2048"
25
25
 
26
- @alert = RCAP::Alert.new( :infos => RCAP::Info.new( :resources => @original_resource ))
26
+ @alert = RCAP::CAP_1_1::Alert.new( :infos => RCAP::CAP_1_1::Info.new( :resources => @original_resource ))
27
27
  @xml_string = @alert.to_xml
28
28
  @xml_document = REXML::Document.new( @xml_string )
29
- @info_element = RCAP.xpath_first( @xml_document.root, RCAP::Info::XPATH )
30
- @resource_element = RCAP.xpath_first( @info_element, RCAP::Resource::XPATH )
29
+ @info_element = RCAP.xpath_first( @xml_document.root, RCAP::CAP_1_1::Info::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
30
+ @resource_element = RCAP.xpath_first( @info_element, RCAP::CAP_1_1::Resource::XPATH, RCAP::CAP_1_1::Alert::XMLNS )
31
31
  @resource_element.should_not( be_nil )
32
- @resource = RCAP::Resource.from_xml_element( @resource_element )
32
+ @resource = RCAP::CAP_1_1::Resource.from_xml_element( @resource_element )
33
33
  end
34
34
 
35
35
  it( 'should parse resource_desc correctly' ) do
@@ -60,7 +60,7 @@ describe( RCAP::Resource ) do
60
60
 
61
61
  context( 'from a hash' ) do
62
62
  before( :each ) do
63
- @original_resource = RCAP::Resource.new
63
+ @original_resource = RCAP::CAP_1_1::Resource.new
64
64
  @original_resource.resource_desc = "Image of incident"
65
65
  @original_resource.uri = "http://capetown.gov.za/cap/resources/image.png"
66
66
  @original_resource.mime_type = 'image/png'
@@ -68,7 +68,7 @@ describe( RCAP::Resource ) do
68
68
  @original_resource.size = "20480"
69
69
  @original_resource.digest = "2048"
70
70
 
71
- @resource = RCAP::Resource.from_h( @original_resource.to_h )
71
+ @resource = RCAP::CAP_1_1::Resource.from_h( @original_resource.to_h )
72
72
  end
73
73
 
74
74
  it( 'should parse resource_desc correctly' ) do
@@ -100,7 +100,7 @@ describe( RCAP::Resource ) do
100
100
 
101
101
  context( 'when exported' ) do
102
102
  before( :each ) do
103
- @resource = RCAP::Resource.new
103
+ @resource = RCAP::CAP_1_1::Resource.new
104
104
  @resource.resource_desc = "Image of incident"
105
105
  @resource.uri = "http://capetown.gov.za/cap/resources/image.png"
106
106
  @resource.mime_type = 'image/png'
@@ -115,34 +115,34 @@ describe( RCAP::Resource ) do
115
115
  end
116
116
 
117
117
  it( 'should set the resource description' ) do
118
- @resource_hash[ RCAP::Resource::RESOURCE_DESC_KEY ].should == @resource.resource_desc
118
+ @resource_hash[ RCAP::CAP_1_1::Resource::RESOURCE_DESC_KEY ].should == @resource.resource_desc
119
119
  end
120
120
 
121
121
  it( 'should set the mime type' ) do
122
- @resource_hash[ RCAP::Resource::MIME_TYPE_KEY ].should == @resource.mime_type
122
+ @resource_hash[ RCAP::CAP_1_1::Resource::MIME_TYPE_KEY ].should == @resource.mime_type
123
123
  end
124
124
 
125
125
  it( 'should set the size' ) do
126
- @resource_hash[ RCAP::Resource::SIZE_KEY ].should == @resource.size
126
+ @resource_hash[ RCAP::CAP_1_1::Resource::SIZE_KEY ].should == @resource.size
127
127
  end
128
128
 
129
129
  it( 'should set the URI' ) do
130
- @resource_hash[ RCAP::Resource::URI_KEY ].should == @resource.uri
130
+ @resource_hash[ RCAP::CAP_1_1::Resource::URI_KEY ].should == @resource.uri
131
131
  end
132
132
 
133
133
  it( 'should set the dereferenced URI' ) do
134
- @resource_hash[ RCAP::Resource::DEREF_URI_KEY ].should == @resource.deref_uri
135
- end
134
+ @resource_hash[ RCAP::CAP_1_1::Resource::DEREF_URI_KEY ].should == @resource.deref_uri
135
+ end
136
136
 
137
137
  it( 'should set the digest' ) do
138
- @resource_hash[ RCAP::Resource::DIGEST_KEY ].should == @resource.digest
139
- end
138
+ @resource_hash[ RCAP::CAP_1_1::Resource::DIGEST_KEY ].should == @resource.digest
139
+ end
140
140
  end
141
141
  end
142
142
 
143
143
  context( 'which is valid' ) do
144
144
  before( :each ) do
145
- @resource = RCAP::Resource.new( :resource_desc => 'Resource Description' )
145
+ @resource = RCAP::CAP_1_1::Resource.new( :resource_desc => 'Resource Description' )
146
146
  @resource.should( be_valid )
147
147
  end
148
148
 
@@ -0,0 +1,233 @@
1
+ require 'spec_helper'
2
+
3
+ describe( RCAP::CAP_1_2::Alert ) do
4
+ context( 'on initialisation' ) do
5
+ before( :each ) do
6
+ @alert = RCAP::CAP_1_2::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.2 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 codes correctly' ) { @alert.codes == @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_2::Info }
40
+ end
41
+ end
42
+
43
+ context( 'from XML' ) do
44
+ before( :each ) do
45
+ @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
46
+ :sent => DateTime.now,
47
+ :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
48
+ :scope => RCAP::CAP_1_2::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_2::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_2::Alert.new( :sender => 'Sender2' ).to_reference ],
55
+ :incidents => [ 'Incident1', 'Incident2' ],
56
+ :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::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_2::Alert.from_xml_element( @alert_element )
61
+ end
62
+
63
+ it_should_behave_like( "a successfully parsed CAP 1.2 alert" )
64
+
65
+ end
66
+
67
+ context( 'from YAML' ) do
68
+ before( :each ) do
69
+ @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
70
+ :sent => DateTime.now,
71
+ :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
72
+ :scope => RCAP::CAP_1_2::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_2::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_2::Alert.new( :sender => 'Sender2' ).to_reference ],
79
+ :incidents => [ 'Incident1', 'Incident2' ],
80
+ :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
81
+ @yaml_string = @original_alert.to_yaml
82
+ @alert = RCAP::CAP_1_2::Alert.from_yaml( @yaml_string )
83
+ end
84
+
85
+ it_should_behave_like( "a successfully parsed CAP 1.2 alert" )
86
+ end
87
+
88
+ context( 'from a hash' ) do
89
+ before( :each ) do
90
+ @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
91
+ :sent => DateTime.now,
92
+ :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
93
+ :scope => RCAP::CAP_1_2::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_2::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_2::Alert.new( :sender => 'Sender2' ).to_reference ],
100
+ :incidents => [ 'Incident1', 'Incident2' ],
101
+ :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
102
+ @alert = RCAP::CAP_1_2::Alert.from_h( @original_alert.to_h )
103
+ end
104
+
105
+ it_should_behave_like( "a successfully parsed CAP 1.2 alert" )
106
+ end
107
+
108
+ context( 'from JSON' ) do
109
+ before( :each ) do
110
+ @original_alert = RCAP::CAP_1_2::Alert.new( :sender => 'Sender',
111
+ :sent => DateTime.now,
112
+ :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
113
+ :scope => RCAP::CAP_1_2::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_2::Alert.new( :sender => 'Sender1' ).to_reference, RCAP::CAP_1_2::Alert.new( :sender => 'Sender2' ).to_reference ],
120
+ :incidents => [ 'Incident1', 'Incident2' ],
121
+ :infos => [ RCAP::CAP_1_2::Info.new, RCAP::CAP_1_2::Info.new ])
122
+ @alert = RCAP::CAP_1_2::Alert.from_json( @original_alert.to_json )
123
+ end
124
+
125
+ it_should_behave_like( "a successfully parsed CAP 1.2 alert" )
126
+ end
127
+ end
128
+
129
+ describe( 'is not valid if it' ) do
130
+ before( :each ) do
131
+ @alert = RCAP::CAP_1_2::Alert.new( :identifier => 'Identifier',
132
+ :sender => "cap@tempuri.org",
133
+ :sent => DateTime.now,
134
+ :status => RCAP::CAP_1_2::Alert::STATUS_TEST,
135
+ :msg_type => RCAP::CAP_1_2::Alert::MSG_TYPE_ALERT,
136
+ :scope => RCAP::CAP_1_2::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
+ it( 'does not have a restriction with a Restricted scope' ) do
187
+ @alert.scope = RCAP::CAP_1_2::Alert::SCOPE_RESTRICTED
188
+ @alert.restriction = nil
189
+ @alert.should_not( be_valid )
190
+ end
191
+
192
+ it( 'does not have any addresses with a Private scope' ) do
193
+ @alert.scope = RCAP::CAP_1_2::Alert::SCOPE_PRIVATE
194
+ @alert.addresses.clear
195
+ @alert.should_not( be_valid )
196
+ end
197
+
198
+ context( 'has an info element and it' ) do
199
+ it( 'is not valid' ) do
200
+ @info = RCAP::CAP_1_2::Info.new( :event => 'Info Event',
201
+ :categories => RCAP::CAP_1_2::Info::CATEGORY_GEO,
202
+ :urgency => RCAP::CAP_1_2::Info::URGENCY_IMMEDIATE,
203
+ :severity => RCAP::CAP_1_2::Info::SEVERITY_EXTREME,
204
+ :certainty => RCAP::CAP_1_2::Info::CERTAINTY_OBSERVED )
205
+ @info.event = nil
206
+ @alert.infos << @info
207
+ @info.should_not( be_valid )
208
+ @alert.should_not( be_valid )
209
+ end
210
+ end
211
+ end
212
+
213
+ describe( 'instance methods' ) do
214
+ before( :each ) do
215
+ @alert = RCAP::CAP_1_2::Alert.new
216
+ end
217
+
218
+ describe( '#add_info' ) do
219
+ before( :each ) do
220
+ @info = @alert.add_info( :urgency => 'urgent' )
221
+ @info.urgency.should == 'urgent'
222
+ end
223
+
224
+ it( 'should return a CAP 1.2 Info object' ) do
225
+ @info.class.should == RCAP::CAP_1_2::Info
226
+ end
227
+
228
+ it( 'should add an Info object to the infos array' ) do
229
+ @alert.infos.size.should == 1
230
+ end
231
+ end
232
+ end
233
+ end