You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2012/11/06 23:37:04 UTC
[2/4] git commit: CIMI: ensure that JSON responses have a proper
resourceURI
CIMI: ensure that JSON responses have a proper resourceURI
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/c4889e4d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/c4889e4d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/c4889e4d
Branch: refs/heads/master
Commit: c4889e4d41d21d5a91e4eb3423457307c392fad7
Parents: 230a1e4
Author: David Lutterkort <lu...@redhat.com>
Authored: Fri Nov 2 15:02:33 2012 -0700
Committer: David Lutterkort <lu...@redhat.com>
Committed: Tue Nov 6 14:36:33 2012 -0800
----------------------------------------------------------------------
server/lib/cimi/models/base.rb | 10 ++++++-
tests/cimi/cep_test.rb | 7 +++++
tests/cimi/machine_collection_test.rb | 34 ++++++++++++++++++++++++++
tests/cimi/machine_test.rb | 36 ++++++++++++++++++++++++++++
4 files changed, 85 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c4889e4d/server/lib/cimi/models/base.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb
index fe6016d..d217d4e 100644
--- a/server/lib/cimi/models/base.rb
+++ b/server/lib/cimi/models/base.rb
@@ -219,13 +219,19 @@ class CIMI::Model::Base
self.name.split("::").last
end
+ def self.resource_uri
+ CMWG_NAMESPACE + "/" + self.name.split("::").last
+ end
+
def self.to_json(model)
- JSON::unparse(@schema.to_json(model))
+ json = @schema.to_json(model)
+ json[:resourceURI] = resource_uri
+ JSON::unparse(json)
end
def self.to_xml(model)
xml = @schema.to_xml(model)
- xml["xmlns"] = "http://schemas.dmtf.org/cimi/1"
+ xml["xmlns"] = CMWG_NAMESPACE
XmlSimple.xml_out(xml, :root_name => xml_tag_name)
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c4889e4d/tests/cimi/cep_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/cep_test.rb b/tests/cimi/cep_test.rb
index 4864ada..76ee963 100644
--- a/tests/cimi/cep_test.rb
+++ b/tests/cimi/cep_test.rb
@@ -31,6 +31,8 @@ class CloundEntryPointBehavior < CIMI::Test::Spec
"jobs", "meters", "meterTemplates", "meterConfigs",
"eventLogs", "eventLogTemplates" ]
+ RESOURCE_URI = "http://schemas.dmtf.org/cimi/1/CloudEntryPoint"
+
# We'd like to call this :cep, but there's already a method by that name
model :subject, CIMI::Model::CloudEntryPoint, :cache => true do |fmt|
cep(:accept => fmt)
@@ -48,6 +50,11 @@ class CloundEntryPointBehavior < CIMI::Test::Spec
subject.name.wont_be_empty
end
+ it "should have the correct resourceURI", :only => :json do
+ subject.wont_be_nil # Make sure we talk to the server
+ last_response.json["resourceURI"].must_equal RESOURCE_URI
+ end
+
it "should have root collections" do
ROOTS.each do |root|
r = root.underscore.to_sym
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c4889e4d/tests/cimi/machine_collection_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/machine_collection_test.rb b/tests/cimi/machine_collection_test.rb
new file mode 100644
index 0000000..c390b5b
--- /dev/null
+++ b/tests/cimi/machine_collection_test.rb
@@ -0,0 +1,34 @@
+#
+# 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.
+
+$:.unshift File.join(File.dirname(__FILE__))
+
+require "test_helper.rb"
+
+class MachineCollectionBehavior < CIMI::Test::Spec
+ RESOURCE_URI =
+ "http://schemas.dmtf.org/cimi/1/MachineCollection"
+
+ model :machines, CIMI::Model::MachineCollection do |fmt|
+ mcoll_uri = cep(:accept => :json).json["machines"]["href"]
+ get(mcoll_uri, :accept => :json)
+ end
+
+ it "should have the correct resourceURI", :only => :json do
+ machines.wont_be_nil # Make sure we talk to the server
+ last_response.json["resourceURI"].must_equal RESOURCE_URI
+ end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c4889e4d/tests/cimi/machine_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/machine_test.rb b/tests/cimi/machine_test.rb
new file mode 100644
index 0000000..fd76ee5
--- /dev/null
+++ b/tests/cimi/machine_test.rb
@@ -0,0 +1,36 @@
+#
+# 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.
+
+$:.unshift File.join(File.dirname(__FILE__))
+
+require "test_helper.rb"
+
+class MachineBehavior < CIMI::Test::Spec
+
+ RESOURCE_URI = "http://schemas.dmtf.org/cimi/1/Machine"
+
+ model :machine, CIMI::Model::Machine do |fmt|
+ mcoll_uri = cep(:accept => :json).json["machines"]["href"]
+ mcoll = get(mcoll_uri, :accept => :json).json
+ m_url = mcoll["machines"][0]["id"]
+ get m_url, :accept => fmt
+ end
+
+ it "should have the correct resourceURI", :only => :json do
+ machine.wont_be_nil # Make sure we talk to the server
+ last_response.json["resourceURI"].must_equal RESOURCE_URI
+ end
+end