summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-05-09 16:48:10 +0200
committermguetlein <martin.guetlein@gmail.com>2011-05-09 16:48:10 +0200
commit81609ef5a360e54f26d92236853ec0121fed0d42 (patch)
tree5d4cd2816c9dd1d61e28efdf79da0e7b0316faed /lib
parentd798101491309cd65b0d49ed2993d439a74d7c5e (diff)
restore test_util.rb (accidently removed with unit-tests)
Diffstat (limited to 'lib')
-rwxr-xr-xlib/test_util.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/test_util.rb b/lib/test_util.rb
new file mode 100755
index 0000000..590d295
--- /dev/null
+++ b/lib/test_util.rb
@@ -0,0 +1,76 @@
+
+require 'test/unit'
+
+module Lib
+ # test utitily, to be included rack unit tests
+ module TestUtil
+
+ def wait_for_task(uri)
+ return TestUtil.wait_for_task(uri)
+ end
+
+ def self.wait_for_task(uri)
+ if uri.task_uri?
+ task = OpenTox::Task.find(uri)
+ task.wait_for_completion
+ #raise "task failed: "+uri.to_s+", error is:\n"+task.description if task.error?
+ LOGGER.error "task failed :\n"+task.to_yaml if task.error?
+ uri = task.result_uri
+ end
+ return uri
+ end
+
+ # updloads a dataset
+ def upload_data(ws, file)
+
+ case file.path
+ when /yaml$/
+ type = "application/x-yaml"
+ when /owl$/
+ type = "application/rdf+xml"
+ else
+ raise "unknown type for file: "+file.path.to_s
+ end
+
+ data = File.read(file.path)
+ task_uri = RestClient.post ws, data, :content_type => type
+ data_uri = task_uri.body
+ puts "done: "+data_uri.to_s
+ add_resource(data_uri)
+ return data_uri
+ end
+
+ # adds a resource to delete it later on
+ def add_resource(res)
+ @to_delete = [] unless @to_delete
+ @to_delete.push(res)
+ end
+
+ # deletes all resources
+ def delete_resources
+ if @to_delete
+ @to_delete.each do |d|
+ puts "deleting "+d.to_s
+ if d.to_s =~ /^http.*/
+ ext("curl -X DELETE "+d.to_s)
+ else
+ delete d.to_s
+ end
+ end
+ end
+ end
+
+ # execute an external program like curl
+ def ext(call, indent=" ")
+ response = ""
+ IO.popen(call.to_s+" 2> /dev/null") do |f|
+ while line = f.gets
+ response += indent.to_s+line
+ end
+ end
+ assert $?==0, "returns error "+call+" "+response
+ return response
+ end
+
+ end
+end