resync 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +42 -0
- data/.rubocop.yml +23 -0
- data/.ruby-version +1 -0
- data/.travis.yml +2 -0
- data/Gemfile +3 -0
- data/LICENSE.md +22 -0
- data/README.md +92 -0
- data/Rakefile +56 -0
- data/example.rb +100 -0
- data/lib/resync/capability_list.rb +85 -0
- data/lib/resync/change_dump.rb +15 -0
- data/lib/resync/change_dump_manifest.rb +15 -0
- data/lib/resync/change_list.rb +15 -0
- data/lib/resync/change_list_index.rb +26 -0
- data/lib/resync/link.rb +87 -0
- data/lib/resync/metadata.rb +112 -0
- data/lib/resync/resource.rb +72 -0
- data/lib/resync/resource_dump.rb +15 -0
- data/lib/resync/resource_dump_manifest.rb +15 -0
- data/lib/resync/resource_list.rb +15 -0
- data/lib/resync/resource_list_index.rb +15 -0
- data/lib/resync/shared/augmented.rb +76 -0
- data/lib/resync/shared/base_resource_list.rb +117 -0
- data/lib/resync/shared/descriptor.rb +135 -0
- data/lib/resync/shared/sitemap_index.rb +32 -0
- data/lib/resync/shared/sorted_resource_list.rb +60 -0
- data/lib/resync/source_description.rb +14 -0
- data/lib/resync/types/change.rb +14 -0
- data/lib/resync/types/change_frequency.rb +18 -0
- data/lib/resync/types.rb +6 -0
- data/lib/resync/version.rb +4 -0
- data/lib/resync/xml.rb +216 -0
- data/lib/resync/xml_parser.rb +65 -0
- data/lib/resync.rb +4 -0
- data/resync.gemspec +36 -0
- data/spec/acceptance/xml_parser_spec.rb +1049 -0
- data/spec/data/examples/README.md +1 -0
- data/spec/data/examples/example-1.xml +12 -0
- data/spec/data/examples/example-12.xml +25 -0
- data/spec/data/examples/example-13.xml +25 -0
- data/spec/data/examples/example-14.xml +23 -0
- data/spec/data/examples/example-15.xml +21 -0
- data/spec/data/examples/example-16.xml +24 -0
- data/spec/data/examples/example-17.xml +39 -0
- data/spec/data/examples/example-18.xml +25 -0
- data/spec/data/examples/example-19.xml +28 -0
- data/spec/data/examples/example-2.xml +18 -0
- data/spec/data/examples/example-20.xml +22 -0
- data/spec/data/examples/example-21.xml +31 -0
- data/spec/data/examples/example-22.xml +41 -0
- data/spec/data/examples/example-23.xml +41 -0
- data/spec/data/examples/example-24.xml +28 -0
- data/spec/data/examples/example-25.xml +21 -0
- data/spec/data/examples/example-26.xml +18 -0
- data/spec/data/examples/example-27.xml +36 -0
- data/spec/data/examples/example-28.xml +34 -0
- data/spec/data/examples/example-29.xml +27 -0
- data/spec/data/examples/example-3.xml +17 -0
- data/spec/data/examples/example-30.xml +18 -0
- data/spec/data/examples/example-31.xml +16 -0
- data/spec/data/examples/example-32.xml +22 -0
- data/spec/data/examples/example-33.xml +22 -0
- data/spec/data/examples/example-4.xml +10 -0
- data/spec/data/examples/example-5.xml +18 -0
- data/spec/data/examples/example-6.xml +21 -0
- data/spec/data/examples/example-7.xml +13 -0
- data/spec/data/examples/example-8.xml +12 -0
- data/spec/data/resourcesync.xsd +148 -0
- data/spec/data/siteindex.xsd +75 -0
- data/spec/data/sitemap.xsd +116 -0
- data/spec/rspec_custom_matchers.rb +89 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/todo.rb +11 -0
- data/spec/unit/resync/capability_list_spec.rb +138 -0
- data/spec/unit/resync/change_dump_manifest_spec.rb +75 -0
- data/spec/unit/resync/change_dump_spec.rb +61 -0
- data/spec/unit/resync/change_list_index_spec.rb +49 -0
- data/spec/unit/resync/change_list_spec.rb +75 -0
- data/spec/unit/resync/link_spec.rb +93 -0
- data/spec/unit/resync/metadata_spec.rb +169 -0
- data/spec/unit/resync/resource_dump_manifest_spec.rb +59 -0
- data/spec/unit/resync/resource_dump_spec.rb +62 -0
- data/spec/unit/resync/resource_list_index_spec.rb +53 -0
- data/spec/unit/resync/resource_list_spec.rb +60 -0
- data/spec/unit/resync/resource_spec.rb +176 -0
- data/spec/unit/resync/shared/augmented_examples.rb +58 -0
- data/spec/unit/resync/shared/base_resource_list_examples.rb +103 -0
- data/spec/unit/resync/shared/descriptor_examples.rb +122 -0
- data/spec/unit/resync/shared/descriptor_spec.rb +33 -0
- data/spec/unit/resync/shared/sorted_list_examples.rb +134 -0
- data/spec/unit/resync/shared/uri_field_examples.rb +36 -0
- data/spec/unit/resync/source_description_spec.rb +55 -0
- data/spec/unit/resync/xml/timenode_spec.rb +48 -0
- data/spec/unit/resync/xml/xml_spec.rb +40 -0
- data/spec/unit/resync/xml_parser_spec.rb +82 -0
- metadata +340 -0
@@ -0,0 +1,1049 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Resync
|
4
|
+
|
5
|
+
describe XMLParser do
|
6
|
+
|
7
|
+
it 'parses example 1' do
|
8
|
+
data = File.read('spec/data/examples/example-1.xml')
|
9
|
+
urlset = XMLParser.parse(data)
|
10
|
+
expect(urlset).to be_a(ResourceList)
|
11
|
+
|
12
|
+
md = urlset.metadata
|
13
|
+
expect(md).not_to be_nil
|
14
|
+
expect(md.capability).to eq('resourcelist')
|
15
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
16
|
+
|
17
|
+
urls = urlset.resources
|
18
|
+
expect(urls.size).to eq(2)
|
19
|
+
|
20
|
+
url0 = urls[0]
|
21
|
+
expect(url0.uri).to eq(URI('http://example.com/res1'))
|
22
|
+
|
23
|
+
url1 = urls[1]
|
24
|
+
expect(url1.uri).to eq(URI('http://example.com/res2'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'parses example 2' do
|
28
|
+
data = File.read('spec/data/examples/example-2.xml')
|
29
|
+
urlset = XMLParser.parse(data)
|
30
|
+
expect(urlset).to be_a(ResourceList)
|
31
|
+
|
32
|
+
md = urlset.metadata
|
33
|
+
expect(md).not_to be_nil
|
34
|
+
expect(md.capability).to eq('resourcelist')
|
35
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
36
|
+
|
37
|
+
urls = urlset.resources
|
38
|
+
expect(urls.size).to eq(2)
|
39
|
+
|
40
|
+
url0 = urls[0]
|
41
|
+
expect(url0.uri).to eq(URI('http://example.com/res1'))
|
42
|
+
expect(url0.modified_time).to be_time(Time.utc(2013, 1, 2, 13))
|
43
|
+
md0 = url0.metadata
|
44
|
+
expect(md0).not_to be_nil
|
45
|
+
expect(md0.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
46
|
+
lns0 = urls[0].links
|
47
|
+
expect(lns0.size).to eq(0)
|
48
|
+
|
49
|
+
url1 = urls[1]
|
50
|
+
expect(url1.uri).to eq(URI('http://example.com/res2'))
|
51
|
+
expect(url1.modified_time).to be_time(Time.utc(2013, 1, 2, 14))
|
52
|
+
md1 = url1.metadata
|
53
|
+
expect(md1).not_to be_nil
|
54
|
+
expect(md1.hashes).to eq('md5' => '1e0d5cb8ef6ba40c99b14c0237be735e')
|
55
|
+
lns1 = urls[1].links
|
56
|
+
expect(lns1.size).to eq(1)
|
57
|
+
ln1 = lns1[0]
|
58
|
+
expect(ln1.rel).to eq('duplicate')
|
59
|
+
expect(ln1.uri).to eq(URI('http://mirror.example.com/res2'))
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'parses example 3' do
|
63
|
+
data = File.read('spec/data/examples/example-3.xml')
|
64
|
+
urlset = XMLParser.parse(data)
|
65
|
+
expect(urlset).to be_a(ChangeList)
|
66
|
+
|
67
|
+
urls = urlset.resources
|
68
|
+
expect(urls.size).to eq(2)
|
69
|
+
url0 = urls[0]
|
70
|
+
expect(url0.uri).to eq(URI('http://example.com/res2.pdf'))
|
71
|
+
expect(url0.modified_time).to be_time(Time.utc(2013, 1, 2, 13))
|
72
|
+
md0 = url0.metadata
|
73
|
+
expect(md0).not_to be_nil
|
74
|
+
expect(md0.change).to be(Resync::Types::Change::UPDATED)
|
75
|
+
|
76
|
+
url1 = urls[1]
|
77
|
+
expect(url1.uri).to eq(URI('http://example.com/res3.tiff'))
|
78
|
+
expect(url1.modified_time).to be_time(Time.utc(2013, 1, 2, 18))
|
79
|
+
md1 = url1.metadata
|
80
|
+
expect(md1).not_to be_nil
|
81
|
+
expect(md1.change).to be(Resync::Types::Change::DELETED)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'parses example 4' do
|
85
|
+
data = File.read('spec/data/examples/example-4.xml')
|
86
|
+
urlset = XMLParser.parse(data)
|
87
|
+
expect(urlset).to be_a(ResourceDump)
|
88
|
+
|
89
|
+
md = urlset.metadata
|
90
|
+
expect(md.capability).to eq('resourcedump')
|
91
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
92
|
+
|
93
|
+
urls = urlset.resources
|
94
|
+
expect(urls.size).to eq(1)
|
95
|
+
|
96
|
+
url0 = urls[0]
|
97
|
+
expect(url0.uri).to eq(URI('http://example.com/resourcedump.zip'))
|
98
|
+
expect(url0.modified_time).to be_time(Time.utc(2013, 1, 3, 9))
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'parses example 5' do
|
102
|
+
data = File.read('spec/data/examples/example-5.xml')
|
103
|
+
urlset = XMLParser.parse(data)
|
104
|
+
expect(urlset).to be_a(ResourceDumpManifest)
|
105
|
+
|
106
|
+
md = urlset.metadata
|
107
|
+
expect(md.capability).to eq('resourcedump-manifest')
|
108
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
109
|
+
|
110
|
+
urls = urlset.resources
|
111
|
+
expect(urls.size).to eq(2)
|
112
|
+
url0 = urls[0]
|
113
|
+
expect(url0.uri).to eq(URI('http://example.com/res1'))
|
114
|
+
expect(url0.modified_time).to be_time(Time.utc(2013, 1, 3, 3))
|
115
|
+
md0 = url0.metadata
|
116
|
+
expect(md0.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
117
|
+
expect(md0.path).to eq('/resources/res1')
|
118
|
+
|
119
|
+
url1 = urls[1]
|
120
|
+
expect(url1.uri).to eq(URI('http://example.com/res2'))
|
121
|
+
expect(url1.modified_time).to be_time(Time.utc(2013, 1, 3, 4))
|
122
|
+
md1 = url1.metadata
|
123
|
+
expect(md1.hashes).to eq('md5' => '1e0d5cb8ef6ba40c99b14c0237be735e')
|
124
|
+
expect(md1.path).to eq('/resources/res2')
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'parses example 6' do
|
128
|
+
data = File.read('spec/data/examples/example-6.xml')
|
129
|
+
urlset = XMLParser.parse(data)
|
130
|
+
expect(urlset).to be_a(CapabilityList)
|
131
|
+
|
132
|
+
links = urlset.links
|
133
|
+
expect(links.size).to eq(2)
|
134
|
+
ln0 = links[0]
|
135
|
+
expect(ln0.rel).to eq('describedby')
|
136
|
+
expect(ln0.uri).to eq(URI('http://example.com/info_about_set1_of_resources.xml'))
|
137
|
+
ln1 = links[1]
|
138
|
+
expect(ln1.rel).to eq('up')
|
139
|
+
expect(ln1.uri).to eq(URI('http://example.com/resourcesync_description.xml'))
|
140
|
+
|
141
|
+
md = urlset.metadata
|
142
|
+
expect(md.capability).to eq('capabilitylist')
|
143
|
+
|
144
|
+
urls = urlset.resources
|
145
|
+
expect(urls.size).to eq(3)
|
146
|
+
|
147
|
+
url0 = urls[0]
|
148
|
+
expect(url0.uri).to eq(URI('http://example.com/dataset1/resourcelist.xml'))
|
149
|
+
md0 = url0.metadata
|
150
|
+
expect(md0.capability).to eq('resourcelist')
|
151
|
+
|
152
|
+
url1 = urls[1]
|
153
|
+
expect(url1.uri).to eq(URI('http://example.com/dataset1/resourcedump.xml'))
|
154
|
+
md1 = url1.metadata
|
155
|
+
expect(md1.capability).to eq('resourcedump')
|
156
|
+
|
157
|
+
url2 = urls[2]
|
158
|
+
expect(url2.uri).to eq(URI('http://example.com/dataset1/changelist.xml'))
|
159
|
+
md2 = url2.metadata
|
160
|
+
expect(md2.capability).to eq('changelist')
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'parses example 7' do
|
164
|
+
data = File.read('spec/data/examples/example-7.xml')
|
165
|
+
urlset = XMLParser.parse(data)
|
166
|
+
expect(urlset).to be_a(SourceDescription)
|
167
|
+
|
168
|
+
links = urlset.links
|
169
|
+
expect(links.size).to eq(1)
|
170
|
+
ln = links[0]
|
171
|
+
expect(ln.rel).to eq('describedby')
|
172
|
+
expect(ln.uri).to eq(URI('http://example.com/info-about-source.xml'))
|
173
|
+
|
174
|
+
md = urlset.metadata
|
175
|
+
expect(md.capability).to eq('description')
|
176
|
+
|
177
|
+
urls = urlset.resources
|
178
|
+
expect(urls.size).to eq(1)
|
179
|
+
|
180
|
+
url = urls[0]
|
181
|
+
expect(url.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
182
|
+
md = url.metadata
|
183
|
+
expect(md.capability).to eq('capabilitylist')
|
184
|
+
links = url.links
|
185
|
+
|
186
|
+
expect(links.size).to eq(1)
|
187
|
+
ln = links[0]
|
188
|
+
expect(ln.rel).to eq('describedby')
|
189
|
+
expect(ln.uri).to eq(URI('http://example.com/info_about_set1_of_resources.xml'))
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'parses example 8' do
|
193
|
+
data = File.read('spec/data/examples/example-8.xml')
|
194
|
+
sitemapindex = XMLParser.parse(data)
|
195
|
+
expect(sitemapindex).to be_a(ResourceListIndex)
|
196
|
+
|
197
|
+
md = sitemapindex.metadata
|
198
|
+
expect(md.capability).to eq('resourcelist')
|
199
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
200
|
+
|
201
|
+
sitemap = sitemapindex.resources
|
202
|
+
expect(sitemap.size).to eq(2)
|
203
|
+
|
204
|
+
sitemap0 = sitemap[0]
|
205
|
+
expect(sitemap0.uri).to eq(URI('http://example.com/resourcelist-part1.xml'))
|
206
|
+
|
207
|
+
sitemap1 = sitemap[1]
|
208
|
+
expect(sitemap1.uri).to eq(URI('http://example.com/resourcelist-part2.xml'))
|
209
|
+
end
|
210
|
+
|
211
|
+
# Examples 9-11 aren't ResourceSync documents
|
212
|
+
|
213
|
+
it 'parses example 12' do
|
214
|
+
data = File.read('spec/data/examples/example-12.xml')
|
215
|
+
urlset = XMLParser.parse(data)
|
216
|
+
expect(urlset).to be_a(SourceDescription)
|
217
|
+
|
218
|
+
links = urlset.links
|
219
|
+
expect(links.size).to eq(1)
|
220
|
+
ln = links[0]
|
221
|
+
expect(ln.rel).to eq('describedby')
|
222
|
+
expect(ln.uri).to eq(URI('http://example.com/info_about_source.xml'))
|
223
|
+
|
224
|
+
md = urlset.metadata
|
225
|
+
expect(md.capability).to eq('description')
|
226
|
+
|
227
|
+
urls = urlset.resources
|
228
|
+
expect(urls.size).to eq(3)
|
229
|
+
|
230
|
+
(1..3).each do |i|
|
231
|
+
url = urls[i - 1]
|
232
|
+
expect(url.uri).to eq(URI("http://example.com/capabilitylist#{i}.xml"))
|
233
|
+
md = url.metadata
|
234
|
+
expect(md.capability).to eq('capabilitylist')
|
235
|
+
links = url.links
|
236
|
+
expect(links.size).to eq(1)
|
237
|
+
ln = links[0]
|
238
|
+
expect(ln.rel).to eq('describedby')
|
239
|
+
expect(ln.uri).to eq(URI("http://example.com/info_about_set#{i}_of_resources.xml"))
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'parses example 13' do
|
244
|
+
data = File.read('spec/data/examples/example-13.xml')
|
245
|
+
urlset = XMLParser.parse(data)
|
246
|
+
expect(urlset).to be_a(CapabilityList)
|
247
|
+
|
248
|
+
links = urlset.links
|
249
|
+
expect(links.size).to eq(2)
|
250
|
+
ln0 = links[0]
|
251
|
+
expect(ln0.rel).to eq('describedby')
|
252
|
+
expect(ln0.uri).to eq(URI('http://example.com/info_about_set1_of_resources.xml'))
|
253
|
+
ln1 = links[1]
|
254
|
+
expect(ln1.rel).to eq('up')
|
255
|
+
expect(ln1.uri).to eq(URI('http://example.com/resourcesync_description.xml'))
|
256
|
+
|
257
|
+
md = urlset.metadata
|
258
|
+
expect(md.capability).to eq('capabilitylist')
|
259
|
+
|
260
|
+
urls = urlset.resources
|
261
|
+
expect(urls.size).to eq(4)
|
262
|
+
|
263
|
+
expected_capabilities = %w(resourcelist resourcedump changelist changedump)
|
264
|
+
(0..3).each do |i|
|
265
|
+
url = urls[i]
|
266
|
+
capability = expected_capabilities[i]
|
267
|
+
expect(url.uri).to eq(URI("http://example.com/dataset1/#{capability}.xml"))
|
268
|
+
md = url.metadata
|
269
|
+
expect(md.capability).to eq(capability)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'parses example 14' do
|
274
|
+
data = File.read('spec/data/examples/example-14.xml')
|
275
|
+
urlset = XMLParser.parse(data)
|
276
|
+
expect(urlset).to be_a(ResourceList)
|
277
|
+
|
278
|
+
links = urlset.links
|
279
|
+
expect(links.size).to eq(1)
|
280
|
+
ln0 = links[0]
|
281
|
+
expect(ln0.rel).to eq('up')
|
282
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
283
|
+
|
284
|
+
md = urlset.metadata
|
285
|
+
expect(md.capability).to eq('resourcelist')
|
286
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
287
|
+
expect(md.completed_time).to be_time(Time.utc(2013, 1, 3, 9, 1))
|
288
|
+
|
289
|
+
urls = urlset.resources
|
290
|
+
expect(urls.size).to eq(2)
|
291
|
+
|
292
|
+
expected_lastmods = [Time.utc(2013, 1, 2, 13), Time.utc(2013, 1, 2, 14)]
|
293
|
+
expected_hashes = [{ 'md5' => '1584abdf8ebdc9802ac0c6a7402c03b6' }, { 'md5' => '1e0d5cb8ef6ba40c99b14c0237be735e', 'sha-256' => '854f61290e2e197a11bc91063afce22e43f8ccc655237050ace766adc68dc784' }]
|
294
|
+
expected_lengths = [8876, 14_599]
|
295
|
+
expected_types = ['text/html', 'application/pdf']
|
296
|
+
|
297
|
+
(0..1).each do |i|
|
298
|
+
url = urls[i]
|
299
|
+
expect(url.uri).to eq(URI("http://example.com/res#{i + 1}"))
|
300
|
+
expect(url.modified_time).to be_time(expected_lastmods[i])
|
301
|
+
md = url.metadata
|
302
|
+
expect(md.hashes).to eq(expected_hashes[i])
|
303
|
+
expect(md.length).to eq(expected_lengths[i])
|
304
|
+
expect(md.mime_type).to be_mime_type(expected_types[i])
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'parses example 15' do
|
309
|
+
data = File.read('spec/data/examples/example-15.xml')
|
310
|
+
sitemapindex = XMLParser.parse(data)
|
311
|
+
expect(sitemapindex).to be_a(ResourceListIndex)
|
312
|
+
|
313
|
+
links = sitemapindex.links
|
314
|
+
expect(links.size).to eq(1)
|
315
|
+
ln0 = links[0]
|
316
|
+
expect(ln0.rel).to eq('up')
|
317
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
318
|
+
|
319
|
+
md = sitemapindex.metadata
|
320
|
+
expect(md.capability).to eq('resourcelist')
|
321
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
322
|
+
expect(md.completed_time).to be_time(Time.utc(2013, 1, 3, 9, 10))
|
323
|
+
|
324
|
+
sitemaps = sitemapindex.resources
|
325
|
+
expect(sitemaps.size).to eq(3)
|
326
|
+
|
327
|
+
expected_times = [Time.utc(2013, 1, 3, 9), Time.utc(2013, 1, 3, 9, 3), Time.utc(2013, 1, 3, 9, 7)]
|
328
|
+
(0..2).each do |i|
|
329
|
+
sitemap = sitemaps[i]
|
330
|
+
expect(sitemap.uri).to eq(URI("http://example.com/resourcelist#{i + 1}.xml"))
|
331
|
+
md = sitemap.metadata
|
332
|
+
expect(md.at_time).to be_time(expected_times[i])
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'parses example 16' do
|
337
|
+
data = File.read('spec/data/examples/example-16.xml')
|
338
|
+
urlset = XMLParser.parse(data)
|
339
|
+
expect(urlset).to be_a(ResourceList)
|
340
|
+
|
341
|
+
links = urlset.links
|
342
|
+
expect(links.size).to eq(2)
|
343
|
+
ln0 = links[0]
|
344
|
+
expect(ln0.rel).to eq('up')
|
345
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
346
|
+
ln1 = links[1]
|
347
|
+
expect(ln1.rel).to eq('index')
|
348
|
+
expect(ln1.uri).to eq(URI('http://example.com/dataset1/resourcelist-index.xml'))
|
349
|
+
|
350
|
+
md = urlset.metadata
|
351
|
+
expect(md.capability).to eq('resourcelist')
|
352
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
353
|
+
|
354
|
+
urls = urlset.resources
|
355
|
+
expect(urls.size).to eq(2)
|
356
|
+
|
357
|
+
expected_lastmods = [Time.utc(2013, 1, 2, 13), Time.utc(2013, 1, 2, 14)]
|
358
|
+
expected_hashes = [{ 'md5' => '1584abdf8ebdc9802ac0c6a7402c8753' }, { 'md5' => '4556abdf8ebdc9802ac0c6a7402c9881' }]
|
359
|
+
expected_lengths = [4385, 883]
|
360
|
+
expected_types = ['application/pdf', 'image/png']
|
361
|
+
|
362
|
+
(0..1).each do |i|
|
363
|
+
url = urls[i]
|
364
|
+
expect(url.uri).to eq(URI("http://example.com/res#{i + 3}"))
|
365
|
+
expect(url.modified_time).to be_time(expected_lastmods[i])
|
366
|
+
md = url.metadata
|
367
|
+
expect(md.hashes).to eq(expected_hashes[i])
|
368
|
+
expect(md.length).to eq(expected_lengths[i])
|
369
|
+
expect(md.mime_type).to be_mime_type(expected_types[i])
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
it 'parses example 17' do
|
374
|
+
data = File.read('spec/data/examples/example-17.xml')
|
375
|
+
urlset = XMLParser.parse(data)
|
376
|
+
expect(urlset).to be_a(ResourceDump)
|
377
|
+
|
378
|
+
links = urlset.links
|
379
|
+
expect(links.size).to eq(1)
|
380
|
+
ln0 = links[0]
|
381
|
+
expect(ln0.rel).to eq('up')
|
382
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
383
|
+
|
384
|
+
md = urlset.metadata
|
385
|
+
expect(md.capability).to eq('resourcedump')
|
386
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
387
|
+
expect(md.completed_time).to be_time(Time.utc(2013, 1, 3, 9, 4))
|
388
|
+
|
389
|
+
urls = urlset.resources
|
390
|
+
expect(urls.size).to eq(3)
|
391
|
+
|
392
|
+
expected_lengths = [4765, 9875, 2298]
|
393
|
+
expected_ats = [Time.utc(2013, 1, 3, 9), Time.utc(2013, 1, 3, 9, 1), Time.utc(2013, 1, 3, 9, 3)]
|
394
|
+
expected_completeds = [Time.utc(2013, 1, 3, 9, 2), Time.utc(2013, 1, 3, 9, 3), Time.utc(2013, 1, 3, 9, 4)]
|
395
|
+
|
396
|
+
(0..2).each do |i|
|
397
|
+
url = urls[i]
|
398
|
+
expect(url.uri).to eq(URI("http://example.com/resourcedump-part#{i + 1}.zip"))
|
399
|
+
md = url.metadata
|
400
|
+
expect(md.mime_type).to be_mime_type('application/zip')
|
401
|
+
expect(md.length).to eq(expected_lengths[i])
|
402
|
+
expect(md.at_time).to be_time(expected_ats[i])
|
403
|
+
expect(md.completed_time).to be_time(expected_completeds[i])
|
404
|
+
links = url.links
|
405
|
+
expect(links.size).to eq(1)
|
406
|
+
ln = links[0]
|
407
|
+
expect(ln.rel).to eq('contents')
|
408
|
+
expect(ln.uri).to eq(URI("http://example.com/resourcedump_manifest-part#{i + 1}.xml"))
|
409
|
+
expect(ln.mime_type).to be_mime_type('application/xml')
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'parses example 18' do
|
414
|
+
data = File.read('spec/data/examples/example-18.xml')
|
415
|
+
urlset = XMLParser.parse(data)
|
416
|
+
expect(urlset).to be_a(ResourceDumpManifest)
|
417
|
+
|
418
|
+
links = urlset.links
|
419
|
+
expect(links.size).to eq(1)
|
420
|
+
ln0 = links[0]
|
421
|
+
expect(ln0.rel).to eq('up')
|
422
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
423
|
+
|
424
|
+
md = urlset.metadata
|
425
|
+
expect(md.capability).to eq('resourcedump-manifest')
|
426
|
+
expect(md.at_time).to be_time(Time.utc(2013, 1, 3, 9))
|
427
|
+
expect(md.completed_time).to be_time(Time.utc(2013, 1, 3, 9, 2))
|
428
|
+
|
429
|
+
urls = urlset.resources
|
430
|
+
expect(urls.size).to eq(2)
|
431
|
+
|
432
|
+
expected_lastmods = [Time.utc(2013, 1, 2, 13), Time.utc(2013, 1, 2, 14)]
|
433
|
+
expected_hashes = [{ 'md5' => '1584abdf8ebdc9802ac0c6a7402c03b6' }, { 'md5' => '1e0d5cb8ef6ba40c99b14c0237be735e', 'sha-256' => '854f61290e2e197a11bc91063afce22e43f8ccc655237050ace766adc68dc784' }]
|
434
|
+
expected_lengths = [8876, 14_599]
|
435
|
+
expected_types = ['text/html', 'application/pdf']
|
436
|
+
|
437
|
+
(0..1).each do |i|
|
438
|
+
url = urls[i]
|
439
|
+
expect(url.uri).to eq(URI("http://example.com/res#{i + 1}"))
|
440
|
+
expect(url.modified_time).to be_time(expected_lastmods[i])
|
441
|
+
md = url.metadata
|
442
|
+
expect(md.hashes).to eq(expected_hashes[i])
|
443
|
+
expect(md.length).to eq(expected_lengths[i])
|
444
|
+
expect(md.mime_type).to be_mime_type(expected_types[i])
|
445
|
+
expect(md.path).to eq("/resources/res#{i + 1}")
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
it 'parses example 19' do
|
450
|
+
data = File.read('spec/data/examples/example-19.xml')
|
451
|
+
urlset = XMLParser.parse(data)
|
452
|
+
expect(urlset).to be_a(ChangeList)
|
453
|
+
|
454
|
+
links = urlset.links
|
455
|
+
expect(links.size).to eq(1)
|
456
|
+
ln0 = links[0]
|
457
|
+
expect(ln0.rel).to eq('up')
|
458
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
459
|
+
|
460
|
+
md = urlset.metadata
|
461
|
+
expect(md.capability).to eq('changelist')
|
462
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3))
|
463
|
+
|
464
|
+
urls = urlset.resources
|
465
|
+
expect(urls.size).to eq(4)
|
466
|
+
|
467
|
+
expected_filenames = %w(res1 res2 res3 res2)
|
468
|
+
expected_extensions = %w(html pdf tiff pdf)
|
469
|
+
expected_lastmods = [Time.utc(2013, 1, 3, 11), Time.utc(2013, 1, 3, 13), Time.utc(2013, 1, 3, 18), Time.utc(2013, 1, 3, 21)]
|
470
|
+
|
471
|
+
expected_changes = [Types::Change::CREATED, Types::Change::UPDATED, Types::Change::DELETED, Types::Change::UPDATED]
|
472
|
+
|
473
|
+
(0..3).each do |i|
|
474
|
+
url = urls[i]
|
475
|
+
expect(url.uri).to eq(URI("http://example.com/#{expected_filenames[i]}.#{expected_extensions[i]}"))
|
476
|
+
expect(url.modified_time).to be_time(expected_lastmods[i])
|
477
|
+
expect(url.metadata.change).to eq(expected_changes[i])
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
it 'parses example 20' do
|
482
|
+
data = File.read('spec/data/examples/example-20.xml')
|
483
|
+
sitemapindex = XMLParser.parse(data)
|
484
|
+
expect(sitemapindex).to be_a(ChangeListIndex)
|
485
|
+
|
486
|
+
links = sitemapindex.links
|
487
|
+
expect(links.size).to eq(1)
|
488
|
+
ln0 = links[0]
|
489
|
+
expect(ln0.rel).to eq('up')
|
490
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
491
|
+
|
492
|
+
md = sitemapindex.metadata
|
493
|
+
expect(md.capability).to eq('changelist')
|
494
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 1))
|
495
|
+
|
496
|
+
sitemaps = sitemapindex.resources
|
497
|
+
expect(sitemaps.size).to eq(3)
|
498
|
+
|
499
|
+
expected_froms = [Time.utc(2013, 1, 1), Time.utc(2013, 1, 2), Time.utc(2013, 1, 3)]
|
500
|
+
expected_untils = [Time.utc(2013, 1, 2), Time.utc(2013, 1, 3), nil]
|
501
|
+
(0..2).each do |i|
|
502
|
+
sitemap = sitemaps[i]
|
503
|
+
expect(sitemap.uri).to eq(URI("http://example.com/2013010#{i + 1}-changelist.xml"))
|
504
|
+
md = sitemap.metadata
|
505
|
+
expect(md.from_time).to be_time(expected_froms[i])
|
506
|
+
expect(md.until_time).to be_time(expected_untils[i])
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
it 'parses example 21' do
|
511
|
+
data = File.read('spec/data/examples/example-21.xml')
|
512
|
+
urlset = XMLParser.parse(data)
|
513
|
+
expect(urlset).to be_a(ChangeList)
|
514
|
+
|
515
|
+
links = urlset.links
|
516
|
+
expect(links.size).to eq(2)
|
517
|
+
ln0 = links[0]
|
518
|
+
expect(ln0.rel).to eq('up')
|
519
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
520
|
+
ln1 = links[1]
|
521
|
+
expect(ln1.rel).to eq('index')
|
522
|
+
expect(ln1.uri).to eq(URI('http://example.com/dataset1/changelist.xml'))
|
523
|
+
|
524
|
+
md = urlset.metadata
|
525
|
+
expect(md.capability).to eq('changelist')
|
526
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 2))
|
527
|
+
expect(md.until_time).to be_time(Time.utc(2013, 1, 3))
|
528
|
+
|
529
|
+
urls = urlset.resources
|
530
|
+
expect(urls.size).to eq(4)
|
531
|
+
|
532
|
+
expected_filenames = %w(res7 res9 res5 res7)
|
533
|
+
expected_extensions = %w(html pdf tiff html)
|
534
|
+
expected_lastmods = [
|
535
|
+
Time.utc(2013, 1, 2, 12),
|
536
|
+
Time.utc(2013, 1, 2, 13),
|
537
|
+
Time.utc(2013, 1, 2, 19),
|
538
|
+
Time.utc(2013, 1, 2, 20)
|
539
|
+
]
|
540
|
+
|
541
|
+
expected_changes = [Types::Change::CREATED, Types::Change::UPDATED, Types::Change::DELETED, Types::Change::UPDATED]
|
542
|
+
|
543
|
+
(0..3).each do |i|
|
544
|
+
url = urls[i]
|
545
|
+
expect(url.uri).to eq(URI("http://example.com/#{expected_filenames[i]}.#{expected_extensions[i]}"))
|
546
|
+
expect(url.modified_time).to be_time(expected_lastmods[i])
|
547
|
+
expect(url.metadata.change).to eq(expected_changes[i])
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
it 'parses example 22' do
|
552
|
+
data = File.read('spec/data/examples/example-22.xml')
|
553
|
+
urlset = XMLParser.parse(data)
|
554
|
+
expect(urlset).to be_a(ChangeDump)
|
555
|
+
|
556
|
+
links = urlset.links
|
557
|
+
expect(links.size).to eq(1)
|
558
|
+
ln0 = links[0]
|
559
|
+
expect(ln0.rel).to eq('up')
|
560
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
561
|
+
|
562
|
+
md = urlset.metadata
|
563
|
+
expect(md.capability).to eq('changedump')
|
564
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 1))
|
565
|
+
|
566
|
+
urls = urlset.resources
|
567
|
+
expect(urls.size).to eq(3)
|
568
|
+
|
569
|
+
expected_lastmods = [
|
570
|
+
Time.utc(2013, 1, 1, 23, 59, 59),
|
571
|
+
Time.utc(2013, 1, 2, 23, 59, 59),
|
572
|
+
Time.utc(2013, 1, 3, 23, 59, 59)
|
573
|
+
]
|
574
|
+
expected_lengths = [3109, 6629, 8124]
|
575
|
+
|
576
|
+
(0..2).each do |i|
|
577
|
+
url = urls[i]
|
578
|
+
expect(url.uri).to eq(URI("http://example.com/2013010#{i + 1}-changedump.zip"))
|
579
|
+
expect(url.modified_time).to eq(expected_lastmods[i])
|
580
|
+
md = url.metadata
|
581
|
+
expect(md.mime_type).to be_mime_type('application/zip')
|
582
|
+
expect(md.length).to eq(expected_lengths[i])
|
583
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, i + 1))
|
584
|
+
expect(md.until_time).to be_time(Time.utc(2013, 1, i + 2))
|
585
|
+
links = url.links
|
586
|
+
expect(links.size).to eq(1)
|
587
|
+
ln = links[0]
|
588
|
+
expect(ln.rel).to eq('contents')
|
589
|
+
expect(ln.uri).to eq(URI("http://example.com/2013010#{i + 1}-changedump-manifest.xml"))
|
590
|
+
expect(ln.mime_type).to be_mime_type('application/xml')
|
591
|
+
end
|
592
|
+
|
593
|
+
end
|
594
|
+
|
595
|
+
it 'parses example 23' do
|
596
|
+
data = File.read('spec/data/examples/example-23.xml')
|
597
|
+
urlset = XMLParser.parse(data)
|
598
|
+
expect(urlset).to be_a(ChangeDumpManifest)
|
599
|
+
|
600
|
+
links = urlset.links
|
601
|
+
expect(links.size).to eq(1)
|
602
|
+
ln0 = links[0]
|
603
|
+
expect(ln0.rel).to eq('up')
|
604
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
605
|
+
|
606
|
+
md = urlset.metadata
|
607
|
+
expect(md.capability).to eq('changedump-manifest')
|
608
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 2))
|
609
|
+
expect(md.until_time).to be_time(Time.utc(2013, 1, 3))
|
610
|
+
|
611
|
+
urls = urlset.resources
|
612
|
+
expect(urls.size).to eq(4)
|
613
|
+
|
614
|
+
expected_filenames = %w(res7 res9 res5 res7)
|
615
|
+
expected_extensions = %w(html pdf tiff html)
|
616
|
+
expected_lastmods = [
|
617
|
+
Time.utc(2013, 1, 2, 12),
|
618
|
+
Time.utc(2013, 1, 2, 13),
|
619
|
+
Time.utc(2013, 1, 2, 19),
|
620
|
+
Time.utc(2013, 1, 2, 20)
|
621
|
+
]
|
622
|
+
expected_changes = [Types::Change::CREATED, Types::Change::UPDATED, Types::Change::DELETED, Types::Change::UPDATED]
|
623
|
+
expected_hashes = [
|
624
|
+
{ 'md5' => '1c1b0e264fa9b7e1e9aa6f9db8d6362b' },
|
625
|
+
{ 'md5' => 'f906610c3d4aa745cb2b986f25b37c5a' },
|
626
|
+
{},
|
627
|
+
{ 'md5' => '0988647082c8bc51778894a48ec3b576' }
|
628
|
+
]
|
629
|
+
expected_lengths = [4339, 38_297, nil, 5426]
|
630
|
+
expected_types = [
|
631
|
+
'text/html',
|
632
|
+
'application/pdf',
|
633
|
+
nil,
|
634
|
+
'text/html'
|
635
|
+
]
|
636
|
+
expected_paths = ['/changes/res7.html', '/changes/res9.pdf', nil, '/changes/res7-v2.html']
|
637
|
+
|
638
|
+
(0..3).each do |i|
|
639
|
+
url = urls[i]
|
640
|
+
expect(url.uri).to eq(URI("http://example.com/#{expected_filenames[i]}.#{expected_extensions[i]}"))
|
641
|
+
expect(url.modified_time).to be_time(expected_lastmods[i])
|
642
|
+
md = url.metadata
|
643
|
+
expect(md.change).to eq(expected_changes[i])
|
644
|
+
expect(md.hashes).to eq(expected_hashes[i])
|
645
|
+
expect(md.length).to eq(expected_lengths[i])
|
646
|
+
expect(md.mime_type).to be_mime_type(expected_types[i])
|
647
|
+
expect(md.path).to eq(expected_paths[i])
|
648
|
+
end
|
649
|
+
end
|
650
|
+
|
651
|
+
it 'parses example 24' do
|
652
|
+
data = File.read('spec/data/examples/example-24.xml')
|
653
|
+
urlset = XMLParser.parse(data)
|
654
|
+
expect(urlset).to be_a(ChangeList)
|
655
|
+
|
656
|
+
links = urlset.links
|
657
|
+
expect(links.size).to eq(1)
|
658
|
+
ln0 = links[0]
|
659
|
+
expect(ln0.rel).to eq('up')
|
660
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
661
|
+
|
662
|
+
md = urlset.metadata
|
663
|
+
expect(md.capability).to eq('changelist')
|
664
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3))
|
665
|
+
|
666
|
+
urls = urlset.resources
|
667
|
+
expect(urls.size).to eq(1)
|
668
|
+
|
669
|
+
url = urls[0]
|
670
|
+
expect(url.uri).to eq(URI('http://example.com/res1'))
|
671
|
+
expect(url.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
672
|
+
md = url.metadata
|
673
|
+
expect(md.change).to be(Types::Change::UPDATED)
|
674
|
+
expect(md.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
675
|
+
expect(md.length).to eq(8876)
|
676
|
+
expect(md.mime_type).to be_mime_type('text/html')
|
677
|
+
|
678
|
+
links = url.links
|
679
|
+
expect(links.size).to eq(3)
|
680
|
+
expected_uris = [URI('http://mirror1.example.com/res1'),
|
681
|
+
URI('http://mirror2.example.com/res1'),
|
682
|
+
URI('gsiftp://gridftp.example.com/res1')]
|
683
|
+
|
684
|
+
(0..2).each do |i|
|
685
|
+
ln = links[i]
|
686
|
+
expect(ln.rel).to eq('duplicate')
|
687
|
+
expect(ln.priority).to eq(i + 1)
|
688
|
+
expect(ln.uri).to eq(expected_uris[i])
|
689
|
+
expect(ln.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
693
|
+
it 'parses example 25' do
|
694
|
+
data = File.read('spec/data/examples/example-25.xml')
|
695
|
+
urlset = XMLParser.parse(data)
|
696
|
+
expect(urlset).to be_a(ChangeList)
|
697
|
+
|
698
|
+
links = urlset.links
|
699
|
+
expect(links.size).to eq(1)
|
700
|
+
ln0 = links[0]
|
701
|
+
expect(ln0.rel).to eq('up')
|
702
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
703
|
+
|
704
|
+
md = urlset.metadata
|
705
|
+
expect(md.capability).to eq('changelist')
|
706
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3, 11))
|
707
|
+
|
708
|
+
urls = urlset.resources
|
709
|
+
expect(urls.size).to eq(1)
|
710
|
+
|
711
|
+
url = urls[0]
|
712
|
+
expect(url.uri).to eq(URI('http://example.com/res1'))
|
713
|
+
expect(url.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
714
|
+
md = url.metadata
|
715
|
+
expect(md.change).to be(Types::Change::UPDATED)
|
716
|
+
links = url.links
|
717
|
+
expect(links.size).to eq(2)
|
718
|
+
ln0 = links[0]
|
719
|
+
expect(ln0.rel).to eq('alternate')
|
720
|
+
expect(ln0.uri).to eq(URI('http://example.com/res1.html'))
|
721
|
+
expect(ln0.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
722
|
+
expect(ln0.mime_type).to be_mime_type('text/html')
|
723
|
+
ln1 = links[1]
|
724
|
+
expect(ln1.rel).to eq('alternate')
|
725
|
+
expect(ln1.uri).to eq(URI('http://example.com/res1.pdf'))
|
726
|
+
expect(ln1.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
727
|
+
expect(ln1.mime_type).to be_mime_type('application/pdf')
|
728
|
+
end
|
729
|
+
|
730
|
+
it 'parses example 26' do
|
731
|
+
data = File.read('spec/data/examples/example-26.xml')
|
732
|
+
urlset = XMLParser.parse(data)
|
733
|
+
expect(urlset).to be_a(ChangeList)
|
734
|
+
|
735
|
+
links = urlset.links
|
736
|
+
expect(links.size).to eq(1)
|
737
|
+
ln = links[0]
|
738
|
+
expect(ln.rel).to eq('up')
|
739
|
+
expect(ln.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
740
|
+
|
741
|
+
md = urlset.metadata
|
742
|
+
expect(md.capability).to eq('changelist')
|
743
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3))
|
744
|
+
|
745
|
+
urls = urlset.resources
|
746
|
+
expect(urls.size).to eq(1)
|
747
|
+
|
748
|
+
url = urls[0]
|
749
|
+
expect(url.uri).to eq(URI('http://example.com/res1.html'))
|
750
|
+
expect(url.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
751
|
+
md = url.metadata
|
752
|
+
expect(md.change).to be(Types::Change::UPDATED)
|
753
|
+
expect(md.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
754
|
+
expect(md.length).to eq(8876)
|
755
|
+
links = url.links
|
756
|
+
expect(links.size).to eq(1)
|
757
|
+
ln = links[0]
|
758
|
+
expect(ln.rel).to eq('canonical')
|
759
|
+
expect(ln.uri).to eq(URI('http://example.com/res1'))
|
760
|
+
expect(ln.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
761
|
+
end
|
762
|
+
|
763
|
+
it 'parses example 27' do
|
764
|
+
data = File.read('spec/data/examples/example-27.xml')
|
765
|
+
urlset = XMLParser.parse(data)
|
766
|
+
expect(urlset).to be_a(ChangeList)
|
767
|
+
|
768
|
+
links = urlset.links
|
769
|
+
expect(links.size).to eq(1)
|
770
|
+
ln0 = links[0]
|
771
|
+
expect(ln0.rel).to eq('up')
|
772
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
773
|
+
|
774
|
+
md = urlset.metadata
|
775
|
+
expect(md.capability).to eq('changelist')
|
776
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3))
|
777
|
+
|
778
|
+
urls = urlset.resources
|
779
|
+
expect(urls.size).to eq(2)
|
780
|
+
|
781
|
+
url0 = urls[0]
|
782
|
+
expect(url0.uri).to eq(URI('http://example.com/res4'))
|
783
|
+
expect(url0.modified_time).to be_time(Time.utc(2013, 1, 3, 17))
|
784
|
+
md0 = url0.metadata
|
785
|
+
expect(md0.change).to be(Types::Change::UPDATED)
|
786
|
+
expect(md0.hashes).to eq('sha-256' => 'f4OxZX_x_DFGFDgghgdfb6rtSx-iosjf6735432nklj')
|
787
|
+
expect(md0.length).to eq(56_778)
|
788
|
+
expect(md0.mime_type).to be_mime_type('application/json')
|
789
|
+
lns0 = url0.links
|
790
|
+
expect(lns0.size).to eq(1)
|
791
|
+
ln0 = lns0[0]
|
792
|
+
expect(ln0.rel).to(eq('http://www.openarchives.org/rs/terms/patch'))
|
793
|
+
expect(ln0.uri).to(eq(URI('http://example.com/res4-json-patch')))
|
794
|
+
expect(ln0.modified_time).to(eq(Time.utc(2013, 1, 3, 17)))
|
795
|
+
expect(ln0.hashes).to(eq('sha-256' => 'y66dER_t_HWEIKpesdkeb7rtSc-ippjf9823742opld'))
|
796
|
+
expect(ln0.length).to(eq(73))
|
797
|
+
expect(ln0.mime_type).to(be_mime_type('application/json-patch'))
|
798
|
+
|
799
|
+
url1 = urls[1]
|
800
|
+
expect(url1.uri).to eq(URI('http://example.com/res5-full.tiff'))
|
801
|
+
expect(url1.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
802
|
+
md1 = url1.metadata
|
803
|
+
expect(md1.change).to be(Types::Change::UPDATED)
|
804
|
+
expect(md1.hashes).to eq('sha-256' => 'f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk')
|
805
|
+
expect(md1.length).to eq(9_788_456_778)
|
806
|
+
expect(md1.mime_type).to be_mime_type('image/tiff')
|
807
|
+
lns1 = url1.links
|
808
|
+
expect(lns1.size).to eq(1)
|
809
|
+
ln1 = lns1[0]
|
810
|
+
expect(ln1.rel).to(eq('http://www.openarchives.org/rs/terms/patch'))
|
811
|
+
expect(ln1.uri).to(eq(URI('http://example.com/res5-diff')))
|
812
|
+
expect(ln1.modified_time).to(eq(Time.utc(2013, 1, 3, 18)))
|
813
|
+
expect(ln1.hashes).to(eq('sha-256' => 'h986gT_t_87HTkjHYE76G558hY-jdfgy76t55sadJUYT'))
|
814
|
+
expect(ln1.length).to(eq(4533))
|
815
|
+
expect(ln1.mime_type).to(be_mime_type('application/x-tiff-diff'))
|
816
|
+
end
|
817
|
+
|
818
|
+
it 'parses example 28' do
|
819
|
+
data = File.read('spec/data/examples/example-28.xml')
|
820
|
+
urlset = XMLParser.parse(data)
|
821
|
+
expect(urlset).to be_a(ChangeList)
|
822
|
+
|
823
|
+
links = urlset.links
|
824
|
+
expect(links.size).to eq(1)
|
825
|
+
ln0 = links[0]
|
826
|
+
expect(ln0.rel).to eq('up')
|
827
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
828
|
+
|
829
|
+
md = urlset.metadata
|
830
|
+
expect(md.capability).to eq('changelist')
|
831
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3))
|
832
|
+
|
833
|
+
urls = urlset.resources
|
834
|
+
expect(urls.size).to eq(2)
|
835
|
+
|
836
|
+
url0 = urls[0]
|
837
|
+
expect(url0.uri).to eq(URI('http://example.com/res2.pdf'))
|
838
|
+
expect(url0.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
839
|
+
md0 = url0.metadata
|
840
|
+
expect(md0.change).to be(Types::Change::UPDATED)
|
841
|
+
expect(md0.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
842
|
+
expect(md0.length).to eq(8876)
|
843
|
+
expect(md0.mime_type).to be_mime_type('application/pdf')
|
844
|
+
lns0 = url0.links
|
845
|
+
expect(lns0.size).to eq(1)
|
846
|
+
ln0 = lns0[0]
|
847
|
+
expect(ln0.rel).to(eq('describedby'))
|
848
|
+
expect(ln0.uri).to(eq(URI('http://example.com/res2_dublin-core_metadata.xml')))
|
849
|
+
expect(ln0.modified_time).to(eq(Time.utc(2013, 1, 1, 12)))
|
850
|
+
expect(ln0.mime_type).to(be_mime_type('application/xml'))
|
851
|
+
|
852
|
+
url1 = urls[1]
|
853
|
+
expect(url1.uri).to eq(URI('http://example.com/res2_dublin-core_metadata.xml'))
|
854
|
+
expect(url1.modified_time).to be_time(Time.utc(2013, 1, 3, 19))
|
855
|
+
md1 = url1.metadata
|
856
|
+
expect(md1.change).to be(Types::Change::UPDATED)
|
857
|
+
expect(md1.mime_type).to be_mime_type('application/xml')
|
858
|
+
lns1 = url1.links
|
859
|
+
expect(lns1.size).to eq(2)
|
860
|
+
ln1 = lns1[0]
|
861
|
+
expect(ln1.rel).to(eq('describes'))
|
862
|
+
expect(ln1.uri).to(eq(URI('http://example.com/res2.pdf')))
|
863
|
+
expect(ln1.modified_time).to(eq(Time.utc(2013, 1, 3, 18)))
|
864
|
+
expect(ln1.hashes).to(eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6'))
|
865
|
+
expect(ln1.length).to(eq(8876))
|
866
|
+
expect(ln1.mime_type).to(be_mime_type('application/pdf'))
|
867
|
+
ln2 = lns1[1]
|
868
|
+
expect(ln2.rel).to(eq('profile'))
|
869
|
+
expect(ln2.uri).to(eq(URI('http://purl.org/dc/elements/1.1/')))
|
870
|
+
end
|
871
|
+
|
872
|
+
it 'parses example 29' do
|
873
|
+
data = File.read('spec/data/examples/example-29.xml')
|
874
|
+
urlset = XMLParser.parse(data)
|
875
|
+
expect(urlset).to be_a(ChangeList)
|
876
|
+
|
877
|
+
links = urlset.links
|
878
|
+
expect(links.size).to eq(1)
|
879
|
+
ln0 = links[0]
|
880
|
+
expect(ln0.rel).to eq('up')
|
881
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
882
|
+
|
883
|
+
md = urlset.metadata
|
884
|
+
expect(md.capability).to eq('changelist')
|
885
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3))
|
886
|
+
|
887
|
+
urls = urlset.resources
|
888
|
+
expect(urls.size).to eq(1)
|
889
|
+
|
890
|
+
url = urls[0]
|
891
|
+
expect(url.uri).to eq(URI('http://example.com/res1'))
|
892
|
+
expect(url.modified_time).to be_time(Time.utc(2013, 1, 3, 18))
|
893
|
+
md = url.metadata
|
894
|
+
expect(md.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
895
|
+
expect(md.length).to eq(8876)
|
896
|
+
expect(md.mime_type).to be_mime_type('text/html')
|
897
|
+
expect(md.change).to be(Types::Change::UPDATED)
|
898
|
+
|
899
|
+
links = url.links
|
900
|
+
expect(links.size).to eq(3)
|
901
|
+
ln0 = links[0]
|
902
|
+
expect(ln0.rel).to eq('memento')
|
903
|
+
expect(ln0.uri).to eq(URI('http://example.com/20130103070000/res1'))
|
904
|
+
expect(ln0.modified_time).to be_time(Time.utc(2013, 1, 2, 18))
|
905
|
+
expect(ln0.mime_type).to be_mime_type('text/html')
|
906
|
+
expect(md.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
907
|
+
expect(md.length).to eq(8876)
|
908
|
+
expect(md.mime_type).to be_mime_type('text/html')
|
909
|
+
ln1 = links[1]
|
910
|
+
expect(ln1.rel).to eq('timegate')
|
911
|
+
expect(ln1.uri).to eq(URI('http://example.com/timegate/http://example.com/res1'))
|
912
|
+
ln2 = links[2]
|
913
|
+
expect(ln2.rel).to eq('timemap')
|
914
|
+
expect(ln2.uri).to eq(URI('http://example.com/timemap/http://example.com/res1'))
|
915
|
+
expect(ln2.mime_type).to be_mime_type('application/link-format')
|
916
|
+
end
|
917
|
+
|
918
|
+
it 'parses example 30' do
|
919
|
+
data = File.read('spec/data/examples/example-30.xml')
|
920
|
+
urlset = XMLParser.parse(data)
|
921
|
+
expect(urlset).to be_a(ChangeList)
|
922
|
+
|
923
|
+
links = urlset.links
|
924
|
+
expect(links.size).to eq(1)
|
925
|
+
ln0 = links[0]
|
926
|
+
expect(ln0.rel).to eq('up')
|
927
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
928
|
+
|
929
|
+
md = urlset.metadata
|
930
|
+
expect(md.capability).to eq('changelist')
|
931
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3))
|
932
|
+
urls = urlset.resources
|
933
|
+
expect(urls.size).to eq(1)
|
934
|
+
|
935
|
+
url = urls[0]
|
936
|
+
expect(url.uri).to eq(URI('http://example.com/res1'))
|
937
|
+
expect(url.modified_time).to be_time(Time.utc(2013, 1, 3, 7))
|
938
|
+
md = url.metadata
|
939
|
+
expect(md.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
940
|
+
expect(md.length).to eq(8876)
|
941
|
+
expect(md.mime_type).to be_mime_type('text/html')
|
942
|
+
expect(md.change).to be(Types::Change::UPDATED)
|
943
|
+
|
944
|
+
links = url.links
|
945
|
+
ln = links[0]
|
946
|
+
expect(ln.rel).to eq('collection')
|
947
|
+
expect(ln.uri).to eq(URI('http://example.com/aggregation/0601007'))
|
948
|
+
end
|
949
|
+
|
950
|
+
it 'parses example 31' do
|
951
|
+
data = File.read('spec/data/examples/example-31.xml')
|
952
|
+
urlset = XMLParser.parse(data)
|
953
|
+
expect(urlset).to be_a(ChangeList)
|
954
|
+
|
955
|
+
links = urlset.links
|
956
|
+
expect(links.size).to eq(1)
|
957
|
+
ln0 = links[0]
|
958
|
+
expect(ln0.rel).to eq('up')
|
959
|
+
expect(ln0.uri).to eq(URI('http://example.com/dataset1/capabilitylist.xml'))
|
960
|
+
|
961
|
+
md = urlset.metadata
|
962
|
+
expect(md.capability).to eq('changelist')
|
963
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3))
|
964
|
+
urls = urlset.resources
|
965
|
+
expect(urls.size).to eq(1)
|
966
|
+
|
967
|
+
url = urls[0]
|
968
|
+
expect(url.uri).to eq(URI('http://original.example.com/res1.html'))
|
969
|
+
expect(url.modified_time).to be_time(Time.utc(2013, 1, 3, 7))
|
970
|
+
md = url.metadata
|
971
|
+
expect(md.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
972
|
+
expect(md.length).to eq(8876)
|
973
|
+
expect(md.mime_type).to be_mime_type('text/html')
|
974
|
+
expect(md.change).to be(Types::Change::UPDATED)
|
975
|
+
end
|
976
|
+
|
977
|
+
it 'parses example 32' do
|
978
|
+
data = File.read('spec/data/examples/example-32.xml')
|
979
|
+
urlset = XMLParser.parse(data)
|
980
|
+
expect(urlset).to be_a(ChangeList)
|
981
|
+
|
982
|
+
links = urlset.links
|
983
|
+
expect(links.size).to eq(1)
|
984
|
+
ln0 = links[0]
|
985
|
+
expect(ln0.rel).to eq('up')
|
986
|
+
expect(ln0.uri).to eq(URI('http://aggregator1.example.com/dataset1/capabilitylist.xml'))
|
987
|
+
|
988
|
+
md = urlset.metadata
|
989
|
+
expect(md.capability).to eq('changelist')
|
990
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3, 11))
|
991
|
+
urls = urlset.resources
|
992
|
+
expect(urls.size).to eq(1)
|
993
|
+
|
994
|
+
url = urls[0]
|
995
|
+
expect(url.uri).to eq(URI('http://aggregator1.example.com/res1.html'))
|
996
|
+
expect(url.modified_time).to be_time(Time.utc(2013, 1, 3, 20))
|
997
|
+
md = url.metadata
|
998
|
+
expect(md.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
999
|
+
expect(md.length).to eq(8876)
|
1000
|
+
expect(md.mime_type).to be_mime_type('text/html')
|
1001
|
+
expect(md.change).to be(Types::Change::UPDATED)
|
1002
|
+
|
1003
|
+
links = url.links
|
1004
|
+
ln = links[0]
|
1005
|
+
expect(ln.rel).to eq('via')
|
1006
|
+
expect(ln.uri).to eq(URI('http://original.example.com/res1.html'))
|
1007
|
+
expect(ln.modified_time).to be_time(Time.utc(2013, 1, 3, 7))
|
1008
|
+
expect(ln.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
1009
|
+
expect(ln.length).to eq(8876)
|
1010
|
+
expect(ln.mime_type).to be_mime_type('text/html')
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
it 'parses example 33' do
|
1014
|
+
data = File.read('spec/data/examples/example-33.xml')
|
1015
|
+
urlset = XMLParser.parse(data)
|
1016
|
+
expect(urlset).to be_a(ChangeList)
|
1017
|
+
|
1018
|
+
links = urlset.links
|
1019
|
+
expect(links.size).to eq(1)
|
1020
|
+
ln0 = links[0]
|
1021
|
+
expect(ln0.rel).to eq('up')
|
1022
|
+
expect(ln0.uri).to eq(URI('http://aggregator2.example.com/dataset1/capabilitylist.xml'))
|
1023
|
+
|
1024
|
+
md = urlset.metadata
|
1025
|
+
expect(md.capability).to eq('changelist')
|
1026
|
+
expect(md.from_time).to be_time(Time.utc(2013, 1, 3, 12))
|
1027
|
+
urls = urlset.resources
|
1028
|
+
expect(urls.size).to eq(1)
|
1029
|
+
|
1030
|
+
url = urls[0]
|
1031
|
+
expect(url.uri).to eq(URI('http://aggregator2.example.com/res1.html'))
|
1032
|
+
expect(url.modified_time).to be_time(Time.utc(2013, 1, 4, 9))
|
1033
|
+
md = url.metadata
|
1034
|
+
expect(md.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
1035
|
+
expect(md.length).to eq(8876)
|
1036
|
+
expect(md.mime_type).to be_mime_type('text/html')
|
1037
|
+
expect(md.change).to be(Types::Change::UPDATED)
|
1038
|
+
|
1039
|
+
links = url.links
|
1040
|
+
ln = links[0]
|
1041
|
+
expect(ln.rel).to eq('via')
|
1042
|
+
expect(ln.uri).to eq(URI('http://original.example.com/res1.html'))
|
1043
|
+
expect(ln.modified_time).to be_time(Time.utc(2013, 1, 3, 7))
|
1044
|
+
expect(ln.hashes).to eq('md5' => '1584abdf8ebdc9802ac0c6a7402c03b6')
|
1045
|
+
expect(ln.length).to eq(8876)
|
1046
|
+
expect(ln.mime_type).to be_mime_type('text/html')
|
1047
|
+
end
|
1048
|
+
end
|
1049
|
+
end
|