ruby-fedora 0.1.0
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/History.txt +4 -0
- data/License.txt +58 -0
- data/Manifest.txt +34 -0
- data/README.txt +19 -0
- data/Rakefile +5 -0
- data/config/hoe.rb +69 -0
- data/config/requirements.rb +17 -0
- data/lib/active-fedora.rb +1 -0
- data/lib/active_fedora/base.rb +22 -0
- data/lib/ambition/adapters/active_fedora.rb +10 -0
- data/lib/ambition/adapters/active_fedora/base.rb +14 -0
- data/lib/ambition/adapters/active_fedora/query.rb +48 -0
- data/lib/ambition/adapters/active_fedora/select.rb +104 -0
- data/lib/ambition/adapters/active_fedora/slice.rb +19 -0
- data/lib/ambition/adapters/active_fedora/sort.rb +43 -0
- data/lib/fedora/base_object.rb +19 -0
- data/lib/fedora/connection.rb +97 -0
- data/lib/fedora/datastream.rb +21 -0
- data/lib/fedora/fedora_object.rb +119 -0
- data/lib/fedora/formats.rb +30 -0
- data/lib/fedora/repository.rb +199 -0
- data/lib/ruby-fedora.rb +17 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_fedora.rb +55 -0
- data/test/test_helper.rb +6 -0
- data/test/test_httpclient.rb +73 -0
- data/test/test_restful_bits.rb +63 -0
- data/test/test_restful_fedora.rb +160 -0
- data/website/index.html +93 -0
- data/website/index.txt +39 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +113 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :manifest do
|
30
|
+
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
+
task :refresh do
|
32
|
+
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
+
end
|
34
|
+
end
|
data/tasks/website.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
desc 'Generate website files'
|
2
|
+
task :website_generate => :ruby_env do
|
3
|
+
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
+
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Upload website files to rubyforge'
|
9
|
+
task :website_upload do
|
10
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
+
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
12
|
+
local_dir = 'website'
|
13
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate and upload website files'
|
17
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/test/test_fedora.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# test_fedora.rb
|
3
|
+
#
|
4
|
+
# Created: Nov 3, 2007, 6:28:37 PM
|
5
|
+
#
|
6
|
+
# Author: Matt Zumwalt <matt.zumwalt@yourmediashelf.com>
|
7
|
+
# Copyright: Copyright (c) 2007 Matt Zumwalt <matt.zumwalt@yourmediashelf.com>
|
8
|
+
# License:
|
9
|
+
#
|
10
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
11
|
+
|
12
|
+
class TestFedoraRepository < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@fedora = Fedora::Repository.new(FEDORA_URL, :user => 'fedoraAdmin', :password => 'fedoraAdmin')
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
# TODO cleanup
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_namespace_juggling
|
23
|
+
namespace_info = @fedora.namespace_info
|
24
|
+
new_pid = @fedora.next_pid
|
25
|
+
|
26
|
+
assert_equal "#{namespace_info[:default_namespace]}#{namespace_info[:pid_delimiter]}100", namespace_info[:sample_pid]
|
27
|
+
assert_true namespace_info[:retained_pids].include?("fedora-bdef")
|
28
|
+
assert_true namespace_info[:retained_pids].include?("fedora-bmech")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_objects
|
32
|
+
puts 'DEBUG 3'
|
33
|
+
test_object_1 = @fedora.objects.create(:namespace => "test") # Create a new empty object with an auto-assigned pid
|
34
|
+
# Creating multiple objects simultaneously by submitting an array
|
35
|
+
objects_array = @fedora.objects.create([{:owner_id => "MISC_USER_ID", :namespace => "test"},{:pid => "test:OBJECT_FROM_ARRAY_CREATE_TEST"}])
|
36
|
+
|
37
|
+
test_object_1.label = "DELETE_ME"
|
38
|
+
test_object_1.state = "I"
|
39
|
+
|
40
|
+
# Not sure if "save should return PID or "true"
|
41
|
+
assert_equal(true, test_object_1.save)
|
42
|
+
assert_equal(test_object_1.state, "I")
|
43
|
+
|
44
|
+
found_by_pid = @fedora.objects.find_by_pid(test_object_1.pid)
|
45
|
+
|
46
|
+
assert_equal(found_by_pid.label, test_object_1.label)
|
47
|
+
assert_equal(objects_array[0].owner_id, @fedora.objects.find_by_pid(objects_array[0].pid).owner_id)
|
48
|
+
|
49
|
+
test_object1.destroy
|
50
|
+
objects_array.each do |obj|
|
51
|
+
obj.destroy
|
52
|
+
end
|
53
|
+
# test_object2.destroy # leave this until the final cleanup...
|
54
|
+
end
|
55
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# @Creator Matt Zumwalt, MediaShelf LLC
|
3
|
+
# @Copyright Matt Zumwalt, 2007. All Rights Reserved.
|
4
|
+
#
|
5
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
6
|
+
|
7
|
+
require 'uri'
|
8
|
+
require 'httpclient'
|
9
|
+
|
10
|
+
class TestFedoraHttpClient < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@test_pid = "mshlf:test_httpclient"
|
14
|
+
@user = "fedoraAdmin"
|
15
|
+
@password = "fedoraAdmin"
|
16
|
+
end
|
17
|
+
|
18
|
+
def url_for(pid, dsid = nil, params = {})
|
19
|
+
url = "#{FEDORA_URL}/objects/#{@test_pid}"
|
20
|
+
url += "/datastreams/#{dsid}" if dsid
|
21
|
+
url += ("?" + params.collect { |key, value| "#{key}=#{value}" } * '&') unless params.empty?
|
22
|
+
url
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_post_empty
|
26
|
+
client = HTTPClient.new
|
27
|
+
|
28
|
+
extheader = {'User-Agent' => 'RubyFedora'}
|
29
|
+
extheader['content-type'] = "text/xml"
|
30
|
+
uri = url_for(@test_pid)
|
31
|
+
|
32
|
+
client.set_basic_auth(uri, @user, @password)
|
33
|
+
create_response = client.post(uri, "", extheader)
|
34
|
+
|
35
|
+
assert_equal 201, create_response.header.response_status_code
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_post_xml
|
40
|
+
client = HTTPClient.new
|
41
|
+
sample_xml_1 = File.new(File.dirname(__FILE__) + '/fixtures/mods-mskcc-filledsample.xml')
|
42
|
+
|
43
|
+
extheader = {'User-Agent' => 'RubyFedora'}
|
44
|
+
extheader['content-type'] = "text/xml"
|
45
|
+
request_body = sample_xml_1
|
46
|
+
uri = url_for(@test_pid, "XML_DS")
|
47
|
+
client.set_basic_auth(uri, @user, @password)
|
48
|
+
create_response = client.post(uri, request_body, extheader)
|
49
|
+
delete_response = client.delete(uri)
|
50
|
+
|
51
|
+
assert_equal 201, create_response.header.response_status_code
|
52
|
+
assert_equal 200, delete_response.header.response_status_code
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_multipart_post
|
56
|
+
client = HTTPClient.new
|
57
|
+
sample_binary_file_1 = File.open(File.dirname(__FILE__) + "/fixtures/dino.jpg" )
|
58
|
+
|
59
|
+
boundary = Array::new(8){ "%2.2d" % rand(42) }.join('__')
|
60
|
+
extheader = {'User-Agent' => 'RubyFedora'}
|
61
|
+
extheader['content-type'] = "multipart/form-data; boundary=___#{ boundary }___"
|
62
|
+
extheader['Content-Type'] = "image/jpeg"
|
63
|
+
|
64
|
+
request_body = {'inputfile' => sample_binary_file_1}
|
65
|
+
uri = url_for(@test_pid, "BINARY_DS", { :dsLabel => "Foo+Bar" })
|
66
|
+
client.set_basic_auth(uri, @user, @password)
|
67
|
+
create_response = client.post(uri, request_body, extheader)
|
68
|
+
delete_response = client.delete(uri)
|
69
|
+
|
70
|
+
assert_equal 201, create_response.header.response_status_code
|
71
|
+
assert_equal 200, delete_response.header.response_status_code
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#
|
2
|
+
# @Creator Matt Zumwalt, MediaShelf LLC
|
3
|
+
# @Copyright Matt Zumwalt, 2007. All Rights Reserved.
|
4
|
+
#
|
5
|
+
#++
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
8
|
+
|
9
|
+
class TestRestfulFedora < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@fedora = RubyFedora::RestfulFedora.new(FEDORA_URL, :user=>'fedoraAdmin', :password=>'fedoraAdmin')
|
12
|
+
@search_term = "test" # this should be a search term that will return at least one hit
|
13
|
+
@pid_delimiter = ":"
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_simple_search
|
17
|
+
test_object_pid = "test:do_not_delete"
|
18
|
+
should_not_exist = "test:never_use_this_pid"
|
19
|
+
|
20
|
+
find_by_pid_response = @fedora.simple_search(:conditions => {:pid => test_object_pid})
|
21
|
+
find_by_pid_convenience_response = @fedora.find_by_pid(test_object_pid)
|
22
|
+
|
23
|
+
#Should support conditions provided as an array and conditions provided as a hash.
|
24
|
+
namespace = "test"
|
25
|
+
find_by_namespace_response1 = @fedora.simple_search(:conditions => {:namespace => namespace})
|
26
|
+
#puts find_by_namespace_response1.body.content
|
27
|
+
# Decided not to support directly feeding in url query strings verbatim...
|
28
|
+
# found_by_namespace2 = @fedora.simple_search(:conditions => ["pid~#{namespace}:*"])
|
29
|
+
find_with_conditions_response = @fedora.simple_search(:conditions => {:fType => "O"})
|
30
|
+
#puts find_with_conditions_response.body.content
|
31
|
+
|
32
|
+
# found_all = @fedora.simple_search(:all)
|
33
|
+
# found_all_limited = @fedora.simple_search(:all, :limit => 10)
|
34
|
+
#
|
35
|
+
# found_by_created_range = @fedora.simple_search(:conditions => {:created_before => "2008-01-22", :created_after => "2008-01-20"})
|
36
|
+
# found_by_created_on = @fedora.simple_search(:conditions => {:date_created => "2008-01-21"})
|
37
|
+
#
|
38
|
+
# found_by_modified_range = @fedora.simple_search(:conditions => {:modified_before => "2008-01-22", :modified_after => "2008-01-20"})
|
39
|
+
# found_by_modified_on = @fedora.simple_search(:conditions => {:date_modified => "2008-01-21"})
|
40
|
+
|
41
|
+
|
42
|
+
## TODO: Decide if this is the right way to go. Possibly return XMLSimple objects instead?
|
43
|
+
assert_equal Array, find_by_pid_response.class
|
44
|
+
assert_equal Array, find_by_pid_convenience_response.class
|
45
|
+
assert_equal Array, find_by_namespace_response1.class
|
46
|
+
assert_equal Array, find_with_conditions_response.class
|
47
|
+
assert_equal test_object_pid, find_by_pid_response.first[:pid]
|
48
|
+
assert_equal test_object_pid, find_by_pid_convenience_response.first[:pid]
|
49
|
+
|
50
|
+
assert_throws RecordNotFound, @fedora.simple_search(:conditions => {:pid => should_not_exist})
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_datetime_finders
|
54
|
+
created_after_response = @fedora.find_by_create_date(:after => "2008-01-01")
|
55
|
+
created_before_response = @fedora.find_by_create_date(:before => "2008-01-22")
|
56
|
+
|
57
|
+
## TODO: Decide if this is the right way to go. Possibly return XMLSimple objects instead?
|
58
|
+
assert_equal Array, created_after_response
|
59
|
+
assert_equal Array, created_before_response
|
60
|
+
assert_true created_after_response.first.has_key?(:pid)
|
61
|
+
assert_true created_before_response.last.has_key?(:pid)
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#
|
2
|
+
# @Creator Matt Zumwalt, MediaShelf LLC
|
3
|
+
# @Copyright Matt Zumwalt, 2007. All Rights Reserved.
|
4
|
+
#
|
5
|
+
#++
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
8
|
+
|
9
|
+
class TestRestfulFedora < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@fedora = Fedora::RestfulFedora.new(FEDORA_URL, :user=>'fedoraAdmin', :password=>'fedoraAdmin')
|
13
|
+
@search_term = "test" # this should be a search term that will return at least one hit
|
14
|
+
@pid_delimiter = ":"
|
15
|
+
@test_object_pid = "test:do_not_delete"
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_pid_generator
|
19
|
+
pid1 = @fedora.next_pid
|
20
|
+
pid2 = @fedora.next_pid
|
21
|
+
pid_from_old_api = @fedora.next_pid_old_api
|
22
|
+
|
23
|
+
# Everything up to the pid_delimiter should be identical in pid1 & pid_from_old_api
|
24
|
+
assert_equal pid1[0..pid1.index(@pid_delimiter)], pid_from_old_api[0..pid1.index(@pid_delimiter)]
|
25
|
+
# After the pid_delimiter should be two integers, where the pid2 = pid1 + 1
|
26
|
+
assert_equal pid1[pid1.index(@pid_delimiter)+1..pid1.length].to_i, pid2[pid1.index(@pid_delimiter)+1..pid2.length].to_i-1
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_datastream_resource
|
31
|
+
pid_of_test_object = @fedora.create_object(:pid=>"test:test_datastream_resource", :params=>{:label=>"DELETE ME"})
|
32
|
+
|
33
|
+
sample_xml_1 = File.new(File.dirname(__FILE__) + '/fixtures/mods-mskcc-filledsample.xml')
|
34
|
+
sample_xml_2 = File.new(File.dirname(__FILE__) + '/fixtures/sample_mods_file_A.xml')
|
35
|
+
sample_binary_file_1 = File.open(File.dirname(__FILE__) + "/fixtures/dino.jpg" )
|
36
|
+
sample_binary_file_2 = File.open(File.dirname(__FILE__) + "/fixtures/minivan-in-minneapolis.jpg" )
|
37
|
+
|
38
|
+
create_xml_result = @fedora.add_xml_datastream(:pid=>pid_of_test_object, :dsid=>"XML_DS", :xml_content=>sample_xml_1.read, :params=>{:ds_label=>"Sample XML"})
|
39
|
+
create_binary_result = @fedora.add_binary_datastream(:pid=>pid_of_test_object, :dsid=>"BINARY_DS", :file=>sample_binary_file_1, :content_type => "image/jpeg", :params=>{:ds_label=>"Sample Binary File"})
|
40
|
+
object_xml = REXML::Document.new(@fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid_of_test_object}/objectXML").content)
|
41
|
+
create_redirect_result = @fedora.add_redirect_datastream(:pid=>pid_of_test_object, :dsid=>"REDIRECT", :content_type=>"image/jpeg", :params=>{:ds_label=>"Sample Redirect", :ds_location=>create_binary_result.header['Location'].to_s})
|
42
|
+
|
43
|
+
assert_equal 201, create_xml_result.header.response_status_code
|
44
|
+
assert_equal 201, create_binary_result.header.response_status_code
|
45
|
+
#puts object_xml.elements["foxml:digitalObject/foxml:datastream[@ID='BINARY_DS']"].attributes
|
46
|
+
assert_equal "image/jpeg", object_xml.elements["foxml:digitalObject/foxml:datastream[@ID='BINARY_DS']/foxml:datastreamVersion"].attributes["MIMETYPE"]
|
47
|
+
assert_equal 201, create_redirect_result.header.response_status_code
|
48
|
+
# GETting the REDIRECT datastream should return a Location header that points to the BINARY datastream
|
49
|
+
assert_equal @fedora.get_datastream(pid_of_test_object, "REDIRECT").header['Location'], create_binary_result.header['Location']
|
50
|
+
|
51
|
+
update_xml_result = @fedora.update_datastream(:pid=>pid_of_test_object, :dsid=>"XML_DS", :xml_content=>sample_xml_2.read, :params=>{:ds_label=>"Updated XML Datastream"})
|
52
|
+
update_binary_result = @fedora.update_datastream(:pid=>pid_of_test_object, :dsid=>"BINARY_DS", :file=>sample_binary_file_1, :content_type => "image/jpeg")
|
53
|
+
|
54
|
+
assert_equal 201, update_xml_result.header.response_status_code
|
55
|
+
assert_equal 201, update_binary_result.header.response_status_code
|
56
|
+
|
57
|
+
update_attributes_only_result = @fedora.update_datastream(:pid=>pid_of_test_object, :dsid=>"XML_DS", :params=>{:ds_label=>"Updated Datastream"})
|
58
|
+
|
59
|
+
# TODO: Fix update_datastream to support updating attributes only. (Requires fix in Fedora REST code)
|
60
|
+
#assert_equal 200, update_attributes_only_result.header.response_status_code
|
61
|
+
# Make sure that updating attributes didn't change the datastream content
|
62
|
+
#assert_equal sample_xml_2, @fedora.get_datastream(:pid=>pid_of_test_object, :dsid=>"XML_DS")
|
63
|
+
|
64
|
+
delete_xml_result = @fedora.delete_datastream(:pid=>pid_of_test_object, :dsid=>"XML_DS")
|
65
|
+
delete_binary_result = @fedora.delete_datastream(:pid=>pid_of_test_object, :dsid=>"BINARY_DS")
|
66
|
+
|
67
|
+
assert_equal 200, delete_xml_result.header.response_status_code
|
68
|
+
assert_equal 200, delete_binary_result.header.response_status_code
|
69
|
+
|
70
|
+
@fedora.delete_object(:pid=>pid_of_test_object)
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_simple_search
|
75
|
+
should_not_exist = "test:never_use_this_pid"
|
76
|
+
|
77
|
+
find_by_pid_response = @fedora.simple_search(:conditions => {:pid => @test_object_pid})
|
78
|
+
find_by_pid_convenience_response = @fedora.find_by_pid(@test_object_pid)
|
79
|
+
|
80
|
+
#Should support conditions provided as an array and conditions provided as a hash.
|
81
|
+
namespace = "test"
|
82
|
+
find_by_namespace_response1 = @fedora.simple_search(:conditions => {:namespace => namespace})
|
83
|
+
#puts find_by_namespace_response1.body.content
|
84
|
+
# Decided not to support directly feeding in url query strings verbatim...
|
85
|
+
# found_by_namespace2 = @fedora.simple_search(:conditions => ["pid~#{namespace}:*"])
|
86
|
+
find_with_conditions_response = @fedora.simple_search(:conditions => {:fType => "O"})
|
87
|
+
#puts find_with_conditions_response.body.content
|
88
|
+
# found_all = @fedora.simple_search(:all)
|
89
|
+
# found_all_limited = @fedora.simple_search(:all, :limit => 10)
|
90
|
+
#
|
91
|
+
# found_by_created_range = @fedora.simple_search(:conditions => {:created_before => "2008-01-22", :created_after => "2008-01-20"})
|
92
|
+
# found_by_created_on = @fedora.simple_search(:conditions => {:date_created => "2008-01-21"})
|
93
|
+
#
|
94
|
+
# found_by_modified_range = @fedora.simple_search(:conditions => {:modified_before => "2008-01-22", :modified_after => "2008-01-20"})
|
95
|
+
# found_by_modified_on = @fedora.simple_search(:conditions => {:date_modified => "2008-01-21"})
|
96
|
+
|
97
|
+
assert true
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
def test_datetime_finders
|
104
|
+
|
105
|
+
created_after = @fedora.find_by_create_date(:after => "2008-01-01")
|
106
|
+
created_before = @fedora.find_by_create_date(:before => "2008-01-22")
|
107
|
+
|
108
|
+
assert true
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_call_resource
|
112
|
+
|
113
|
+
sample_xml_1 = File.new(File.dirname(__FILE__) + '/fixtures/mods-mskcc-filledsample.xml')
|
114
|
+
sample_binary_file_1 = File.open(File.dirname(__FILE__) + "/fixtures/dino.jpg" )
|
115
|
+
search_result = @fedora.call_resource(:method => "GET", :resource_path => "/objects", :request_body => "", :content_type => "text/xml", :auth => {}, :params => {:query =>"", :pid=>"true", :format=>"xml", :terms=>@search_term})
|
116
|
+
result_rexml = REXML::Document.new(search_result.content)
|
117
|
+
pid = result_rexml.elements["result/resultList/objectFields/pid"].text
|
118
|
+
#pid = "changeme:1"
|
119
|
+
|
120
|
+
assert_equal(result_rexml.root.name, "result")
|
121
|
+
assert_equal result_rexml.elements["result/resultList/objectFields"][1].name, "pid"
|
122
|
+
# test each of the endpoints that we want to be able to send requests to...
|
123
|
+
|
124
|
+
# Other RETRIEVE Operaitons ..
|
125
|
+
assert_equal 200, @fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid}", :params=>{:format=>"xml"}).header.response_status_code
|
126
|
+
assert_equal 200, @fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid}/objectXML", :params=>{:format=>"xml"}).header.response_status_code
|
127
|
+
assert_equal 200, @fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid}/versions", :params=>{:format=>"xml"}).header.response_status_code
|
128
|
+
assert_equal 200, @fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid}/export", :params=>{}).header.response_status_code
|
129
|
+
assert_equal 200, @fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid}/methods", :params=>{:format=>"xml"}).header.response_status_code
|
130
|
+
assert_equal 200, @fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid}/datastreams", :params=>{:format=>"xml"}).header.response_status_code
|
131
|
+
assert_equal 200, @fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid}/datastreams/DC", :params=>{:format=>"xml"}).header.response_status_code
|
132
|
+
|
133
|
+
pid = "test:test_object_1"
|
134
|
+
# Create Object
|
135
|
+
object_create_response = @fedora.call_resource(:method => "POST", :resource_path =>"/objects/#{pid}", :request_body => "", :params => {"label"=>"TEST ME"})
|
136
|
+
|
137
|
+
assert_equal "#{@@fedora_url}/#{@fedora.resource_base}/objects/test%3Atest_object_1", object_create_response.header['location'][0]
|
138
|
+
assert_equal 201, object_create_response.header.response_status_code
|
139
|
+
|
140
|
+
# Create XML Datastream
|
141
|
+
xml_datastream_create_response = @fedora.call_resource(:method => "POST", :resource_path =>"/objects/#{pid}/datastreams/XML", :request_body => sample_xml_1.read, :params => {"dsLabel"=>"Sample XML File"})
|
142
|
+
# Create Binary Datastream
|
143
|
+
# !! set mimetype by setting :content_type !!
|
144
|
+
binary_datastream_create_response = @fedora.call_resource(:method => "UPLOAD", :resource_path =>"/objects/#{pid}/datastreams/BINARY", :request_body => sample_binary_file_1, :content_type => "image/jpeg", :params => {"dsLabel"=>"Sample XML File"})
|
145
|
+
assert_equal 201, xml_datastream_create_response.header.response_status_code
|
146
|
+
assert_equal 201, binary_datastream_create_response.header.response_status_code
|
147
|
+
|
148
|
+
|
149
|
+
object_xml = REXML::Document.new(@fedora.call_resource(:method => "GET", :resource_path =>"/objects/#{pid}/objectXML").content)
|
150
|
+
assert_equal "image/jpeg", object_xml.elements["foxml:digitalObject/foxml:datastream[@ID='BINARY']/foxml:datastreamVersion"].attributes["MIMETYPE"]
|
151
|
+
assert_equal "X", object_xml.elements["foxml:digitalObject/foxml:datastream[@ID='XML']"].attributes["CONTROL_GROUP"]
|
152
|
+
assert_equal "M", object_xml.elements["foxml:digitalObject/foxml:datastream[@ID='BINARY']"].attributes["CONTROL_GROUP"]
|
153
|
+
#puts object_xml.elements["foxml:digitalObject/foxml:datastream[@ID='BINARY']/foxml:datastreamVersion"].attributes["MIMETYPE"]
|
154
|
+
|
155
|
+
# Delete Object
|
156
|
+
delete_response = @fedora.call_resource(:method => "DELETE", :resource_path =>"/objects/#{pid}")
|
157
|
+
|
158
|
+
assert_equal 200, delete_response.header.response_status_code
|
159
|
+
end
|
160
|
+
end
|
data/website/index.html
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>
|
8
|
+
RubyFedora
|
9
|
+
</title>
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
+
<style>
|
12
|
+
|
13
|
+
</style>
|
14
|
+
<script type="text/javascript">
|
15
|
+
window.onload = function() {
|
16
|
+
settings = {
|
17
|
+
tl: { radius: 10 },
|
18
|
+
tr: { radius: 10 },
|
19
|
+
bl: { radius: 10 },
|
20
|
+
br: { radius: 10 },
|
21
|
+
antiAlias: true,
|
22
|
+
autoPad: true,
|
23
|
+
validTags: ["div"]
|
24
|
+
}
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
+
versionBox.applyCornersToAll();
|
27
|
+
}
|
28
|
+
</script>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="main">
|
32
|
+
|
33
|
+
<h1>RubyFedora</h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/RubyFedora"; return false'>
|
35
|
+
<p>Get Version</p>
|
36
|
+
<a href="http://rubyforge.org/projects/RubyFedora" class="numbers">0.1.0</a>
|
37
|
+
</div>
|
38
|
+
<h1>→ ‘RubyFedora’</h1>
|
39
|
+
|
40
|
+
|
41
|
+
<h2>What</h2>
|
42
|
+
|
43
|
+
|
44
|
+
<h2>Installing</h2>
|
45
|
+
|
46
|
+
|
47
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="constant">RubyFedora</span></pre></p>
|
48
|
+
|
49
|
+
|
50
|
+
<h2>The basics</h2>
|
51
|
+
|
52
|
+
|
53
|
+
<h2>Demonstration of usage</h2>
|
54
|
+
|
55
|
+
|
56
|
+
<h2>Forum</h2>
|
57
|
+
|
58
|
+
|
59
|
+
<p><a href="http://groups.google.com/group/RubyFedora">http://groups.google.com/group/RubyFedora</a></p>
|
60
|
+
|
61
|
+
|
62
|
+
<p><span class="caps">TODO</span> – create Google Group – RubyFedora</p>
|
63
|
+
|
64
|
+
|
65
|
+
<h2>How to submit patches</h2>
|
66
|
+
|
67
|
+
|
68
|
+
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
69
|
+
|
70
|
+
|
71
|
+
<p>The trunk repository is <code>svn://rubyforge.org/var/svn/RubyFedora/trunk</code> for anonymous access.</p>
|
72
|
+
|
73
|
+
|
74
|
+
<h2>License</h2>
|
75
|
+
|
76
|
+
|
77
|
+
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
78
|
+
|
79
|
+
|
80
|
+
<h2>Contact</h2>
|
81
|
+
|
82
|
+
|
83
|
+
<p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/RubyFedora">forum</a></p>
|
84
|
+
<p class="coda">
|
85
|
+
<a href="FIXME email">FIXME full name</a>, 30th March 2008<br>
|
86
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
87
|
+
</p>
|
88
|
+
</div>
|
89
|
+
|
90
|
+
<!-- insert site tracking codes here, like Google Urchin -->
|
91
|
+
|
92
|
+
</body>
|
93
|
+
</html>
|