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.
- data/.gitignore +1 -0
- data/Gemfile +8 -0
- data/README.md +49 -17
- data/lib/occi/collection.rb +37 -21
- data/lib/occi/core/action.rb +5 -5
- data/lib/occi/core/action_instance.rb +45 -3
- data/lib/occi/core/actions.rb +2 -1
- data/lib/occi/core/attributes.rb +253 -73
- data/lib/occi/core/categories.rb +1 -0
- data/lib/occi/core/category.rb +25 -8
- data/lib/occi/core/entities.rb +1 -0
- data/lib/occi/core/entity.rb +51 -74
- data/lib/occi/core/kind.rb +15 -11
- data/lib/occi/core/kinds.rb +1 -1
- data/lib/occi/core/link.rb +14 -15
- data/lib/occi/core/links.rb +1 -1
- data/lib/occi/core/mixin.rb +5 -5
- data/lib/occi/core/mixins.rb +2 -2
- data/lib/occi/core/properties.rb +90 -12
- data/lib/occi/core/resource.rb +7 -3
- data/lib/occi/core/resources.rb +2 -2
- data/lib/occi/errors/attribute_definitions_converted_error.rb +5 -0
- data/lib/occi/errors/attribute_missing_error.rb +5 -0
- data/lib/occi/errors/attribute_name_invalid_error.rb +5 -0
- data/lib/occi/errors/attribute_not_defined_error.rb +5 -0
- data/lib/occi/errors/attribute_property_type_error.rb +5 -0
- data/lib/occi/errors/attribute_type_error.rb +5 -0
- data/lib/occi/errors/kind_not_defined_error.rb +5 -0
- data/lib/occi/errors/parser_input_error.rb +5 -0
- data/lib/occi/errors/parser_type_error.rb +5 -0
- data/lib/occi/errors.rb +1 -0
- data/lib/occi/extensions/hashie.rb +25 -0
- data/lib/occi/helpers/comparators/action_instance.rb +22 -0
- data/lib/occi/helpers/comparators/attributes.rb +22 -0
- data/lib/occi/helpers/comparators/categories.rb +22 -0
- data/lib/occi/helpers/comparators/category.rb +22 -0
- data/lib/occi/helpers/comparators/collection.rb +40 -0
- data/lib/occi/helpers/comparators/entities.rb +22 -0
- data/lib/occi/helpers/comparators/entity.rb +22 -0
- data/lib/occi/helpers/comparators/properties.rb +26 -0
- data/lib/occi/helpers/comparators.rb +1 -0
- data/lib/occi/infrastructure/compute.rb +11 -9
- data/lib/occi/infrastructure/network.rb +27 -27
- data/lib/occi/infrastructure/networkinterface.rb +22 -23
- data/lib/occi/infrastructure/os_tpl.rb +1 -1
- data/lib/occi/infrastructure/resource_tpl.rb +1 -1
- data/lib/occi/infrastructure/storage.rb +7 -6
- data/lib/occi/infrastructure/storagelink.rb +4 -4
- data/lib/occi/log.rb +13 -10
- data/lib/occi/model.rb +9 -8
- data/lib/occi/parser/json.rb +11 -9
- data/lib/occi/parser/ova.rb +12 -6
- data/lib/occi/parser/ovf.rb +173 -116
- data/lib/occi/parser/text/constants.rb +87 -0
- data/lib/occi/parser/text.rb +161 -200
- data/lib/occi/parser/xml.rb +10 -8
- data/lib/occi/parser.rb +100 -50
- data/lib/occi/settings.rb +2 -1
- data/lib/occi/version.rb +1 -1
- data/lib/occi-core.rb +6 -4
- data/occi-core.gemspec +0 -7
- data/spec/occi/collection_samples/collection1.json +1 -0
- data/spec/occi/collection_samples/directory2/collection2.json +1 -0
- data/spec/occi/collection_spec.rb +961 -31
- data/spec/occi/core/action_instance_spec.rb +317 -0
- data/spec/occi/core/action_spec.rb +71 -0
- data/spec/occi/core/attributes_spec.rb +582 -27
- data/spec/occi/core/category_spec.rb +194 -18
- data/spec/occi/core/entities_spec.rb +96 -0
- data/spec/occi/core/entity_spec.rb +317 -28
- data/spec/occi/core/kind_spec.rb +127 -16
- data/spec/occi/core/link_spec.rb +35 -0
- data/spec/occi/core/links_spec.rb +130 -0
- data/spec/occi/core/mixins_spec.rb +107 -0
- data/spec/occi/core/properties_spec.rb +167 -0
- data/spec/occi/core/resource_spec.rb +23 -9
- data/spec/occi/core_spec.rb +12 -0
- data/spec/occi/infrastructure/compute_spec.rb +218 -18
- data/spec/occi/infrastructure/network_spec.rb +96 -0
- data/spec/occi/infrastructure/networkinterface_spec.rb +96 -0
- data/spec/occi/infrastructure/storage_spec.rb +33 -0
- data/spec/occi/infrastructure/storagelink_spec.rb +45 -0
- data/spec/occi/log_spec.rb +104 -1
- data/spec/occi/model_spec.rb +251 -39
- data/spec/occi/{test.json → parser/json_samples/test.json} +0 -0
- data/spec/occi/parser/ova_samples/test.dump +0 -0
- data/spec/occi/{test.ova → parser/ova_samples/test.ova} +0 -0
- data/spec/occi/parser/ovf_samples/test.dump +0 -0
- data/spec/occi/{test.ovf → parser/ovf_samples/test.ovf} +0 -0
- data/spec/occi/parser/text_samples/occi_categories.dump +0 -0
- data/spec/occi/parser/text_samples/occi_categories.text +2 -0
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.dump +0 -0
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.resource.dump +0 -0
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +10 -0
- data/spec/occi/parser/text_samples/occi_link_resource_instance.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_resource_instance.text +7 -0
- data/spec/occi/parser/text_samples/occi_link_simple.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_simple.link_string.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_simple.text +1 -0
- data/spec/occi/parser/text_samples/occi_link_w_attributes.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_w_attributes.text +7 -0
- data/spec/occi/parser/text_samples/occi_link_w_category.dump +0 -0
- data/spec/occi/parser/text_samples/occi_link_w_category.text +3 -0
- data/spec/occi/parser/text_samples/occi_model_rocci_server.dump +0 -0
- data/spec/occi/parser/text_samples/occi_model_rocci_server.text +51 -0
- data/spec/occi/parser/text_samples/occi_network_rocci_server.dump +0 -0
- data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.dump +0 -0
- data/spec/occi/parser/text_samples/occi_network_rocci_server.text +11 -0
- data/spec/occi/parser/text_samples/occi_resource_w_attributes.dump +0 -0
- data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +11 -0
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links.dump +0 -0
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +16 -0
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.dump +0 -0
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +13 -0
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.dump +0 -0
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.resource.dump +0 -0
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +9 -0
- data/spec/occi/parser/text_spec.rb +274 -78
- data/spec/occi/parser/xml_samples/test.xml +352 -0
- data/spec/occi/parser_spec.rb +255 -104
- data/spec/occi-core_spec.rb +31 -0
- data/spec/spec_helper.rb +6 -2
- metadata +110 -111
- checksums.yaml +0 -7
- data/spec/occi/core/attribute_spec.rb +0 -0
data/spec/occi/parser_spec.rb
CHANGED
@@ -1,116 +1,267 @@
|
|
1
1
|
module Occi
|
2
2
|
describe "Parser" do
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|