summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-03-15 13:13:44 +0100
committerChristoph Helma <helma@in-silico.ch>2012-03-15 13:13:44 +0100
commit585a0185af082bc3999375bfcd78677f4dc25059 (patch)
tree74d891d3dca895d762598ca1f79ef9ab767b481b
parente7f1ecb35d0522890a31b9ba44ebf10b05da80a8 (diff)
metadata reload fixed
-rw-r--r--lib/opentox.rb9
-rw-r--r--lib/task.rb12
-rw-r--r--test/task.rb16
3 files changed, 20 insertions, 17 deletions
diff --git a/lib/opentox.rb b/lib/opentox.rb
index 9493362..4338302 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -27,8 +27,9 @@ module OpenTox
# Get object metadata
# @return [Hash] Metadata
+ # TODO: rename to_hash? or store in object variables
def metadata
- pull if @rdf.empty?
+ pull # force update
metadata = {}
@rdf.query([RDF::URI.new(@uri),nil,nil]).collect do |statement|
metadata[statement.predicate] ||= []
@@ -41,9 +42,11 @@ module OpenTox
# @param [RDF] Key from RDF Vocabularies
# @return [Array] Values for supplied key
def [](key)
- pull if @rdf.empty?
+ pull # force update
result = @rdf.query([RDF::URI.new(@uri),key,nil]).collect{|statement| statement.object}
- result.size == 1 ? result.first : result
+ return nil if result.empty?
+ return result.first.to_s if result.size == 1
+ return result.collect{|r| r.to_s}
end
# Save object at service
diff --git a/lib/task.rb b/lib/task.rb
index 2f79cf1..7452012 100644
--- a/lib/task.rb
+++ b/lib/task.rb
@@ -97,12 +97,12 @@ module OpenTox
code >= 400 and code != 503
end
- def method_missing(method,*args)
- method = method.to_s
- response = self.[](RDF::OT[method])
- response = self.[](RDF::OT1[method]) if response.empty? # API 1.1 compatibility
- internal_server_error "Unknown #{self.class} method #{method} for #{@uri}" if response.is_a? Array and response.empty?
- return response.to_s
+ [:hasStatus, :resultURI].each do |method|
+ define_method method do
+ response = self.[](RDF::OT[method])
+ response = self.[](RDF::OT1[method]) unless response # API 1.1 compatibility
+ response
+ end
end
#TODO: subtasks
diff --git a/test/task.rb b/test/task.rb
index 955d67a..ae323e8 100644
--- a/test/task.rb
+++ b/test/task.rb
@@ -26,10 +26,10 @@ class TaskTest < Test::Unit::TestCase
TASK_SERVICE_URI
end
assert task.running?
- #assert_equal "Running", task.hasStatus
+ assert_equal "Running", task.hasStatus
task.wait
assert task.completed?
- #assert_equal "Completed", task.hasStatus
+ assert_equal "Completed", task.hasStatus
assert_equal TASK_SERVICE_URI, task.resultURI
end
@@ -46,11 +46,11 @@ class TaskTest < Test::Unit::TestCase
def test_create_and_fail
task = OpenTox::Task.create TASK_SERVICE_URI, :description => "test failure", :creator => "http://test.org/fake_creator" do
- sleep 0.5
+ sleep 1
raise "A runtime error occured"
end
assert task.running?
- #assert_equal "Running", task.hasStatus
+ assert_equal "Running", task.hasStatus
task.wait
assert task.error?
assert_equal "Error", task.hasStatus
@@ -58,11 +58,11 @@ class TaskTest < Test::Unit::TestCase
def test_create_and_fail_with_opentox_error
task = OpenTox::Task.create TASK_SERVICE_URI, :description => "test failure", :creator => "http://test.org/fake_creator" do
- sleep 0.5
+ sleep 1
raise OpenTox::Error.new 500, "An OpenTox::Error occured"
end
assert task.running?
- #assert_equal "Running", task.hasStatus
+ assert_equal "Running", task.hasStatus
task.wait
assert task.error?
assert_equal "Error", task.hasStatus
@@ -70,11 +70,11 @@ class TaskTest < Test::Unit::TestCase
def test_wrong_result_uri
task = OpenTox::Task.create TASK_SERVICE_URI, :description => "test wrong result uri", :creator => "http://test.org/fake_creator" do
- sleep 0.5
+ sleep 1
"Asasadasd"
end
assert task.running?
- #assert_equal "Running", task.hasStatus
+ assert_equal "Running", task.hasStatus
task.wait
assert task.error?
assert_equal "Error", task.hasStatus