umlaut-primo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +10 -0
  3. data/Rakefile +35 -0
  4. data/lib/umlaut_primo/primo_service.rb +522 -0
  5. data/lib/umlaut_primo/primo_source.rb +59 -0
  6. data/lib/umlaut_primo/version.rb +3 -0
  7. data/lib/umlaut_primo.rb +2 -0
  8. data/test/dummy/Rakefile +7 -0
  9. data/test/dummy/app/assets/images/rails.png +0 -0
  10. data/test/dummy/app/assets/javascripts/application.js +15 -0
  11. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  12. data/test/dummy/app/controllers/application_controller.rb +3 -0
  13. data/test/dummy/app/controllers/umlaut_controller.rb +122 -0
  14. data/test/dummy/app/helpers/application_helper.rb +2 -0
  15. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  16. data/test/dummy/config/application.rb +63 -0
  17. data/test/dummy/config/boot.rb +6 -0
  18. data/test/dummy/config/database.yml +61 -0
  19. data/test/dummy/config/environment.rb +5 -0
  20. data/test/dummy/config/environments/development.rb +41 -0
  21. data/test/dummy/config/environments/production.rb +67 -0
  22. data/test/dummy/config/environments/test.rb +37 -0
  23. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  24. data/test/dummy/config/initializers/inflections.rb +15 -0
  25. data/test/dummy/config/initializers/mime_types.rb +5 -0
  26. data/test/dummy/config/initializers/secret_token.rb +7 -0
  27. data/test/dummy/config/initializers/session_store.rb +8 -0
  28. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  29. data/test/dummy/config/locales/en.yml +5 -0
  30. data/test/dummy/config/primo.yml +55 -0
  31. data/test/dummy/config/routes.rb +60 -0
  32. data/test/dummy/config/umlaut_services.yml +29 -0
  33. data/test/dummy/config.ru +4 -0
  34. data/test/dummy/db/migrate/20130306173028_umlaut_init.umlaut.rb +106 -0
  35. data/test/dummy/db/migrate/20130306173029_umlaut_add_service_response_index.umlaut.rb +10 -0
  36. data/test/dummy/db/schema.rb +118 -0
  37. data/test/dummy/db/seeds.rb +7 -0
  38. data/test/dummy/log/development.log +4 -0
  39. data/test/dummy/log/test.log +19611 -0
  40. data/test/dummy/public/404.html +26 -0
  41. data/test/dummy/public/422.html +26 -0
  42. data/test/dummy/public/500.html +25 -0
  43. data/test/dummy/public/favicon.ico +0 -0
  44. data/test/dummy/public/robots.txt +5 -0
  45. data/test/dummy/script/rails +6 -0
  46. data/test/fixtures/referent_values.yml +96 -0
  47. data/test/fixtures/referents.yml +12 -0
  48. data/test/fixtures/requests.yml +20 -0
  49. data/test/fixtures/sfx_urls.yml +4 -0
  50. data/test/test_helper.rb +30 -0
  51. data/test/unit/primo_service_test.rb +228 -0
  52. data/test/unit/primo_source_test.rb +78 -0
  53. data/test/vcr_cassettes/australian_journal_of_international_affairs_by_id.yml +284 -0
  54. data/test/vcr_cassettes/musical_quarterly_by_issn.yml +263 -0
  55. data/test/vcr_cassettes/travels_with_my_by_id.yml +167 -0
  56. metadata +284 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,96 @@
1
+ travels_with_my_aunt_1:
2
+ referent: travels_with_my_aunt
3
+ key_name: "format"
4
+ value: "book"
5
+ normalized_value: "book"
6
+ metadata: true
7
+ private_data: false
8
+
9
+ travels_with_my_aunt_2:
10
+ referent: travels_with_my_aunt
11
+ key_name: "genre"
12
+ value: "book"
13
+ normalized_value: "book"
14
+ metadata: true
15
+ private_data: false
16
+
17
+ travels_with_my_aunt_3:
18
+ referent: travels_with_my_aunt
19
+ key_name: "title"
20
+ value: "Travels with my aunt"
21
+ normalized_value: "Travels with my aunt"
22
+ metadata: true
23
+ private_data: false
24
+
25
+ travels_with_my_aunt_4:
26
+ referent: travels_with_my_aunt
27
+ key_name: "btitle"
28
+ value: "Travels with my aunt"
29
+ normalized_value: "Travels with my aunt"
30
+ metadata: true
31
+ private_data: false
32
+
33
+ travels_with_my_aunt_5:
34
+ referent: travels_with_my_aunt
35
+ key_name: "isbn"
36
+ value: "0143039008"
37
+ normalized_value: "0143039008"
38
+ metadata: true
39
+ private_data: false
40
+
41
+ australian_journal_of_international_affairs_1:
42
+ referent: australian_journal_of_international_affairs
43
+ key_name: "format"
44
+ value: "journal"
45
+ normalized_value: "journal"
46
+ metadata: false
47
+ private_data: false
48
+
49
+ australian_journal_of_international_affairs_2:
50
+ referent: australian_journal_of_international_affairs
51
+ key_name: "genre"
52
+ value: "journal"
53
+ normalized_value: "journal"
54
+ metadata: true
55
+ private_data: false
56
+
57
+ australian_journal_of_international_affairs_3:
58
+ referent: australian_journal_of_international_affairs
59
+ key_name: "issn"
60
+ value: "1035-7718"
61
+ normalized_value: "1035-7718"
62
+ metadata: true
63
+ private_data: false
64
+
65
+ the_musical_quarterly_1:
66
+ referent: the_musical_quarterly
67
+ key_name: "format"
68
+ value: "journal"
69
+ normalized_value: "journal"
70
+ metadata: true
71
+ private_data: false
72
+
73
+ the_musical_quarterly_2:
74
+ referent: the_musical_quarterly
75
+ key_name: "genre"
76
+ value: "journal"
77
+ normalized_value: "journal"
78
+ metadata: true
79
+ private_data: false
80
+
81
+ the_musical_quarterly_3:
82
+ referent: the_musical_quarterly
83
+ key_name: "title"
84
+ value: "The Musical quarterly."
85
+ normalized_value: "The Musical quarterly."
86
+ metadata: true
87
+ private_data: false
88
+
89
+ the_musical_quarterly_4:
90
+ referent: the_musical_quarterly
91
+ key_name: "issn"
92
+ value: "0027-4631"
93
+ normalized_value: "0027-4631"
94
+ metadata: true
95
+ private_data: false
96
+
@@ -0,0 +1,12 @@
1
+ travels_with_my_aunt:
2
+ title: "Travels with my aunt"
3
+ isbn: "0143039008"
4
+
5
+ australian_journal_of_international_affairs:
6
+ title: "Australian journal of international affairs"
7
+ issn: "1035-7718"
8
+
9
+ the_musical_quarterly:
10
+ title: "The Musical quarterly."
11
+ issn: "0027-4631"
12
+
@@ -0,0 +1,20 @@
1
+ travels_with_my_aunt_by_id:
2
+ referrer_id: info:sid/primo.exlibrisgroup.com:primo-aleph000062856
3
+ referent: travels_with_my_aunt
4
+
5
+ travels_with_my_aunt_by_isbn:
6
+ referent: travels_with_my_aunt
7
+
8
+ australian_journal_of_international_affairs_by_id:
9
+ referrer_id: info:sid/primo.exlibrisgroup.com:primo-dedupmrg17737330
10
+ referent: australian_journal_of_international_affairs
11
+
12
+ australian_journal_of_international_affairs_by_issn:
13
+ referent: australian_journal_of_international_affairs
14
+
15
+ the_musical_quarterly_by_id:
16
+ referrer_id: info:sid/primo.exlibrisgroup.com:primo-aleph002895625
17
+ referent: the_musical_quarterly
18
+
19
+ the_musical_quarterly_by_issn:
20
+ referent: the_musical_quarterly
@@ -0,0 +1,4 @@
1
+ gateway:
2
+ url: gateway.ovid.com
3
+ proquest:
4
+ url: proquest.umi.com
@@ -0,0 +1,30 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+ # Configure Rails Environment
4
+ ENV["RAILS_ENV"] = "test"
5
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
+ require "rails/test_help"
7
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
8
+ Rails.backtrace_cleaner.remove_silencers!
9
+ # Complete stack trace with deprecation warnings from rails
10
+ ActiveSupport::Deprecation.debug = true
11
+
12
+ require File.expand_path("../../lib/umlaut_primo.rb", __FILE__)
13
+
14
+ # VCR is used to 'record' HTTP interactions with
15
+ # third party services used in tests, and play em
16
+ # back. Useful for efficiency, also useful for
17
+ # testing code against API's that not everyone
18
+ # has access to -- the responses can be cached
19
+ # and re-used.
20
+ require 'vcr'
21
+ require 'webmock'
22
+
23
+ VCR.configure do |c|
24
+ c.cassette_library_dir = 'test/vcr_cassettes'
25
+ # webmock needed for HTTPClient testing
26
+ c.hook_into :webmock
27
+ # c.debug_logger = $stderr
28
+ c.filter_sensitive_data("primo.library.edu") { "bobcat.library.nyu.edu" }
29
+ c.filter_sensitive_data("LIB01") { "NYU01" }
30
+ end
@@ -0,0 +1,228 @@
1
+ require 'test_helper'
2
+ require 'fileutils'
3
+ class PrimoServiceTest < ActiveSupport::TestCase
4
+ fixtures :requests, :referents, :referent_values, :sfx_urls
5
+
6
+ setup do
7
+ @base_url = "http://bobcat.library.nyu.edu"
8
+ @vid = "VID"
9
+ @institution = "NYU"
10
+ @holding_search_institution = "NYU"
11
+ @holding_search_text = "Search for this title in BobCat."
12
+ @holding_search_institution = "NYU"
13
+ @primo_minimum = PrimoService.new({
14
+ "priority"=>1, "service_id" => "Primo",
15
+ "base_url" => @base_url, "vid" => @vid, "institution" => @institution,
16
+ "holding_search_institution" => @holding_search_institution })
17
+ @primo_old_minimum = PrimoService.new({
18
+ "priority"=>1, "service_id" => "Primo",
19
+ "base_path" => @base_url, "base_view_id" => @vid, "institution" => @institution })
20
+ @primo_minimum_no_config = PrimoService.new({
21
+ "priority"=>1, "service_id" => "Primo",
22
+ "base_url" => @base_url, "vid" => @vid, "institution" => @institution,
23
+ "holding_search_institution" => @holding_search_institution,
24
+ "primo_config" => "missing_config.yml" })
25
+ @primo_service = ServiceStore.instantiate_service!("Primo", nil)
26
+ end
27
+
28
+ test "missing primo config" do
29
+ @primo_minimum.send(:reset_primo_config)
30
+ FileUtils.mv(PrimoService.default_config_file, "#{PrimoService.default_config_file}.bak")
31
+ assert_nothing_raised {
32
+ PrimoService.new({
33
+ "priority"=>1, "service_id" => "Primo",
34
+ "base_url" => @base_url, "vid" => @vid, "institution" => @institution,
35
+ "holding_search_institution" => @holding_search_institution})
36
+ }
37
+ FileUtils.mv("#{PrimoService.default_config_file}.bak", PrimoService.default_config_file)
38
+ end
39
+
40
+ test "minimum config request by id" do
41
+ request = requests(:travels_with_my_aunt_by_id)
42
+ VCR.use_cassette("travels with my by id") do
43
+ @primo_minimum.handle(request)
44
+ end
45
+
46
+ # Get latest from the DB after handling the service.
47
+ request.referent.referent_values.reset
48
+ request.dispatched_services.reset
49
+ request.service_responses.reset
50
+
51
+ # Test that the referent was enhanced
52
+ assert_equal("Greene", request.referent.metadata["aulast"])
53
+ assert_equal("Graham,", request.referent.metadata["aufirst"])
54
+ assert_equal("Greene, Graham, 1904-1991", request.referent.metadata["au"])
55
+ assert_equal("Travels with my aunt", request.referent.metadata["title"])
56
+ assert_equal("Travels with my aunt", request.referent.metadata["btitle"])
57
+ assert_equal("New York", request.referent.metadata["place"])
58
+ assert_equal("Penguin Books", request.referent.metadata["pub"])
59
+ assert_equal("56781200", request.referent.metadata["oclcnum"])
60
+ assert_equal("2004559272", request.referent.metadata["lccn"])
61
+
62
+ # Get the returned holdings service responses
63
+ holdings = request.get_service_type('holding')
64
+ # Should only be 1 holding service response
65
+ assert_equal(1, holdings.length)
66
+ # Get the holding service response view data
67
+ view_data = holdings.first.view_data
68
+ # Test the holding service response view data
69
+ assert_equal("aleph000062856", view_data[:record_id])
70
+ assert_equal("aleph", view_data[:source_id])
71
+ assert_equal("NYU01", view_data[:original_source_id])
72
+ assert_equal("000062856", view_data[:source_record_id])
73
+ assert_equal("NYU", view_data[:institution_code])
74
+ assert_equal("NYU", view_data[:institution])
75
+ assert_equal("BOBST", view_data[:library_code])
76
+ assert_equal("NYU Bobst", view_data[:library])
77
+ assert_equal("check_holdings", view_data[:status_code])
78
+ assert_equal("Check Availability", view_data[:status])
79
+ assert_equal("Main Collection", view_data[:collection])
80
+ assert_equal("(PR6013.R44 T7 2004 )", view_data[:call_number])
81
+ assert_equal(nil, view_data[:origin])
82
+ assert_equal("book", view_data[:display_type])
83
+ assert_equal([], view_data[:coverage])
84
+ assert_equal({}, view_data[:source_data])
85
+ assert_equal("#{@base_url}/primo_library/libweb/action/dlDisplay.do?docId=aleph000062856&institution=NYU&vid=#{@vid}", view_data[:url])
86
+ assert_equal(nil, view_data[:request_url])
87
+ assert_equal(ServiceResponse::MatchExact, view_data[:match_reliability])
88
+
89
+ # Get the returned table of contents service responses
90
+ tables_of_contents = request.get_service_type('table_of_contents')
91
+ # Should only be 1 table of contents service response
92
+ assert_equal(1, tables_of_contents.length)
93
+ assert_equal("https://ezproxy.library.edu/login?url=http://dummy.toc.com", tables_of_contents.first.url)
94
+ assert_equal("Dummy Table of Contents", tables_of_contents.first.display_text)
95
+ # Get the table of contents service response view data
96
+ view_data = tables_of_contents.first.view_data
97
+ assert_equal("aleph000062856", view_data[:record_id])
98
+ assert_equal("aleph000062856", view_data[:original_id])
99
+ assert_equal("Dummy Table of Contents", view_data[:display])
100
+ end
101
+
102
+ test "no config request by id" do
103
+ request = requests(:travels_with_my_aunt_by_id)
104
+ @primo_minimum_no_config.send(:reset_primo_config)
105
+ VCR.use_cassette("travels with my by id") do
106
+ @primo_minimum_no_config.handle(request)
107
+ end
108
+
109
+ # Get latest from the DB after handling the service.
110
+ request.referent.referent_values.reset
111
+ request.dispatched_services.reset
112
+ request.service_responses.reset
113
+
114
+ # Test that the referent was enhanced
115
+ assert_equal("Greene", request.referent.metadata["aulast"])
116
+ assert_equal("Graham,", request.referent.metadata["aufirst"])
117
+ assert_equal("Greene, Graham, 1904-1991", request.referent.metadata["au"])
118
+ assert_equal("Travels with my aunt", request.referent.metadata["title"])
119
+ assert_equal("Travels with my aunt", request.referent.metadata["btitle"])
120
+ assert_equal("New York", request.referent.metadata["place"])
121
+ assert_equal("Penguin Books", request.referent.metadata["pub"])
122
+ assert_equal("56781200", request.referent.metadata["oclcnum"])
123
+ assert_equal("2004559272", request.referent.metadata["lccn"])
124
+
125
+ # Get the returned holdings service responses
126
+ holdings = request.get_service_type('holding')
127
+ # Should only be 1 holding service response
128
+ assert_equal(1, holdings.length)
129
+ # Get the holding service response view data
130
+ view_data = holdings.first.view_data
131
+ # Test the holding service response view data
132
+ assert_equal("aleph000062856", view_data[:record_id])
133
+ assert_equal("aleph", view_data[:source_id])
134
+ assert_equal("NYU01", view_data[:original_source_id])
135
+ assert_equal("000062856", view_data[:source_record_id])
136
+ assert_equal("NYU", view_data[:institution_code])
137
+ assert_equal("NYU", view_data[:institution])
138
+ assert_equal("BOBST", view_data[:library_code])
139
+ assert_equal("BOBST", view_data[:library])
140
+ assert_equal("check_holdings", view_data[:status_code])
141
+ assert_equal("check_holdings", view_data[:status])
142
+ assert_equal("Main Collection", view_data[:collection])
143
+ assert_equal("(PR6013.R44 T7 2004 )", view_data[:call_number])
144
+ assert_equal(nil, view_data[:origin])
145
+ assert_equal("book", view_data[:display_type])
146
+ assert_equal([], view_data[:coverage])
147
+ assert_equal({}, view_data[:source_data])
148
+ assert_equal("#{@base_url}/primo_library/libweb/action/dlDisplay.do?docId=aleph000062856&institution=NYU&vid=#{@vid}", view_data[:url])
149
+ assert_equal(nil, view_data[:request_url])
150
+ assert_equal(ServiceResponse::MatchExact, view_data[:match_reliability])
151
+ end
152
+
153
+ test "legacy config request by id" do
154
+ request = requests(:travels_with_my_aunt_by_id)
155
+ VCR.use_cassette("travels with my by id") do
156
+ @primo_old_minimum.handle(request)
157
+ end
158
+
159
+ # Get latest from the DB after handling the service.
160
+ request.referent.referent_values.reset
161
+ request.dispatched_services.reset
162
+ request.service_responses.reset
163
+
164
+ # Test that the referent was enhanced
165
+ assert_equal("Greene", request.referent.metadata["aulast"])
166
+ assert_equal("Graham,", request.referent.metadata["aufirst"])
167
+ assert_equal("Greene, Graham, 1904-1991", request.referent.metadata["au"])
168
+ assert_equal("Travels with my aunt", request.referent.metadata["title"])
169
+ assert_equal("Travels with my aunt", request.referent.metadata["btitle"])
170
+ assert_equal("New York", request.referent.metadata["place"])
171
+ assert_equal("Penguin Books", request.referent.metadata["pub"])
172
+ assert_equal("56781200", request.referent.metadata["oclcnum"])
173
+ assert_equal("2004559272", request.referent.metadata["lccn"])
174
+
175
+ # Get the returned holdings service responses
176
+ holdings = request.get_service_type('holding')
177
+ # Should only be 1 holding service response
178
+ assert_equal(1, holdings.length)
179
+ # Get the holding service response view data
180
+ view_data = holdings.first.view_data
181
+ # Test the holding service response view data
182
+ assert_equal("aleph000062856", view_data[:record_id])
183
+ assert_equal("aleph", view_data[:source_id])
184
+ assert_equal("NYU01", view_data[:original_source_id])
185
+ assert_equal("000062856", view_data[:source_record_id])
186
+ assert_equal("NYU", view_data[:institution_code])
187
+ assert_equal("NYU", view_data[:institution])
188
+ assert_equal("BOBST", view_data[:library_code])
189
+ assert_equal("NYU Bobst", view_data[:library])
190
+ assert_equal("check_holdings", view_data[:status_code])
191
+ assert_equal("Check Availability", view_data[:status])
192
+ assert_equal("Main Collection", view_data[:collection])
193
+ assert_equal("(PR6013.R44 T7 2004 )", view_data[:call_number])
194
+ assert_equal(nil, view_data[:origin])
195
+ assert_equal("book", view_data[:display_type])
196
+ assert_equal([], view_data[:coverage])
197
+ assert_equal({}, view_data[:source_data])
198
+ assert_equal("#{@base_url}/primo_library/libweb/action/dlDisplay.do?docId=aleph000062856&institution=NYU&vid=#{@vid}", view_data[:url])
199
+ assert_equal(nil, view_data[:request_url])
200
+ assert_equal(ServiceResponse::MatchExact, view_data[:match_reliability])
201
+ end
202
+
203
+ test "sfx owner but fulltext empty" do
204
+ request = requests(:australian_journal_of_international_affairs_by_id)
205
+ VCR.use_cassette("australian journal of international affairs by id") do
206
+ @primo_service.handle(request)
207
+ end
208
+
209
+ # Get latest from the DB after handling the service.
210
+ request.dispatched_services.reset
211
+ request.service_responses.reset
212
+
213
+ # Get the returned fulltext service responses
214
+ fulltexts = request.get_service_type('fulltext')
215
+ # Remove the ezproxy url
216
+ url = @primo_service.send(:handle_ezproxy, fulltexts.first.url)
217
+ assert(SfxUrl.sfx_controls_url?(url))
218
+ assert_equal(6, fulltexts.length)
219
+ fulltext = fulltexts.first
220
+ assert_equal("https://ezproxy.library.edu/login?url=http://proquest.umi.com/pqdweb?RQT=318&VName=PQD&clientid=9269&pmid=34445", fulltext.url )
221
+ assert_equal("1997 - 2000 Full Text available from ProQuest", fulltext.display_text )
222
+ # Get the fulltext service response view_data
223
+ view_data = fulltext.view_data
224
+ assert_equal("dedupmrg17737330", view_data[:record_id])
225
+ assert_equal("aleph000935132", view_data[:original_id])
226
+ assert_equal("1997 - 2000 Full Text available from ProQuest", view_data[:display])
227
+ end
228
+ end
@@ -0,0 +1,78 @@
1
+ require 'test_helper'
2
+ require 'fileutils'
3
+ class PrimoSourceTest < ActiveSupport::TestCase
4
+ fixtures :requests, :referents, :referent_values, :sfx_urls
5
+
6
+ setup do
7
+ @primo_service_definition = YAML.load(%{
8
+ service_id: Primo
9
+ type: PrimoService
10
+ priority: 2 # After SFX, to get SFX metadata enhancement
11
+ status: active
12
+ base_url: http://bobcat.library.nyu.edu
13
+ vid: NYU
14
+ institution: NYU
15
+ suppress_holdings: [ !ruby/regexp '/\$\$LBWEB/', !ruby/regexp '/\$\$LNWEB/', !ruby/regexp '/\$\$LTWEB/', !ruby/regexp '/\$\$LWEB/', !ruby/regexp '/\$\$1Restricted Internet Resources/' ]
16
+ ez_proxy: https://ezproxy.library.edu/login?url=
17
+ service_types:
18
+ - primo_source })
19
+ @primo_source_definition = YAML.load(%{
20
+ service_id: PrimoSource
21
+ type: PrimoSource
22
+ priority: 3 # After PrimoService, to get store Primo sources.
23
+ status: active
24
+ base_url: http://bobcat.library.nyu.edu
25
+ vid: NYU
26
+ institution: NYU })
27
+ @primo_service = PrimoService.new(@primo_service_definition)
28
+ @primo_source = PrimoSource.new(@primo_source_definition)
29
+ end
30
+
31
+ test "new" do
32
+ assert_nothing_raised {
33
+ primo_source = PrimoSource.new(@primo_source_definition)
34
+ }
35
+ end
36
+
37
+ test "primo source by id" do
38
+ VCR.use_cassette("travels with my by id") do
39
+ request = requests(:travels_with_my_aunt_by_id)
40
+ @primo_service.handle(request)
41
+ request.dispatched_services.reload
42
+ request.service_responses.reload
43
+ @primo_source.handle(request)
44
+ request.dispatched_services.reload
45
+ request.service_responses.reload
46
+ holdings = request.get_service_type('holding', {:refresh => true})
47
+ assert_equal(1, holdings.size)
48
+ holdings.each do |holding|
49
+ view_data = holding.view_data
50
+ assert((not view_data[:source_data].nil?), "Book :source_data is nil.")
51
+ assert((not view_data[:source_data].empty?), "Book :source_data is empty.")
52
+ assert_equal("NYU01", view_data[:source_data][:doc_library], "Book :source_data[:doc_library] is unexpected.")
53
+ end
54
+ end
55
+ end
56
+
57
+ test "primo source by issn" do
58
+ VCR.use_cassette("musical quarterly by issn") do
59
+ request = requests(:the_musical_quarterly_by_issn)
60
+ @primo_service.handle(request)
61
+ request.dispatched_services.reload
62
+ request.service_responses.reload
63
+ holdings = request.get_service_type('holding', {:refresh => true})
64
+ assert_equal(0, holdings.size)
65
+ @primo_source.handle(request)
66
+ request.dispatched_services.reload
67
+ request.service_responses.reload
68
+ holdings = request.get_service_type('holding', {:refresh => true})
69
+ assert_equal(5, holdings.size)
70
+ holdings.each do |holding|
71
+ view_data = holding.view_data
72
+ assert((not view_data[:source_data].nil?), "Journal :source_data is nil.")
73
+ assert((not view_data[:source_data].empty?), "Journal :source_data is empty.")
74
+ assert_equal("NYU01", view_data[:source_data][:doc_library], "Journal :source_data[:doc_library] is unexpected.")
75
+ end
76
+ end
77
+ end
78
+ end