-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtc_provider.rb
137 lines (120 loc) · 4.6 KB
/
tc_provider.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require 'test_helper_provider'
class OaiTest < Test::Unit::TestCase
def setup
@mapped_provider = MappedProvider.new
@big_provider = BigProvider.new
@described_provider = DescribedProvider.new
end
def test_additional_description
doc = REXML::Document.new(@described_provider.identify)
assert_equal "oai:test:13900", doc.elements['OAI-PMH/Identify/description/oai-identifier/sampleIdentifier'].text
assert_not_nil doc.elements['OAI-PMH/Identify/my_custom_xml']
end
def test_list_identifiers_for_correct_xml
doc = REXML::Document.new(
@mapped_provider.list_identifiers(:metadata_prefix => 'oai_dc'))
assert_not_nil doc.elements['OAI-PMH/request']
assert_not_nil doc.elements['OAI-PMH/request/@verb']
assert_not_nil doc.elements['OAI-PMH/ListIdentifiers']
assert_not_nil doc.elements['OAI-PMH/ListIdentifiers/header']
assert_not_nil doc.elements['OAI-PMH/ListIdentifiers/header/identifier']
assert_not_nil doc.elements['OAI-PMH/ListIdentifiers/header/datestamp']
assert_not_nil doc.elements['OAI-PMH/ListIdentifiers/header/setSpec']
end
def test_list_records_for_correct_xml
doc = REXML::Document.new(
@mapped_provider.list_records(:metadata_prefix => 'oai_dc'))
assert_not_nil doc.elements['OAI-PMH/request']
assert_not_nil doc.elements['OAI-PMH/request/@verb']
assert_not_nil doc.elements['OAI-PMH/request/@metadata_prefix']
assert_not_nil doc.elements['OAI-PMH/ListRecords/record/header']
assert_not_nil doc.elements['OAI-PMH/ListRecords/record/metadata']
end
def test_mapped_source
assert_nothing_raised do
REXML::Document.new(
@mapped_provider.list_records(:metadata_prefix => 'oai_dc'))
end
doc = REXML::Document.new(
@mapped_provider.list_records(:metadata_prefix => 'oai_dc'))
assert_equal "title_0", doc.elements['OAI-PMH/ListRecords/record/metadata/oai_dc:dc/dc:creator'].text
assert_equal "creator_0", doc.elements['OAI-PMH/ListRecords/record/metadata/oai_dc:dc/dc:title'].text
assert_equal "tag_0", doc.elements['OAI-PMH/ListRecords/record/metadata/oai_dc:dc/dc:subject'].text
end
def test_from
assert_nothing_raised do
REXML::Document.new(
@big_provider.list_records(:metadata_prefix => 'oai_dc'))
end
doc = REXML::Document.new(
@big_provider.list_records(
:metadata_prefix => 'oai_dc',
:from => Time.parse("February 1 2001"))
)
assert_equal 100, doc.elements['OAI-PMH/ListRecords'].to_a.size
doc = REXML::Document.new(
@big_provider.list_records(
:metadata_prefix => 'oai_dc',
:from => Time.parse("January 1 2001"))
)
assert_equal 200, doc.elements['OAI-PMH/ListRecords'].to_a.size
end
def test_until
assert_nothing_raised do
REXML::Document.new(
@big_provider.list_records(:metadata_prefix => 'oai_dc'))
end
doc = REXML::Document.new(
@big_provider.list_records(
:metadata_prefix => 'oai_dc', :until => Time.parse("November 1 2000"))
)
assert_equal 100, doc.elements['OAI-PMH/ListRecords'].to_a.size
end
def test_from_and_until_match
assert_nothing_raised do
@big_provider.list_records(
:metadata_prefix => 'oai_dc',
:from => "2000-11-01T05:00:00Z",
:until => "2000-11-30T05:00:00Z"
)
end
assert_nothing_raised do
@big_provider.list_records(
:metadata_prefix => 'oai_dc',
:from => "2000-11-01",
:until => "2000-11-30"
)
end
assert_raise(OAI::ArgumentException) do
@big_provider.list_records(
:metadata_prefix => 'oai_dc',
:from => "2000-11-01T05:00:00Z",
:until => "2000-11-30"
)
end
end
def test_from_and_until
assert_nothing_raised do
REXML::Document.new(
@big_provider.list_records(:metadata_prefix => 'oai_dc'))
end
doc = REXML::Document.new(
@big_provider.list_records(
:metadata_prefix => 'oai_dc',
:from => Time.parse("November 1 2000"),
:until => Time.parse("November 30 2000"))
)
assert_not_nil doc.elements['OAI-PMH/request']
assert_not_nil doc.elements['OAI-PMH/request/@verb']
assert_not_nil doc.elements['OAI-PMH/request/@from']
assert_not_nil doc.elements['OAI-PMH/request/@until']
assert_equal 100, doc.elements['OAI-PMH/ListRecords'].to_a.size
doc = REXML::Document.new(
@big_provider.list_records(
:metadata_prefix => 'oai_dc',
:from => Time.parse("December 1 2000"),
:until => Time.parse("December 31 2000"))
)
assert_equal 100, doc.elements['OAI-PMH/ListRecords'].to_a.size
end
end