From: marios <mar...@redhat.com>
Signed-off-by: marios <mar...@redhat.com> --- server/lib/cimi/model.rb | 1 + server/lib/cimi/model/machine_admin.rb | 26 +++++++ server/spec/cimi/data/machine_admin.json | 14 ++++ server/spec/cimi/data/machine_admin.xml | 10 +++ server/spec/cimi/model/machine_admin_spec.rb | 99 ++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 0 deletions(-) create mode 100644 server/lib/cimi/model/machine_admin.rb create mode 100644 server/spec/cimi/data/machine_admin.json create mode 100644 server/spec/cimi/data/machine_admin.xml create mode 100644 server/spec/cimi/model/machine_admin_spec.rb diff --git a/server/lib/cimi/model.rb b/server/lib/cimi/model.rb index 1e4a34a..cfcff72 100644 --- a/server/lib/cimi/model.rb +++ b/server/lib/cimi/model.rb @@ -25,3 +25,4 @@ require 'cimi/model/base' require 'cimi/model/machine_template' require 'cimi/model/machine_image' require 'cimi/model/machine_configuration' +require 'cimi/model/machine_admin' diff --git a/server/lib/cimi/model/machine_admin.rb b/server/lib/cimi/model/machine_admin.rb new file mode 100644 index 0000000..d175bbb --- /dev/null +++ b/server/lib/cimi/model/machine_admin.rb @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +class CIMI::Model::MachineAdmin < CIMI::Model::Base + + scalar :username + scalar :password + text :key + + array :operations do + scalar :rel, :href + end + +end diff --git a/server/spec/cimi/data/machine_admin.json b/server/spec/cimi/data/machine_admin.json new file mode 100644 index 0000000..d6d2622 --- /dev/null +++ b/server/spec/cimi/data/machine_admin.json @@ -0,0 +1,14 @@ +{ + "uri": "http://cimi.example.org/machine_admin/1", + "name": "credentials1", + "description": "Machine Admin One", + "created": "2011-11-16", + "username": "mockuser", + "password": "mockpassword", + "operations": [ + { "rel": "edit", + "href": "http://cimi.example.org/machine_admin/1/edit" }, + { "rel": "delete", + "href": "http://cimi.example.org/machine_admin/1/delete" } + ] +} diff --git a/server/spec/cimi/data/machine_admin.xml b/server/spec/cimi/data/machine_admin.xml new file mode 100644 index 0000000..a3cfd35 --- /dev/null +++ b/server/spec/cimi/data/machine_admin.xml @@ -0,0 +1,10 @@ +<MachineAdmin xmlns="http://www.dmtf.org/cimi"> + <uri>http://cimi.example.org/machine_admin/1</uri> + <name>credentials1</name> + <description>Machine Admin One</description> + <created>2011-11-16</created> + <username>mockuser</username> + <password>mockpassword</password> + <operation rel="edit" href="http://cimi.example.org/machine_admin/1/edit"/> + <operation rel="delete" href="http://cimi.example.org/machine_admin/1/delete"/> +</MachineAdmin> diff --git a/server/spec/cimi/model/machine_admin_spec.rb b/server/spec/cimi/model/machine_admin_spec.rb new file mode 100644 index 0000000..a8763a0 --- /dev/null +++ b/server/spec/cimi/model/machine_admin_spec.rb @@ -0,0 +1,99 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +describe "MachineAdmin model" do + + before(:all) do + @xml = IO::read(File::join(DATA_DIR, "machine_admin.xml")) + @json = IO::read(File::join(DATA_DIR, "machine_admin.json")) + end + + describe "XML" do + it "can be constructed" do + admin = CIMI::Model::MachineAdmin.from_xml(@xml) + admin.should_not be_nil + admin.should serialize_to @xml, :fmt => :xml + end + + it "should have default properties" do + admin = CIMI::Model::MachineAdmin.from_xml(@xml) + admin.uri.should == "http://cimi.example.org/machine_admin/1" + admin.name.should == "credentials1" + admin.description.should == "Machine Admin One" + admin.created.should == "2011-11-16" + end + + it "should have username and password properties" do + admin = CIMI::Model::MachineAdmin.from_xml(@xml) + admin.username.should_not be_nil + admin.username.first["content"].should == "mockuser" + admin.password.should_not be_nil + admin.password.first["content"].should == "mockpassword" + end + + it "should have edit and delete operations" do + admin = CIMI::Model::MachineAdmin.from_xml(@xml) + admin.operations.any? { |operation| operation.rel == 'edit' }.should be_true + admin.operations.any? { |operation| operation.rel == 'delete' }.should be_true + admin.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ } + end + + it "should convert strings in keys to symbols when contructed from XML" do + admin = CIMI::Model::MachineAdmin.from_xml(@xml) + admin.should_not be_nil + admin.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) } + end + end + + describe 'JSON' do + it "can be constructed" do + admin = CIMI::Model::MachineAdmin.from_json(@json) + admin.should_not be_nil + admin.should serialize_to @json, :fmt => :json + end + + it "should have default properties" do + admin = CIMI::Model::MachineAdmin.from_json(@json) + admin.uri.should == "http://cimi.example.org/machine_admin/1" + admin.name.should == "credentials1" + admin.description.should == "Machine Admin One" + admin.created.should == "2011-11-16" + end + + it "should have username and password properties" do + admin = CIMI::Model::MachineAdmin.from_json(@json) + admin.username.should_not be_nil + admin.username.should == "mockuser" + admin.password.should_not be_nil + admin.password.should == "mockpassword" + end + + it "should have edit and delete operations" do + admin = CIMI::Model::MachineAdmin.from_json(@json) + admin.operations.any? { |operation| operation.rel == 'edit' }.should be_true + admin.operations.any? { |operation| operation.rel == 'delete' }.should be_true + admin.operations.each { |operation| operation.href.should =~ /^http:\/\/.*\/(#{operation.rel})$/ } + end + + + it "should convert strings in keys to symbols when contructed from JSON" do + admin = CIMI::Model::MachineAdmin.from_json(@json) + admin.should_not be_nil + admin.attribute_values.keys.each { |key| key.should be_a_kind_of(Symbol) } + end + end + +end -- 1.7.6.4