harvestdor 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,194 @@
1
+ require "spec_helper"
2
+
3
+ # these are Integration specs! They do go out to the purl page.
4
+ describe Harvestdor::Client do
5
+
6
+ before(:all) do
7
+ @druid = 'bb375wb8869'
8
+ @purl = 'http://purl-test.stanford.edu'
9
+ @id_md_xml = "<identityMetadata><objectId>druid:#{@druid}</objectId></identityMetadata>"
10
+ @cntnt_md_xml = "<contentMetadata type='image' objectId='#{@druid}'>foo</contentMetadata>"
11
+ @rights_md_xml = "<rightsMetadata><access type=\"discover\"><machine><world>bar</world></machine></access></rightsMetadata>"
12
+ @rdf_xml = "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'><rdf:Description rdf:about=\"info:fedora/druid:#{@druid}\">relationship!</rdf:Description></rdf:RDF>"
13
+ @dc_xml = "<oai_dc:dc xmlns:oai_dc='#{Harvestdor::OAI_DC_NAMESPACE}'><oai_dc:title>hoo ha</oai_dc:title</oai_dc:dc>"
14
+ @pub_xml = "<publicObject id='druid:#{@druid}'>#{@id_md_xml}#{@cntnt_md_xml}#{@rights_md_xml}#{@rdf_xml}#{@dc_xml}</publicObject>"
15
+ @ng_pub_xml = Nokogiri::XML(@pub_xml)
16
+ @fake_druid = 'oo000oo0000'
17
+ end
18
+
19
+ it "#mods returns a Nokogiri::XML::Document from the purl mods" do
20
+ x = Harvestdor.mods(@druid, @purl)
21
+ x.should be_kind_of(Nokogiri::XML::Document)
22
+ x.root.name.should == 'mods'
23
+ x.root.namespace.href.should == Harvestdor::MODS_NAMESPACE
24
+ end
25
+
26
+ context "#public_xml" do
27
+ it "#public_xml retrieves entire public xml as a Nokogiri::XML::Document when called with druid" do
28
+ px = Harvestdor.public_xml(@druid, @purl)
29
+ px.should be_kind_of(Nokogiri::XML::Document)
30
+ px.root.name.should == 'publicObject'
31
+ px.root.attributes['id'].text.should == "druid:#{@druid}"
32
+ end
33
+ it "raises Harvestdor::Errors::MissingPurlPage if there is no purl page for the druid" do
34
+ expect { Harvestdor.public_xml(@fake_druid, @purl) }.to raise_error(Harvestdor::Errors::MissingPurlPage)
35
+ end
36
+ it "raises Harvestdor::Errors::MissingPublicXML if purl page returns nil document" do
37
+ URI::HTTP.any_instance.should_receive(:open).and_return(nil)
38
+ expect { Harvestdor.public_xml(@fake_druid, @purl) }.to raise_error(Harvestdor::Errors::MissingPublicXml)
39
+ end
40
+ end
41
+
42
+ context "#pub_xml" do
43
+ it "retrieves public_xml via fetch when first arg is a druid" do
44
+ Harvestdor.should_receive(:public_xml).with(@druid, @purl)
45
+ Harvestdor.pub_xml(@druid, @purl)
46
+ end
47
+ it "returns the first arg if it is a Nokogiri::XML::Document" do
48
+ Harvestdor.pub_xml(@ng_pub_xml).should === @ng_pub_xml
49
+ end
50
+ it "raises error for unknown arg type" do
51
+ expect { Harvestdor.pub_xml(Array.new)}.to raise_error(RuntimeError, "expected String or Nokogiri::XML::Document for first argument, got Array")
52
+ end
53
+ end
54
+
55
+ context "#content_metadata" do
56
+ it "returns a Nokogiri::XML::Document from the public xml fetched with druid" do
57
+ cm = Harvestdor.content_metadata(@druid, @purl)
58
+ cm.should be_kind_of(Nokogiri::XML::Document)
59
+ cm.root.name.should == 'contentMetadata'
60
+ cm.root.attributes['objectId'].text.should == @druid
61
+ end
62
+ it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
63
+ cm = Harvestdor.content_metadata(@ng_pub_xml)
64
+ cm.should be_kind_of(Nokogiri::XML::Document)
65
+ cm.root.name.should == 'contentMetadata'
66
+ cm.root.attributes['objectId'].text.should == @druid
67
+ end
68
+ it "raises MissingContentMetadata error if there is no contentMetadata in the public_xml for the druid" do
69
+ pub_xml = "<publicObject id='druid:#{@druid}'>#{@id_md_xml}#{@rights_md_xml}</publicObject>"
70
+ expect { Harvestdor.content_metadata(Nokogiri::XML(pub_xml)) }.to raise_error(Harvestdor::Errors::MissingContentMetadata)
71
+ end
72
+ end
73
+
74
+ context "#identity_metadata" do
75
+ it "returns a Nokogiri::XML::Document from the public xml fetched with druid" do
76
+ im = Harvestdor.identity_metadata(@druid, @purl)
77
+ im.should be_kind_of(Nokogiri::XML::Document)
78
+ im.root.name.should == 'identityMetadata'
79
+ im.root.xpath('objectId').text.should == "druid:#{@druid}"
80
+ end
81
+ it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
82
+ URI::HTTP.any_instance.should_not_receive(:open)
83
+ im = Harvestdor.identity_metadata(@ng_pub_xml)
84
+ im.should be_kind_of(Nokogiri::XML::Document)
85
+ im.root.name.should == 'identityMetadata'
86
+ im.root.xpath('objectId').text.should == "druid:#{@druid}"
87
+ end
88
+ it "raises MissingIdentityMetadata error if there is no identityMetadata in the public_xml for the druid" do
89
+ pub_xml = "<publicObject id='druid:#{@druid}'>#{@cntnt_md_xml}#{@rights_md_xml}</publicObject>"
90
+ expect { Harvestdor.identity_metadata(Nokogiri::XML(pub_xml)) }.to raise_error(Harvestdor::Errors::MissingIdentityMetadata)
91
+ end
92
+ end
93
+
94
+ context "#rights_metadata" do
95
+ it "#rights_metadata returns a Nokogiri::XML::Document from the public xml fetched with druid" do
96
+ rm = Harvestdor.rights_metadata(@druid, @purl)
97
+ rm.should be_kind_of(Nokogiri::XML::Document)
98
+ rm.root.name.should == 'rightsMetadata'
99
+ end
100
+ it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
101
+ URI::HTTP.any_instance.should_not_receive(:open)
102
+ rm = Harvestdor.rights_metadata(@ng_pub_xml)
103
+ rm.should be_kind_of(Nokogiri::XML::Document)
104
+ rm.root.name.should == 'rightsMetadata'
105
+ end
106
+ it "raises MissingRightsMetadata error if there is no identityMetadata in the public_xml for the druid" do
107
+ pub_xml = "<publicObject id='druid:#{@druid}'>#{@cntnt_md_xml}#{@id_md_xml}</publicObject>"
108
+ expect { Harvestdor.rights_metadata(Nokogiri::XML(pub_xml)) }.to raise_error(Harvestdor::Errors::MissingRightsMetadata)
109
+ end
110
+ end
111
+
112
+ context "#rdf" do
113
+ it "returns a Nokogiri::XML::Document from the public xml fetched with druid" do
114
+ rdf = Harvestdor.rdf(@druid, @purl)
115
+ rdf.should be_kind_of(Nokogiri::XML::Document)
116
+ rdf.root.name.should == 'RDF'
117
+ rdf.root.namespace.href.should == Harvestdor::RDF_NAMESPACE
118
+ end
119
+ it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
120
+ URI::HTTP.any_instance.should_not_receive(:open)
121
+ rdf = Harvestdor.rdf(@ng_pub_xml)
122
+ rdf.should be_kind_of(Nokogiri::XML::Document)
123
+ rdf.root.name.should == 'RDF'
124
+ rdf.root.namespace.href.should == Harvestdor::RDF_NAMESPACE
125
+ end
126
+ it "raises MissingRDF error if there is no RDF in the public_xml for the druid" do
127
+ pub_xml = "<publicObject id='druid:#{@druid}'>#{@cntnt_md_xml}#{@id_md_xml}</publicObject>"
128
+ expect { Harvestdor.rdf(Nokogiri::XML(pub_xml)) }.to raise_error(Harvestdor::Errors::MissingRDF)
129
+ end
130
+ end
131
+
132
+ context "#dc" do
133
+ it "returns a Nokogiri::XML::Document from the public xml fetched with druid" do
134
+ dc = Harvestdor.dc(@druid, @purl)
135
+ dc.should be_kind_of(Nokogiri::XML::Document)
136
+ dc.root.name.should == 'dc'
137
+ dc.root.namespace.href.should == Harvestdor::OAI_DC_NAMESPACE
138
+ end
139
+ it "returns a Nokogiri::XML::Document from passed Nokogiri::XML::Document and does no fetch" do
140
+ URI::HTTP.any_instance.should_not_receive(:open)
141
+ dc = Harvestdor.dc(@ng_pub_xml)
142
+ dc.should be_kind_of(Nokogiri::XML::Document)
143
+ dc.root.name.should == 'dc'
144
+ dc.root.namespace.href.should == Harvestdor::OAI_DC_NAMESPACE
145
+ end
146
+ it "raises MissingDC error if there is no DC in the public_xml for the druid" do
147
+ pub_xml = "<publicObject id='druid:#{@druid}'>#{@cntnt_md_xml}#{@id_md_xml}</publicObject>"
148
+ expect { Harvestdor.dc(Nokogiri::XML(pub_xml)) }.to raise_error(Harvestdor::Errors::MissingDC)
149
+ end
150
+ end
151
+
152
+ context "Harvestdor:Client calls methods with config.purl" do
153
+ before(:all) do
154
+ @client = Harvestdor::Client.new({:purl_url => 'http://thisone.org'})
155
+ @druid = 'bb375wb8869'
156
+ end
157
+ it "public_xml calls Harvestdor.public_xml with config.purl" do
158
+ Harvestdor.should_receive(:public_xml).with(@druid, @client.config.purl)
159
+ @client.public_xml(@druid)
160
+ end
161
+ it "content_metadata calls Harvestdor.content_metadata with config.purl" do
162
+ Harvestdor.should_receive(:content_metadata).with(@druid, @client.config.purl)
163
+ @client.content_metadata(@druid)
164
+ end
165
+ it "identity_metadata calls Harvestdor.identity_metadata with config.purl" do
166
+ Harvestdor.should_receive(:identity_metadata).with(@druid, @client.config.purl)
167
+ @client.identity_metadata(@druid)
168
+ end
169
+ it "rights_metadata calls Harvestdor.rights_metadata with config.purl" do
170
+ Harvestdor.should_receive(:rights_metadata).with(@druid, @client.config.purl)
171
+ @client.rights_metadata(@druid)
172
+ end
173
+ it "rdf calls Harvestdor.rdf with config.purl" do
174
+ Harvestdor.should_receive(:rdf).with(@druid, @client.config.purl)
175
+ @client.rdf(@druid)
176
+ end
177
+ it "dc calls Harvestdor.dc with config.purl" do
178
+ Harvestdor.should_receive(:dc).with(@druid, @client.config.purl)
179
+ @client.dc(@druid)
180
+ end
181
+ it "mods calls Harvestdor.mods with config.purl" do
182
+ Harvestdor.should_receive(:mods).with(@druid, @client.config.purl)
183
+ @client.mods(@druid)
184
+ end
185
+ it "methods for parts of public_xml should work with Nokogiri::XML::Document arg (and not fetch)" do
186
+ URI::HTTP.any_instance.should_not_receive(:open)
187
+ @client.content_metadata(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
188
+ @client.identity_metadata(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
189
+ @client.rights_metadata(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
190
+ @client.rdf(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
191
+ @client.dc(@ng_pub_xml).should be_kind_of(Nokogiri::XML::Document)
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,21 @@
1
+ # for test coverage
2
+ require 'simplecov'
3
+ require 'simplecov-rcov'
4
+ class SimpleCov::Formatter::MergedFormatter
5
+ def format(result)
6
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
7
+ SimpleCov::Formatter::RcovFormatter.new.format(result)
8
+ end
9
+ end
10
+ SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
11
+ SimpleCov.start do
12
+ add_filter "/spec/"
13
+ end
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+
18
+ require 'harvestdor'
19
+
20
+ #RSpec.configure do |config|
21
+ #end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harvestdor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.13
5
+ platform: ruby
6
+ authors:
7
+ - Naomi Dushay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oai
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.3.0
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: 0.9.0
39
+ prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: confstruct
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ prerelease: false
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ prerelease: false
110
+ type: :development
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ prerelease: false
124
+ type: :development
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirement: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ prerelease: false
138
+ type: :development
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov-rcov
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirement: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ prerelease: false
152
+ type: :development
153
+ description: Harvest DOR object metadata via a relationship (e.g. hydra:isGovernedBy rdf:resource="info:fedora/druid:hy787xj5878") and dates
154
+ email:
155
+ - ndushay@stanford.edu
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - .gitignore
161
+ - .travis.yml
162
+ - .yardopts
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.rdoc
166
+ - Rakefile
167
+ - harvestdor.gemspec
168
+ - lib/harvestdor.rb
169
+ - lib/harvestdor/errors.rb
170
+ - lib/harvestdor/oai_harvest.rb
171
+ - lib/harvestdor/purl_xml.rb
172
+ - lib/harvestdor/version.rb
173
+ - spec/config/oai.yml
174
+ - spec/harvestdor_client_spec.rb
175
+ - spec/harvestdor_spec.rb
176
+ - spec/oai_harvest_spec.rb
177
+ - spec/oai_integration_spec.rb
178
+ - spec/purl_xml_spec.rb
179
+ - spec/spec_helper.rb
180
+ homepage: https://consul.stanford.edu/display/chimera/Chimera+project
181
+ licenses: []
182
+ metadata: {}
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.1.9
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: Harvest DOR object metadata
203
+ test_files:
204
+ - spec/config/oai.yml
205
+ - spec/harvestdor_client_spec.rb
206
+ - spec/harvestdor_spec.rb
207
+ - spec/oai_harvest_spec.rb
208
+ - spec/oai_integration_spec.rb
209
+ - spec/purl_xml_spec.rb
210
+ - spec/spec_helper.rb
211
+ has_rdoc: