occi-core 4.1.3 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +8 -0
  3. data/README.md +49 -17
  4. data/lib/occi/collection.rb +37 -21
  5. data/lib/occi/core/action.rb +5 -5
  6. data/lib/occi/core/action_instance.rb +45 -3
  7. data/lib/occi/core/actions.rb +2 -1
  8. data/lib/occi/core/attributes.rb +253 -73
  9. data/lib/occi/core/categories.rb +1 -0
  10. data/lib/occi/core/category.rb +25 -8
  11. data/lib/occi/core/entities.rb +1 -0
  12. data/lib/occi/core/entity.rb +51 -74
  13. data/lib/occi/core/kind.rb +15 -11
  14. data/lib/occi/core/kinds.rb +1 -1
  15. data/lib/occi/core/link.rb +14 -15
  16. data/lib/occi/core/links.rb +1 -1
  17. data/lib/occi/core/mixin.rb +5 -5
  18. data/lib/occi/core/mixins.rb +2 -2
  19. data/lib/occi/core/properties.rb +90 -12
  20. data/lib/occi/core/resource.rb +7 -3
  21. data/lib/occi/core/resources.rb +2 -2
  22. data/lib/occi/errors/attribute_definitions_converted_error.rb +5 -0
  23. data/lib/occi/errors/attribute_missing_error.rb +5 -0
  24. data/lib/occi/errors/attribute_name_invalid_error.rb +5 -0
  25. data/lib/occi/errors/attribute_not_defined_error.rb +5 -0
  26. data/lib/occi/errors/attribute_property_type_error.rb +5 -0
  27. data/lib/occi/errors/attribute_type_error.rb +5 -0
  28. data/lib/occi/errors/kind_not_defined_error.rb +5 -0
  29. data/lib/occi/errors/parser_input_error.rb +5 -0
  30. data/lib/occi/errors/parser_type_error.rb +5 -0
  31. data/lib/occi/errors.rb +1 -0
  32. data/lib/occi/extensions/hashie.rb +25 -0
  33. data/lib/occi/helpers/comparators/action_instance.rb +22 -0
  34. data/lib/occi/helpers/comparators/attributes.rb +22 -0
  35. data/lib/occi/helpers/comparators/categories.rb +22 -0
  36. data/lib/occi/helpers/comparators/category.rb +22 -0
  37. data/lib/occi/helpers/comparators/collection.rb +40 -0
  38. data/lib/occi/helpers/comparators/entities.rb +22 -0
  39. data/lib/occi/helpers/comparators/entity.rb +22 -0
  40. data/lib/occi/helpers/comparators/properties.rb +26 -0
  41. data/lib/occi/helpers/comparators.rb +1 -0
  42. data/lib/occi/infrastructure/compute.rb +11 -9
  43. data/lib/occi/infrastructure/network.rb +27 -27
  44. data/lib/occi/infrastructure/networkinterface.rb +22 -23
  45. data/lib/occi/infrastructure/os_tpl.rb +1 -1
  46. data/lib/occi/infrastructure/resource_tpl.rb +1 -1
  47. data/lib/occi/infrastructure/storage.rb +7 -6
  48. data/lib/occi/infrastructure/storagelink.rb +4 -4
  49. data/lib/occi/log.rb +13 -10
  50. data/lib/occi/model.rb +9 -8
  51. data/lib/occi/parser/json.rb +11 -9
  52. data/lib/occi/parser/ova.rb +12 -6
  53. data/lib/occi/parser/ovf.rb +173 -116
  54. data/lib/occi/parser/text/constants.rb +87 -0
  55. data/lib/occi/parser/text.rb +161 -200
  56. data/lib/occi/parser/xml.rb +10 -8
  57. data/lib/occi/parser.rb +100 -50
  58. data/lib/occi/settings.rb +2 -1
  59. data/lib/occi/version.rb +1 -1
  60. data/lib/occi-core.rb +6 -4
  61. data/occi-core.gemspec +0 -7
  62. data/spec/occi/collection_samples/collection1.json +1 -0
  63. data/spec/occi/collection_samples/directory2/collection2.json +1 -0
  64. data/spec/occi/collection_spec.rb +961 -31
  65. data/spec/occi/core/action_instance_spec.rb +317 -0
  66. data/spec/occi/core/action_spec.rb +71 -0
  67. data/spec/occi/core/attributes_spec.rb +582 -27
  68. data/spec/occi/core/category_spec.rb +194 -18
  69. data/spec/occi/core/entities_spec.rb +96 -0
  70. data/spec/occi/core/entity_spec.rb +317 -28
  71. data/spec/occi/core/kind_spec.rb +127 -16
  72. data/spec/occi/core/link_spec.rb +35 -0
  73. data/spec/occi/core/links_spec.rb +130 -0
  74. data/spec/occi/core/mixins_spec.rb +107 -0
  75. data/spec/occi/core/properties_spec.rb +167 -0
  76. data/spec/occi/core/resource_spec.rb +23 -9
  77. data/spec/occi/core_spec.rb +12 -0
  78. data/spec/occi/infrastructure/compute_spec.rb +218 -18
  79. data/spec/occi/infrastructure/network_spec.rb +96 -0
  80. data/spec/occi/infrastructure/networkinterface_spec.rb +96 -0
  81. data/spec/occi/infrastructure/storage_spec.rb +33 -0
  82. data/spec/occi/infrastructure/storagelink_spec.rb +45 -0
  83. data/spec/occi/log_spec.rb +104 -1
  84. data/spec/occi/model_spec.rb +251 -39
  85. data/spec/occi/{test.json → parser/json_samples/test.json} +0 -0
  86. data/spec/occi/parser/ova_samples/test.dump +0 -0
  87. data/spec/occi/{test.ova → parser/ova_samples/test.ova} +0 -0
  88. data/spec/occi/parser/ovf_samples/test.dump +0 -0
  89. data/spec/occi/{test.ovf → parser/ovf_samples/test.ovf} +0 -0
  90. data/spec/occi/parser/text_samples/occi_categories.dump +0 -0
  91. data/spec/occi/parser/text_samples/occi_categories.text +2 -0
  92. data/spec/occi/parser/text_samples/occi_compute_rocci_server.dump +0 -0
  93. data/spec/occi/parser/text_samples/occi_compute_rocci_server.resource.dump +0 -0
  94. data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +10 -0
  95. data/spec/occi/parser/text_samples/occi_link_resource_instance.dump +0 -0
  96. data/spec/occi/parser/text_samples/occi_link_resource_instance.text +7 -0
  97. data/spec/occi/parser/text_samples/occi_link_simple.dump +0 -0
  98. data/spec/occi/parser/text_samples/occi_link_simple.link_string.dump +0 -0
  99. data/spec/occi/parser/text_samples/occi_link_simple.text +1 -0
  100. data/spec/occi/parser/text_samples/occi_link_w_attributes.dump +0 -0
  101. data/spec/occi/parser/text_samples/occi_link_w_attributes.text +7 -0
  102. data/spec/occi/parser/text_samples/occi_link_w_category.dump +0 -0
  103. data/spec/occi/parser/text_samples/occi_link_w_category.text +3 -0
  104. data/spec/occi/parser/text_samples/occi_model_rocci_server.dump +0 -0
  105. data/spec/occi/parser/text_samples/occi_model_rocci_server.text +51 -0
  106. data/spec/occi/parser/text_samples/occi_network_rocci_server.dump +0 -0
  107. data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.dump +0 -0
  108. data/spec/occi/parser/text_samples/occi_network_rocci_server.text +11 -0
  109. data/spec/occi/parser/text_samples/occi_resource_w_attributes.dump +0 -0
  110. data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +11 -0
  111. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.dump +0 -0
  112. data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +16 -0
  113. data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.dump +0 -0
  114. data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +13 -0
  115. data/spec/occi/parser/text_samples/occi_storage_rocci_server.dump +0 -0
  116. data/spec/occi/parser/text_samples/occi_storage_rocci_server.resource.dump +0 -0
  117. data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +9 -0
  118. data/spec/occi/parser/text_spec.rb +274 -78
  119. data/spec/occi/parser/xml_samples/test.xml +352 -0
  120. data/spec/occi/parser_spec.rb +255 -104
  121. data/spec/occi-core_spec.rb +31 -0
  122. data/spec/spec_helper.rb +6 -2
  123. metadata +110 -111
  124. checksums.yaml +0 -7
  125. data/spec/occi/core/attribute_spec.rb +0 -0
@@ -1,116 +1,267 @@
1
1
  module Occi
2
2
  describe "Parser" do
3
3
 
4
- it "parses an OCCI message with MIME type text/plain containing an OCCI resource" do
5
- # create new collection
6
- collection = Occi::Collection.new
7
- # create new resource within collection
8
- resource = collection.resources.create
9
-
10
- # render collection to text/plain MIME type
11
- rendered_collection = collection.to_text
12
- # parse rendered collection and compare with original collection
13
- Occi::Parser.parse('text/plain', rendered_collection).to_json.should == collection.to_json
14
-
15
- # add attributes to resource
16
- resource.id = UUIDTools::UUID.random_create.to_s
17
- resource.title = 'title'
18
-
19
- # render collection to text/plain MIME type
20
- rendered_collection = collection.to_text
21
- # parse rendered collection and compare with original collection
22
- Occi::Parser.parse('text/plain', rendered_collection).to_json.should == collection.to_json
23
-
24
- # add mixin to resource
25
- resource.mixins << Occi::Core::Mixin.new
26
-
27
- # render collection to text/plain MIME type
28
- rendered_collection = collection.to_text
29
- # parse rendered collection and compare with original collection
30
- Occi::Parser.parse('text/plain', rendered_collection).to_json.should == collection.to_json
31
-
32
- # add link to resource
33
- link = resource.links.create
34
- link.id = UUIDTools::UUID.random_create.to_s
35
- link.target = 'http://example.com/resource/aee5acf5-71de-40b0-bd1c-2284658bfd0e'
36
- link.source = resource
37
- collection << link
38
-
39
- # render collection to text/plain MIME type
40
- rendered_collection = collection.to_text
41
- # parse rendered collection and compare with original collection
42
- Occi::Parser.parse('text/plain', rendered_collection).to_json.should == collection.to_json
4
+ context ".parse" do
5
+
6
+ context "render->parse tests" do
7
+ let(:collection){ Occi::Collection.new }
8
+ let(:resource){ collection.resources.create }
9
+ let(:link){ link = resource.links.create
10
+ link.id = UUIDTools::UUID.random_create.to_s
11
+ link.target = 'http://example.com/resource/aee5acf5-71de-40b0-bd1c-2284658bfd0e'
12
+ link.source = resource
13
+ link
14
+ }
15
+
16
+ context "resources from OCCI messages with text/plain MIME type" do
17
+ let(:rendered_collection){ collection.to_text }
18
+
19
+ it 'parses self-generated collection with resources' do
20
+ expect(Occi::Parser.parse('text/plain', rendered_collection).to_json).to eql collection.to_json
21
+ end
22
+
23
+ it 'parses self-generated collection with added attributes' do
24
+ resource.id = UUIDTools::UUID.random_create.to_s
25
+ resource.title = 'title'
26
+ expect(Occi::Parser.parse('text/plain', rendered_collection).to_json).to eql collection.to_json
27
+ end
28
+
29
+ it 'parses self-generated collection with added mixin' do
30
+ resource.mixins << Occi::Core::Mixin.new
31
+ expect(Occi::Parser.parse('text/plain', rendered_collection).to_json).to eql collection.to_json
32
+ end
33
+
34
+ it 'parses self-generated collection with added link' do
35
+ collection << link
36
+ expect(Occi::Parser.parse('text/plain', rendered_collection).to_json).to eql collection.to_json
37
+ end
38
+ end
39
+
40
+ context 'resources from OCCI messages with text/occi MIME type' do
41
+ let(:rendered_collection){ collection.to_header }
42
+
43
+ it 'parses self-generated collection with resources' do
44
+ expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql collection.to_header
45
+ end
46
+
47
+ it 'parses self-generated collection with added attributes' do
48
+ resource.id = UUIDTools::UUID.random_create.to_s
49
+ resource.title = 'title'
50
+ expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql collection.to_header
51
+ end
52
+
53
+ it 'parses self-generated collection with added mixin' do
54
+ resource.mixins << Occi::Core::Mixin.new
55
+ expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql collection.to_header
56
+ end
57
+
58
+ it 'parses self-generated collection with added link' do
59
+ collection << link
60
+ expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql collection.to_header
61
+ end
62
+ end
63
+
64
+ context 'resources from OCCI messages with application/occi+json MIME type' do
65
+ let(:rendered_collection){ collection.to_json }
66
+ it 'parses self-generated collection with resources' do
67
+ expect(Occi::Parser.parse('application/occi+json', rendered_collection)).to eql collection
68
+ end
69
+
70
+ it 'parses self-generated collection with added attributes' do
71
+ resource.id = UUIDTools::UUID.random_create.to_s
72
+ resource.title = 'title'
73
+ expect(Occi::Parser.parse('application/occi+json', rendered_collection)).to eql collection
74
+ end
75
+
76
+ it 'parses self-generated collection with added mixin' do
77
+ resource.mixins << Occi::Core::Mixin.new
78
+ expect(Occi::Parser.parse('application/occi+json', rendered_collection)).to eql collection
79
+ end
80
+
81
+ it 'parses self-generated collection with added link' #do #Already deactivated in previous version
82
+ # collection << link
83
+ # expect(Occi::Parser.parse('application/occi+json', rendered_collection)).to eql collection
84
+ # end
85
+
86
+ end
87
+ end
88
+
89
+ it "parses an OVF file" do
90
+ media_type = 'application/ovf+xml'
91
+ body = File.read('spec/occi/parser/ovf_samples/test.ovf')
92
+ collection = Occi::Parser.parse(media_type, body)
93
+
94
+ collection.resources.each { |res| res.id="noid" } #Equalize auto-generated IDs
95
+
96
+ expected = Marshal.load(File.open("spec/occi/parser/ovf_samples/test.dump", "rb"))
97
+ expect(collection).to eql expected
98
+ end
99
+
100
+ it 'copes with faulty OVF' #do
101
+ # expect{ Occi::Parser.parse('application/ovf', "{This is not an OVF}")}.to raise_error(Occi::Errors::ParserInputError)
102
+ # end
103
+
104
+ it "parses an OVA container" do
105
+ media_type = 'application/ova'
106
+ body = File.read('spec/occi/parser/ova_samples/test.ova')
107
+ collection = Occi::Parser.parse(media_type, body)
108
+
109
+ collection.resources.each { |res| res.id="noid" } #Equalize auto-generated IDs
110
+
111
+ expected = Marshal.load(File.open("spec/occi/parser/ova_samples/test.dump", "rb"))
112
+ expect(collection).to eql expected
113
+ end
114
+
115
+ it 'copes with faulty OVA' do
116
+ expect{ Occi::Parser.parse('application/ova', "{This is not an OVA}")}.to raise_error(Occi::Errors::ParserInputError)
117
+ end
118
+
119
+ # ZS 11 Oct 2013: XML format not yet properly specified
120
+ # it "parses a XML file" do
121
+ # media_type = 'application/xml'
122
+ # body = File.read('spec/occi/parser/xml_samples/test.xml')
123
+ # collection = Occi::Parser.parse(media_type, body)
124
+ #
125
+ # end
126
+
127
+ it 'copes with faulty XML' do
128
+ expect{ collection = Occi::Parser.parse('application/xml', "{This is not a XML}") }.to raise_error(Occi::Errors::ParserInputError)
129
+ end
130
+
131
+ it 'copes with non-existent MIME-type' do
132
+ expect{ collection = Occi::Parser.parse('application/notexist', 'X-OCCI-Location: http://example.com:8090/a/b/vm1"') }.to raise_error(Occi::Errors::ParserTypeError)
133
+ end
134
+
135
+ it 'copes with type text/uri-list' do
136
+ expect{ collection = Occi::Parser.parse('text/uri-list', 'http://example.com:8090/a/b/vm1"') }.to raise_error(Occi::Errors::ParserTypeError)
137
+ end
138
+
139
+ it 'skips type text/occi in body' do
140
+ collection = Occi::Parser.parse('text/occi', 'Category: TERM;scheme="http://a.a/a#";class=kind')
141
+ expected = Occi::Collection.new
142
+ expect(collection).to eql expected
143
+ end
144
+
43
145
  end
44
146
 
45
- it "parses an OCCI message with MIME type application/occi+json containing an OCCI resource" do
46
- # create new collection
47
- collection = Occi::Collection.new
48
- # create new resource within collection
49
- resource = collection.resources.create
50
-
51
- # render collection to text/plain MIME type
52
- rendered_collection = collection.to_json
53
- # parse rendered collection and compare with original collection
54
- Occi::Parser.parse('application/occi+json', rendered_collection).should == collection
55
-
56
- # add attributes to resource
57
- resource.id = UUIDTools::UUID.random_create.to_s
58
- resource.title = 'title'
59
-
60
- # render collection to text/plain MIME type
61
- rendered_collection = collection.to_json
62
- # parse rendered collection and compare with original collection
63
- Occi::Parser.parse('application/occi+json', rendered_collection).should == collection
64
-
65
- # add mixin to resource
66
- resource.mixins << Occi::Core::Mixin.new
67
-
68
- # render collection to text/plain MIME type
69
- rendered_collection = collection.to_json
70
- # parse rendered collection and compare with original collection
71
- Occi::Parser.parse('application/occi+json', rendered_collection).should == collection
72
-
73
- # add link to resource
74
- link = resource.links.create
75
- link.target = 'http://example.com/resource/aee5acf5-71de-40b0-bd1c-2284658bfd0e'
76
-
77
- # render collection to text/plain MIME type
78
- rendered_collection = collection.to_json
79
- # parse rendered collection and compare with original collection
80
- Occi::Parser.parse('application/occi+json', rendered_collection).should == collection
147
+ context '.parse_headers' do
148
+ it 'parses categories' do
149
+ categories_string = File.open("spec/occi/parser/text_samples/occi_categories.text", "rb").read
150
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_categories.dump", "rb"))
151
+ categories = Occi::Parser.parse('text/plain', categories_string, true)
152
+ expect(categories).to eql expected
153
+ end
154
+
155
+ it 'parses resources' do
156
+ resource_string = File.open("spec/occi/parser/text_samples/occi_network_rocci_server.text", "rb").read
157
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_network_rocci_server.resource.dump", "rb"))
158
+ resource = Occi::Parser.parse('text/plain', resource_string, false, Occi::Core::Resource)
159
+ expect(resource).to eql expected
160
+ end
161
+
162
+ it 'parses link' do
163
+ link_string = File.open("spec/occi/parser/text_samples/occi_link_resource_instance.text", "rb").read
164
+ link = Occi::Parser.parse('text/plain', link_string, false, Occi::Core::Link)
165
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_link_resource_instance.dump", "rb"))
166
+ expected.links.each { |exp| exp.id = 'emptied' }
167
+ link.links.each { |lnk| lnk.id = 'emptied' }
168
+ expect(link).to eql expected
169
+ end
170
+
171
+ it 'fails gracefully for unknown entity type' do
172
+ resource_string = File.open("spec/occi/parser/text_samples/occi_network_rocci_server.text", "rb").read
173
+ expect{ Occi::Parser.parse('text/plain', resource_string, false, Occi::Core::ActionInstance) }.to raise_error(Occi::Errors::ParserTypeError)
174
+ end
81
175
  end
82
176
 
83
- it "parses an OVF file" do
84
- media_type = 'application/ovf+xml'
85
- body = File.read('spec/occi/test.ovf')
86
- collection = Occi::Parser.parse(media_type, body)
87
- storage_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#storage' }
88
- storage_resources.should have(1).storage_resource
89
- storage_resources.first.title.should == 'lamp'
90
- network_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#network' }
91
- network_resources.should have(1).network_resource
92
- network_resources.first.title.should == 'VM Network'
93
- compute_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#compute' }
94
- compute_resources.should have(1).compute_resource
95
- compute_resources.first.attributes.occi!.compute!.cores.should == 1
96
- compute_resources.first.attributes.occi!.compute!.memory.should == 0.25
177
+ context '.locations' do
178
+ let(:expected){ ["http://example.com:8090/a/b/vm1", "http://example.com:8090/a/b/vm2"] }
179
+ let(:single_expected){ ["http://example.com:8090/a/b/vm1"] }
180
+ it 'parses single location from headers' do
181
+ header = Hashie::Mash.new
182
+ header['X-OCCI-Location'] = 'http://example.com:8090/a/b/vm1'
183
+ location = Occi::Parser.locations("", "", header)
184
+ expect(location).to eql single_expected
185
+ end
186
+
187
+ it 'parses multiple locations from headers' do
188
+ header = Hashie::Mash.new
189
+ header['X-OCCI-Location'] = "http://example.com:8090/a/b/vm1,http://example.com:8090/a/b/vm2"
190
+ location = Occi::Parser.locations("", "", header)
191
+ expect(location).to eql expected
192
+ end
193
+
194
+ it 'parses locations from headers, skipping attributes' do
195
+ header = Hashie::Mash.new
196
+ header['X-OCCI-Location'] = "http://example.com:8090/a/b/vm1,http://example.com:8090/a/b/vm2"
197
+ header['X-OCCI-Attribute'] = "occi.core.title=\"test\""
198
+ location = Occi::Parser.locations("", "", header)
199
+ expect(location).to eql expected
200
+ end
201
+
202
+ it 'parses multiple locations from an URI list' do
203
+ locations_text = "http://example.com:8090/a/b/vm1\nhttp://example.com:8090/a/b/vm2"
204
+ location = Occi::Parser.locations("text/uri-list", locations_text, {})
205
+ expect(location).to eql expected
206
+ end
207
+
208
+ it 'parses multiple locations from plain text' do
209
+ locations_text = "X-OCCI-Location: http://example.com:8090/a/b/vm1\nX-OCCI-Location: http://example.com:8090/a/b/vm2"
210
+ location = Occi::Parser.locations("text/plain", locations_text, {})
211
+ expect(location).to eql expected
212
+ end
213
+
214
+ it 'copes with unmeaningful input' do
215
+ location = Occi::Parser.locations("nonexistent", "", {})
216
+ expect(location).to eql []
217
+ end
218
+
219
+ it 'parses "Location" hashes from header, solo' do
220
+ header = Hashie::Mash.new
221
+ header['Location'] = "http://example.com:8090/a/b/vm1"
222
+ location = Occi::Parser.locations("", "", header)
223
+ expect(location).to eql single_expected
224
+ end
225
+
226
+ it 'parses "Location" hashes from header in combination with X-OCCI-Location strings' do
227
+ header = Hashie::Mash.new
228
+ header['Location'] = "http://example.com:8090/a/b/vm1"
229
+ header['X-OCCI-Location'] = "http://example.com:8090/a/b/vm2"
230
+ locations_text = "X-OCCI-Location: http://example.com:8090/a/b/vm1\nX-OCCI-Location: http://example.com:8090/a/b/vm2"
231
+ location = Occi::Parser.locations("", "", header)
232
+ expect(location).to eql expected
233
+ end
97
234
  end
98
235
 
99
- it "parses an OVA container" do
100
- media_type = 'application/ova'
101
- body = File.read('spec/occi/test.ova')
102
- collection = Occi::Parser.parse(media_type, body)
103
- storage_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#storage' }
104
- storage_resources.should have(1).storage_resource
105
- storage_resources.first.title.should == 'lamp'
106
- network_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#network' }
107
- network_resources.should have(1).network_resource
108
- network_resources.first.title.should == 'VM Network'
109
- compute_resources = collection.resources.select { |resource| resource.kind.to_s == 'http://schemas.ogf.org/occi/infrastructure#compute' }
110
- compute_resources.should have(1).compute_resource
111
- compute_resources.first.attributes.occi!.compute!.cores.should == 1
112
- compute_resources.first.attributes.occi!.compute!.memory.should == 0.25
236
+ context '.parse_body_plain' do
237
+ it 'parses categories' do
238
+ categories_string = File.open("spec/occi/parser/text_samples/occi_categories.text", "rb").read
239
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_categories.dump", "rb"))
240
+ categories = Occi::Parser.parse('text/plain', categories_string, true)
241
+ expect(categories).to eql expected
242
+ end
243
+
244
+ it 'parses resources' do
245
+ resource_string = File.open("spec/occi/parser/text_samples/occi_network_rocci_server.text", "rb").read
246
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_network_rocci_server.resource.dump", "rb"))
247
+ resource = Occi::Parser.parse('text/plain', resource_string, false, Occi::Core::Resource)
248
+ expect(resource).to eql expected
249
+ end
250
+
251
+ it 'parses links' do
252
+ link_string = File.open("spec/occi/parser/text_samples/occi_link_resource_instance.text", "rb").read
253
+ link = Occi::Parser.parse('text/plain', link_string, false, Occi::Core::Link)
254
+ expected = Marshal.load(File.open("spec/occi/parser/text_samples/occi_link_resource_instance.dump", "rb"))
255
+ expected.links.each { |exp| exp.id = 'emptied' }
256
+ link.links.each { |lnk| lnk.id = 'emptied' }
257
+ expect(link).to eql expected
258
+ end
259
+
260
+ it 'copes with unknown entity type' do
261
+ expect{Occi::Parser.parse('text/plain', 'Category: TERM;scheme="http://a.a/a#";class=kind', false, Occi::Core::Kind)}.to raise_exception(Occi::Errors::ParserTypeError)
262
+ # This test works but the exception is actually raised in parse_headers(). Execution never gets to this branch in parse_body_plain()
263
+ end
113
264
  end
114
265
 
115
266
  end
116
- end
267
+ end
@@ -0,0 +1,31 @@
1
+ describe Occi do
2
+ include Occi
3
+
4
+ context ".kinds" do
5
+ it 'initializes kinds' do
6
+ kind = kinds
7
+ expect(kind).to eql []
8
+ end
9
+ end
10
+
11
+ context ".mixins" do
12
+ it 'initializes mixins' do
13
+ mixin = mixins
14
+ expect(mixin).to eql []
15
+ end
16
+ end
17
+
18
+ context ".actions" do
19
+ it 'initializes actions' do
20
+ action = actions
21
+ expect(actions).to eql []
22
+ end
23
+ end
24
+
25
+ context ".categories" do
26
+ it 'returns lists of categories' do
27
+ cat = categories
28
+ expect(cat).to eql []
29
+ end
30
+ end
31
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  require 'rubygems'
2
2
 
3
- require 'occi-core'
4
-
5
3
  # enable coverage reports
6
4
  if ENV['COVERAGE']
7
5
  require 'simplecov'
6
+
7
+ SimpleCov.add_filter "/spec/"
8
8
  SimpleCov.start
9
9
  end
10
10
 
11
+ require 'occi-core'
12
+ require 'json_spec'
13
+
11
14
  # simplify the usage of VCR; this will allow us to use
12
15
  #
13
16
  # it "does something", :vcr do
@@ -22,4 +25,5 @@ end
22
25
  RSpec.configure do |c|
23
26
  # in RSpec 3 this will no longer be necessary.
24
27
  c.treat_symbols_as_metadata_keys_with_true_values = true
28
+ c.include JsonSpec::Helpers
25
29
  end