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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
|
require_relative "toxbank-setup.rb"
require File.join(File.expand_path(File.dirname(__FILE__)),".." ,".." ,"toxbank-investigation", "util.rb")
begin
puts "Service URI is: #{$investigation[:uri]}"
rescue
puts "Configuration Error: $investigation[:uri] is not defined in: " + File.join(ENV["HOME"],".opentox","config","test.rb")
exit
end
class TBInvestigationBasic < MiniTest::Test
#i_suck_and_my_tests_are_order_dependent!
# check response from service without header,
# @note expect OpenTox::BadRequestError
def test_01_get_investigations_400
assert_raises OpenTox::BadRequestError do
response = OpenTox::RestClientWrapper.get $investigation[:uri], {}, { :subjectid => $pi[:subjectid] }
end
end
# give wrong header
# @note expect OpenTox::BadRequestError
def test_01_b_wrong_header
assert_raises OpenTox::BadRequestError do
response = OpenTox::RestClientWrapper.get $investigation[:uri], {:accept => "text/text"}, { :subjectid => $pi[:subjectid] }
end
end
# check response from service with header text/uri-list, application/rdf+xml
# @note expect code 200
def test_02_get_investigations_200
response = OpenTox::RestClientWrapper.get $investigation[:uri], {}, { :accept => 'text/uri-list', :subjectid => $pi[:subjectid] }
assert_equal "text/uri-list", response.headers[:content_type]
assert_equal 200, response.code
end
def test_02b_get_investigations_200
response = OpenTox::RestClientWrapper.get $investigation[:uri], {}, { :accept => 'application/rdf+xml', :subjectid => $pi[:subjectid] }
assert_equal "application/rdf+xml", response.headers[:content_type]
assert_equal 200, response.code
end
# check header from service without accept + subjectid
# @note expect 200
def test_03_get_service_header
response = OpenTox::RestClientWrapper.head($investigation[:uri])
assert_equal 200, response.code
end
end
class TBInvestigationREST < MiniTest::Test
i_suck_and_my_tests_are_order_dependent!
def test_00_pre_01_check_subjectids
assert OpenTox::Authorization.is_token_valid(OpenTox::RestClientWrapper.subjectid), "Subjectid for default test user is not valid."
assert OpenTox::Authorization.is_token_valid($pi[:subjectid]), "Subjectid for user: #{$pi[:subjectid]} is not valid."
assert OpenTox::Authorization.is_token_valid($secondpi[:subjectid]), "Subjectid for user: #{$secondpi[:subjectid]} is not valid."
end
# check if the userservice is available
# @note return the secondpi user URI
def test_00_pre_get_user_from_userservice
#guesturi = OpenTox::RestClientWrapper.get("#{$user_service[:uri]}/user?username=guest", nil, {:Accept => "text/uri-list", :subjectid => $pi[:subjectid]}).sub("\n","")
pi2uri = `curl -Lk -X GET -H "Accept:text/uri-list" -H "subjectid:#{$pi[:subjectid]}" #{$user_service[:uri]}/user?username=#{$secondpi[:name]}`.chomp.sub("\n","")
assert_equal "#{$secondpi[:uri]}", pi2uri
end
# check post to investigation service without file,
# @note expect OpenTox::BadRequestError
def test_01a_post_investigation_400_no_file
response = OpenTox::RestClientWrapper.post $investigation[:uri], {}, { :subjectid => $pi[:subjectid] }
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
puts "\nno file: #{task.uri} \n"
assert_equal "Error", task.hasStatus, "Task should be not completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
end
# post with wrong mime type,
# @note expect OpenTox::BadRequestError
def test_01b_wrong_mime_type
file = File.join File.dirname(__FILE__), "data/toxbank-investigation/invalid", "empty.zup"
response = OpenTox::RestClientWrapper.post $investigation[:uri], {:file => File.open(file)}, { :subjectid => $pi[:subjectid] }
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
puts "wrong mime: #{task.uri} \n"
assert_equal "Error", task.hasStatus, "Task should be not completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
end
# post an empty zip,
# @note expect OpenTox::BadRequestError
def test_01c_upload_empty_zip
file = File.join File.dirname(__FILE__), "data/toxbank-investigation/invalid", "empty.zip"
response = OpenTox::RestClientWrapper.post $investigation[:uri], {:file => File.open(file)}, { :subjectid => $pi[:subjectid] }
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
puts "empty file: #{task.uri} \n"
assert_equal "Error", task.hasStatus, "Task should be not completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
end
# post a zip file with whitespace in title,
def test_01d_upload_zip_with_whitespace_in_title
file = File.join File.dirname(__FILE__), "data/toxbank-investigation/invalid", "BII\ I\ 1\ tb2.zip"
response = OpenTox::RestClientWrapper.post $investigation[:uri], {:file => File.open(file)}, { :subjectid => $pi[:subjectid] }
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
uri = task.resultURI
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
OpenTox::RestClientWrapper.delete uri.to_s, {}, {:subjectid => $pi[:subjectid]}
end
def test_01e_upload_zip_with_whitespace_in_file_title
file = File.join File.dirname(__FILE__), "data/toxbank-investigation/valid", "BII-I-1-tb2_whitespaces.zip"
response = OpenTox::RestClientWrapper.post $investigation[:uri], {:file => File.open(file)}, { :subjectid => $pi[:subjectid] }
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
uri = task.resultURI
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
urilist = OpenTox::RestClientWrapper.get( uri, {}, {:accept => 'text/uri-list', :subjectid => $pi[:subjectid] }).split("\n")
assert_match /a_micro%20array\.txt/, urilist.to_s
singlefile = OpenTox::RestClientWrapper.get "#{uri}/isatab/a_micro%20array.txt", {}, {:accept => 'text/plain', :subjectid => $pi[:subjectid] }
assert_equal singlefile.code.to_s, "200"
OpenTox::RestClientWrapper.delete uri.to_s, {}, {:subjectid => $pi[:subjectid]}
end
# create an investigation by uploading a zip file,
# @todo TODO create by uploading text/tab-separated-values
# @todo TODO create by uploading application/vnd.ms-excel
# @note return metadata as application/rdf+xml,
# check for title "BII-I-1b"
def test_02_post_investigation
@@uri = ""
file = File.join File.dirname(__FILE__), "data/toxbank-investigation/valid", "BII-I-1b-tb2.zip"
response = OpenTox::RestClientWrapper.post $investigation[:uri], {:file => File.open(file)}, { :subjectid => $pi[:subjectid] }
task_uri = response.chomp
#puts task_uri
task = OpenTox::Task.new task_uri
task.wait
uri = task.resultURI
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
#puts uri
@@uri = URI(uri)
response = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
assert @@uri.host == URI($investigation[:uri]).host
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(response.to_s){|r| r.each{|s| @g << s}}
assert @g.has_predicate?(RDF::DC.title), "Metadata Graph don't have predicate #{RDF::DC.title}"
@g.query(:predicate => RDF::DC.title){|r| assert_match /Growth control of the eukaryote cell: a systems biology study in yeast/, r[2].to_s}
#TODO add raw data for testing. Subtask is already removed at this point for this investigation
# check subtask uri for raw data
#assert @g.has_predicate?(RDF::ISA.hasSubTaskURI), "Metadata Graph don't have predicate #{RDF::ISA.hasSubTaskURI}"
end
# check that policy files not listed in uri-list
# check that log, modified, published, searchable helper files not listed in uri-list
def test_02a_check_policy_file_not_listed
result = OpenTox::RestClientWrapper.get("#{@@uri}", {}, {:accept => "text/uri-list", :subjectid => $pi[:subjectid]}).split("\n")
assert result.grep(/user_policies/).size == 0
assert result.grep(/log|modified|published|searchable/i).size == 0
end
# check for uri-list as text/uri-list
# @note returns all listet investigations in service
def test_02b_check_for_text_uri_list
result = OpenTox::RestClientWrapper.get("#{$investigation[:uri]}", {}, {:accept => "text/uri-list", :subjectid => $pi[:subjectid]}).split("\n")
assert_match /#{@@uri}/, result.to_s
end
# check for uri-list as application/rdf+xml
# @note returns all listet investigtions in service
def test_02b2_check_for_rdfxml_uri_list
result = OpenTox::RestClientWrapper.get("#{$investigation[:uri]}", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}).split("\n")
assert_match /rdf\:RDF xmlns\:rdf/, result.to_s
assert_match /#{@@uri}/, result.to_s
end
# check for uri-list as application/rdf+xml
# @note returns list of user investigations as rdf+xml
def test_02c_check_for_rdf_uri_list
result = OpenTox::RestClientWrapper.get("#{$investigation[:uri]}", {}, {:user => "#{$pi[:uri]}", :accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}).split("\n")
assert_match /#{@@uri}/, result.to_s
end
# check for uri-list of a given user as application/json
# @note returns list of users investigations as json
def test_02d_check_for_users_investigations
result = OpenTox::RestClientWrapper.get("#{$investigation[:uri]}", {}, {:user => "#{$pi[:uri]}", :accept => "application/json", :subjectid => $pi[:subjectid]})
#puts result
assert_match /#{@@uri}/, result
assert_match /(\d{10})/, result # quickcheck for timestamp
end
# check for uri-list of an inexisting user
# @note returns nothing if inexisting user
def test_02e_check_with_inexisting_user
result = OpenTox::RestClientWrapper.get("#{$investigation[:uri]}", {}, {:user => "#{$user_service[:uri]}/user/U01", :accept => "application/json", :subjectid => $pi[:subjectid]})
refute_match /#{@@uri}/, result.to_s
end
# check for uri-list of a secondpi user
# @note returns nothing because there are no investigations of this user
def test_02f_check_for_pi2user_uris
result = OpenTox::RestClientWrapper.get("#{$investigation[:uri]}", {}, {:user => "#{$secondpi[:uri]}", :accept => "application/json", :subjectid => $secondpi[:subjectid]})
refute_match /#{@@uri}/, result.to_s
end
# check for flag "isPublished" is false,
# @note default behaviour on new investigations
def test_03a_check_published_false
data = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(data.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::TB.isPublished){|r| assert_match /false/, r[2].to_s}
end
# update flag "isPublished",
# @note try to update with other value than "true" and expect flag value "false",
# try to update with value "true" and expect flag value "true",
# update policy to allow read by group "G2",
# @todo TODO try to get data without membership to "G2",
# @todo TODO try to give inexisting group read policy
def test_03b_put_published
res = OpenTox::RestClientWrapper.put @@uri.to_s, { :published => "yes"}, { :subjectid => $pi[:subjectid] }
task_uri = res.chomp
task = OpenTox::Task.new task_uri
task.wait
uri = task.resultURI
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
assert_equal uri, @@uri.to_s
result = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(result.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::TB.isPublished){|r| assert_match /false/, r[2].to_s}
response = OpenTox::RestClientWrapper.put @@uri.to_s, { :published => "true", :allowReadByGroup => "#{$user_service[:uri]}/project/G2"},{ :subjectid => $pi[:subjectid] }
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
uri = task.resultURI
assert_equal @@uri.to_s, uri
data = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(data.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::TB.isPublished){|r| assert_match /true/, r[2].to_s}
end
# check flag "isSummarySearchable" is false,
# @note default behaviour on new investigation
def test_04a_check_summary_searchable_false
data = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(data.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::TB.isSummarySearchable){|r| assert_match /false/, r[2].to_s}
end
# update flag "isSummarySearchable" to "true",
# @note try to update with other value than "true" and expect flag value "false",
# try to update with value "true" and expect flag value "true",
def test_04b_put_summary_searchable
res = OpenTox::RestClientWrapper.put @@uri.to_s, { :summarySearchable => "yes"}, { :subjectid => $pi[:subjectid] }
task_uri = res.chomp
task = OpenTox::Task.new task_uri
task.wait
uri = task.resultURI
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
assert_equal uri, @@uri.to_s
result = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(result.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::TB.isSummarySearchabel){|r| assert_match /false/, r[2].to_s}
response = OpenTox::RestClientWrapper.put @@uri.to_s,{ :summarySearchable => "true" },{ :subjectid => $pi[:subjectid] }
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
uri = task.resultURI
assert_equal uri, @@uri.to_s
data = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(data.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::TB.isSummarySearchable){|r| assert_match /true/, r[2].to_s}
end
# get investigation/{id}/metadata in rdf+xml
# @note check nodes and content: title, abstract,
# hasKeyword, hasOwner, isPublished, isSummarySearchable, hasOrganisation
# @note accept:application/rdf+xml
def test_05a_check_metadata
response = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(response.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::DC.modified){|r| @@modified_time = r[2].to_s}
predicates_to_check = [RDF::TB.hasAuthor,RDF::DC.title,RDF::DC.abstract,RDF::TB.hasKeyword,RDF::TB.hasOwner,RDF::TB.isPublished,RDF::TB.isSummarySearchable,RDF::TB.hasProject,RDF::TB.hasOrganisation,RDF::DC.modified]
predicates_to_check.each do |pred|
assert @g.has_predicate?(pred), "Metadata do not have Predicate #{pred}"
end
@g.query(:predicate => RDF::DC.title){|r| assert_match /Growth control of the eukaryote cell: a systems biology study in yeast/, r[2].to_s}
@g.query(:predicate => RDF::TB.hasOwner){|r| assert_match /U271/, r[2].to_s.split("/").last}
#@g.query(:predicate => RDF::TB.hasOwner){|r| assert_match r[2].to_s.split("/").last, /U115/}
@g.query(:predicate => RDF::TB.hasOrganisation){|r| assert_match /G176/, r[2].to_s.split("/").last}
@g.query(:predicate => RDF::TB.hasProject){|r| assert_match /G2/, r[2].to_s}
@g.query(:predicate => RDF::TB.hasKeyword){|r| assert_match /[Epigenetics|CellViabilityAssay|CellMigrationAssays]/, r[2].to_s.split("#").last}
@g.query(:predicate => RDF::TB.isPublished){|r| assert_match /true/, r[2].to_s}
@g.query(:predicate => RDF::TB.isSummarySearchable){|r| assert_match /true/, r[2].to_s}
@g.query(:predicate => RDF::ISA.hasStudy){|r| assert_match /[S192|S193]/, r[2].to_s.split("/").last}
@g.query(:predicate => RDF::DC.abstract){|r| assert_match /Background Cell growth underlies many key cellular and developmental processes/, r[2].to_s}
end
# get related protocol uris
# @note returns related protocol uri of a study
def test_05_b
response = OpenTox::RestClientWrapper.get "#{@@uri}/protocol", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
assert_match /SEURAT\-Protocol\-245\-1/, response.to_s
end
# get metadata
# @note accept:text/turtle
def test_05c
response = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "text/turtle", :subjectid => $pi[:subjectid]}
assert_equal "text/turtle", response.headers[:content_type]
end
# get metadata
# @note accept:text/plain
def test_05d
response = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "text/plain", :subjectid => $pi[:subjectid]}
assert_match /^text\/plain/ , response.headers[:content_type]
end
# get a resource as owner
# @note expect result
def test_05e
metadata = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
@@resource = ""
RDF::Reader.for(:rdfxml).new(metadata.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::ISA.hasStudy){|r| @@resource = r[2].to_s.split("/").last}
response = OpenTox::RestClientWrapper.get "#{@@uri}/#{@@resource}", {}, {:accept => "text/plain", :subjectid => $pi[:subjectid]}
puts "\nresource: #{@@resource}"
assert_match /Comprehensive high-throughput analyses at the levels of mRNAs|hasProtocol|hasAssay/, response
end
# get a resource as guest
# @note expect no result until investigation is published
def test_05f
assert_raises OpenTox::UnauthorizedError do
response = OpenTox::RestClientWrapper.get "#{@@uri}/#{@@resource}", {}, {:accept => "text/plain"}
end
end
# get investigation/{id}
# @note accept:text/uri-list
def test_06_get_investigation_uri_list
result = OpenTox::RestClientWrapper.get @@uri.to_s, {}, {:accept => "text/uri-list", :subjectid => $pi[:subjectid]}
assert_equal "text/uri-list", result.headers[:content_type]
end
# check that linked FTP file is listed in uri-list
def test_06a_check_ftpfiles
result = OpenTox::RestClientWrapper.get("#{@@uri}", {}, {:accept => "text/uri-list", :subjectid => $pi[:subjectid]}).split("\n")
assert_match "#{@@uri}/files/JIC37_Ethanol_0.07_Internal_1_3.txt", result.to_s
end
# check that linked FTP file has mime_type
def test_06b_check_ftpfiles_type
result = OpenTox::RestClientWrapper.get("#{@@uri}/isatab/JIC37_Ethanol_0.07_Internal_1_3.txt", {}, {:subjectid => $pi[:subjectid]})
assert_match "text/plain", result.headers[:content_type]
end
# get investigation/{id}
# @note accept:application/zip
def test_07_get_investigation_zip
result = OpenTox::RestClientWrapper.get @@uri.to_s, {}, {:accept => "application/zip", :subjectid => $pi[:subjectid]}
assert_equal "application/zip", result.headers[:content_type]
end
# get investigation/{id}
# @note accept:text/tab-separated-values
def test_08_get_investigation_tab
result = OpenTox::RestClientWrapper.get @@uri.to_s, {}, {:accept => "text/tab-separated-values", :subjectid => $pi[:subjectid]}
assert_equal "text/tab-separated-values;charset=utf-8", result.headers[:content_type]
end
# get investigation/{id}
# @note accept:application/rdf+xml
def test_09_get_investigation_check_accept_headers
result = OpenTox::RestClientWrapper.get @@uri.to_s, {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
assert_equal "application/rdf+xml", result.headers[:content_type]
end
# update existing investigation with zip
# @note check flags are "false" and update them to "true"
# @todo TODO update existing investigation with single files
def test_10_a_update_investigation
file = File.join File.dirname(__FILE__), "data/toxbank-investigation/valid", "BII-I-1-tb2.zip"
response = OpenTox::RestClientWrapper.put @@uri.to_s, {:file => File.open(file)}, { :subjectid => $pi[:subjectid] }
assert_equal 202, response.code
task_uri = response.chomp
puts "update investigation:#{task_uri}"
task = OpenTox::Task.new task_uri
task.wait
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
end
# check flags are working after update
# @note expect flags are set to "false",
# default behaviour after update without
# given param on upload.
# @note expect Guest user can not get metadata,
# expect OpenTox::NotAuthorizedError
def test_10_b_check_flags_after_update
response = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
assert_match /<\?xml/, response #PI can get
assert_raises OpenTox::UnauthorizedError do
res = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $secondpi[:subjectid]}
end #Guest can not get
end
# update flag isSummarySearchable
# @note expect secondpi user can get metadata after update
def test_10_c_update_flag_isSearchable
response = OpenTox::RestClientWrapper.put @@uri.to_s,{ :summarySearchable => "true" },{ :subjectid => $pi[:subjectid] }
task_uri = response.chomp
puts "update isSS:#{task_uri}"
task = OpenTox::Task.new task_uri
task.wait
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
response = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
assert_match /<\?xml/, response #PI can get
#secondpi can not get unless published
assert_raises OpenTox::UnauthorizedError do
res = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $secondpi[:subjectid]}
end
end
# check title has changed by update
# @note expect title after update is "BII-I-1"
def test_10_d_check_if_title_has_changed_by_update
# check content
res = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(res.to_s){|r| r.each{|s| @g << s}}
@g.query(:predicate => RDF::TB.isPublished){|r| assert_match /false/, r[2].to_s}
@g.query(:predicate => RDF::TB.isSummarySearchable){|r| assert_match /true/, r[2].to_s}
end
# check investigation data still not reachable as secondpi
# @note expect OpenTox::NotAuthorizedError
def test_10_e_check_investigation_data_still_not_reachable_for_pi2
assert_raises OpenTox::UnauthorizedError do
res = OpenTox::RestClientWrapper.get @@uri.to_s, {}, {:accept => "application/rdf+xml", :subjectid => $secondpi[:subjectid]}
end
end
# update flag isPublished
def test_10_f_update_flag_isPublished
response = OpenTox::RestClientWrapper.put @@uri.to_s, {:published => "true"},{:subjectid => $pi[:subjectid]}
task_uri = response.chomp
puts "isPublished:#{task_uri}"
task = OpenTox::Task.new task_uri
task.wait
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
# check owner can get
res = OpenTox::RestClientWrapper.get @@uri.to_s, {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
assert_match /<\?xml/, res
# check guest can get now metadata
res = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $secondpi[:subjectid]}
assert_match /<\?xml/, res
end
# @note expect data is still not reachable without policy
def test_10_g_guest_can_not_get
assert_raises OpenTox::UnauthorizedError do
res = OpenTox::RestClientWrapper.get @@uri.to_s, {}, {:accept => "application/rdf+xml"}
end
end
# update policy
def test_10_h_update_guest_policy
response = OpenTox::RestClientWrapper.put @@uri.to_s, {:allowReadByUser => "#{$user_service[:uri]}/user/U479"},{:subjectid => $pi[:subjectid]}
task_uri = response.chomp
puts "update Policy: #{task_uri}"
task = OpenTox::Task.new task_uri
task.wait
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
end
# @note data is available with policy
def test_10_i_guest_can_get
res = OpenTox::RestClientWrapper.get @@uri.to_s, {}, {:accept => "application/rdf+xml", :subjectid => $secondpi[:subjectid]}
assert_match /<\?xml/, res
#guest is authorized to get ftp file
result = OpenTox::RestClientWrapper.get("#{@@uri}", {}, {:accept => "text/uri-list", :subjectid => $secondpi[:subjectid]}).split("\n")
assert_match "#{@@uri}/files/JIC37_Ethanol_0.07_Internal_1_3.txt", result.to_s
end
# get investigation/{id}/metadata in rdf and check content
# @see test_05a_check_metadata
# @note expect same content as in test_05a_check_metadata,
# but title has changed
def test_11_check_metadata_again
response = OpenTox::RestClientWrapper.get "#{@@uri}/metadata", {}, {:accept => "application/rdf+xml", :subjectid => $pi[:subjectid]}
@g = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(response.to_s){|r| r.each{|s| @g << s}}
[RDF::TB.hasAuthor,RDF::DC.title,RDF::DC.abstract,RDF::TB.hasKeyword,RDF::TB.hasOwner,RDF::TB.isPublished,RDF::TB.hasProject,RDF::TB.hasOrganisation]. each do |pred|
assert @g.has_predicate?(pred), "Graph do not have predicate #{pred}"
end
@g.query(:predicate => RDF::DC.title){|r| assert_match /Growth control of the eukaryote cell: a systems biology study in yeast/, r[2].to_s}
@g.query(:predicate => RDF::TB.hasOwner){|r| assert_match /U271/, r[2].to_s.split("/").last}
#@g.query(:predicate => RDF::TB.hasOwner){|r| assert_match r[2].to_s.split("/").last, /U115/}
@g.query(:predicate => RDF::TB.hasOrganisation){|r| assert_match /G176/, r[2].to_s.split("/").last}
@g.query(:predicate => RDF::TB.hasProject){|r| assert_match /G2/, r[2].to_s}
@g.query(:predicate => RDF::TB.hasKeyword){|r| assert_match /[Epigenetics|CellViabilityAssay|CellMigrationAssays]/, r[2].to_s.split("#").last}
@g.query(:predicate => RDF::TB.isPublished){|r| assert_match /true/, r[2].to_s}
@g.query(:predicate => RDF::TB.isSummarySearchable){|r| assert_match /true/, r[2].to_s}
@g.query(:predicate => RDF::ISA.hasStudy){|r| assert_match /[S192|S193]/, r[2].to_s.split("/").last}
@g.query(:predicate => RDF::DC.abstract){|r| assert_match /Background Cell growth underlies many key cellular and developmental processes/, r[2].to_s}
@g.query(:predicate => RDF::DC.modified){|r| assert r[2] > @@modified_time.to_s; puts "\nfirst mod: #{@@modified_time} \nsecond mod: #{r[2]}"}
end
# upload a investigation as secondpi
# @note expect only secondpi uris in uri-list
def test_20_a_post_data
uri = ""
file = File.join File.dirname(__FILE__), "data/toxbank-investigation/valid", "BII-I-1b-tb2.zip"
response = OpenTox::RestClientWrapper.post $investigation[:uri], {:file => File.open(file)}, { :subjectid => $secondpi[:subjectid] }
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
u = task.resultURI
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
uri = URI(u)
puts "secondpi-> uri: #{uri}"
puts "pi-> uri: #{@@uri}"
# pi get uris of secondpi
response = OpenTox::RestClientWrapper.get $investigation[:uri], {}, {:user => "#{$user_service[:uri]}/user/U479", :accept => "application/json", :subjectid => $pi[:subjectid]}
refute_match /#{@@uri}/, response
assert_match /#{uri}/, response
result = OpenTox::RestClientWrapper.delete uri.to_s, {}, {:subjectid => $secondpi[:subjectid]}
assert_equal 200, result.code
end
# check the investigation owner's policy
def test_30_check_owner_policy
assert_equal true, OpenTox::Authorization.authorize(@@uri.to_s, "POST", $pi[:subjectid])
assert_equal true, OpenTox::Authorization.authorize(@@uri.to_s, "PUT", $pi[:subjectid])
assert_equal true, OpenTox::Authorization.authorize(@@uri.to_s, "DELETE", $pi[:subjectid])
assert_equal true, OpenTox::Authorization.authorize(@@uri.to_s, "GET", $pi[:subjectid])
# check for guest policy
assert_equal true, OpenTox::Authorization.authorize(@@uri.to_s, "GET", $secondpi[:subjectid])
end
# check how many policies,
# @note expect two policies,
# one for owner, one for group
def test_31_check_policies
OpenTox::RestClientWrapper.subjectid = $pi[:subjectid]
assert_equal Array, OpenTox::Authorization.list_uri_policies(@@uri.to_s).class
assert_equal 3, OpenTox::Authorization.list_uri_policies(@@uri.to_s).size
end
# check if the UI index responses with 200
def test_40_check_ui_index
response = OpenTox::RestClientWrapper.get "#{$search_service[:uri]}/search/index",{},{:subjectid => $pi[:subjectid]}
puts response.inspect
assert_equal 200, response.code
n=0
begin
@response = OpenTox::RestClientWrapper.get "#{$search_service[:uri]}/search/index/investigation?resourceUri=#{CGI.escape(@@uri.to_s)}",{},{:subjectid => $pi[:subjectid]}
n+=1
sleep 1
end while @response.body != @@uri.to_s && n < 10
assert_equal 200, response.code
assert_equal @@uri.to_s, @response.body
end
# try to delete investigation as "guest",
# @note expect OpenTox::UnauthorizedError
def test_90_try_to_delete_id_as_guest
assert_raises OpenTox::UnauthorizedError do
OpenTox::RestClientWrapper.delete @@uri.to_s, {}, {:subjectid => $guestid}
end
end
# try to delete single file of investigation as "guest",
# @note expect OpenTox::UnauthorizedError
def test_91_try_to_delete_id_file_as_guest
assert_raises OpenTox::UnauthorizedError do
OpenTox::RestClientWrapper.delete "#{@@uri.to_s}/a_proteome.txt", {}, {:subjectid => $guestid}
end
end
# try to update an investigation as 'guest',
# @note expect OpenTox::UnauthorizedError
def test_92_try_to_update_id_as_guest
assert_raises OpenTox::UnauthorizedError do
OpenTox::RestClientWrapper.put @@uri.to_s, {:published => "true"}, {:subjectid => $guestid}
end
end
=begin
# delete single file of investigation, currently not implemented
def test_93a_delete_single_file
response = OpenTox::RestClientWrapper.delete "#{@@uri.to_s}/a_proteome.txt", {}, {:subjectid => $pi[:subjectid]}
task_uri = response.chomp
task = OpenTox::Task.new task_uri
task.wait
assert_equal "Completed", task.hasStatus, "Task should be completed but is: #{task.hasStatus}. Task URI is #{task_uri} ."
end
# delete single file of investigation, currently not implemented
def test_93b_delete_single_file
assert_raises OpenTox::ResourceNotFoundError do
OpenTox::RestClientWrapper.get "#{@@uri.to_s}/a_proteome.txt", {}, {:subjectid => $pi[:subjectid]}
end
end
=end
# check if uri is in uri-list
# @note expect investigation uri exist
def test_98_get_investigation
response = OpenTox::RestClientWrapper.get $investigation[:uri], {}, {:accept => "text/uri-list", :subjectid => $pi[:subjectid]}
assert response.index(@@uri.to_s) != nil, "URI: #{@@uri} is not in uri-list"
end
# delete investigation/{id}
# @note expect code 200
def test_99_a_delete_investigation
result = OpenTox::RestClientWrapper.delete @@uri.to_s, {}, {:subjectid => $pi[:subjectid]}
assert_equal 200, result.code
#assert result.match(/^Investigation [a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12} deleted$/)
assert !OpenTox::Authorization.uri_has_policy(@@uri.to_s)
end
# check if @@uri is indexed
def test_99_b_investigation_not_in_index
#response = request_ssl3 "#{$search_service[:uri]}/search/index/investigation?resourceUri=#{CGI.escape(@@uri.to_s)}", "get", $pi[:subjectid]
response = OpenTox::RestClientWrapper.get "#{$search_service[:uri]}/search/index/investigation?resourceUri=#{CGI.escape(@@uri.to_s)}",{},{:subjectid => $pi[:subjectid]}
assert_equal 200, response.code
refute_match /#{@@uri}/, response.to_s
end
# check that deleted uri is no longer in uri-list
# @note expect investigation uri not in uri-list
def test_99_c_check_urilist
response = OpenTox::RestClientWrapper.get $investigation[:uri], {}, {:accept => "text/uri-list", :subjectid => $pi[:subjectid]}
refute_match /#{@@uri}/, response.to_s
end
end
|