rbook 0.4.3 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/Rakefile +13 -176
  2. metadata +57 -117
  3. data/COPYING +0 -340
  4. data/LICENSE +0 -13
  5. data/README +0 -17
  6. data/examples/gbip.rb +0 -12
  7. data/examples/onix/stream_reader.rb +0 -13
  8. data/examples/pacstream.rb +0 -13
  9. data/examples/titlepage.rb +0 -14
  10. data/examples/titlepage_with_proxy.rb +0 -14
  11. data/examples/titlepage_www.rb +0 -18
  12. data/examples/www/find_all.rb +0 -23
  13. data/examples/www/find_cover_from_amazon.rb +0 -16
  14. data/examples/www/find_url_from_rainbow.rb +0 -12
  15. data/examples/www/list.rb +0 -13
  16. data/lib/rbook/bisac.rb +0 -31
  17. data/lib/rbook/bisac/message.rb +0 -99
  18. data/lib/rbook/bisac/po.rb +0 -97
  19. data/lib/rbook/bisac/po_line_item.rb +0 -33
  20. data/lib/rbook/bisac/product.rb +0 -176
  21. data/lib/rbook/errors.rb +0 -8
  22. data/lib/rbook/gbip.rb +0 -21
  23. data/lib/rbook/gbip/pos.rb +0 -118
  24. data/lib/rbook/gbip/title.rb +0 -36
  25. data/lib/rbook/gbip/warehouse.rb +0 -27
  26. data/lib/rbook/isbn.rb +0 -255
  27. data/lib/rbook/onix.rb +0 -70
  28. data/lib/rbook/onix/contributor.rb +0 -60
  29. data/lib/rbook/onix/lists.rb +0 -2
  30. data/lib/rbook/onix/lists/contributor_role.rb +0 -10
  31. data/lib/rbook/onix/lists/product_form.rb +0 -100
  32. data/lib/rbook/onix/message.rb +0 -112
  33. data/lib/rbook/onix/product.rb +0 -189
  34. data/lib/rbook/onix/sales_restriction.rb +0 -51
  35. data/lib/rbook/onix/stream_reader.rb +0 -120
  36. data/lib/rbook/onix/stream_writer.rb +0 -40
  37. data/lib/rbook/onix/supply_detail.rb +0 -68
  38. data/lib/rbook/onix/xchar.rb +0 -98
  39. data/lib/rbook/pacstream.rb +0 -64
  40. data/lib/rbook/titlepage.rb +0 -37
  41. data/lib/rbook/titlepage/client.rb +0 -126
  42. data/lib/rbook/titlepage/titlepage_driver.rb +0 -137
  43. data/lib/rbook/titlepage/titlepage_utils.rb +0 -379
  44. data/lib/rbook/titlepage/wwwclient.rb +0 -96
  45. data/lib/rbook/www.rb +0 -172
  46. data/lib/rbook/www/aau_scraper.rb +0 -76
  47. data/lib/rbook/www/amazon_uk_scraper.rb +0 -44
  48. data/lib/rbook/www/ban_scraper.rb +0 -62
  49. data/lib/rbook/www/base.rb +0 -87
  50. data/lib/rbook/www/harper_au_scraper.rb +0 -56
  51. data/lib/rbook/www/harper_us_scraper.rb +0 -55
  52. data/lib/rbook/www/hha_scraper.rb +0 -50
  53. data/lib/rbook/www/macmillan_scraper.rb +0 -62
  54. data/lib/rbook/www/orbis_scraper.rb +0 -48
  55. data/lib/rbook/www/oup_scraper.rb +0 -64
  56. data/lib/rbook/www/paulist_scraper.rb +0 -53
  57. data/lib/rbook/www/pearson_au_scraper.rb +0 -52
  58. data/lib/rbook/www/penguin_scraper.rb +0 -45
  59. data/lib/rbook/www/random_au_scraper.rb +0 -90
  60. data/lib/rbook/www/random_us_scraper.rb +0 -59
  61. data/lib/rbook/www/sas_scraper.rb +0 -54
  62. data/lib/rbook/www/unireps_scraper.rb +0 -58
  63. data/lib/rbook/www/wiley_us_scraper.rb +0 -54
  64. data/test/data/abingdon.xml +0 -38931
  65. data/test/data/augsburg.xml +0 -39009
  66. data/test/data/bisac_po.txt +0 -112
  67. data/test/data/chalice.xml +0 -10851
  68. data/test/data/eerdsman.xml +0 -36942
  69. data/test/data/invalid_no_product.xml +0 -9
  70. data/test/data/not_xml.csv +0 -1
  71. data/test/data/single_product.xml +0 -50
  72. data/test/data/valid_bisac.txt +0 -213
  73. data/test/data/xml_not_onix.xml +0 -7
  74. data/test/mocks/titlepage_driver.rb +0 -111
  75. data/test/unit/bisac/bisac_test.rb +0 -96
  76. data/test/unit/bisac/po_line_item_test.rb +0 -38
  77. data/test/unit/bisac/po_test.rb +0 -82
  78. data/test/unit/isbn_test.rb +0 -153
  79. data/test/unit/onix/contributor_test.rb +0 -50
  80. data/test/unit/onix/message_test.rb +0 -119
  81. data/test/unit/onix/product_test.rb +0 -101
  82. data/test/unit/onix/sales_restriction_test.rb +0 -48
  83. data/test/unit/onix/stream_reader_test.rb +0 -22
  84. data/test/unit/onix/stream_writer_test.rb +0 -32
  85. data/test/unit/onix/supply_detail_test.rb +0 -53
  86. data/test/unit/onix/xchar_test.rb +0 -37
  87. data/test/unit/titlepage_test.rb +0 -140
@@ -1,38 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../../lib')
2
-
3
- require 'test/unit'
4
- require 'rbook/bisac'
5
-
6
- class POLineItemTest < Test::Unit::TestCase
7
-
8
- def setup
9
- @row = "4000003 14976 Y000000000102978513220000100000000000000000000550000000"
10
- end
11
-
12
- # ensure the load_from_string method works as expected
13
- def test_load_from_string
14
- item = RBook::Bisac::POLineItem.load_from_string(@row)
15
- assert_kind_of RBook::Bisac::POLineItem, item
16
-
17
- assert_equal item.sequence_number, 3
18
- assert_equal item.po_number, "14976"
19
- assert_equal item.line_item_number, "0000000001"
20
- assert_equal item.isbn, "0297851322"
21
- assert_equal item.qty, 1
22
- assert_equal item.catalogue_code, "0"
23
- assert_equal item.price, 0
24
- end
25
-
26
- # ensure the load_from_file method throws the correct exceptions
27
- # when it encounters a problem
28
- def test_product_validation
29
-
30
- #assert_raise(RVista::InvalidLineItemError) {
31
- # item = RVista::LineItem.load_from_array(%w[D blah])
32
- #}
33
-
34
- end
35
-
36
- end
37
-
38
-
@@ -1,82 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../../lib')
2
-
3
- require 'test/unit'
4
- require 'rbook/bisac'
5
-
6
- class POTest < Test::Unit::TestCase
7
-
8
- VALID = File.dirname(__FILE__) + "/../../data/bisac_po.txt"
9
- #INVALID_MISSING_HEADER = File.dirname(__FILE__) + "/../data/invalid_missing_header.txt"
10
- #INVALID_MISSING_FOOTER = File.dirname(__FILE__) + "/../data/invalid_missing_footer.txt"
11
- #INVALID_LINE = File.dirname(__FILE__) + "/../data/invalid_line.txt"
12
- #INVALID_DOESNT_EXIST = File.dirname(__FILE__) + "/../data/blah.txt"
13
-
14
- # ensure the load_from_file method works as expected
15
- def test_load_from_file
16
- msg = RBook::Bisac::PO.load_from_file(VALID)
17
- assert_kind_of RBook::Bisac::PO, msg
18
- assert_equal msg.items.size, 36
19
-
20
- validate_msg(msg)
21
- end
22
-
23
- # ensure the load_from_file method works as expected
24
- def test_load_from_string
25
- msg = RBook::Bisac::PO.load_from_string(File.read(VALID))
26
- assert_kind_of RBook::Bisac::PO, msg
27
- assert_equal msg.items.size, 36
28
-
29
- assert_equal "Finding Sanctuary :Monastic St", msg.items.first.title
30
- assert_equal "JAMISON ABBOT CHRISTOPH", msg.items.first.author
31
-
32
- validate_msg(msg)
33
- end
34
-
35
- # ensure the load_from_file method throws the correct exceptions
36
- # when it encounters a problem
37
- def test_product_validation
38
-
39
- #assert_raise(RVista::InvalidFileError) {
40
- # msg = RVista::Message.load_from_file(INVALID_MISSING_HEADER)
41
- #}
42
-
43
- #assert_raise(RVista::InvalidFileError) {
44
- # msg = RVista::Message.load_from_file(INVALID_MISSING_FOOTER)
45
- #}
46
-
47
- #assert_raise(RVista::InvalidLineItemError) {
48
- # msg = RVista::Message.load_from_file(INVALID_LINE)
49
- #}
50
-
51
- #assert_raise(RVista::InvalidFileError) {
52
- # msg = RVista::Message.load_from_file(INVALID_DOESNT_EXIST)
53
- #}
54
-
55
- end
56
-
57
- private
58
-
59
- # ensures the properties of the supplied RVista::Message object
60
- # match the properties specified in the VALID file
61
- def validate_msg(msg)
62
- assert_equal msg.source_san, "9013725"
63
- assert_equal msg.source_suffix, ""
64
- assert_equal msg.source_name, "Rainbow Book"
65
- assert_equal msg.date, "061112"
66
- assert_equal msg.filename, "INTERNET.BSC"
67
- assert_equal msg.format_version, "F03"
68
- assert_equal msg.destination_san, "9021000"
69
- assert_equal msg.destination_suffix, ""
70
- assert_equal msg.po_number, "14976"
71
- assert_equal msg.cancellation_date, "000000"
72
- assert_equal msg.backorder, true
73
- assert_equal msg.do_not_exceed_action, ""
74
- assert_equal msg.do_not_exceed_amount, "0000000"
75
- assert_equal msg.invoice_copies, "01"
76
- assert_equal msg.special_instructions, false
77
- assert_equal msg.do_not_ship_before, "000000"
78
- end
79
-
80
- end
81
-
82
-
@@ -1,153 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
-
3
- require 'test/unit'
4
- require 'rbook/isbn'
5
-
6
- class ISBNTest < Test::Unit::TestCase
7
-
8
- include RBook
9
-
10
- def test_add_groups
11
- assert_equal ISBN::add_groups('020161622X'), '0-20161-622-X'
12
- assert_equal ISBN::add_groups('9780201616224'), '978-0-20161-622-4'
13
- assert_equal ISBN::add_groups('invalId'), 'invalId'
14
- end
15
-
16
- def test_add_groups_destructive
17
- isbn = '020161622X'
18
- new_isbn = ISBN::add_groups(isbn)
19
- assert_equal( isbn, '020161622X')
20
-
21
- isbn = '978201616224'
22
- new_isbn = ISBN::add_groups(isbn)
23
- assert_equal( isbn, '978201616224')
24
- end
25
-
26
- def test_add_boundaries
27
- assert_equal ISBN::add_groups(''), ''
28
- assert_equal ISBN::add_groups(nil), nil
29
- end
30
-
31
- def test_valid_isbn10
32
- assert_equal ISBN::valid_isbn10?('020161622X'), true
33
- assert_equal ISBN::valid_isbn10?('020161622'), false
34
- assert_equal ISBN::valid_isbn10?('023252565X'), true
35
- assert_equal ISBN::valid_isbn10?('023252565x'), true
36
- assert_equal ISBN::valid_isbn10?('020-161-622-X'), true
37
- assert_equal ISBN::valid_isbn10?('9780764812200'), false
38
- assert_equal ISBN::valid_isbn10?('12345'), false
39
- assert_equal ISBN::valid_isbn10?('12345 7890'), false
40
- assert_equal ISBN::valid_isbn10?('CD-DSE'), false
41
- end
42
-
43
- def test_valid_isbn10_boundaries
44
- assert_equal ISBN::valid_isbn10?(''), false
45
- assert_equal ISBN::valid_isbn10?('11278217391827398217391723918723918'), false
46
- assert_equal ISBN::valid_isbn10?(nil), false
47
- assert_equal ISBN::valid_isbn10?(1234567890), false
48
- end
49
-
50
- def test_valid_isbn13
51
- assert_equal ISBN::valid_isbn13?('9780201616224'), true
52
- assert_equal ISBN::valid_isbn13?('978020161622'), false
53
- assert_equal ISBN::valid_isbn13?('9780764812200'), true
54
- assert_equal ISBN::valid_isbn13?('978-02016-1622-4'), true
55
- assert_equal ISBN::valid_isbn13?('978076481220'), false
56
- assert_equal ISBN::valid_isbn13?('978 NCR 4611'), false
57
- assert_equal ISBN::valid_isbn13?('12345'), false
58
- assert_equal ISBN::valid_isbn13?('CD-DSE'), false
59
- assert_equal ISBN::valid_isbn13?('020161622X'), false
60
- end
61
-
62
- def test_valid_isbn13_boundaries
63
- assert_equal ISBN::valid_isbn13?(''), false
64
- assert_equal ISBN::valid_isbn13?('11278217391827398217391723918723918'), false
65
- assert_equal ISBN::valid_isbn13?(nil), false
66
- assert_equal ISBN::valid_isbn13?(9781234567890), false
67
- end
68
-
69
- def test_calc_isbn10_check
70
- assert_equal ISBN::calc_isbn10_check('020161622'), 'X'
71
- assert_equal ISBN::calc_isbn10_check('055299777'), '3'
72
- end
73
-
74
- def test_calc_isbn10_check_boundaries
75
- assert_equal ISBN::calc_isbn10_check(''), nil
76
- assert_equal ISBN::calc_isbn10_check(nil), nil
77
- assert_equal ISBN::calc_isbn10_check(978020161622), nil
78
- assert_equal ISBN::calc_isbn10_check(' - '), nil
79
- end
80
-
81
- def test_calc_isbn13_check
82
- assert_equal ISBN::calc_isbn13_check('978020161622'), '4'
83
- assert_equal ISBN::calc_isbn13_check('978055299777'), '5'
84
- end
85
-
86
- def test_calc_isbn13_boundaries
87
- assert_equal ISBN::calc_isbn13_check(''), nil
88
- assert_equal ISBN::calc_isbn13_check(nil), nil
89
- assert_equal ISBN::calc_isbn13_check(978020161622), nil
90
- assert_equal ISBN::calc_isbn13_check(' - '), nil
91
- end
92
-
93
- def test_convert_to_isbn10
94
- #some random titles
95
- assert_equal ISBN::convert_to_isbn10('9780764812200'), '0764812203'
96
- assert_equal ISBN::convert_to_isbn10('9781856075336'), '1856075338'
97
- assert_equal ISBN::convert_to_isbn10('9780232525656'), '023252565X'
98
- assert_equal ISBN::convert_to_isbn10('9781863951340'), '1863951342'
99
- assert_equal ISBN::convert_to_isbn10('978 NCR 4611'), nil
100
-
101
- # a 979 ISBN13 that can't be converted to isbn10
102
- assert_equal ISBN::convert_to_isbn10('9791863951340'), nil
103
-
104
- # already isbn10
105
- assert_equal ISBN::convert_to_isbn10('1856075338'), '1856075338'
106
-
107
- # valid isbn without a checkdigit
108
- assert_equal ISBN::convert_to_isbn10('185607533'), nil
109
-
110
- #non valid isbns
111
- assert_equal ISBN::convert_to_isbn10('AAAAAAA'), nil
112
-
113
- end
114
-
115
- def test_convert_to_isbn10_boundaries
116
- assert_equal ISBN::convert_to_isbn13(' '), nil
117
- assert_equal ISBN::convert_to_isbn13(nil), nil
118
- assert_equal ISBN::convert_to_isbn13(120234203), nil
119
- assert_equal ISBN::convert_to_isbn13('18273987123987129387192873912820234203'), nil
120
- end
121
-
122
- def test_convert_to_isbn13
123
- #some random titles
124
- assert_equal ISBN::convert_to_isbn13('0764812203'), '9780764812200'
125
- assert_equal ISBN::convert_to_isbn13('1856075338'), '9781856075336'
126
- assert_equal ISBN::convert_to_isbn13('023252565X'), '9780232525656'
127
- assert_equal ISBN::convert_to_isbn13('023252565x'), '9780232525656'
128
- assert_equal ISBN::convert_to_isbn13('1863951342'), '9781863951340'
129
- assert_equal ISBN::convert_to_isbn13('186-395-134-2'), '9781863951340'
130
-
131
- #already isbn13
132
- assert_equal ISBN::convert_to_isbn13('9781856075336'), '9781856075336'
133
-
134
- # valid isbn without a check digit
135
- assert_equal ISBN::convert_to_isbn13('978185607533'), nil
136
-
137
- #non valid isbns
138
- assert_equal ISBN::convert_to_isbn13('651887010820'), nil
139
- assert_equal ISBN::convert_to_isbn13('AAAAAAA'), nil
140
- assert_equal ISBN::convert_to_isbn13('CX-188'), nil
141
-
142
- end
143
-
144
- def test_convert_to_isbn13_boundaries
145
- assert_equal ISBN::convert_to_isbn13(' '), nil
146
- assert_equal ISBN::convert_to_isbn13(nil), nil
147
- assert_equal ISBN::convert_to_isbn13(120234203), nil
148
- assert_equal ISBN::convert_to_isbn13('18273987123987129387192873912820234203'), nil
149
- end
150
-
151
- end
152
-
153
-
@@ -1,50 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
-
3
- require 'test/unit'
4
- require 'rexml/document'
5
- require 'rbook/onix'
6
-
7
- class ContributorTest < Test::Unit::TestCase
8
-
9
- def test_load_from_element
10
-
11
- file = File.open(File.dirname(__FILE__)+"/../../data/single_product.xml", "r")
12
- doc = REXML::Document.new(file)
13
- contributor = RBook::Onix::Contributor.load_from_element(REXML::XPath.first(doc, '/ONIXMessage/Product/Contributor'))
14
-
15
- file.close
16
-
17
- assert_equal('0', contributor.sequence_number)
18
- assert_equal('A01', contributor.role)
19
- assert_equal('Healy, James', contributor.name_inverted)
20
- end
21
-
22
- def test_load_from_element_not_contributor
23
-
24
- element = REXML::Element.new('NonContributor')
25
- element.add_element('SequenceNumber').text = 'blah'
26
-
27
- assert_raise(LoadError) {
28
- product = RBook::Onix::Contributor.load_from_element(element)
29
- }
30
-
31
- end
32
-
33
- # ensure product information is output to xml correctly
34
- def test_to_element
35
-
36
- contributor = RBook::Onix::Contributor.new
37
- contributor.name_inverted = 'Healy, James'
38
- contributor.sequence_number = '01'
39
- contributor.role = 'A01'
40
-
41
- doc = contributor.to_element
42
-
43
- assert_not_equal(nil,REXML::XPath.first(doc, '/PersonNameInverted'), 'Person Name Inverted must not be nil')
44
- assert_equal("Healy, James", REXML::XPath.first(doc, '/PersonNameInverted').text)
45
- assert_not_equal(nil,REXML::XPath.first(doc, '/ContributorRole'), 'Contributor Role must not be nil')
46
- assert_equal("A01", REXML::XPath.first(doc, '/ContributorRole').text)
47
-
48
- end
49
-
50
- end
@@ -1,119 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
-
3
- require 'test/unit'
4
- require 'rexml/document'
5
- require 'date'
6
- require 'rbook/onix'
7
-
8
- class MessageTest < Test::Unit::TestCase
9
-
10
- # test loading a valid onix file. Make sure the correct number of products
11
- # exist, but don't worry about the content. The product unit tests can check them
12
- def test_load_from_xmldoc
13
-
14
- file = File.open(File.dirname(__FILE__)+"/../../data/single_product.xml", "r")
15
- doc = REXML::Document.new(file)
16
- msg = RBook::Onix::Message.load_from_xmldoc(doc)
17
-
18
- file.close
19
-
20
- #check header elements
21
- assert_equal('Chalice', msg.from_company)
22
- assert_equal('James Healy', msg.from_person)
23
- assert Date.civil(2006, 5, 21) === msg.sent_date
24
-
25
- #check product count
26
- assert_equal(1, msg.products.size)
27
-
28
- end
29
-
30
- # try loading an onix file with no products
31
- def test_load_from_xmldoc_invalid_no_product
32
- file = File.open(File.dirname(__FILE__)+"/../../data/invalid_no_product.xml", "r")
33
- doc = REXML::Document.new(file)
34
-
35
- assert_raise(LoadError) {
36
- msg = RBook::Onix::Message.load_from_xmldoc(doc)
37
- }
38
- end
39
-
40
- # test loading an xml file that's not an onix file
41
- def test_load_from_xmldoc_invalid_not_onix
42
- file = File.open(File.dirname(__FILE__)+"/../../data/xml_not_onix.xml", "r")
43
- doc = REXML::Document.new(file)
44
-
45
- assert_raise(LoadError) {
46
- msg = RBook::Onix::Message.load_from_xmldoc(doc)
47
- }
48
-
49
- end
50
-
51
- # test loading a non XML file
52
- def test_load_from_xmldoc_invalid_not_xml
53
- file = File.open(File.dirname(__FILE__)+"/../../data/not_xml.csv", "r")
54
- doc = REXML::Document.new(file)
55
-
56
- assert_raise(LoadError) {
57
- msg = RBook::Onix::Message.load_from_xmldoc(doc)
58
- }
59
-
60
- end
61
-
62
- # ensure header information is output to xml correctly and that a
63
- # product is created
64
- def test_to_xml
65
- msg = RBook::Onix::Message.new
66
- msg.from_person = "James Healy"
67
- msg.from_company = "Healy Inc."
68
- msg.to_person = "Test::Unit"
69
-
70
- product = RBook::Onix::Product.new
71
- product.product_identifier = '0977616606'
72
- msg.add_product(product)
73
-
74
- doc = msg.to_xml
75
-
76
- assert_not_equal(nil,REXML::XPath.first(doc, '/ONIXMessage/Header/FromPerson'))
77
- assert_equal("James Healy", REXML::XPath.first(doc, '/ONIXMessage/Header/FromPerson').text)
78
- assert_not_equal(nil,REXML::XPath.first(doc, '/ONIXMessage/Header/FromCompany'))
79
- assert_equal("Healy Inc.", REXML::XPath.first(doc, '/ONIXMessage/Header/FromCompany').text)
80
- assert_not_equal(nil,REXML::XPath.first(doc, '/ONIXMessage/Header/ToPerson'))
81
- assert_equal("Test::Unit", REXML::XPath.first(doc, '/ONIXMessage/Header/ToPerson').text)
82
- assert_not_equal(nil,REXML::XPath.first(doc, '/ONIXMessage/Product'))
83
- end
84
-
85
- # test for an exception when a onixmessage with no products is converted to an xml document
86
- def test_to_xml_no_product
87
- msg = RBook::Onix::Message.new
88
- msg.from_person = "James Healy"
89
- msg.from_company = "Healy Inc."
90
- msg.to_person = "Test::Unit"
91
-
92
- assert_raise(RuntimeError) {
93
- doc = msg.to_xml
94
- }
95
- end
96
-
97
- def test_to_s_valid_utf8_charset
98
- msg = RBook::Onix::Message.new
99
- msg.from_person = "James Healy\x11"
100
- msg.from_company = "Healy Inc.\x11"
101
- msg.from_email = "someone@example.com\x11"
102
- msg.to_person = "Test::Unit\x11"
103
- msg.to_company = "Sample Company\x11"
104
- msg.message_note = "This is a sample ONIX message\x11"
105
-
106
- product = RBook::Onix::Product.new
107
- product.product_identifier = '0977616606'
108
- product.title = 'Test Title'
109
- msg.add_product(product)
110
-
111
- doc = msg.to_s
112
-
113
- doc.each_byte do |c|
114
- n = XChar::CP1252[c] || c
115
- n = nil unless XChar::VALID.find {|range| range.include? n}
116
- assert_not_equal nil, n, "Non valid UTF8 char detected (code: #{n.to_s})"
117
- end
118
- end
119
- end
@@ -1,101 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
-
3
- require 'test/unit'
4
- require 'rexml/document'
5
- require 'date'
6
- require 'rbook/onix'
7
-
8
- class ProductTest < Test::Unit::TestCase
9
-
10
- def test_load_from_element
11
-
12
- file = File.open(File.dirname(__FILE__)+"/../../data/single_product.xml", "r")
13
- doc = REXML::Document.new(file)
14
- product = RBook::Onix::Product.load_from_element(REXML::XPath.first(doc, '/ONIXMessage/Product'))
15
-
16
- file.close
17
-
18
- #check header elements
19
- assert_equal('03', product.notification_type)
20
- assert_equal('0827200528', product.record_reference)
21
- assert_equal('BA', product.form)
22
- assert_equal('0', product.pages)
23
- assert_equal('YFH', product.bicmainsubject)
24
- assert_equal('And Their Eyes Are Opened', product.title)
25
- assert_equal('Story Sermons Embracing the World', product.subtitle)
26
- assert_equal('Chalice', product.publisher)
27
- assert Date.civil(2005, 3, 3) === product.publication_date
28
-
29
- assert_equal(1, product.contributors.size, 'Product should contain 1 contributor')
30
- assert_equal(1, product.supply_details.size, 'Product should contain 1 supply detail')
31
-
32
- end
33
-
34
- def test_load_from_element_not_product
35
-
36
- element = REXML::Element.new('NonProduct')
37
- element.add_element('NonContributor').text = 'blah'
38
-
39
- assert_raise(LoadError) {
40
- product = RBook::Onix::Product.load_from_element(element)
41
- }
42
-
43
- end
44
-
45
- # ensure product information is output to xml correctly
46
- # TODO: test more than just IDValue and TitleText
47
- def test_to_element
48
-
49
- product = RBook::Onix::Product.new
50
- product.product_identifier = '0977616606'
51
- product.title = 'This is a title'
52
- product.publisher = 'Chalice'
53
-
54
- contributor = RBook::Onix::Contributor.new
55
- contributor.sequence_number = '0'
56
- contributor.name_inverted = 'Healy, James'
57
- contributor.role = 'A01'
58
- product.add_contributor(contributor)
59
-
60
- supply_detail = RBook::Onix::SupplyDetail.new
61
- supply_detail.supplier_name = 'Walker'
62
- supply_detail.availability_code = 'CS'
63
- supply_detail.price = 29.95
64
- product.add_supply_detail(supply_detail)
65
-
66
- doc = product.to_element
67
-
68
- assert_not_equal(nil,REXML::XPath.first(doc, '/ProductIdentifier/IDValue'))
69
- assert_equal("0977616606", REXML::XPath.first(doc, '/ProductIdentifier/IDValue').text)
70
- assert_not_equal(nil,REXML::XPath.first(doc, '/Title/TitleText'), 'TitleText must not be nil')
71
- assert_equal("This is a title", REXML::XPath.first(doc, '/Title/TitleText').text)
72
- assert_not_equal(nil, REXML::XPath.first(doc, '/Contributor'), 'Expected product element to contain a contributor')
73
- assert_not_equal(nil, REXML::XPath.first(doc, '/Publisher/PublisherName'), 'Expected publisher name element to contain a contributor')
74
- assert_equal("Chalice", REXML::XPath.first(doc, '/Publisher/PublisherName').text)
75
- assert_not_equal(nil, REXML::XPath.first(doc, '/SupplyDetail'), 'Expected product element to contain a supply detail')
76
- end
77
-
78
- def test_to_s_valid_utf8_charset
79
-
80
- # create an Onix::Product fragment
81
- product = RBook::Onix::Product.new
82
- product.product_identifier = "0977616606"
83
- product.title = "Test Title\x11"
84
- product.subtitle = "Test Subtitle\x11"
85
- product.website = "http://www.google.com\x11"
86
- product.form = "BA\x11"
87
- product.bicmainsubject = "FGD\x11"
88
- product.description = "This is a sample description\x11"
89
- product.publisher = "Publisher\x11"
90
-
91
- fragment = product.to_s
92
-
93
- # loop over each byte in the product element and check it's
94
- # a valid UTF-8 character
95
- fragment.each_byte do |c|
96
- n = XChar::CP1252[c] || c
97
- n = nil unless XChar::VALID.find {|range| range.include? n}
98
- assert_not_equal nil, n, "Non valid UTF8 char detected (code: #{n.to_s})"
99
- end
100
- end
101
- end