occi-core 4.1.3 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,317 @@
1
+ module Occi
2
+ module Core
3
+ describe ActionInstance do
4
+
5
+ let(:ai){ Occi::Core::ActionInstance.new }
6
+ let(:action){ Occi::Core::Action.new }
7
+
8
+ let(:attributes){ Occi::Core::Attributes.new }
9
+ let(:attributes_one){
10
+ attrs = Occi::Core::Attributes.new
11
+ attrs["occi.core.title"] = "test"
12
+
13
+ attrs
14
+ }
15
+ let(:attributes_wnil){
16
+ attrs = Occi::Core::Attributes.new
17
+ attrs["occi.core.title"] = nil
18
+
19
+ attrs
20
+ }
21
+ let(:attributes_multi){
22
+ attrs = Occi::Core::Attributes.new
23
+ attrs["occi.core.title"] = "test"
24
+ attrs["occi.core.id"] = "1"
25
+ attrs["org.opennebula.network.id"] = 1
26
+
27
+ attrs
28
+ }
29
+ let(:attributes_unconvertable){ { "not" => "convertable" } }
30
+
31
+ let(:action_string){ 'http://rspec.rocci.cesnet.cz/occi/core#action' }
32
+ let(:action_string_invalid){ 'http://rspec.rocci.cesnet.cz/occi/core_action' }
33
+
34
+ context '#new' do
35
+ it 'with defaults' do
36
+ expect { ai }.not_to raise_error
37
+ end
38
+
39
+ it 'fails without an action' do
40
+ expect { Occi::Core::ActionInstance.new nil }.to raise_error(ArgumentError)
41
+ end
42
+
43
+ it 'fails without attributes' do
44
+ expect { Occi::Core::ActionInstance.new action, nil }.to raise_error(ArgumentError)
45
+ end
46
+
47
+ it 'with an Occi::Core::Action instance' do
48
+ expect { Occi::Core::ActionInstance.new action }.not_to raise_error
49
+ end
50
+
51
+ it 'with a valid action type identifier' do
52
+ expect { Occi::Core::ActionInstance.new action_string }.not_to raise_error
53
+ end
54
+
55
+ it 'with an invalid action type identifier' do
56
+ expect { Occi::Core::ActionInstance.new action_string_invalid }.to raise_error(ArgumentError)
57
+ end
58
+
59
+ it 'with an Occi::Core::Attributes instance' do
60
+ expect { Occi::Core::ActionInstance.new action, attributes }.not_to raise_error
61
+ end
62
+
63
+ it 'with un-convertable attribute values' do
64
+ expect { Occi::Core::ActionInstance.new action, attributes_unconvertable}.to raise_error(ArgumentError)
65
+ end
66
+ end
67
+
68
+ context '#action' do
69
+ it 'exposes associated action as Occi::Core::Action' do
70
+ expect(ai.action).to be_a(Occi::Core::Action)
71
+ end
72
+ end
73
+
74
+ context '#attributes' do
75
+ it 'exposes associated attributes as Occi::Core::Attributes' do
76
+ expect(ai.attributes).to be_a(Occi::Core::Attributes)
77
+ end
78
+ end
79
+
80
+ context '#model' do
81
+ # TODO: should ActionInstance have an associated model?
82
+ it 'exposes associated model as Occi::Model (??)' #do
83
+ #expect(ai.model).to be_a(Occi::Model)
84
+ #end
85
+ end
86
+
87
+ context '#to_text' do
88
+ it 'renders default to text' do
89
+ expected = "Category: action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
90
+ expect(ai.to_text).to eq(expected)
91
+ end
92
+
93
+ it 'renders to text w/ an attribute' do
94
+ expected = %Q|Category: action;scheme="http://schemas.ogf.org/occi/core#";class="action"
95
+ X-OCCI-Attribute: occi.core.title="test"|
96
+ expect(Occi::Core::ActionInstance.new(action, attributes_one).to_text).to eq(expected)
97
+ end
98
+
99
+ it 'renders to text w/ attributes' do
100
+ expected = %Q|Category: action;scheme="http://schemas.ogf.org/occi/core#";class="action"
101
+ X-OCCI-Attribute: occi.core.title="test"
102
+ X-OCCI-Attribute: occi.core.id="1"
103
+ X-OCCI-Attribute: org.opennebula.network.id=1|
104
+ expect(Occi::Core::ActionInstance.new(action, attributes_multi).to_text).to eq(expected)
105
+ end
106
+
107
+ it 'renders to text w/ a nil attribute' do
108
+ expected = "Category: action;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
109
+ expect(Occi::Core::ActionInstance.new(action, attributes_wnil).to_text).to eq(expected)
110
+ end
111
+ end
112
+
113
+ context '#to_header' do
114
+ it 'renders default to hash' do
115
+ expected = {"Category" => "action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""}
116
+ expect(ai.to_header).to eq(expected)
117
+ end
118
+
119
+ it 'renders to hash w/ an attribute' do
120
+ expected = {
121
+ "Category" => "action;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\"",
122
+ "X-OCCI-Attribute" => "occi.core.title=\"test\""
123
+ }
124
+ expect(Occi::Core::ActionInstance.new(action, attributes_one).to_header).to eq(expected)
125
+ end
126
+
127
+ it 'renders to hash w/ attributes' do
128
+ expected = {
129
+ "Category" => "action;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\"",
130
+ "X-OCCI-Attribute" => "occi.core.title=\"test\",occi.core.id=\"1\",org.opennebula.network.id=1"
131
+ }
132
+ expect(Occi::Core::ActionInstance.new(action, attributes_multi).to_header).to eq(expected)
133
+ end
134
+
135
+ it 'renders to hash w/ a nil attribute' do
136
+ expected = {"Category" => "action;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""}
137
+ expect(Occi::Core::ActionInstance.new(action, attributes_wnil).to_header).to eq(expected)
138
+ end
139
+ end
140
+
141
+ context '#to_json' do
142
+ let(:actioninstance){ Occi::Core::ActionInstance.new }
143
+ it 'renders default to JSON' do
144
+ expected = '{"action":"http://schemas.ogf.org/occi/core#action_instance","attributes":{}}'
145
+ expect(actioninstance.to_json).to eql expected
146
+ end
147
+
148
+ it 'renders to JSON w/ an attribute' do
149
+ actioninstance.attributes.testattr = 'test'
150
+ expected = '{"action":"http://schemas.ogf.org/occi/core#action_instance","attributes":{"testattr":"test"}}'
151
+ expect(actioninstance.to_json).to eql expected
152
+ end
153
+
154
+ it 'renders to JSON w/ multiple attributes' do
155
+ actioninstance.attributes.testattr = 'test'
156
+ actioninstance.attributes.anotherattr = 42
157
+ expected = '{"action":"http://schemas.ogf.org/occi/core#action_instance","attributes":{"testattr":"test","anotherattr":42}}'
158
+ expect(actioninstance.to_json).to eql expected
159
+ end
160
+
161
+ it 'renders to JSON w/ a nil attribute' do
162
+ actioninstance.attributes.testattr = nil
163
+ expected = '{"action":"http://schemas.ogf.org/occi/core#action_instance","attributes":{}}'
164
+ expect(actioninstance.to_json).to eql expected
165
+ end
166
+ end
167
+
168
+ context '#as_json' do
169
+ it 'renders default to Hashie::Mash' do
170
+ expected = Hashie::Mash.new({"action" => "http://schemas.ogf.org/occi/core#action_instance", "attributes" => {}})
171
+ expect(ai.as_json).to eq(expected)
172
+ end
173
+
174
+ it 'renders to Hashie::Mash w/ an attribute' do
175
+ expected = Hashie::Mash.new
176
+ expected.action = "http://schemas.ogf.org/occi/core#action"
177
+ expected.attributes = {"occi" => {"core" => {"title" => "test"}}}
178
+
179
+ expect(Occi::Core::ActionInstance.new(action, attributes_one).as_json).to eq(expected)
180
+ end
181
+
182
+ it 'renders to Hashie::Mash w/ attributes' do
183
+ expected = Hashie::Mash.new
184
+ expected.action = "http://schemas.ogf.org/occi/core#action"
185
+ expected.attributes = {
186
+ "occi" => {"core" => {"title" => "test", "id" => "1"}},
187
+ "org" => {"opennebula" => {"network" => {"id" => 1}}}
188
+ }
189
+
190
+ expect(Occi::Core::ActionInstance.new(action, attributes_multi).as_json).to eq(expected)
191
+ end
192
+ end
193
+
194
+ context '#==' do
195
+
196
+ it 'matches the same instance' do
197
+ expect(ai).to eq ai
198
+ end
199
+
200
+ it 'matches a clone' do
201
+ expect(ai).to eq ai.clone
202
+ end
203
+
204
+ it 'does not match with a different action' do
205
+ changed = ai.clone
206
+ changed.action = Occi::Core::Action.new(action_string)
207
+
208
+ expect(ai).not_to eq changed
209
+ end
210
+
211
+ it 'does not match with different attributes' do
212
+ changed = ai.clone
213
+ changed.attributes = attributes_one
214
+
215
+ expect(ai).not_to eq changed
216
+ end
217
+
218
+ it 'does not match a nil' do
219
+ expect(ai).not_to eq nil
220
+ end
221
+
222
+ end
223
+
224
+ context '#eql?' do
225
+
226
+ it 'matches the same instance' do
227
+ expect(ai).to eql ai
228
+ end
229
+
230
+ it 'matches a clone' do
231
+ expect(ai).to eql ai.clone
232
+ end
233
+
234
+ it 'does not match with a different action' do
235
+ changed = ai.clone
236
+ changed.action = Occi::Core::Action.new(action_string)
237
+
238
+ expect(ai).not_to eql changed
239
+ end
240
+
241
+ it 'does not match with different attributes' do
242
+ changed = ai.clone
243
+ changed.attributes = attributes_one
244
+
245
+ expect(ai).not_to eql changed
246
+ end
247
+
248
+ it 'does not match a nil' do
249
+ expect(ai).not_to eql nil
250
+ end
251
+
252
+ end
253
+
254
+ context '#equal?' do
255
+
256
+ it 'matches the same instance' do
257
+ expect(ai).to equal ai
258
+ end
259
+
260
+ it 'does not match clones' do
261
+ expect(ai).not_to equal ai.clone
262
+ end
263
+
264
+ end
265
+
266
+ context '#hash' do
267
+
268
+ it 'matches for clones' do
269
+ expect(ai.hash).to eq ai.clone.hash
270
+ end
271
+
272
+ it 'matches for the same instance' do
273
+ expect(ai.hash).to eq ai.hash
274
+ end
275
+
276
+ it 'does not match when action is different' do
277
+ ai_changed = ai.clone
278
+ ai_changed.action = Occi::Core::Action.new action_string
279
+
280
+ expect(ai.hash).not_to eq ai_changed.hash
281
+ end
282
+
283
+ it 'does not match when attributes are different' do
284
+ ai_changed = ai.clone
285
+ ai_changed.attributes = attributes_one
286
+
287
+ expect(ai.hash).not_to eq ai_changed.hash
288
+ end
289
+
290
+ end
291
+
292
+ context '#empty?' do
293
+
294
+ it 'returns false for a new instance with defaults' do
295
+ expect(ai.empty?).to be_false
296
+ end
297
+
298
+ it 'returns true for an instance without an action' do
299
+ ai_changed = ai.clone
300
+ ai_changed.action = nil
301
+
302
+ expect(ai_changed.empty?).to be_true
303
+ end
304
+
305
+ it 'returns true for an instance with an empty action' do
306
+ ai_changed = ai.clone
307
+ ai_changed.action = Occi::Core::Action.new
308
+ ai_changed.action.term = nil
309
+
310
+ expect(ai_changed.empty?).to be_true
311
+ end
312
+
313
+ end
314
+
315
+ end
316
+ end
317
+ end
@@ -0,0 +1,71 @@
1
+ module Occi
2
+ module Core
3
+ describe Action do
4
+ let(:action){ Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action' }
5
+
6
+ it 'can be instantiated' do
7
+ expect(action).to be_an_instance_of(Occi::Core::Action)
8
+ end
9
+
10
+ context '#term' do
11
+ it 'has correct term' do
12
+ expect(action.term).to eql 'testaction'
13
+ end
14
+ end
15
+
16
+ context '#title' do
17
+ it 'has correct title' do
18
+ expect(action.title).to eql 'testaction action'
19
+ end
20
+ end
21
+
22
+ context '#scheme' do
23
+ it 'has correct scheme' do
24
+ expect(action.scheme).to eql 'http://schemas.ogf.org/occi/core/entity/action#'
25
+ end
26
+ end
27
+
28
+ context '#to_text' do
29
+ it 'renders text correctly' do
30
+ action.attributes = Occi::Core::Attributes.new
31
+ action.attributes['numbertype'] = { :type => 'number',
32
+ :default => 42,
33
+ :mutable => true }
34
+ action.attributes['stringtype'] = { :type => 'string',
35
+ :pattern => '[adefltuv]+',
36
+ :default => 'defaultvalue',
37
+ :mutable => true }
38
+ action.attributes['booleantype'] = { :type => 'boolean',
39
+ :default => true,
40
+ :mutable => true }
41
+
42
+ expected = 'Category: testaction;scheme="http://schemas.ogf.org/occi/core/entity/action#";class="action";title="testaction action";attributes="numbertype stringtype booleantype"'
43
+
44
+ expect(action.to_text).to eql expected
45
+ end
46
+ end
47
+
48
+ context '#to_header' do
49
+ it 'renders text correctly' do
50
+ action.attributes = Occi::Core::Attributes.new
51
+ action.attributes['numbertype'] = { :type => 'number',
52
+ :default => 42,
53
+ :mutable => true }
54
+ action.attributes['stringtype'] = { :type => 'string',
55
+ :pattern => '[adefltuv]+',
56
+ :default => 'defaultvalue',
57
+ :mutable => true }
58
+ action.attributes['booleantype'] = { :type => 'boolean',
59
+ :default => true,
60
+ :mutable => true }
61
+
62
+ expected = {:Category => "testaction;scheme=\"http://schemas.ogf.org/occi/core/entity/action#\";class=\"action\";title=\"testaction action\";attributes=\"numbertype stringtype booleantype\""}
63
+ expect(action.to_header).to eql expected
64
+ end
65
+ end
66
+
67
+
68
+ end
69
+ end
70
+ end
71
+