rubydora 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,260 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubydora::DigitalObject do
4
+ describe "new" do
5
+ it "should load a DigitalObject instance" do
6
+ Rubydora::DigitalObject.new("pid").should be_a_kind_of(Rubydora::DigitalObject)
7
+ end
8
+ end
9
+
10
+ describe "profile" do
11
+ before(:each) do
12
+ @mock_repository = mock(Rubydora::Repository)
13
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
14
+ end
15
+
16
+ it "should convert object profile to a simple hash" do
17
+ @mock_repository.should_receive(:object).with(:pid => 'pid').and_return("<objectProfile><a>1</a><b>2</b><objModels><model>3</model><model>4</model></objectProfile>")
18
+ h = @object.profile
19
+
20
+ h.should have_key("a")
21
+ h['a'].should == '1'
22
+ h.should have_key("b")
23
+ h['b'].should == '2'
24
+ h.should have_key("objModels")
25
+ h['objModels'].should == ['3', '4']
26
+
27
+ end
28
+ end
29
+
30
+ describe "new" do
31
+ before(:each) do
32
+ @mock_repository = mock(Rubydora::Repository)
33
+ @mock_repository.should_receive(:object).any_number_of_times.and_raise ""
34
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
35
+ end
36
+
37
+ it "should be new" do
38
+ @object.new?.should == true
39
+ end
40
+
41
+ it "should call ingest on save" do
42
+ @object.should_receive(:datastreams).and_return({})
43
+ @mock_repository.should_receive(:ingest).with(hash_including(:pid => 'pid'))
44
+ @object.save
45
+ end
46
+ end
47
+
48
+ describe "create" do
49
+ it "should call the Fedora REST API to create a new object" do
50
+ @mock_repository = mock(Rubydora::Repository)
51
+ @mock_repository.should_receive(:ingest).with(instance_of(Hash)).and_return(nil)
52
+ obj = Rubydora::DigitalObject.create "pid", { :a => 1, :b => 2}, @mock_repository
53
+ obj.should be_a_kind_of(Rubydora::DigitalObject)
54
+ end
55
+ end
56
+
57
+ describe "retreive" do
58
+ before(:each) do
59
+ @mock_repository = mock(Rubydora::Repository)
60
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
61
+ end
62
+
63
+ describe "datastreams" do
64
+ it "should provide a hash populated by the existing datastreams" do
65
+ @mock_repository.should_receive(:datastreams).with(:pid => 'pid').and_return("<objectDatastreams><datastream dsid='a'></datastream>><datastream dsid='b'></datastream>><datastream dsid='c'></datastream></objectDatastreams>")
66
+
67
+ @object.datastreams.should have_key("a")
68
+ @object.datastreams.should have_key("b")
69
+ @object.datastreams.should have_key("c")
70
+ end
71
+
72
+ it "should allow other datastreams to be added" do
73
+ @mock_repository.should_receive(:datastreams).with(:pid => 'pid').and_return("<objectDatastreams><datastream dsid='a'></datastream>><datastream dsid='b'></datastream>><datastream dsid='c'></datastream></objectDatastreams>")
74
+ @mock_repository.should_receive(:datastream).with(:pid => 'pid', :dsid => 'z').and_raise("")
75
+
76
+ @object.datastreams.length.should == 3
77
+
78
+ ds = @object.datastreams["z"]
79
+ ds.should be_a_kind_of(Rubydora::Datastream)
80
+ ds.new?.should == true
81
+
82
+ @object.datastreams.length.should == 4
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+
89
+ describe "retrieve" do
90
+
91
+ end
92
+
93
+ describe "save" do
94
+ before(:each) do
95
+ @mock_repository = mock(Rubydora::Repository)
96
+ @mock_repository.should_receive(:object).any_number_of_times.with({:pid => 'pid'}).and_return <<-XML
97
+ <objectProfile>
98
+ </objectProfile>
99
+ XML
100
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
101
+ end
102
+
103
+ it "should save all dirty datastreams" do
104
+ @ds1 = mock()
105
+ @ds1.should_receive(:dirty?).and_return(false)
106
+ @ds1.should_not_receive(:save)
107
+ @ds2 = mock()
108
+ @ds2.should_receive(:dirty?).and_return(true)
109
+ @ds2.should_receive(:new?).and_return(true)
110
+ @ds2.should_not_receive(:save)
111
+ @ds3 = mock()
112
+ @ds3.should_receive(:dirty?).and_return(true)
113
+ @ds3.should_receive(:new?).and_return(false)
114
+ @ds3.should_receive(:save)
115
+
116
+ @object.should_receive(:datastreams).and_return({:ds1 => @ds1, :ds2 => @ds2, :ds3 => @ds3 })
117
+
118
+ @object.save
119
+ end
120
+
121
+ it "should save all dirty attributes" do
122
+ @object.label = "asdf"
123
+ @object.should_receive(:datastreams).and_return({})
124
+ @mock_repository.should_receive(:modify_object).with(hash_including(:pid => 'pid'))
125
+ @object.save
126
+ end
127
+ end
128
+
129
+ describe "delete" do
130
+ before(:each) do
131
+ @mock_repository = mock()
132
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
133
+ end
134
+
135
+ it "should call the Fedora REST API" do
136
+ @mock_repository.should_receive(:purge_object).with({:pid => 'pid'})
137
+ @object.delete
138
+ end
139
+ end
140
+
141
+ describe "extensions" do
142
+ module FakeExtension
143
+ end
144
+
145
+ module OtherFakeExtension
146
+
147
+ end
148
+ before(:each) do
149
+ @mock_repository = mock()
150
+ end
151
+
152
+ after(:each) do
153
+ Rubydora::DigitalObject.registered_extensions = []
154
+ end
155
+
156
+ it "should be extendable" do
157
+ Rubydora::DigitalObject.use_extension FakeExtension
158
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
159
+ @object.is_a?(FakeExtension).should == true
160
+ end
161
+
162
+ it "should be extendable conditionally" do
163
+ Rubydora::DigitalObject.use_extension(FakeExtension) { |x| true }
164
+ Rubydora::DigitalObject.use_extension(OtherFakeExtension) { |x| false }
165
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
166
+ @object.is_a?(FakeExtension).should == true
167
+ @object.is_a?(OtherFakeExtension).should == false
168
+ end
169
+
170
+ it "should be able to introspect object profiles" do
171
+ @mock_repository.should_receive(:object).any_number_of_times.with({:pid => 'pid'}).and_return <<-XML
172
+ <objectProfile>
173
+ <a>1</a>
174
+ </objectProfile>
175
+ XML
176
+ Rubydora::DigitalObject.use_extension(FakeExtension) { |x| x.profile['a'] == '1' }
177
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
178
+ @object.is_a?(FakeExtension).should == true
179
+ end
180
+
181
+ end
182
+
183
+ describe "models" do
184
+ before(:each) do
185
+ @mock_repository = mock(Rubydora::Repository)
186
+ @mock_repository.should_receive(:object).any_number_of_times.with({:pid => 'pid'}).and_return <<-XML
187
+ <objectProfile>
188
+ </objectProfile>
189
+ XML
190
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
191
+ end
192
+
193
+ it "should add models to fedora" do
194
+ @mock_repository.should_receive(:add_relationship) do |params|
195
+ params.should have_key(:subject)
196
+ params[:predicate].should == 'info:fedora/fedora-system:def/model#hasModel'
197
+ params[:object].should == 'asdf'
198
+ end
199
+ @object.models << "asdf"
200
+ end
201
+
202
+ it "should remove models from fedora" do
203
+ @object.should_receive(:profile).any_number_of_times.and_return({"objModels" => ['asdf']})
204
+ @mock_repository.should_receive(:purge_relationship) do |params|
205
+ params.should have_key(:subject)
206
+ params[:predicate].should == 'info:fedora/fedora-system:def/model#hasModel'
207
+ params[:object].should == 'asdf'
208
+ end
209
+ @object.models.delete("asdf")
210
+ end
211
+
212
+ it "should be able to handle complete model replacemenet" do
213
+ @object.should_receive(:profile).any_number_of_times.and_return({"objModels" => ['asdf']})
214
+ @mock_repository.should_receive(:add_relationship).with(instance_of(Hash))
215
+ @mock_repository.should_receive(:purge_relationship).with(instance_of(Hash))
216
+ @object.models = '1234'
217
+
218
+ end
219
+ end
220
+
221
+ describe "relations" do
222
+ before(:each) do
223
+ @mock_repository = mock()
224
+ @mock_repository.should_receive(:object).any_number_of_times.with({:pid => 'pid'}).and_return <<-XML
225
+ <objectProfile>
226
+ </objectProfile>
227
+ XML
228
+ @object = Rubydora::DigitalObject.new 'pid', @mock_repository
229
+ end
230
+
231
+ it "should fetch related objects using sparql" do
232
+ @mock_repository.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([1])
233
+ @object.parts.should == [1]
234
+ end
235
+
236
+ it "should add related objects" do
237
+ @mock_repository.should_receive(:add_relationship) do |params|
238
+ params.should have_key(:subject)
239
+ params[:predicate].should == 'info:fedora/fedora-system:def/relations-external#hasPart'
240
+ params[:object].should == 'asdf'
241
+ end
242
+ @mock_object = mock(Rubydora::DigitalObject)
243
+ @mock_object.should_receive(:fqpid).and_return('asdf')
244
+ @mock_repository.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([])
245
+ @object.parts << @mock_object
246
+ end
247
+
248
+ it "should remove related objects" do
249
+ @mock_repository.should_receive(:purge_relationship) do |params|
250
+ params.should have_key(:subject)
251
+ params[:predicate].should == 'info:fedora/fedora-system:def/relations-external#hasPart'
252
+ params[:object].should == 'asdf'
253
+ end
254
+ @mock_object = mock(Rubydora::DigitalObject)
255
+ @mock_object.should_receive(:fqpid).and_return('asdf')
256
+ @mock_repository.should_receive(:find_by_sparql_relationship).with('info:fedora/pid', 'info:fedora/fedora-system:def/relations-external#hasPart').and_return([@mock_object])
257
+ @object.parts.delete(@mock_object)
258
+ end
259
+ end
260
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'rubydora/ext/solr'
3
+
4
+ describe Rubydora::Ext::Solr do
5
+ describe "load" do
6
+ it "should load mixins" do
7
+ Rubydora::Ext::Solr.load
8
+ @mock_repository = mock(Rubydora::Repository)
9
+ obj = Rubydora::DigitalObject.new('pid', @mock_repository)
10
+ obj.should be_a_kind_of(Rubydora::Ext::Solr::DigitalObjectMixin)
11
+ end
12
+ end
13
+
14
+ describe "solr_mapping_logic" do
15
+ class MockSolrMappingClass
16
+
17
+ end
18
+ before(:each) do
19
+ Rubydora::Ext::Solr.load :digital_object => MockSolrMappingClass
20
+ end
21
+
22
+ it "should provide a class-level step list" do
23
+ MockSolrMappingClass.solr_mapping_logic.should_not be_empty
24
+ end
25
+
26
+ it "should be overridable on the class level" do
27
+ expect { MockSolrMappingClass.solr_mapping_logic << :a }.to change{MockSolrMappingClass.solr_mapping_logic.length}.by(1)
28
+ end
29
+
30
+ it "should be overridable on the instance level" do
31
+ MockSolrMappingClass.solr_mapping_logic = []
32
+ mock = MockSolrMappingClass.new
33
+
34
+ mock.solr_mapping_logic.should be_empty
35
+ mock.solr_mapping_logic << :a
36
+ mock.solr_mapping_logic.should == [:a]
37
+ MockSolrMappingClass.solr_mapping_logic.should == []
38
+ end
39
+
40
+ end
41
+
42
+ describe "to_solr" do
43
+ before(:each) do
44
+ @mock_repository = mock(Rubydora::Repository)
45
+ @object = Rubydora::DigitalObject.new('pid', @mock_repository)
46
+ end
47
+ it "should call the members of solr_mapping_logic" do
48
+
49
+ @object.should_receive(:solr_mapping_logic).and_return([:mock_solr_step, :another_mock_solr_step])
50
+ @object.should_receive(:mock_solr_step)
51
+ @object.should_receive(:another_mock_solr_step)
52
+ @object.to_solr
53
+ end
54
+
55
+ it "should allow steps to modify the resulting solr document" do
56
+ @object.should_receive(:solr_mapping_logic).and_return([:mock_solr_step, :another_mock_solr_step])
57
+ @object.stub(:mock_solr_step) do |doc|
58
+ doc[:a] = 'a'
59
+ doc[:b] = 0
60
+ end
61
+
62
+ @object.stub(:another_mock_solr_step) do |doc|
63
+ doc[:b] = 'b'
64
+ end
65
+
66
+ @object.to_solr.should == { :a => 'a', :b => 'b'}
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ # These tests require a fedora repository with the resource index enabled (and with syncUpdates = true)
5
+ describe "Integration testing against a live Fedora repository" do
6
+ REPOSITORY_CONFIG = { :url => 'http://localhost:8080/fedora', :user => 'fedoraAdmin', :password => 'fedoraAdmin' }
7
+ before(:all) do
8
+ @repository = Rubydora.connect REPOSITORY_CONFIG
9
+ end
10
+
11
+ it "should connect" do
12
+ @repository.ping.should == true
13
+ end
14
+
15
+ it "should create an object" do
16
+ obj = @repository.find('test:1')
17
+ obj.new?.should == true
18
+ obj = obj.save
19
+ obj.new?.should == false
20
+ end
21
+
22
+ it "should have default datastreams" do
23
+ obj = @repository.find('test:1')
24
+ obj.datastreams.keys.should include("DC")
25
+ end
26
+
27
+ it "should list object models" do
28
+ obj = @repository.find('test:1')
29
+ obj.models.should include("info:fedora/fedora-system:FedoraObject-3.0")
30
+ end
31
+
32
+ it "should create another object" do
33
+ obj = @repository.find('test:2')
34
+ obj.save
35
+ obj.new?.should == false
36
+ end
37
+
38
+ it "should create parts" do
39
+ obj = @repository.find('test:1')
40
+ obj2 = @repository.find('test:2')
41
+ obj.parts << obj2
42
+ end
43
+
44
+ it "should persist parts" do
45
+ obj = @repository.find('test:1')
46
+ end
47
+
48
+ it "should have a RELS-EXT datastream" do
49
+ obj = @repository.find('test:1')
50
+ obj.datastreams.keys.should include("RELS-EXT")
51
+ end
52
+
53
+ it "should create a managed datastream" do
54
+ obj = @repository.find('test:1')
55
+ obj = obj.save
56
+ ds = obj.datastreams["Test"]
57
+
58
+ ds.content = open(__FILE__).read
59
+ ds.mimeType = 'text/plain'
60
+ ds.save
61
+ end
62
+
63
+ it "should create a redirect datastream" do
64
+ obj = @repository.find('test:1')
65
+ ds = obj.datastreams["Redirect"]
66
+ ds.controlGroup = "R"
67
+ ds.dsLocation = "http://example.org"
68
+ ds.save
69
+ end
70
+
71
+ it "should have datastreams" do
72
+ obj = @repository.find('test:1')
73
+ obj.datastreams.keys.should include("Test")
74
+ obj.datastreams.keys.should include("Redirect")
75
+ end
76
+
77
+ it "should have datastream content" do
78
+ obj = @repository.find('test:1')
79
+ obj.datastreams["Test"].content.should match( "Integration testing against a live Fedora repository")
80
+ end
81
+
82
+ it "should delete datastreams" do
83
+ obj = @repository.find('test:1')
84
+ ds = obj.datastreams["Test"].delete
85
+ obj.datastreams.keys.should_not include("Test")
86
+ end
87
+
88
+
89
+ after(:all) do
90
+ @repository.find('test:1').delete rescue nil
91
+ @repository.find('test:2').delete rescue nil
92
+ end
93
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubydora::Repository do
4
+ before(:each) do
5
+ @repository = Rubydora::Repository.new
6
+ end
7
+
8
+ describe "client" do
9
+ it "should return a RestClient resource" do
10
+ client = @repository.client :url => 'http://example.org', :user => 'fedoraAdmin', :password => 'fedoraAdmin'
11
+
12
+ client.should be_a_kind_of(RestClient::Resource)
13
+ end
14
+ end
15
+
16
+ describe "find" do
17
+
18
+ it "should load objects by pid" do
19
+ @mock_object = mock(Rubydora::DigitalObject)
20
+ Rubydora::DigitalObject.should_receive(:find).with("pid", instance_of(Rubydora::Repository)).and_return @mock_object
21
+
22
+ @repository.find('pid')
23
+ end
24
+
25
+ end
26
+
27
+ describe "sparql" do
28
+ it "should return csv results for sparql queries" do
29
+ resource_index_query = ""
30
+ @repository.should_receive(:risearch).with(resource_index_query).and_return("pid\na\nb\nc\n")
31
+
32
+ csv = @repository.sparql(resource_index_query)
33
+ end
34
+
35
+ describe "profile" do
36
+ it "should map the fedora repository description to a hash" do
37
+ @mock_response = mock()
38
+ @mock_client = mock(RestClient::Resource)
39
+ @mock_response.should_receive(:get).and_return <<-XML
40
+ <?xml version="1.0" encoding="UTF-8"?><fedoraRepository xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/ http://www.fedora.info/definitions/1/0/fedoraRepository.xsd"><repositoryName>Fedora Repository</repositoryName><repositoryBaseURL>http://localhost:8983/fedora</repositoryBaseURL><repositoryVersion>3.3</repositoryVersion><repositoryPID> <PID-namespaceIdentifier>changeme</PID-namespaceIdentifier> <PID-delimiter>:</PID-delimiter> <PID-sample>changeme:100</PID-sample> <retainPID>*</retainPID></repositoryPID><repositoryOAI-identifier> <OAI-namespaceIdentifier>example.org</OAI-namespaceIdentifier> <OAI-delimiter>:</OAI-delimiter> <OAI-sample>oai:example.org:changeme:100</OAI-sample></repositoryOAI-identifier><sampleSearch-URL>http://localhost:8983/fedora/search</sampleSearch-URL><sampleAccess-URL>http://localhost:8983/fedora/get/demo:5</sampleAccess-URL><sampleOAI-URL>http://localhost:8983/fedora/oai?verb=Identify</sampleOAI-URL><adminEmail>bob@example.org</adminEmail><adminEmail>sally@example.org</adminEmail></fedoraRepository>
41
+ XML
42
+ @mock_client.should_receive(:[]).with('describe?xml=true').and_return(@mock_response)
43
+ @repository.should_receive(:client).and_return(@mock_client)
44
+ profile = @repository.profile
45
+ profile['repositoryVersion'].should == '3.3'
46
+ end
47
+ end
48
+
49
+ describe "ping" do
50
+ it "should raise an error if a connection cannot be established" do
51
+ @repository.should_receive(:profile).and_return nil
52
+ lambda { @repository.ping }.should raise_error
53
+ end
54
+ end
55
+
56
+
57
+ end
58
+
59
+ describe "load_api_abstraction" do
60
+ class ApiAbstractionTestClass < Rubydora::Repository
61
+ def version; 3.3; end
62
+ end
63
+ it "should load an abstraction layer for relationships for older versions of the fedora rest api" do
64
+ @mock_repository = ApiAbstractionTestClass.new
65
+ @mock_repository.should be_a_kind_of(Rubydora::RestApiClient::V33)
66
+ end
67
+ end
68
+
69
+ describe "find_by_sparql" do
70
+ it "should attempt to load objects from the results of a sparql query" do
71
+
72
+ resource_index_query = ""
73
+ @repository.should_receive(:risearch).with(resource_index_query).and_return("pid\na\nb\nc\n")
74
+
75
+ @repository.should_receive(:find).with('a').and_return(1)
76
+ @repository.should_receive(:find).with('b').and_return(1)
77
+ @repository.should_receive(:find).with('c').and_return(1)
78
+
79
+ objects = @repository.find_by_sparql(resource_index_query)
80
+
81
+ objects.length.should == 3
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubydora::ResourceIndex do
4
+ class MockRepository
5
+ include Rubydora::ResourceIndex
6
+ end
7
+
8
+ before(:each) do
9
+ @mock_repository = MockRepository.new
10
+ end
11
+
12
+ it "should map a simple relationship query into SPARQL" do
13
+ @mock_repository.should_receive(:find_by_sparql) do |query|
14
+ query.should match(/\<pid\> \<predicate\> \?pid/)
15
+ end
16
+
17
+ @mock_repository.find_by_sparql_relationship('pid', 'predicate')
18
+ end
19
+
20
+ it "should send sparql queries with appropriate parameters" do
21
+ @mock_risearch = mock()
22
+ @mock_client = mock(RestClient::Resource)
23
+ @mock_risearch.should_receive(:post).with(hash_including(:dt => 'on', :format => 'CSV', :lang => 'sparql', :limit => nil, :query => 'placeholder SPARQL query', :type => 'tuples' ))
24
+ @mock_client.should_receive(:[]).with('risearch').and_return(@mock_risearch)
25
+ @mock_repository.should_receive(:client).and_return(@mock_client)
26
+ @mock_repository.send(:risearch, 'placeholder SPARQL query')
27
+ end
28
+ end
@@ -0,0 +1,146 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubydora::RestApiClient do
4
+ class MockRepository
5
+ include Rubydora::RestApiClient
6
+
7
+ attr_accessor :config
8
+ end
9
+
10
+ before(:each) do
11
+ @mock_repository = MockRepository.new
12
+ @mock_repository.config = { :url => 'http://example.org',:user => 'fedoraAdmin', :password => 'fedoraAdmin'}
13
+ end
14
+
15
+ it "should call nextPID" do
16
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/nextPID?format=xml"))
17
+ @mock_repository.next_pid
18
+ end
19
+
20
+ it "should find objects" do
21
+ RestClient::Request.should_receive(:execute) do |params|
22
+ params.should have_key(:url)
23
+ params[:url].should =~ /^#{Regexp.escape("http://example.org/objects?")}.*query=a/
24
+ end
25
+ @mock_repository.find_objects :query => 'a'
26
+ end
27
+
28
+ it "should show object properties" do
29
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/z?format=xml"))
30
+ @mock_repository.object :pid => 'z'
31
+ end
32
+
33
+ it "ingest" do
34
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/new"))
35
+ @mock_repository.ingest
36
+ end
37
+
38
+ it "ingest with pid" do
39
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid"))
40
+ @mock_repository.ingest :pid => 'mypid'
41
+ end
42
+
43
+ it "modify_object" do
44
+ RestClient::Request.should_receive(:execute) do |params|
45
+ params.should have_key(:url)
46
+ params[:url].should =~ /^#{Regexp.escape("http://example.org/objects/mypid?")}.*state=Z/
47
+ end
48
+ @mock_repository.modify_object :pid => 'mypid', :state => 'Z'
49
+ end
50
+
51
+ it "purge_object" do
52
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid"))
53
+ @mock_repository.purge_object :pid => 'mypid'
54
+ end
55
+
56
+ it "object_versions" do
57
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/versions?format=xml"))
58
+ @mock_repository.object_versions :pid => 'mypid'
59
+ end
60
+
61
+ it "object_xml" do
62
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/objectXML?format=xml"))
63
+ @mock_repository.object_xml :pid => 'mypid'
64
+ end
65
+
66
+ it "datastream" do
67
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams?format=xml"))
68
+ @mock_repository.datastream :pid => 'mypid'
69
+ end
70
+
71
+ it "datastream" do
72
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa?format=xml"))
73
+ @mock_repository.datastream :pid => 'mypid', :dsid => 'aaa'
74
+ end
75
+
76
+ it "datastream_dissemination" do
77
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/content"))
78
+ @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa'
79
+ end
80
+
81
+ it "add_datastream" do
82
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa"))
83
+ @mock_repository.add_datastream :pid => 'mypid', :dsid => 'aaa'
84
+ end
85
+
86
+ it "modify_datastream" do
87
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa"))
88
+ @mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa'
89
+ end
90
+
91
+ it "purge_datastream" do
92
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa"))
93
+ @mock_repository.purge_datastream :pid => 'mypid', :dsid => 'aaa'
94
+ end
95
+
96
+ it "set_datastream_options" do
97
+ RestClient::Request.should_receive(:execute) do |params|
98
+ params.should have_key(:url)
99
+ params[:url].should =~ /^#{Regexp.escape("http://example.org/objects/mypid/datastreams/aaa?")}.*aparam=true/
100
+ end
101
+ @mock_repository.set_datastream_options :pid => 'mypid', :dsid => 'aaa', :aparam => true
102
+ end
103
+
104
+ it "datastream_versions" do
105
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/versions?format=xml"))
106
+ @mock_repository.datastream_versions :pid => 'mypid', :dsid => 'aaa'
107
+
108
+ end
109
+
110
+ it "relationships" do
111
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/relationships?format=xml"))
112
+ @mock_repository.relationships :pid => 'mypid'
113
+ end
114
+
115
+ it "add_relationship" do
116
+ RestClient::Request.should_receive(:execute) do |params|
117
+ params.should have_key(:url)
118
+ params[:url].should =~ /^#{Regexp.escape("http://example.org/objects/mypid/relationships/new?")}.*subject=z/
119
+ end
120
+ @mock_repository.add_relationship :pid => 'mypid', :subject => 'z'
121
+ end
122
+
123
+ it "purge_relationships" do
124
+ RestClient::Request.should_receive(:execute) do |params|
125
+ params.should have_key(:url)
126
+ params[:url].should =~ /^#{Regexp.escape("http://example.org/objects/mypid/relationships?")}.*subject=z/
127
+ end
128
+ @mock_repository.purge_relationship :pid => 'mypid', :subject => 'z'
129
+ end
130
+
131
+ it "dissemination" do
132
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods?format=xml"))
133
+ @mock_repository.dissemination :pid => 'mypid'
134
+ end
135
+
136
+ it "dissemination" do
137
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods/sdef?format=xml"))
138
+ @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef'
139
+ end
140
+
141
+ it "dissemination" do
142
+ RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/methods/sdef/method"))
143
+ @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef', :method => 'method'
144
+ end
145
+
146
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rubydora'
4
+ require 'rspec'