occi-core 4.2.12 → 4.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ae8a9a2f1e04abc912900002e1a20ffc7d14c4a
4
- data.tar.gz: e61f0a1b597466384b814c331792dd27e0cfd0e9
3
+ metadata.gz: 9b13e9998a9a2ccb704efa4c1cbb283ae7aa7d46
4
+ data.tar.gz: c8e5a5a2dfe2df264cd24c46e86f7ec3d28b10b9
5
5
  SHA512:
6
- metadata.gz: 80566d28dd52b33ce23de9cb2dff9943d2a082a04a6acf8dfecdab40b79a20aaa08b20f7b7bcd7712c4dfad34d85e2c6de82a9b8cacc3729db4069e65d50e9ec
7
- data.tar.gz: 09dfb7c50b7ad1c603df9affc70406e4bb59a430844f965e8380430bc957af17cf0e5dcbe525d5935fc7e42b69a8edb8bc95953761670be128daf04ed044f21e
6
+ metadata.gz: 2093cc6c116bf9dc2e281a57ba5cfc2b05528e81da87695bc6a46c4078830c4575e9fde4aff0392edcea820b6c6f20e5c3a9232e83aacb54930f09d9701b9937
7
+ data.tar.gz: 01acb909e3a5942c83988de6966fb036827d07e7ac481b6862358356b99d06d79c0335de9151d9bdf3ab8f2d6fda5dbb38dba44a22eea40331568358ac069740
data/LICENSE CHANGED
@@ -1,13 +1,19 @@
1
- Copyright (c) 2012 GWDG
1
+ # @markup text
2
+
3
+ The work represented by this source file is partially or entirely funded
4
+ by the EGI-InSPIRE project through the European Commission's 7th Framework
5
+ Programme (contract # INFSO-RI-261323)
6
+
7
+ Copyright (c) 2012-2014 GWDG, CESNET
2
8
 
3
9
  Licensed under the Apache License, Version 2.0 (the "License");
4
10
  you may not use this file except in compliance with the License.
5
11
  You may obtain a copy of the License at
6
12
 
7
- http://www.apache.org/licenses/LICENSE-2.0
13
+ http://www.apache.org/licenses/LICENSE-2.0
8
14
 
9
15
  Unless required by applicable law or agreed to in writing, software
10
16
  distributed under the License is distributed on an "AS IS" BASIS,
11
17
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
18
  See the License for the specific language governing permissions and
13
- limitations under the License.
19
+ limitations under the License.
data/Rakefile CHANGED
@@ -6,6 +6,9 @@ task :default => 'test'
6
6
  desc "Run all tests; includes rspec and coverage reports"
7
7
  task :test => 'rcov:all'
8
8
 
9
+ desc "Run all tests; includes rspec and coverage reports"
10
+ task :spec => 'test'
11
+
9
12
  Gem::Tasks.new(:build => {:tar => true, :zip => true}, :sign => {:checksum => true, :pgp => false})
10
13
 
11
14
  namespace :rcov do
@@ -65,11 +65,12 @@ module Occi
65
65
  end
66
66
 
67
67
  # @param incl_categories [Boolean] check every category against the model
68
+ # @param set_default_attrs [Boolean] set default attribute values for all entities
68
69
  # @return [Boolean] result
69
- def check(incl_categories = false)
70
- @resources.check
71
- @links.check
72
- @action.check if @action
70
+ def check(incl_categories = false, set_default_attrs = false)
71
+ @resources.check(set_default_attrs)
72
+ @links.check(set_default_attrs)
73
+ @action.check(set_default_attrs) if @action
73
74
 
74
75
  if incl_categories
75
76
  @kinds.check
@@ -222,7 +223,7 @@ module Occi
222
223
  elsif standalone_action_instance?
223
224
  header = self.action.to_header
224
225
  else
225
- header['Category'] = self.categories.collect { |category| category.to_string_short }.join(',') if self.categories.any?
226
+ header['Category'] = self.categories.collect { |category| category.to_string }.join(',') if self.categories.any?
226
227
  raise "Only one resource allowed for rendering to text/occi!" if self.resources.size > 1
227
228
  header = self.class.header_merge(header, self.resources.first.to_header) if self.resources.any?
228
229
  header['Link'] = self.links.collect { |link| link.to_string }.join(',') if self.links.any?
@@ -21,8 +21,8 @@ module Occi
21
21
  each { |entity| entity.model = model }
22
22
  end
23
23
 
24
- def check
25
- each { |entity| entity.check }
24
+ def check(set_defaults = false)
25
+ each { |entity| entity.check(set_defaults) }
26
26
  end
27
27
 
28
28
  def create(*args)
@@ -171,22 +171,22 @@ module Occi
171
171
  # @param [true,false] set default values for all empty attributes
172
172
  def check(set_defaults = false)
173
173
  raise ArgumentError, 'No model has been assigned to this entity' unless @model
174
-
174
+
175
175
  kind = @model.get_by_id(@kind.to_s, true)
176
176
  raise Occi::Errors::KindNotDefinedError,
177
177
  "Kind not found for entity #{self.class.name}[#{self.to_s.inspect}]!" unless kind
178
-
178
+
179
179
  definitions = Occi::Core::Attributes.new
180
180
  definitions.merge! kind.attributes
181
-
181
+
182
182
  @mixins.each do |mxn|
183
183
  mixin = @model.get_by_id(mxn.to_s)
184
184
  raise Occi::Errors::CategoryNotDefinedError,
185
185
  "Mixin #{mxn.to_s.inspect} not declared in the model!" unless mixin && mixin.kind_of?(Occi::Core::Mixin)
186
-
186
+
187
187
  definitions.merge!(mixin.attributes) if mixin.attributes
188
188
  end if @mixins
189
-
189
+
190
190
  @attributes.check!(definitions, set_defaults)
191
191
  end
192
192
 
@@ -208,11 +208,11 @@ module Occi
208
208
 
209
209
  # @return [String] text representation
210
210
  def to_text
211
- text = "Category: #{self.kind.term};scheme=#{self.kind.scheme.inspect};class=\"kind\";location=#{self.kind.location.inspect}"
211
+ text = "Category: #{self.kind.term};scheme=#{self.kind.scheme.inspect};class=\"kind\";location=#{self.kind.location.inspect};title=#{self.kind.title.inspect}"
212
212
  @mixins.each do |mixin|
213
213
  scheme, term = mixin.to_s.split('#')
214
214
  scheme << '#'
215
- text << "\nCategory: #{term};scheme=#{scheme.inspect};class=\"mixin\";location=#{mixin.location.inspect}"
215
+ text << "\nCategory: #{term};scheme=#{scheme.inspect};class=\"mixin\";location=#{mixin.location.inspect};title=#{mixin.title ? mixin.title.inspect : ''.inspect}"
216
216
  end
217
217
 
218
218
  text << @attributes.to_text
@@ -225,12 +225,12 @@ module Occi
225
225
  # @return [Hash] hash containing the HTTP headers of the text/occi rendering
226
226
  def to_header
227
227
  header = Hashie::Mash.new
228
- header['Category'] = "#{self.kind.term};scheme=#{self.kind.scheme.inspect};class=\"kind\";location=#{self.kind.location.inspect}"
228
+ header['Category'] = "#{self.kind.term};scheme=#{self.kind.scheme.inspect};class=\"kind\";location=#{self.kind.location.inspect};title=#{self.kind.title.inspect}"
229
229
 
230
230
  @mixins.each do |mixin|
231
231
  scheme, term = mixin.to_s.split('#')
232
232
  scheme << '#'
233
- header['Category'] << ",#{term};scheme=#{scheme.inspect};class=\"mixin\";location=#{mixin.location.inspect}"
233
+ header['Category'] << ",#{term};scheme=#{scheme.inspect};class=\"mixin\";location=#{mixin.location.inspect};title=#{mixin.title ? mixin.title.inspect : ''.inspect}"
234
234
  end
235
235
 
236
236
  attributes = @attributes.to_header
data/lib/occi/parser.rb CHANGED
@@ -119,7 +119,13 @@ module Occi
119
119
 
120
120
  header.delete_if { |k, v| v.blank? || !OCCI_HEADERS.include?(k) }
121
121
 
122
- header.map { |k, v| v.to_s.split(',').collect { |w| "#{k}: #{w}" } }.flatten
122
+ header = header.map do |k, v|
123
+ # sometimes header values arrive as single-value arrays!
124
+ v = v.first if v.kind_of?(Array)
125
+ v.to_s.split(',').collect { |w| "#{k}: #{w}".strip }
126
+ end
127
+
128
+ header.flatten
123
129
  end
124
130
 
125
131
  end
@@ -108,7 +108,7 @@ module Occi
108
108
  # match string to regular expression
109
109
  match = regexp.match string
110
110
 
111
- raise Occi::Errors::ParserInputError, "Could not match #{string}" unless match
111
+ raise Occi::Errors::ParserInputError, "Could not match #{string.inspect}" unless match
112
112
 
113
113
  term = match[:term].downcase
114
114
  scheme = match[:scheme]
@@ -135,16 +135,16 @@ module Occi
135
135
 
136
136
  case match[:class]
137
137
  when 'kind'
138
- Occi::Log.debug "[#{self}] class #{match[:class]} identified as kind"
138
+ Occi::Log.debug "[#{self}] class #{match[:class].inspect} identified as kind"
139
139
  Occi::Core::Kind.new scheme, term, title, attributes, related, actions, location
140
140
  when 'mixin'
141
- Occi::Log.debug "[#{self}] class #{match[:class]} identified as mixin"
141
+ Occi::Log.debug "[#{self}] class #{match[:class].inspect} identified as mixin"
142
142
  Occi::Core::Mixin.new scheme, term, title, attributes, related, actions, location
143
143
  when 'action'
144
- Occi::Log.debug "[#{self}] class #{match[:class]} identified as action"
144
+ Occi::Log.debug "[#{self}] class #{match[:class].inspect} identified as action"
145
145
  Occi::Core::Action.new scheme, term, title, attributes
146
146
  else
147
- raise Occi::Errors::ParserInputError, "Category with class #{match[:class]} not recognized in string: #{string}"
147
+ raise Occi::Errors::ParserInputError, "Category with class #{match[:class].inspect} not recognized in string: #{string}"
148
148
  end
149
149
  end
150
150
 
@@ -155,7 +155,7 @@ module Occi
155
155
  # match string to regular expression
156
156
  match = regexp.match string
157
157
 
158
- raise Occi::Errors::ParserInputError, "Could not match #{string}" unless match
158
+ raise Occi::Errors::ParserInputError, "Could not match #{string.inspect}" unless match
159
159
 
160
160
  value = match[:string] if match[:string]
161
161
 
@@ -174,7 +174,7 @@ module Occi
174
174
  # match string to regular expression
175
175
  match = regexp.match string
176
176
 
177
- raise Occi::Errors::ParserInputError, "Could not match #{string}" unless match
177
+ raise Occi::Errors::ParserInputError, "Could not match #{string.inspect}" unless match
178
178
 
179
179
  if match[:uri].include?('?action=')
180
180
  link_string_action match
@@ -223,7 +223,7 @@ module Occi
223
223
  # match string to regular expression
224
224
  match = regexp.match string
225
225
 
226
- raise Occi::Errors::ParserInputError, "Could not match #{string}" unless match
226
+ raise Occi::Errors::ParserInputError, "Could not match #{string.inspect}" unless match
227
227
 
228
228
  match[:location]
229
229
  end
data/lib/occi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Occi
2
- VERSION = "4.2.12" unless defined?(::Occi::VERSION)
2
+ VERSION = "4.2.13" unless defined?(::Occi::VERSION)
3
3
  end
@@ -3,7 +3,7 @@ module Occi
3
3
 
4
4
  context 'initialization' do
5
5
  let(:collection){ collection = Occi::Collection.new }
6
-
6
+
7
7
  context 'with base objects' do
8
8
  before(:each) {
9
9
  collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
@@ -39,14 +39,14 @@ module Occi
39
39
  end
40
40
  end
41
41
  end
42
-
42
+
43
43
  context '#model' do
44
44
  let(:collection){ collection = Occi::Collection.new }
45
45
  it 'registers a model' do
46
46
  expect(collection.model).to be_kind_of Occi::Model
47
47
  end
48
48
  end
49
-
49
+
50
50
  context '#resources' do
51
51
  let(:collection){ collection = Occi::Collection.new }
52
52
  it 'can create a new OCCI Resource' do
@@ -57,10 +57,22 @@ module Occi
57
57
 
58
58
  context '#check' do
59
59
  let(:collection){ collection = Occi::Collection.new }
60
+
60
61
  it 'checks against model without failure' do
61
62
  collection.resources.create 'http://schemas.ogf.org/occi/core#resource'
62
63
  expect{ collection.check }.to_not raise_error
63
64
  end
65
+
66
+ it 'does not raise an error for unknown categories by default' do
67
+ collection.kinds << Occi::Core::Kind.new('http://example.org/test/stuff#', 'here')
68
+ expect { collection.check }.to_not raise_error
69
+ end
70
+
71
+ it 'raises an error for unknown categories when requested' do
72
+ collection.kinds << Occi::Core::Kind.new('http://example.org/test/stuff#', 'here')
73
+ expect { collection.check(true) }.to raise_error
74
+ end
75
+
64
76
  end
65
77
 
66
78
  context '#get_related_to' do
@@ -218,7 +230,7 @@ module Occi
218
230
  it 'kept the correct number of mixins' do
219
231
  expect(coll2.mixins.count).to eql 1
220
232
  end
221
-
233
+
222
234
  it 'kept the correct number of actions' do
223
235
  expect(coll2.actions.count).to eql 1
224
236
  end
@@ -247,7 +259,7 @@ module Occi
247
259
  end
248
260
 
249
261
  context '#merge!' do
250
- let(:collection){ collection = Occi::Collection.new
262
+ let(:collection){ collection = Occi::Collection.new
251
263
  collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
252
264
  collection.mixins << "http://example.com/occi/tags#my_mixin"
253
265
  collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
@@ -327,7 +339,7 @@ module Occi
327
339
  it 'kept the correct number of mixins' do
328
340
  expect(coll2.mixins.count).to eql 1
329
341
  end
330
-
342
+
331
343
  it 'kept the correct number of actions' do
332
344
  expect(coll2.actions.count).to eql 1
333
345
  end
@@ -500,7 +512,7 @@ module Occi
500
512
  it 'kept the correct number of mixins' do
501
513
  expect(coll2.mixins.count).to eql 2
502
514
  end
503
-
515
+
504
516
  it 'kept the correct number of actions' do
505
517
  expect(coll2.actions.count).to eql 2
506
518
  end
@@ -528,7 +540,7 @@ module Occi
528
540
  end
529
541
  context '#intersect!' do
530
542
  let(:collection){
531
- collection = Occi::Collection.new
543
+ collection = Occi::Collection.new
532
544
  collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
533
545
  collection.kinds << "http://schemas.ogf.org/occi/infrastructure#network"
534
546
  collection.mixins << "http://example.com/occi/tags#my_mixin"
@@ -634,7 +646,7 @@ module Occi
634
646
  it 'kept the correct number of mixins' do
635
647
  expect(coll2.mixins.count).to eql 2
636
648
  end
637
-
649
+
638
650
  it 'kept the correct number of actions' do
639
651
  expect(coll2.actions.count).to eql 2
640
652
  end
@@ -652,7 +664,7 @@ module Occi
652
664
  context 'collections with no intersection' do
653
665
  let(:action){ Occi::Core::Action.new scheme='http://schemas.ogf.org/occi/core/entity/action#', term='testaction', title='testaction action' }
654
666
  let(:uniq1) {
655
- uniq1 = Occi::Collection.new
667
+ uniq1 = Occi::Collection.new
656
668
  uniq1.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
657
669
  uniq1.mixins << "http://example.com/occi/tags#my_mixin"
658
670
  uniq1.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
@@ -686,14 +698,14 @@ module Occi
686
698
 
687
699
  it 'works with first collection empty' do
688
700
  empty = Occi::Collection.new
689
-
701
+
690
702
  uniq1.intersect!(empty)
691
703
  expect(empty.empty?).to eql true
692
704
  end
693
705
 
694
706
  it 'works with second collection empty' do
695
707
  empty = Occi::Collection.new
696
-
708
+
697
709
  empty.intersect!(uniq2)
698
710
  expect(empty.empty?).to eql true
699
711
  end
@@ -701,7 +713,7 @@ module Occi
701
713
  end
702
714
 
703
715
  context '#get_by_...' do
704
- let(:collection){ collection = Occi::Collection.new
716
+ let(:collection){ collection = Occi::Collection.new
705
717
  collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
706
718
  collection.mixins << "http://example.com/occi/tags#my_mixin"
707
719
  collection.actions << "http://schemas.ogf.org/occi/infrastructure/compute/action#start"
@@ -798,15 +810,15 @@ module Occi
798
810
  collection.resources << Occi::Core::Resource.new
799
811
  collection.links << Occi::Core::Link.new
800
812
  expected = "{\"actions\":[{\"scheme\":\"http://schemas.ogf.org/occi/infrastructure/compute/action#\",\"term\":\"start\",\"attributes\":{}}],\"kinds\":[{\"parent\":\"http://schemas.ogf.org/occi/core#resource\",\"related\":[\"http://schemas.ogf.org/occi/core#resource\"],\"actions\":[\"http://schemas.ogf.org/occi/infrastructure/compute/action#start\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#stop\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#restart\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"],\"location\":\"/compute/\",\"scheme\":\"http://schemas.ogf.org/occi/infrastructure#\",\"term\":\"compute\",\"title\":\"compute resource\",\"attributes\":{\"occi\":{\"core\":{\"id\":{\"type\":\"string\",\"required\":false,\"mutable\":false,\"pattern\":\"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\"},\"title\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"summary\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"}},\"compute\":{\"architecture\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\"x86|x64\"},\"cores\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"hostname\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\"(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\\\-]*[a-zA-Z0-9])\\\\.)*\"},\"memory\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"speed\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"state\":{\"default\":\"inactive\",\"type\":\"string\",\"required\":false,\"mutable\":false,\"pattern\":\"inactive|active|suspended|error\"}}}}}],\"links\":[{\"kind\":\"http://schemas.ogf.org/occi/core#link\",\"attributes\":{\"occi\":{\"core\":{\"id\":\"#{collection.links.first.id}\"}}},\"id\":\"#{collection.links.first.id}\",\"rel\":\"http://schemas.ogf.org/occi/core#link\"}],\"mixins\":[{\"location\":\"/mixin/my_mixin/\",\"scheme\":\"http://example.com/occi/tags#\",\"term\":\"my_mixin\",\"attributes\":{}}],\"resources\":[{\"kind\":\"http://schemas.ogf.org/occi/core#resource\",\"attributes\":{\"occi\":{\"core\":{\"id\":\"#{collection.resources.first.id}\"}}},\"id\":\"#{collection.resources.first.id}\"}]}"
801
-
813
+
802
814
  hash=Hashie::Mash.new(JSON.parse(expected))
803
- expect(collection.as_json).to eql(hash)
815
+ expect(collection.as_json).to eql(hash)
804
816
  end
805
817
 
806
818
  it 'renders JSON for an empty collection' do
807
819
  collection = Occi::Collection.new
808
820
  hash=Hashie::Mash.new
809
- expect(collection.as_json).to eql(hash)
821
+ expect(collection.as_json).to eql(hash)
810
822
  end
811
823
 
812
824
  it 'renders JSON for a collection with no resources' do
@@ -817,9 +829,9 @@ module Occi
817
829
  collection.action = Occi::Core::ActionInstance.new
818
830
  collection.links << Occi::Core::Link.new
819
831
  expected = "{\"actions\":[{\"scheme\":\"http://schemas.ogf.org/occi/infrastructure/compute/action#\",\"term\":\"start\",\"attributes\":{}}],\"kinds\":[{\"parent\":\"http://schemas.ogf.org/occi/core#resource\",\"related\":[\"http://schemas.ogf.org/occi/core#resource\"],\"actions\":[\"http://schemas.ogf.org/occi/infrastructure/compute/action#start\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#stop\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#restart\",\"http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"],\"location\":\"/compute/\",\"scheme\":\"http://schemas.ogf.org/occi/infrastructure#\",\"term\":\"compute\",\"title\":\"compute resource\",\"attributes\":{\"occi\":{\"core\":{\"id\":{\"type\":\"string\",\"required\":false,\"mutable\":false,\"pattern\":\"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\"},\"title\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"summary\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"}},\"compute\":{\"architecture\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\"x86|x64\"},\"cores\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"hostname\":{\"type\":\"string\",\"required\":false,\"mutable\":true,\"pattern\":\"(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\\\-]*[a-zA-Z0-9])\\\\.)*\"},\"memory\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"speed\":{\"type\":\"number\",\"required\":false,\"mutable\":true,\"pattern\":\".*\"},\"state\":{\"default\":\"inactive\",\"type\":\"string\",\"required\":false,\"mutable\":false,\"pattern\":\"inactive|active|suspended|error\"}}}}}],\"links\":[{\"kind\":\"http://schemas.ogf.org/occi/core#link\",\"attributes\":{\"occi\":{\"core\":{\"id\":\"#{collection.links.first.id}\"}}},\"id\":\"#{collection.links.first.id}\",\"rel\":\"http://schemas.ogf.org/occi/core#link\"}],\"mixins\":[{\"location\":\"/mixin/my_mixin/\",\"scheme\":\"http://example.com/occi/tags#\",\"term\":\"my_mixin\",\"attributes\":{}}]}"
820
-
832
+
821
833
  hash=Hashie::Mash.new(JSON.parse(expected))
822
- expect(collection.as_json).to eql(hash)
834
+ expect(collection.as_json).to eql(hash)
823
835
  end
824
836
  end
825
837
 
@@ -833,7 +845,7 @@ module Occi
833
845
  collection.resources << Occi::Core::Resource.new
834
846
  collection.links << Occi::Core::Link.new
835
847
 
836
- expected = "Category: compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"\nCategory: my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\"\nCategory: start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\"\nCategory: resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.resources.first.id}\"Link: <>;rel=\"http://schemas.ogf.org/occi/core#link\";self=\"/link/#{collection.links.first.id}\";category=\"http://schemas.ogf.org/occi/core#link\";occi.core.id=\"#{collection.links.first.id}\"Category: action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
848
+ expected = "Category: compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"\nCategory: my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\"\nCategory: start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\"\nCategory: resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\";title=\"resource\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.resources.first.id}\"Link: <>;rel=\"http://schemas.ogf.org/occi/core#link\";self=\"/link/#{collection.links.first.id}\";category=\"http://schemas.ogf.org/occi/core#link\";occi.core.id=\"#{collection.links.first.id}\"Category: action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
837
849
  expect(collection.to_text).to eql(expected)
838
850
  end
839
851
 
@@ -871,13 +883,13 @@ module Occi
871
883
 
872
884
  it 'renders text correctly, resources only' do
873
885
  collection.resources << Occi::Core::Resource.new
874
- expected = "Category: resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.resources.first.id}\""
886
+ expected = "Category: resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\";title=\"resource\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.resources.first.id}\""
875
887
  expect(collection.to_text).to eql(expected)
876
888
  end
877
889
 
878
890
  it 'renders text correctly, links only' do
879
891
  collection.links << Occi::Core::Link.new
880
- expected = "Category: link;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/link/\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.links.first.id}\""
892
+ expected = "Category: link;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/link/\";title=\"link\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.links.first.id}\""
881
893
  expect(collection.to_text).to eql(expected)
882
894
  end
883
895
 
@@ -894,7 +906,7 @@ module Occi
894
906
  collection.links << Occi::Core::Link.new
895
907
 
896
908
  expected=Hashie::Mash.new
897
- expected["Category"] = "compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\",my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\",start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\",resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\",action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
909
+ expected["Category"] = "compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\",my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\",start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\",resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\";title=\"resource\",action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
898
910
  expected["Link"] = "<>;rel=\"http://schemas.ogf.org/occi/core#link\";self=\"/link/#{collection.links.first.id}\";category=\"http://schemas.ogf.org/occi/core#link\";occi.core.id=\"#{collection.links.first.id}\""
899
911
  expected["X-OCCI-Attribute"] = "occi.core.id=\"#{collection.resources.first.id}\""
900
912
  expect(collection.to_header).to eql(expected)
@@ -908,14 +920,14 @@ module Occi
908
920
  it 'renders text correctly, kinds only' do
909
921
  collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
910
922
  expected=Hashie::Mash.new
911
- expected["Category"] = "compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\""
923
+ expected["Category"] = "compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\""
912
924
  expect(collection.to_header).to eql(expected)
913
925
  end
914
926
 
915
927
  it 'renders text correctly, mixins only' do
916
928
  collection.mixins << "http://example.com/occi/tags#my_mixin"
917
929
  expected=Hashie::Mash.new
918
- expected["Category"] = "my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\""
930
+ expected["Category"] = "my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\""
919
931
  expect(collection.to_header).to eql(expected)
920
932
  end
921
933
 
@@ -939,7 +951,7 @@ module Occi
939
951
  it 'renders text correctly, resources only' do
940
952
  collection.resources << Occi::Core::Resource.new
941
953
  expected=Hashie::Mash.new
942
- expected["Category"] = "resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\""
954
+ expected["Category"] = "resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\";title=\"resource\""
943
955
  expected["X-OCCI-Attribute"] = "occi.core.id=\"#{collection.resources.first.id}\""
944
956
  expect(collection.to_header).to eql(expected)
945
957
  end
@@ -947,7 +959,7 @@ module Occi
947
959
  it 'renders text correctly, links only' do
948
960
  collection.links << Occi::Core::Link.new
949
961
  expected=Hashie::Mash.new
950
- expected["Category"] = "link;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/link/\""
962
+ expected["Category"] = "link;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/link/\";title=\"link\""
951
963
  expected["X-OCCI-Attribute"] = "occi.core.id=\"#{collection.links.first.id}\""
952
964
  expect(collection.to_header).to eql(expected)
953
965
  end
@@ -974,7 +986,7 @@ module Occi
974
986
  expected['c'] = 'c'
975
987
  expect(mash1).to eql expected
976
988
  end
977
-
989
+
978
990
  it 'merges two mashes correctly with custom separator' do
979
991
  Occi::Collection.header_merge(mash1, second, ' : ')
980
992
 
@@ -984,7 +996,7 @@ module Occi
984
996
  expected['c'] = 'c'
985
997
  expect(mash1).to eql expected
986
998
  end
987
-
999
+
988
1000
  end
989
1001
 
990
1002
  end
@@ -15,70 +15,86 @@ module Occi
15
15
  it 'is created empty' do
16
16
  expect(entities.count).to eq 0
17
17
  end
18
+
18
19
  it 'gets entity Nos. right, 1' do
19
20
  entities << entity1
20
21
  expect(entities.count).to eq 1
21
22
  end
23
+
22
24
  it 'gets entity Nos. right, 2' do
23
25
  entities << entity1
24
26
  entities << entity2
25
27
  expect(entities.count).to eq 2
26
28
  end
29
+
27
30
  it 'gets correctly-typed elements' do
28
31
  entities << entity1
29
32
  entities << entity2
30
33
  expect(entities.first).to be_an_instance_of(Occi::Core::Entity)
31
34
  end
35
+
32
36
  end
33
37
 
34
38
  context '#model' do
39
+
35
40
  it 'has no model by default' do
36
41
  expect(entities.model).to be nil
37
42
  end
43
+
38
44
  it 'can be assigned model' do
39
45
  modl = Occi::Model.new
40
46
  entities.model = modl
41
47
  expect(entities.model).to eql modl
42
48
  end
49
+
43
50
  it 'uses the assigned model for new members' do
44
51
  modl = Occi::Model.new
45
52
  entities.model = modl
46
53
  entities << entity1
47
54
  expect(entities.first.model).to eql modl
48
55
  end
56
+
49
57
  it 'uses the assigned model for existing members' do
50
58
  entities << entity1
51
59
  modl = Occi::Model.new
52
60
  entities.model = modl
53
61
  expect(entities.first.model).to eql modl
54
62
  end
63
+
55
64
  it 'does not use unassigned model' do
56
65
  modl = Occi::Model.new
57
66
  entities << entity1
58
67
  expect(entities.first.model).to_not eql modl
59
68
  end
69
+
60
70
  end
61
71
 
62
72
  context '#create' do
73
+
63
74
  it 'creates a new element' do
64
75
  entities.create
65
76
  expect(entities.first).to be_instance_of(Occi::Core::Entity)
66
77
  end
78
+
67
79
  it 'accepts argument' do
68
80
  entities.create 'http://example.com/testnamespace#test'
69
81
  expect(entities.first).to be_kind_of 'Com::Example::Testnamespace::Test'.constantize
70
82
  end
83
+
71
84
  end
72
85
 
73
86
  context '#join' do
87
+
74
88
  it 'joins elements correctly' do
75
89
  entities << entity1
76
90
  entities << entity2
77
91
  expect(entities.join('|')).to eq '/entity/e1testid|/entity2/e2testid'
78
92
  end
93
+
79
94
  end
80
95
 
81
96
  context '#as_json' do
97
+
82
98
  it 'renders elements with various attributes' do
83
99
  entity2.actions << testaction
84
100
  entities << entity1
@@ -90,6 +106,54 @@ module Occi
90
106
  expected << hash2
91
107
  expect(entities.as_json).to eql expected
92
108
  end
109
+
110
+ end
111
+
112
+ context '#check' do
113
+
114
+ let(:attr_w_defaults) do
115
+ { :type => 'string',
116
+ :pattern => '[adefltuv]+',
117
+ :default => 'defaultvalue',
118
+ :mutable => true }
119
+ end
120
+ let(:model) do
121
+ model = Occi::Model.new
122
+ model.kinds.first.attributes['string_attribute'] = attr_w_defaults
123
+ model
124
+ end
125
+ let(:entities_w_defaults) do
126
+ entities << Occi::Core::Entity.new
127
+ entities.model = model
128
+ entities
129
+ end
130
+ let(:entities_w_wrong_attrs) do
131
+ ent1 = Occi::Core::Entity.new
132
+ ent1.attributes['fake.attr.here'] = 1
133
+ entities << ent1
134
+ entities.model = model
135
+ entities
136
+ end
137
+
138
+ it 'raises an error on undeclared attributes' do
139
+ expect { entities_w_wrong_attrs.check }.to raise_error
140
+ end
141
+
142
+ it 'passes on an empty collection' do
143
+ expect { entities.check }.not_to raise_error
144
+ expect { entities.check(true) }.not_to raise_error
145
+ end
146
+
147
+ it 'does not set attribute defaults by default' do
148
+ entities_w_defaults.check
149
+ expect(entities_w_defaults.first.attributes['string_attribute']).to be_blank
150
+ end
151
+
152
+ it 'sets attributes default when requested' do
153
+ entities_w_defaults.check(true)
154
+ expect(entities_w_defaults.first.attributes['string_attribute']).to eq 'defaultvalue'
155
+ end
156
+
93
157
  end
94
158
  end
95
159
  end
@@ -59,7 +59,7 @@ module Occi
59
59
  end
60
60
 
61
61
  context '#mixins' do
62
- let(:mixin){ 'http://example.com/mynamespace#mymixin' }
62
+ let(:mixin){ 'http://example.com/mynamespace#mymixin' }
63
63
 
64
64
  it "converts mixin type identifiers to objects if a mixin is added to the entities mixins" do
65
65
  entity.mixins << mixin
@@ -91,9 +91,9 @@ module Occi
91
91
  Occi::Settings['verify_attribute_pattern']=true
92
92
  expect{ entity.id = 'id with spaces' }.to raise_error Occi::Errors::AttributeTypeError
93
93
  end
94
-
94
+
95
95
  end
96
-
96
+
97
97
  context '#location' do
98
98
  it 'can be set and read' do
99
99
  entity.location = 'TestLoc'
@@ -150,7 +150,7 @@ module Occi
150
150
 
151
151
  context '#to_text' do
152
152
  it 'renders fresh instance in text correctly' do
153
- expected = %Q|Category: entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/"
153
+ expected = %Q|Category: entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/";title="entity"
154
154
  X-OCCI-Attribute: occi.core.id="baf1"|
155
155
  expect(entity.to_text).to eq(expected)
156
156
  end
@@ -161,8 +161,8 @@ X-OCCI-Attribute: occi.core.id="baf1"|
161
161
  entity.location = '/TestLoc/1'
162
162
  entity.mixins << 'http://example.com/mynamespace#mymixin'
163
163
 
164
- expected = %Q|Category: entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/"
165
- Category: mymixin;scheme="http://example.com/mynamespace#";class="mixin";location="/mixin/mymixin/"
164
+ expected = %Q|Category: entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/";title="entity"
165
+ Category: mymixin;scheme="http://example.com/mynamespace#";class="mixin";location="/mixin/mymixin/";title=""
166
166
  X-OCCI-Attribute: occi.core.id="baf1"
167
167
  X-OCCI-Attribute: occi.core.title="TestTitle"
168
168
  Link: </TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entity/action#testaction"|
@@ -173,7 +173,7 @@ Link: </TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entit
173
173
  context '#to_header' do
174
174
  it 'renders fresh instance in HTTP Header correctly' do
175
175
  expected = Hashie::Mash.new
176
- expected['Category'] = 'entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/"'
176
+ expected['Category'] = 'entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/";title="entity"'
177
177
  expected['X-OCCI-Attribute'] = 'occi.core.id="baf1"'
178
178
 
179
179
  expect(entity.to_header).to eql(expected)
@@ -186,7 +186,7 @@ Link: </TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entit
186
186
  entity.mixins << 'http://example.com/mynamespace#mymixin'
187
187
 
188
188
  expected = Hashie::Mash.new
189
- expected['Category'] = 'entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/",mymixin;scheme="http://example.com/mynamespace#";class="mixin";location="/mixin/mymixin/"'
189
+ expected['Category'] = 'entity;scheme="http://schemas.ogf.org/occi/core#";class="kind";location="/entity/";title="entity",mymixin;scheme="http://example.com/mynamespace#";class="mixin";location="/mixin/mymixin/";title=""'
190
190
  expected['X-OCCI-Attribute'] = 'occi.core.id="baf1",occi.core.title="TestTitle"'
191
191
  expected['Link'] = '</TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entity/action#testaction"'
192
192
 
@@ -245,9 +245,9 @@ Link: </TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entit
245
245
  entity.model = model
246
246
  entity.mixins << mixin
247
247
  entity }
248
-
249
-
250
- before(:each){ Occi::Settings['compatibility']=false
248
+
249
+
250
+ before(:each){ Occi::Settings['compatibility']=false
251
251
  Occi::Settings['verify_attribute_pattern']=true }
252
252
  after(:each) { Occi::Settings.reload! }
253
253
 
@@ -39,25 +39,32 @@ module Occi
39
39
 
40
40
  context 'resources from OCCI messages with text/occi MIME type' do
41
41
  let(:rendered_collection){ collection.to_header }
42
+ let(:real_world_example_model) {
43
+ {"category"=>["entity;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/entity/\",resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/resource/\",link;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\";location=\"/link/\",compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";location=\"/compute/\",storage;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";location=\"/storage/\",network;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";location=\"/network/\",networkinterface;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";location=\"/networkinterface/\",storagelink;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";location=\"/storagelink/\",console;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute#\";class=\"kind\";location=\"/console/\",resource_tpl;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"mixin\";location=\"/mixin/resource_tpl/\",os_tpl;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"mixin\";location=\"/mixin/os_tpl/\",ipnetwork;scheme=\"http://schemas.ogf.org/occi/infrastructure/network#\";class=\"mixin\";location=\"/mixin/ipnetwork/\",ipnetworkinterface;scheme=\"http://schemas.ogf.org/occi/infrastructure/networkinterface#\";class=\"mixin\";location=\"/mixin/ipnetworkinterface/\",networkinterface;scheme=\"http://opennebula.org/occi/infrastructure#\";class=\"mixin\";location=\"/mixin/networkinterface/\",compute;scheme=\"http://opennebula.org/occi/infrastructure#\";class=\"mixin\";location=\"/mixin/compute/\",storage;scheme=\"http://opennebula.org/occi/infrastructure#\";class=\"mixin\";location=\"/mixin/storage/\",public_key;scheme=\"http://schemas.openstack.org/instance/credentials#\";class=\"mixin\";location=\"/mixin/public_key/\",user_data;scheme=\"http://schemas.openstack.org/compute/instance#\";class=\"mixin\";location=\"/mixin/user_data/\",network;scheme=\"http://opennebula.org/occi/infrastructure#\";class=\"mixin\";location=\"/mixin/network/\",storagelink;scheme=\"http://opennebula.org/occi/infrastructure#\";class=\"mixin\";location=\"/mixin/storagelink/\",uuid_monitoring_20;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_monitoring_20/\",uuid_egi_sl6goldenimage_cesnet_50;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_egi_sl6goldenimage_cesnet_50/\",uuid_generic_vm_54;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_generic_vm_54/\",uuid_octave_55;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_octave_55/\",uuid_r_56;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_r_56/\",uuid_egi_compss_cesnet_57;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_egi_compss_cesnet_57/\",uuid_esa_sl64_cesnet_58;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_esa_sl64_cesnet_58/\",uuid_generic_www_60;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_generic_www_60/\",uuid_egi_compss_62;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_egi_compss_62/\",uuid_egi_test_compss_69;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_egi_test_compss_69/\",uuid_genericcloud_debian_7_0_x86_64_0001_cloud_dukan_71;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_genericcloud_debian_7_0_x86_64_0001_cloud_dukan_71/\",uuid_genericcloud_ubuntu_12_04_lts_x86_64_0001_cloud_dukan_72;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_genericcloud_ubuntu_12_04_lts_x86_64_0001_cloud_dukan_72/\",uuid_genericcloud_scilinux_6_5_x86_64_0001_cloud_dukan_73;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_genericcloud_scilinux_6_5_x86_64_0001_cloud_dukan_73/\",uuid_egi_compss_debian_7_0_x86_64_0001_cloud_dukan_74;scheme=\"http://occi.localhost/occi/infrastructure/os_tpl#\";class=\"mixin\";location=\"/mixin/uuid_egi_compss_debian_7_0_x86_64_0001_cloud_dukan_74/\",extra_large;scheme=\"http://sitespecific.cesnet.cz/occi/infrastructure/resource_tpl#\";class=\"mixin\";location=\"/mixin/extra_large/\",medium;scheme=\"http://sitespecific.cesnet.cz/occi/infrastructure/resource_tpl#\";class=\"mixin\";location=\"/mixin/medium/\",small;scheme=\"http://sitespecific.cesnet.cz/occi/infrastructure/resource_tpl#\";class=\"mixin\";location=\"/mixin/small/\",large;scheme=\"http://sitespecific.cesnet.cz/occi/infrastructure/resource_tpl#\";class=\"mixin\";location=\"/mixin/large/\""]}
44
+ }
42
45
 
43
46
  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
47
+ expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql rendered_collection
45
48
  end
46
49
 
47
50
  it 'parses self-generated collection with added attributes' do
48
51
  resource.id = UUIDTools::UUID.random_create.to_s
49
52
  resource.title = 'title'
50
- expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql collection.to_header
53
+ expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql rendered_collection
51
54
  end
52
55
 
53
56
  it 'parses self-generated collection with added mixin' do
54
57
  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
58
+ expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql rendered_collection
56
59
  end
57
60
 
58
61
  it 'parses self-generated collection with added link' do
59
62
  collection << link
60
- expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql collection.to_header
63
+ expect(Occi::Parser.parse('text/occi', '', false, Occi::Core::Resource, rendered_collection).to_header).to eql rendered_collection
64
+ end
65
+
66
+ it 'parses a real-world example of the OCCI model' do
67
+ expect(Occi::Parser.parse('text/occi', '', true, Occi::Core::Resource, real_world_example_model).to_header.to_hash).to eql({ 'Category' => real_world_example_model['category'].first })
61
68
  end
62
69
  end
63
70
 
@@ -161,13 +168,13 @@ module Occi
161
168
  locations_text = "http://example.com:8090/a/b/vm1\nhttp://example.com:8090/a/b/vm2"
162
169
  location = Occi::Parser.locations("text/uri-list", locations_text, {})
163
170
  expect(location).to eql expected
164
- end
171
+ end
165
172
 
166
173
  it 'parses multiple locations from plain text' do
167
174
  locations_text = "X-OCCI-Location: http://example.com:8090/a/b/vm1\nX-OCCI-Location: http://example.com:8090/a/b/vm2"
168
175
  location = Occi::Parser.locations("text/plain", locations_text, {})
169
176
  expect(location).to eql expected
170
- end
177
+ end
171
178
 
172
179
  it 'copes with unmeaningful input' do
173
180
  location = Occi::Parser.locations("nonexistent", "", {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.12
4
+ version: 4.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Feldhaus
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-13 00:00:00.000000000 Z
13
+ date: 2014-04-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json