omf_sfa 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +24 -0
- data/Gemfile +6 -0
- data/README.md +211 -0
- data/Rakefile +23 -0
- data/bin/parse_rspec.rb +167 -0
- data/etc/omf-sfa/omf-sfa-am.yaml +12 -0
- data/examples/exogeni5nodemanifest.rspec +105 -0
- data/examples/instageni5nodemanifest.rspec +150 -0
- data/lib/omf-sfa/am/am-rest/REST_API.md +301 -0
- data/lib/omf-sfa/am/am-rest/account_handler.rb +145 -0
- data/lib/omf-sfa/am/am-rest/am_rest_server.rb +255 -0
- data/lib/omf-sfa/am/am-rest/api_template.html +48 -0
- data/lib/omf-sfa/am/am-rest/config.ru +110 -0
- data/lib/omf-sfa/am/am-rest/resource_handler.rb +178 -0
- data/lib/omf-sfa/am/am-rest/rest_handler.rb +573 -0
- data/lib/omf-sfa/am/am-rest/session_authenticator.rb +130 -0
- data/lib/omf-sfa/am/am-rpc/abstract_rpc_service.rb +60 -0
- data/lib/omf-sfa/am/am-rpc/am_authorizer.rb +161 -0
- data/lib/omf-sfa/am/am-rpc/am_rpc_api.rb +450 -0
- data/lib/omf-sfa/am/am-rpc/am_rpc_service.rb +402 -0
- data/lib/omf-sfa/am/am_liaison.rb +93 -0
- data/lib/omf-sfa/am/am_manager.rb +859 -0
- data/lib/omf-sfa/am/am_runner.rb +108 -0
- data/lib/omf-sfa/am/am_scheduler.rb +146 -0
- data/lib/omf-sfa/am/am_server.rb +194 -0
- data/lib/omf-sfa/am/config.ru +122 -0
- data/lib/omf-sfa/am/credential.rb +145 -0
- data/lib/omf-sfa/am/default_authorizer.rb +44 -0
- data/lib/omf-sfa/am/privilege_credential.rb +76 -0
- data/lib/omf-sfa/am/signature.rb +37 -0
- data/lib/omf-sfa/am/user_credential.rb +56 -0
- data/lib/omf-sfa/am.rb +7 -0
- data/lib/omf-sfa/model/abstract_prop_description.rb +87 -0
- data/lib/omf-sfa/model/model_class_description.rb +145 -0
- data/lib/omf-sfa/model/model_data_prop_description.rb +28 -0
- data/lib/omf-sfa/model/model_obj_prop_description.rb +49 -0
- data/lib/omf-sfa/model/ontology.rb +169 -0
- data/lib/omf-sfa/resource/README.md +24 -0
- data/lib/omf-sfa/resource/channel.rb +49 -0
- data/lib/omf-sfa/resource/comp_group.rb +41 -0
- data/lib/omf-sfa/resource/component_lease.rb +10 -0
- data/lib/omf-sfa/resource/constants.rb +24 -0
- data/lib/omf-sfa/resource/group_component.rb +35 -0
- data/lib/omf-sfa/resource/group_membership.rb +17 -0
- data/lib/omf-sfa/resource/gurn.rb +187 -0
- data/lib/omf-sfa/resource/interface.rb +78 -0
- data/lib/omf-sfa/resource/ip.rb +48 -0
- data/lib/omf-sfa/resource/link.rb +29 -0
- data/lib/omf-sfa/resource/node.rb +75 -0
- data/lib/omf-sfa/resource/oaccount.rb +94 -0
- data/lib/omf-sfa/resource/ocomponent.rb +134 -0
- data/lib/omf-sfa/resource/ogroup.rb +106 -0
- data/lib/omf-sfa/resource/olease.rb +61 -0
- data/lib/omf-sfa/resource/oproperty.rb +178 -0
- data/lib/omf-sfa/resource/oreference.rb +15 -0
- data/lib/omf-sfa/resource/oresource.rb +491 -0
- data/lib/omf-sfa/resource/project.rb +28 -0
- data/lib/omf-sfa/resource/project_membership.rb +13 -0
- data/lib/omf-sfa/resource/sfa_base.rb +544 -0
- data/lib/omf-sfa/resource/user.rb +25 -0
- data/lib/omf-sfa/resource.rb +20 -0
- data/lib/omf-sfa/util/create_sample_testbed.rb +68 -0
- data/lib/omf-sfa/util/load_from_sfa_xml.rb +65 -0
- data/lib/omf-sfa/version.rb +4 -0
- data/lib/omf_sfa.rb +5 -0
- data/omf_sfa.gemspec +46 -0
- data/owl/README +3 -0
- data/owl/ben-6509.rdf +1377 -0
- data/owl/ben-dell.rdf +586 -0
- data/owl/ben-dtn.rdf +1698 -0
- data/owl/ben.rdf +1335 -0
- data/owl/collections.owl +309 -0
- data/owl/compute.owl +1486 -0
- data/owl/domain.owl +444 -0
- data/owl/dtn.owl +1165 -0
- data/owl/ec2.owl +385 -0
- data/owl/ethernet.owl +466 -0
- data/owl/eucalyptus.owl +431 -0
- data/owl/id-mp-Request1.rdf +247 -0
- data/owl/itu-grid.owl +147 -0
- data/owl/kansei.owl +511 -0
- data/owl/layer.owl +645 -0
- data/owl/location.owl +117 -0
- data/owl/mass.rdf +608 -0
- data/owl/nlr.rdf +901 -0
- data/owl/orca.owl +181 -0
- data/owl/planetlab.owl +124 -0
- data/owl/protogeni.owl +467 -0
- data/owl/request-6509-2.rdf +150 -0
- data/owl/request-6509-3.rdf +158 -0
- data/owl/request-6509.rdf +199 -0
- data/owl/request.owl +222 -0
- data/owl/storage.owl +511 -0
- data/owl/topology.owl +608 -0
- data/schema/rspec-v3/ad-common.xsd +269 -0
- data/schema/rspec-v3/ad-reservation.rnc +12 -0
- data/schema/rspec-v3/ad-reservation.rng +28 -0
- data/schema/rspec-v3/ad-reservation.xsd +13 -0
- data/schema/rspec-v3/ad.rnc +151 -0
- data/schema/rspec-v3/ad.xsd +77 -0
- data/schema/rspec-v3/any-extension-schema.xsd +38 -0
- data/schema/rspec-v3/any-extension.rnc +30 -0
- data/schema/rspec-v3/common.rnc +185 -0
- data/schema/rspec-v3/manifest-common.xsd +244 -0
- data/schema/rspec-v3/manifest-request.xsd +95 -0
- data/schema/rspec-v3/manifest.rnc +62 -0
- data/schema/rspec-v3/manifest.xsd +34 -0
- data/schema/rspec-v3/request-common.xsd +219 -0
- data/schema/rspec-v3/request-reservation.rnc +12 -0
- data/schema/rspec-v3/request-reservation.xsd +13 -0
- data/schema/rspec-v3/request.rnc +118 -0
- data/schema/rspec-v3/request.xsd +94 -0
- data/share/assets/css/default.css +147 -0
- data/share/assets/css/rest_api.css +0 -0
- data/share/assets/network.html +28 -0
- data/share/assets/network.js +82 -0
- data/spec/am/am-rest/common.rb +29 -0
- data/spec/am/am-rest/resource_group_handler_XspecX.rb +97 -0
- data/spec/am/am-rest/resource_handler_spec.rb +204 -0
- data/spec/am/am-rpc/sfa_methods_spec.rb +150 -0
- data/spec/am/am_manager_spec.rb +307 -0
- data/spec/am/am_scheduler_spec.rb +57 -0
- data/spec/am/common.rb +24 -0
- data/spec/resource/common.rb +31 -0
- data/spec/resource/node_spec.rb +171 -0
- data/spec/resource/oaccount_spec.rb +92 -0
- data/spec/resource/ocomponent_spec.rb +225 -0
- data/spec/resource/ogroup_spec.rb +93 -0
- data/spec/resource/oresource_spec.rb +208 -0
- data/spec/resource_and_leases_spec.rb +377 -0
- data/test/OLD_FILES/assertion1.xml +117 -0
- data/test/OLD_FILES/greeter_spec.rb +15 -0
- data/test/OLD_FILES/mongo_test.rb +45 -0
- data/test/OLD_FILES/req-sfa-2.xml +6 -0
- data/test/OLD_FILES/req-sfa-g.xml +8 -0
- data/test/OLD_FILES/req-sfa-g2.xml +10 -0
- data/test/OLD_FILES/req-sfa-g3.xml +14 -0
- data/test/OLD_FILES/req-sfa.xml +6 -0
- data/test/OLD_FILES/req1.xml +22 -0
- data/test/OLD_FILES/req1b.xml +15 -0
- data/test/OLD_FILES/rspec-test.xml +1867 -0
- data/test/OLD_FILES/test.rb +67 -0
- data/test/OLD_FILES/test2.rb +32 -0
- data/test/am/am_manager_rspec_tests.rb +378 -0
- data/test/am/am_manager_tests.rb +518 -0
- data/test/am/am_scheduler_tests.rb +173 -0
- data/test/resource/olease_test.rb +74 -0
- data/test/sfa_requests/request.xml +5 -0
- data/test/sfa_requests/request1.xml +5 -0
- data/test/sfa_requests/request2.xml +5 -0
- data/test/sfa_requests/request3.xml +5 -0
- metadata +601 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
|
|
2
|
+
require 'equivalent-xml'
|
|
3
|
+
|
|
4
|
+
require "#{File.dirname(__FILE__)}/common"
|
|
5
|
+
require 'omf-sfa/resource/ocomponent'
|
|
6
|
+
require 'omf-sfa/resource/ogroup'
|
|
7
|
+
require 'omf-sfa/resource/group_component'
|
|
8
|
+
|
|
9
|
+
include OMF::SFA::Resource
|
|
10
|
+
|
|
11
|
+
class TComp < OComponent
|
|
12
|
+
sfa_class 'T'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class TComp2 < TComp
|
|
16
|
+
oproperty :available, Boolean, :default => true
|
|
17
|
+
sfa_class 'T2'
|
|
18
|
+
sfa :available #, :attr_value => 'now'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
describe OComponent do
|
|
24
|
+
before :all do
|
|
25
|
+
init_dm
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
before :each do
|
|
29
|
+
GURN.clear_cache
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'can create a basic component' do
|
|
33
|
+
OComponent.create()
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'can destroy a basic component' do
|
|
37
|
+
OComponent.create().destroy
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'has default domain' do
|
|
41
|
+
c = OComponent.create
|
|
42
|
+
c.domain.should == OComponent.default_domain
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'has default domain' do
|
|
46
|
+
c = OComponent.create(:domain => 'the_domain')
|
|
47
|
+
c.domain.should == 'the_domain'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'can be sfa-xml serialised' do
|
|
51
|
+
c = TComp.create(:name => :foo)
|
|
52
|
+
assert_sfa_xml c,%{<T %s id="#{c.uuid}"
|
|
53
|
+
omf:href="/resources/#{c.uuid}"
|
|
54
|
+
component_id="urn:publicid:IDN+mytestbed.net+T+#{c.uuid}"
|
|
55
|
+
component_manager_id="authority+am"
|
|
56
|
+
component_name="foo"/>}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'can have simple attributes' do
|
|
60
|
+
c = TComp2.create(:name => :foo)
|
|
61
|
+
c.to_sfa_hash().should == {
|
|
62
|
+
"href" => "/resources/#{c.uuid}", "uuid" => c.uuid.to_s,
|
|
63
|
+
"sfa_class" => "T2",
|
|
64
|
+
"component_name" => "foo", "component_manager_id" => "authority+am",
|
|
65
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+T2+#{c.uuid}",
|
|
66
|
+
"available" => "true"
|
|
67
|
+
}
|
|
68
|
+
assert_sfa_xml c, %{
|
|
69
|
+
<T2 %s
|
|
70
|
+
id="#{c.uuid}"
|
|
71
|
+
omf:href="/resources/#{c.uuid}"
|
|
72
|
+
component_id="urn:publicid:IDN+mytestbed.net+T2+#{c.uuid}"
|
|
73
|
+
component_manager_id="authority+am"
|
|
74
|
+
component_name="foo">
|
|
75
|
+
<available>true</available>
|
|
76
|
+
</T2>}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'can have group components' do
|
|
80
|
+
g = GroupComponent.create(:name => 'g')
|
|
81
|
+
g.to_sfa_hash().should == {
|
|
82
|
+
"href" => "/resources/#{g.uuid}", "uuid" => g.uuid.to_s,
|
|
83
|
+
"sfa_class" => "group",
|
|
84
|
+
"component_name" => "g", "component_manager_id" => "authority+am",
|
|
85
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+group+#{g.uuid}",
|
|
86
|
+
"components" => []
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
g.to_hash.should == {:name => "g", :type=>"group", :uuid=>"#{g.uuid}", :href=>"/resources/#{g.uuid}", :resources => []}
|
|
90
|
+
assert_sfa_xml g, %{
|
|
91
|
+
<group %s
|
|
92
|
+
id="#{g.uuid}"
|
|
93
|
+
omf:href="/resources/#{g.uuid}"
|
|
94
|
+
component_id="urn:publicid:IDN+mytestbed.net+group+#{g.uuid}"
|
|
95
|
+
component_manager_id="authority+am"
|
|
96
|
+
component_name="g">
|
|
97
|
+
<components/>
|
|
98
|
+
</group>
|
|
99
|
+
}
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'can have group components holding components' do
|
|
103
|
+
g = GroupComponent.create(:name => 'g')
|
|
104
|
+
g.contains_resources << (n = TComp.create(:name => 'n'))
|
|
105
|
+
|
|
106
|
+
g.to_hash.should == {
|
|
107
|
+
:name=>"g",
|
|
108
|
+
:uuid => g.uuid.to_s,
|
|
109
|
+
:type=> "group",
|
|
110
|
+
:href=> "/resources/#{g.uuid}",
|
|
111
|
+
:resources => [{
|
|
112
|
+
:name => "n",
|
|
113
|
+
:type => "T",
|
|
114
|
+
:status=>"unknown",
|
|
115
|
+
:domain => "mytestbed.net",
|
|
116
|
+
:uuid => n.uuid.to_s,
|
|
117
|
+
:href=> "/resources/#{n.uuid}",
|
|
118
|
+
}]
|
|
119
|
+
}
|
|
120
|
+
g.to_sfa_hash().should == {
|
|
121
|
+
"href" => "/resources/#{g.uuid}", "uuid" => g.uuid.to_s, "sfa_class" => "group",
|
|
122
|
+
"component_name" => "g", "component_manager_id" => "authority+am",
|
|
123
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+group+#{g.uuid}",
|
|
124
|
+
"components" => [{
|
|
125
|
+
"href" => "/resources/#{n.uuid}",
|
|
126
|
+
"uuid" => n.uuid.to_s,
|
|
127
|
+
"component_name" => "n",
|
|
128
|
+
"component_manager_id" => "authority+am",
|
|
129
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+T+#{n.uuid}",
|
|
130
|
+
"sfa_class" => "T"
|
|
131
|
+
}]
|
|
132
|
+
}
|
|
133
|
+
assert_sfa_xml g, %{
|
|
134
|
+
<group %s
|
|
135
|
+
id="#{g.uuid}"
|
|
136
|
+
omf:href="/resources/#{g.uuid}"
|
|
137
|
+
component_id="urn:publicid:IDN+mytestbed.net+group+#{g.uuid}"
|
|
138
|
+
component_manager_id="authority+am" component_name="g">
|
|
139
|
+
<components>
|
|
140
|
+
<T
|
|
141
|
+
id="#{n.uuid}"
|
|
142
|
+
omf:href="/resources/#{n.uuid}"
|
|
143
|
+
component_id="urn:publicid:IDN+mytestbed.net+T+#{n.uuid}"
|
|
144
|
+
component_manager_id="authority+am"
|
|
145
|
+
component_name="n"/>
|
|
146
|
+
</components>
|
|
147
|
+
</group>
|
|
148
|
+
}
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it 'can have group components holding other groups' do
|
|
152
|
+
g = GroupComponent.create(:name => 'g')
|
|
153
|
+
g.contains_resources << (g2 = GroupComponent.create(:name => 'g2'))
|
|
154
|
+
|
|
155
|
+
g.to_hash.should == {
|
|
156
|
+
:name => "g",
|
|
157
|
+
:type => "group",
|
|
158
|
+
:uuid => g.uuid.to_s,
|
|
159
|
+
:href => "/resources/#{g.uuid}",
|
|
160
|
+
:resources => [{
|
|
161
|
+
:name => "g2",
|
|
162
|
+
:type => "group",
|
|
163
|
+
:href => "/resources/#{g2.uuid}",
|
|
164
|
+
:resources => [],
|
|
165
|
+
:uuid => g2.uuid.to_s
|
|
166
|
+
}]
|
|
167
|
+
}
|
|
168
|
+
g.to_sfa_hash().should == {
|
|
169
|
+
"component_name" => "g",
|
|
170
|
+
"component_manager_id" => "authority+am",
|
|
171
|
+
"href" => "/resources/#{g.uuid}",
|
|
172
|
+
"uuid" => g.uuid.to_s,
|
|
173
|
+
"sfa_class" => "group",
|
|
174
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+group+#{g.uuid}",
|
|
175
|
+
"components" => [{
|
|
176
|
+
"component_name" => "g2",
|
|
177
|
+
"href" => "/resources/#{g2.uuid}",
|
|
178
|
+
"uuid" => g2.uuid.to_s,
|
|
179
|
+
"sfa_class" => "group",
|
|
180
|
+
"component_manager_id" => "authority+am",
|
|
181
|
+
"component_id" => "urn:publicid:IDN+mytestbed.net+group+#{g2.uuid}",
|
|
182
|
+
"components" => []
|
|
183
|
+
}]
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
assert_sfa_xml g, %{
|
|
188
|
+
<group %s
|
|
189
|
+
id="#{g.uuid}"
|
|
190
|
+
omf:href="/resources/#{g.uuid}"
|
|
191
|
+
component_id="urn:publicid:IDN+mytestbed.net+group+#{g.uuid}"
|
|
192
|
+
component_manager_id="authority+am" component_name="g">
|
|
193
|
+
<components>
|
|
194
|
+
<group
|
|
195
|
+
id="#{g2.uuid}"
|
|
196
|
+
omf:href="/resources/#{g2.uuid}"
|
|
197
|
+
component_id="urn:publicid:IDN+mytestbed.net+group+#{g2.uuid}"
|
|
198
|
+
component_manager_id="authority+am"
|
|
199
|
+
component_name="g2">
|
|
200
|
+
<components/>
|
|
201
|
+
</group>
|
|
202
|
+
</components>
|
|
203
|
+
</group>
|
|
204
|
+
}
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
it 'should be able to provide a clone of itself' do
|
|
208
|
+
c1 = OComponent.create(:name => 'comp1')
|
|
209
|
+
c2 = c1.clone
|
|
210
|
+
c2.provided_by = c1
|
|
211
|
+
|
|
212
|
+
c2.save
|
|
213
|
+
|
|
214
|
+
c1.provides << c2
|
|
215
|
+
c1.save
|
|
216
|
+
|
|
217
|
+
c1.reload
|
|
218
|
+
c2.reload
|
|
219
|
+
|
|
220
|
+
c1.provides.should == [c2]
|
|
221
|
+
c2.provided_by.should == c1
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
end
|
|
225
|
+
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
require "#{File.dirname(__FILE__)}/common"
|
|
3
|
+
require 'omf-sfa/resource/ogroup'
|
|
4
|
+
|
|
5
|
+
include OMF::SFA::Resource
|
|
6
|
+
|
|
7
|
+
describe OGroup do
|
|
8
|
+
before :all do
|
|
9
|
+
init_dm
|
|
10
|
+
r1_id = UUIDTools::UUID.random_create
|
|
11
|
+
g1_id = UUIDTools::UUID.random_create
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
before :each do
|
|
15
|
+
#DataMapper.repository.delete
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'can create a group' do
|
|
19
|
+
OGroup.create()
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'can contain resources' do
|
|
23
|
+
g = OGroup.create()
|
|
24
|
+
r = OResource.create()
|
|
25
|
+
|
|
26
|
+
g.contains_resources << r
|
|
27
|
+
g.save
|
|
28
|
+
g.reload
|
|
29
|
+
r.reload
|
|
30
|
+
|
|
31
|
+
g.contains_resources.size.should == 1
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'should also show up on the resource side' do
|
|
35
|
+
g = OGroup.create()
|
|
36
|
+
gid = g.uuid
|
|
37
|
+
r = OResource.create()
|
|
38
|
+
|
|
39
|
+
g.contains_resources << r
|
|
40
|
+
g.save
|
|
41
|
+
g.reload
|
|
42
|
+
r.reload
|
|
43
|
+
|
|
44
|
+
ga = r.included_in_groups
|
|
45
|
+
ga.size.should == 1
|
|
46
|
+
ga[0].uuid.should == gid
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'can contain multiple resources' do
|
|
50
|
+
g = OGroup.create()
|
|
51
|
+
|
|
52
|
+
g.contains_resources << OResource.create()
|
|
53
|
+
g.contains_resources << OResource.create()
|
|
54
|
+
g.save
|
|
55
|
+
g.reload
|
|
56
|
+
|
|
57
|
+
g.contains_resources.size.should == 2
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'can contain multiple resources and remove them' do
|
|
61
|
+
g = OGroup.create()
|
|
62
|
+
g.contains_resources << OResource.create(:name => 'r1')
|
|
63
|
+
g.contains_resources << OResource.create()
|
|
64
|
+
g.save
|
|
65
|
+
g.reload
|
|
66
|
+
|
|
67
|
+
g.empty_group
|
|
68
|
+
g.save
|
|
69
|
+
g.reload
|
|
70
|
+
|
|
71
|
+
g.contains_resources.size.should == 0
|
|
72
|
+
OResource.first(:name => 'r1').should_not == nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
it 'can contain other groups as well' do
|
|
77
|
+
parent = OGroup.create(:name => :parent)
|
|
78
|
+
child = OGroup.create(:name => :child)
|
|
79
|
+
|
|
80
|
+
parent.contains_resources << child
|
|
81
|
+
parent.save
|
|
82
|
+
child.save
|
|
83
|
+
|
|
84
|
+
parent.reload
|
|
85
|
+
child.reload
|
|
86
|
+
|
|
87
|
+
parent.contains_resources.size.should == 1
|
|
88
|
+
child.included_in_groups.size.should == 1
|
|
89
|
+
child.included_in_groups[0].name.should == 'parent'
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
require "#{File.dirname(__FILE__)}/common"
|
|
2
|
+
require 'omf-sfa/resource/oresource'
|
|
3
|
+
require 'omf-sfa/resource/node'
|
|
4
|
+
require 'omf-sfa/resource/ogroup'
|
|
5
|
+
require 'json'
|
|
6
|
+
|
|
7
|
+
include OMF::SFA::Resource
|
|
8
|
+
|
|
9
|
+
def init_logger
|
|
10
|
+
OMF::Common::Loggable.init_log 'OResource', :searchPath => File.join(File.dirname(__FILE__), 'OResource')
|
|
11
|
+
#@config = OMF::Common::YAML.load('omf-sfa-am', :path => [File.dirname(__FILE__) + '/../../etc/omf-sfa'])[:omf_sfa_am]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class TA < OResource
|
|
15
|
+
oproperty :flag, Boolean, :default => true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class A < OResource
|
|
19
|
+
oproperty :b, :B
|
|
20
|
+
oproperty :ba, :B, :functional => false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class B < OResource
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class G < OResource
|
|
27
|
+
oproperty :g, :o_group
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe OResource do
|
|
31
|
+
|
|
32
|
+
init_logger
|
|
33
|
+
|
|
34
|
+
before :each do
|
|
35
|
+
init_dm
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'can create a basic resource' do
|
|
39
|
+
OResource.create()
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'can destroy a basic resource' do
|
|
43
|
+
OResource.create().destroy
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'assigns a UUID by default' do
|
|
47
|
+
r = OResource.create()
|
|
48
|
+
r.uuid.should_not be(nil)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'can serialize' do
|
|
52
|
+
o = OResource.create()
|
|
53
|
+
js = o.to_json
|
|
54
|
+
o.reload
|
|
55
|
+
# http://www.ruby-lang.org/en/news/2013/02/22/json-dos-cve-2013-0269/
|
|
56
|
+
# alternative: o2 = JSON.load(js)
|
|
57
|
+
o2 = JSON.parse(js, :create_additions => true)
|
|
58
|
+
o2.uuid.should == o.uuid
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'can be serialized into a hash' do
|
|
62
|
+
o = OResource.create(:name => :foo)
|
|
63
|
+
o.to_hash.should == {:type=>"unknown", :name=>"foo", :uuid=>"#{o.uuid.to_s}", :href => "/resources/#{o.uuid}"}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
it 'can have simple properties' do
|
|
68
|
+
o = OResource.create()
|
|
69
|
+
o.o_properties.create(:name => 'p1', :value => 'v1')
|
|
70
|
+
o.o_properties.create(:name => 'p2', :value => 123)
|
|
71
|
+
o.save
|
|
72
|
+
o.reload
|
|
73
|
+
|
|
74
|
+
p = o.o_properties[0]
|
|
75
|
+
p.name.should == 'p1'
|
|
76
|
+
p.value.should == 'v1'
|
|
77
|
+
|
|
78
|
+
p2 = o.o_properties[1]
|
|
79
|
+
p2.name.should == 'p2'
|
|
80
|
+
p2.value.should == 123
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'can have properties pointing to other resources' do
|
|
85
|
+
o1 = OResource.create(:name => 'o1')
|
|
86
|
+
o2 = OResource.create(:name => 'o2')
|
|
87
|
+
u2 = o2.uuid
|
|
88
|
+
|
|
89
|
+
o1.oproperties.create(:name => 'p1', :value => o2)
|
|
90
|
+
o1.save
|
|
91
|
+
o1.reload; o2.reload
|
|
92
|
+
|
|
93
|
+
p = o1.oproperties[0]
|
|
94
|
+
v = p.value
|
|
95
|
+
v.class.should == OResource
|
|
96
|
+
v.uuid.should == u2
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'can have named properties as [] on resource' do
|
|
100
|
+
o = OResource.create(:name => 'foobar')
|
|
101
|
+
o['name'].should == 'foobar'
|
|
102
|
+
|
|
103
|
+
o['foo'] = 1
|
|
104
|
+
o['foo'].should == 1
|
|
105
|
+
o[:foo].should == 1
|
|
106
|
+
o.save
|
|
107
|
+
o.reload
|
|
108
|
+
o['foo'].should == 1
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'can define properties with +oproperty+' do
|
|
112
|
+
o = TA.create(:name => 'o')
|
|
113
|
+
o.flag = true
|
|
114
|
+
o.save
|
|
115
|
+
|
|
116
|
+
o.reload
|
|
117
|
+
o.flag.should == true
|
|
118
|
+
o.to_hash.should == {:type=>"unknown", :uuid=>"#{o.uuid}", :href => "/resources/#{o.uuid}", :name => 'o', :flag => true}
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it 'can have properties linking to other object' do
|
|
122
|
+
a = A.create(:name => 'a')
|
|
123
|
+
a.b.should == nil
|
|
124
|
+
a.bas.should == []
|
|
125
|
+
|
|
126
|
+
b = B.create
|
|
127
|
+
a.b = b
|
|
128
|
+
|
|
129
|
+
a.save
|
|
130
|
+
a.reload
|
|
131
|
+
|
|
132
|
+
a.b.uuid.should == b.uuid
|
|
133
|
+
a.to_hash.should == {
|
|
134
|
+
:type=>"unknown", :uuid=>"#{a.uuid}", :href => "/resources/#{a.uuid}", :name => 'a',
|
|
135
|
+
:b => b.uuid.to_s
|
|
136
|
+
}
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it 'can have properties linking to groups' do
|
|
140
|
+
r = G.create(:name => 'r')
|
|
141
|
+
g = OGroup.create(:name => 'g')
|
|
142
|
+
r.g = g
|
|
143
|
+
|
|
144
|
+
r.g.should == g
|
|
145
|
+
r.to_hash.should == {:name => "r", :type=>"unknown", :uuid=>"#{r.uuid}", :g => g.uuid.to_s, :href => "/resources/#{r.uuid}"}
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it 'can have non-functional properties' do
|
|
149
|
+
a = A.create(:name => 'a')
|
|
150
|
+
a.bas.should == []
|
|
151
|
+
|
|
152
|
+
a.save
|
|
153
|
+
a.reload
|
|
154
|
+
|
|
155
|
+
b = B.create
|
|
156
|
+
a.bas = b
|
|
157
|
+
#a.bas << b
|
|
158
|
+
a.bas.should == [b]
|
|
159
|
+
a.save
|
|
160
|
+
a.reload
|
|
161
|
+
|
|
162
|
+
a.bas.should == [b]
|
|
163
|
+
|
|
164
|
+
b2 = B.create
|
|
165
|
+
a.bas << b2
|
|
166
|
+
a.save
|
|
167
|
+
a.reload
|
|
168
|
+
|
|
169
|
+
a.bas.should == [b, b2]
|
|
170
|
+
a.to_hash.should == {
|
|
171
|
+
:type=>"unknown", :uuid=>"#{a.uuid}", :href=>"/resources/#{a.uuid}", :name => 'a',
|
|
172
|
+
:bas => [b.uuid.to_s, b2.uuid.to_s]
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
a.bas = []
|
|
176
|
+
a.save
|
|
177
|
+
a.reload
|
|
178
|
+
a.bas.should == []
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'returns properties as a hash' do
|
|
182
|
+
a = A.create
|
|
183
|
+
b = B.create
|
|
184
|
+
a.bas << b
|
|
185
|
+
a.b = b
|
|
186
|
+
a.save
|
|
187
|
+
a.reload
|
|
188
|
+
|
|
189
|
+
a.oproperties_as_hash.should == {'b' => b, 'bas' => [b]}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it 'can have Time oproperties' do
|
|
193
|
+
class Bar < OResource
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
class Foo < Bar
|
|
197
|
+
oproperty :created_at, DataMapper::Property::Time
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
f = Foo.new
|
|
201
|
+
f.created_at = Time.now
|
|
202
|
+
f.save
|
|
203
|
+
|
|
204
|
+
f.created_at.should be_a_kind_of(Time)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
end
|
|
208
|
+
|