test/unit/searcher_test.rb in exlibris-primo-0.0.2 vs test/unit/searcher_test.rb in exlibris-primo-0.0.3
- old
+ new
@@ -1,7 +1,8 @@
+# encoding: utf-8
require 'test_helper'
-class SearcherTest < Test::Unit::TestCase
+class SearcherTest < ActiveSupport::TestCase
PNX_NS = {'pnx' => 'http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib'}
SEARCH_NS = {'search' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
def setup
@primo_definition = YAML.load( %{
@@ -58,31 +59,31 @@
:vid => @vid
}
end
# Test search for a single Primo document.
- def test_search_by_doc_id
+ test "search_by_doc_id" do
searcher = Exlibris::Primo::Searcher.new(@searcher_setup, {:primo_id => @primo_holdings_doc_id})
assert_not_nil(searcher, "#{searcher.class} returned nil when instantiated.")
search_results = searcher.response
assert_instance_of(Nokogiri::XML::Document, search_results, "#{searcher.class} search result is an unexpected object: #{search_results.class}")
assert_equal(@primo_holdings_doc_id, search_results.at("//pnx:control/pnx:recordid", PNX_NS).inner_text, "#{searcher.class} returned an unexpected record: #{search_results.to_xml(:indent => 5, :encoding => 'UTF-8')}")
assert(searcher.count.to_i > 0, "#{searcher.class} returned 0 results for doc id: #{@primo_holdings_doc_id}.")
end
# Test search for a Primo problem record
- def test_search_by_genre_discrepancy
+ test "search_by_genre_discrepancy" do
searcher = Exlibris::Primo::Searcher.new(@searcher_setup, {:primo_id => @primo_test_problem_doc_id})
assert_not_nil(searcher, "#{searcher.class} returned nil when instantiated.")
search_results = searcher.response
assert_instance_of(Nokogiri::XML::Document, search_results, "#{searcher.class} search result is an unexpected object: #{search_results.class}")
assert_equal(@primo_test_problem_doc_id, search_results.at("//pnx:control/pnx:recordid", PNX_NS).inner_text, "#{searcher.class} returned an unexpected record: #{search_results.to_xml(:indent => 5, :encoding => 'UTF-8')}")
assert(searcher.count.to_i > 0, "#{searcher.class} returned 0 results for doc id: #{@primo_test_problem_doc_id}.")
assert_equal(1, searcher.holdings.length, "#{searcher.class} returned unexpected holdings")
end
- def test_search_by_bug1361
+ test "search_by_bug1361" do
searcher = Exlibris::Primo::Searcher.new(@searcher_setup, {:primo_id => @primo_test_bug1361_id})
assert_not_nil(searcher, "#{searcher.class} returned nil when instantiated.")
search_results = searcher.response
assert_instance_of(Nokogiri::XML::Document, search_results, "#{searcher.class} search result is an unexpected object: #{search_results.class}")
assert_equal(@primo_test_bug1361_id, search_results.at("//pnx:control/pnx:recordid", PNX_NS).inner_text, "#{searcher.class} returned an unexpected record: #{search_results.to_xml(:indent => 5, :encoding => 'UTF-8')}")
@@ -90,32 +91,32 @@
assert_equal(0, searcher.holdings.length, "#{searcher.class} returned unexpected holdings")
assert_equal(4, searcher.rsrcs.length, "#{searcher.class} returned unexpected rsrcs")
end
# Test search for an invalid Primo document.
- def test_search_by_invalid_doc_id
+ test "search_by_invalid_doc_id" do
assert_raise(RuntimeError) {
searcher = Exlibris::Primo::Searcher.new(@searcher_setup, {:primo_id => @primo_invalid_doc_id})
}
end
# Test invalid setup.
- def test_search_by_invalid_setup1
+ test "search_by_invalid_setup1" do
assert_raise(RuntimeError) {
searcher = Exlibris::Primo::Searcher.new({}, {:primo_id => @primo_invalid_doc_id})
}
end
# Test invalid setup.
- def test_search_by_invalid_setup2
+ test "search_by_invalid_setup2" do
assert_raise(RuntimeError) {
searcher = Exlibris::Primo::Searcher.new({:base_url => @base_url, :config => nil}, {:primo_id => @primo_invalid_doc_id})
}
end
# Test base setup search for a single Primo document.
- def test_search_base_setup_record_id
+ test "search_base_setup_record_id" do
searcher = Exlibris::Primo::Searcher.new({:base_url => @base_url, :institution => @institution}, {:primo_id => @primo_holdings_doc_id})
holdings = searcher.holdings
assert_instance_of(Array, holdings, "#{searcher.class} holdings is an unexpected object: #{holdings.class}")
assert(holdings.count > 0, "#{searcher.class} returned 0 holdings for doc id: #{@primo_holdings_doc_id}.")
first_holding = holdings.first
@@ -126,11 +127,11 @@
assert_equal("Main Collection", first_holding.collection, "#{searcher.class} first holding has an unexpected collection: #{first_holding.collection}")
assert_equal("(PR6013.R44 T7 2004 )", first_holding.call_number, "#{searcher.class} first holding has an unexpected call number: #{first_holding.call_number}")
end
# Test search by isbn.
- def test_search_by_isbn
+ test "search_by_isbn" do
searcher = Exlibris::Primo::Searcher.new(@searcher_setup, {:isbn => @primo_test_isbn})
assert_not_nil(searcher, "#{searcher.class} returned nil when instantiated.")
search_results = searcher.response
assert_instance_of(Nokogiri::XML::Document, search_results, "#{searcher.class} search result is an unexpected object: #{search_results.class}")
search_results.search("//search/isbn") do |isbn|
@@ -138,11 +139,11 @@
end
assert(searcher.count.to_i > 0, "#{searcher.class} returned 0 results for ISBN: #{@primo_test_isbn}.")
end
# Test search by isbn.
- def test_search_by_issn
+ test "search_by_issn" do
searcher = Exlibris::Primo::Searcher.new(@searcher_setup_without_config, {:issn => "0002-8614"})
assert_not_nil(searcher, "#{searcher.class} returned nil when instantiated.")
search_results = searcher.response
assert_instance_of(Nokogiri::XML::Document, search_results, "#{searcher.class} search result is an unexpected object: #{search_results.class}")
search_results.search("//search/issn") do |isbn|
@@ -150,11 +151,11 @@
end
assert(searcher.count.to_i > 0, "#{searcher.class} returned 0 results for ISSN: 0002-8614.")
end
# Test search by title/author/genre.
- def test_search_by_title_author_genre
+ test "search_by_title_author_genre" do
searcher = Exlibris::Primo::Searcher.new(@searcher_setup, {:title => @primo_test_title, :author => @primo_test_author, :genre => @primo_test_genre})
assert_not_nil(searcher, "#{searcher.class} returned nil when instantiated.")
search_results = searcher.response
assert_instance_of(Nokogiri::XML::Document, search_results, "#{searcher.class} search result is an unexpected object: #{search_results.class}")
search_results.search("//search/title") do |title|
@@ -162,11 +163,11 @@
end
assert(searcher.count.to_i > 0, "#{searcher.class} returned 0 results for Title: #{@primo_test_title}.")
end
# Test search for a single Primo document w/ holdings.
- def test_holdings
+ test "holdings" do
searcher = Exlibris::Primo::Searcher.new(@searcher_setup, {:primo_id => @primo_holdings_doc_id})
holdings = searcher.holdings
assert_instance_of(Array, holdings,
"#{searcher.class} holdings is an unexpected object: #{holdings.class}")
assert_equal(1, holdings.count,
@@ -176,10 +177,12 @@
Exlibris::Primo::Holding,
first_holding,
"#{searcher.class} first holding is an unexpected object: #{first_holding.class}")
test_data = {
:record_id => "nyu_aleph000062856",
+ :title => "Travels with my aunt",
+ :author => "Graham Greene 1904-1991.",
:source_id => "nyu_aleph",
:original_source_id => "NYU01",
:source_record_id => "000062856",
:institution_code => "NYU",
:institution => "NYU",
@@ -204,11 +207,11 @@
"#{searcher.class} first holding has an unexpected #{key}: #{first_holding.send(key)}")
}
end
# Test search for a single Primo document w/ rsrcs.
- def test_rsrcs
+ test "rsrcs" do
searcher = Exlibris::Primo::Searcher.new(
@searcher_setup,
{ :primo_id => @primo_rsrcs_doc_id })
rsrcs = searcher.rsrcs
assert_instance_of(Array, rsrcs,
@@ -235,11 +238,11 @@
"#{searcher.class} first rsrc has an unexpected #{key}: #{first_rsrc.send(key)}")
}
end
# Test search for a single Primo document w/ tocs.
- def test_tocs
+ test "tocs" do
searcher = Exlibris::Primo::Searcher.new(
@searcher_setup,
{ :primo_id => @primo_tocs_doc_id })
tocs = searcher.tocs
assert_instance_of(Array, tocs,
@@ -262,11 +265,11 @@
first_toc.send(key),
"#{searcher.class} first toc has an unexpected #{key}: #{first_toc.send(key)}")
}
end
- def test_dedupmrg
+ test "dedupmrg" do
searcher = Exlibris::Primo::Searcher.new(
@searcher_setup,
{ :primo_id => @primo_dedupmrg_doc_id })
holdings = searcher.holdings
assert_instance_of(Array, holdings,
@@ -278,10 +281,12 @@
Exlibris::Primo::Holding,
first_holding,
"#{searcher.class} first holding is an unexpected object: #{first_holding.class}")
test_data = {
:record_id => "dedupmrg17343091",
+ :title => "The New York times",
+ :author => "",
:source_id => "nyu_aleph",
:original_source_id => "NYU01",
:source_record_id => "000932393",
:institution_code => "NYU",
:institution => "NYU",
@@ -329,55 +334,48 @@
first_rsrc.send(key),
"#{searcher.class} first rsrc has an unexpected #{key}: #{first_rsrc.send(key)}")
}
end
- # def test_holdings_diacritics1
+ test "holdings_diacritics1" do
+ searcher = Exlibris::Primo::Searcher.new(
+ @searcher_setup,
+ { :primo_id => @primo_test_diacritics1_doc_id })
+ assert_equal(
+ "Rubāʻīyāt-i Bābā Ṭāhir",
+ searcher.btitle,
+ "#{searcher.class} has an unexpected btitle: #{searcher.btitle}")
+ assert_equal(
+ "Bābā-Ṭāhir, 11th cent",
+ searcher.au,
+ "#{searcher.class} has an unexpected author: #{searcher.au}")
+ end
+
+# This test fails but I don't know why!
+ # test "holdings_diacritics2" do
# searcher = Exlibris::Primo::Searcher.new(
# @searcher_setup,
- # { :primo_id => @primo_test_diacritics1_doc_id })
+ # { :primo_id => @primo_test_diacritics2_doc_id })
# assert_equal(
- # "Rubāʻīyāt-i Bābā Ṭāhir",
- # searcher.btitle,
- # "#{searcher.class} has an unexpected btitle: #{searcher.btitle}")
- # assert_equal(
- # "Bābā-Ṭāhir, 11th cent",
+ # "Faraj, Faraj Maḥmūd",
# searcher.au,
# "#{searcher.class} has an unexpected author: #{searcher.au}")
+ # assert_equal(
+ # "Iqlīm Tuwāt khilāl al-qarnayn al-thāmin ʻashar wa-al-tāsiʻ ʻashar al-mīlādīyīn : dirāsah li-awḍāʻ al-iqlīm al-siyāsīyah wa-al-ijtimāʻīyah wa-al-iqtiṣādīyah wa-al-thaqāfīyah, maʻa taḥqīq kitāb al-Qawl al-basīṭ fī akhbār Tamanṭīṭ (li-Muḥammad ibn Bābā Ḥaydah)",
+ # searcher.btitle,
+ # "#{searcher.class} has an unexpected btitle: #{searcher.btitle}")
# end
-# # This test fails but I don't know why!
-# def test_holdings_diacritics2
-# searcher = Exlibris::Primo::Searcher.new(
-# @searcher_setup,
-# { :primo_id => @primo_test_diacritics2_doc_id })
-# assert_equal(
-# "أقليم توات خلال القرنين الثامن عشر والتاسع عشر الميلاديين : دراسة لأوضاع الأقليم السياسية والأجتماعية والأقتصادية والثقافية، مع تحقيق كتاب القول البسيط في أخبار تمنطيط (لمحمد بن بابا حيده)",
-# searcher.btitle,
-# "#{searcher.class} has an unexpected btitle: #{searcher.btitle}")
-# puts ("\n")
-# puts searcher.au.bytes.collect.inspect
-# faraj = "Faraj, Faraj Maḥmūd"
-# puts ("\n»")
-# puts "»".bytes.collect.inspect
-# puts faraj.bytes.collect.inspect
-# assert_equal(
-# "Faraj, Faraj Maḥmūd",
-# searcher.au,
-# "#{searcher.class} has an unexpected author: #{searcher.au}")
-# assert_equal("(DT299.T88 F373 2007)", first_holding.call_number, "#{searcher.class} first holding has an unexpected call number: #{first_holding.call_number}")
-# end
-#
-# def test_holdings_diacritics3
-# searcher = Exlibris::Primo::Searcher.new(
-# @searcher_setup,
-# { :primo_id => @primo_test_diacritics3_doc_id })
-# assert_equal(
-# "Mul har ha-gaʻash : ḥoḳre toldot Yiśraʼel le-nokhaḥ ha-Shoʼah",
-# searcher.btitle,
-# "#{searcher.class} has an unexpected btitle: #{searcher.btitle}")
-# assert_equal(
-# "Engel, David",
-# searcher.au,
-# "#{searcher.class} has an unexpected author: #{searcher.au}")
-# end
+ test "holdings_diacritics3" do
+ searcher = Exlibris::Primo::Searcher.new(
+ @searcher_setup,
+ { :primo_id => @primo_test_diacritics3_doc_id })
+ assert_equal(
+ "Mul har ha-gaʻash : ḥoḳre toldot Yiśraʼel le-nokhaḥ ha-Shoʼah",
+ searcher.btitle,
+ "#{searcher.class} has an unexpected btitle: #{searcher.btitle}")
+ assert_equal(
+ "Engel, David",
+ searcher.au,
+ "#{searcher.class} has an unexpected author: #{searcher.au}")
+ end
end
\ No newline at end of file