summaryrefslogtreecommitdiff
path: root/test/store_query.rb
blob: 2ba3665a27e0a85b63704b142938553939db9f1d (plain)
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
require File.join(File.expand_path(File.dirname(__FILE__)),"setup.rb")

class UploadTest < Test::Unit::TestCase
  
  URI = "https://localhost/BII-I-1.n3"

  def setup
  end
  
  def teardown
  end
  
  def test_01_basic_response
    response = `curl -i -k --user #{$four_store[:user]}:#{$four_store[:password]} '#{$four_store[:uri]}/status/'`.chomp
    assert_match /200/, response
    response = `curl -i -k -u guest:guest '#{$four_store[:uri]}/status/'`.chomp
    assert_match /401/, response
  end
  
  def test_02_add_data
    # upload invalid data
    response = `curl -0 -i -k -u #{$four_store[:user]}:#{$four_store[:password]} -T '#{File.join File.dirname(__FILE__),"data/toxbank-investigation/invalid/BII-invalid.n3"}' -H 'Content-type:text/turtle' '#{$four_store[:uri]}/data/?graph=#{URI}'`.chomp
    assert_match /400/, response
    # upload valid data
    response = `curl -0 -i -k -u #{$four_store[:user]}:#{$four_store[:password]} -T '#{File.join File.dirname(__FILE__),"data/toxbank-investigation/valid/BII-I-1.n3"}' -H 'Content-type:text/turtle' '#{$four_store[:uri]}/data/?graph=#{URI}'`.chomp
    assert_match /201/, response
  end
  
  def test_03_query_all
    response = `curl -i -k -u #{$four_store[:user]}:#{$four_store[:password]} '#{$four_store[:uri]}/sparql/'`.chomp
    assert_match /500/, response
    response = `curl -i -k -u #{$four_store[:user]}:#{$four_store[:password]} -H 'Accept:application/sparql-results+xml' -d "query=CONSTRUCT { ?s ?p ?o } WHERE {?s ?p ?o} LIMIT 10" '#{$four_store[:uri]}/sparql/'`.chomp
    assert_match /200/, response
    assert_match /rdf\:RDF/, response
    assert_match /rdf\:Description/, response
    assert_match /ns0\:hasMember/, response
  end
  
  def test_04_query_sparqle
    response = `curl -i -k -u #{$four_store[:user]}:#{$four_store[:password]} '#{$four_store[:uri]}/sparql/'`.chomp
    assert_match /500/, response
    response = `curl -i -k -u #{$four_store[:user]}:#{$four_store[:password]} -H 'Accept:application/rdf+xml' -d "query=CONSTRUCT { ?s ?p ?o } FROM <#{URI}> WHERE {?s ?p ?o} LIMIT 10" '#{$four_store[:uri]}/sparql/'`.chomp
    assert_match /200/, response
    assert_match /rdf\:RDF/, response
    assert_match /rdf\:Description/, response
    #assert_match /ns0\:hasMember/, response
  end
  
  def test_05_delete_data
    #response = `curl -i -k -u #{FOUR_STORE_USER}:#{FOUR_STORE_PASS} -X DELETE '#{FOUR_STORE}/data/?graph=#{FOUR_STORE}/data/#{FOUR_STORE_USER}/BII-I-1.n3'`.chomp
    response = `curl -i -k -u #{$four_store[:user]}:#{$four_store[:password]} -X DELETE '#{$four_store[:uri]}/data/?graph=#{URI}'`.chomp
    assert_match /200/, response
  end
=begin  
  def test_06_simultaneous_uploads 
    threads = []
    5.times do |t|
      threads << Thread.new(t) do |up|
        puts "Start Time >> " << (Time.now).to_s
        response = `curl -0 -i -k -u #{$four_store[:user]}:#{$four_store[:password]} -T '#{File.join File.dirname(__FILE__),"data/toxbank-investigation/valid/BII-I-1.n3"}' '#{$four_store[:uri]}/data/?graph=#{$four_store[:user]}/test#{t}.n3'`.chomp
        assert_match /201/, response
      end
    end
    threads.each {|aThread| aThread.join}
  end
  
  def test_07_delete_simultaneous 
    threads = []
    5.times do |t|
      threads << Thread.new(t) do |up|
        puts "Start Time >> " << (Time.now).to_s
        response = `curl -i -k -u #{$four_store[:user]}:#{$four_store[:password]} -X DELETE '#{$four_store[:uri]}/data/#{$four_store[:user]}/test#{t}.n3'`.chomp
        assert_match /200/, response
      end
    end
    threads.each {|aThread| aThread.join}
  end
=end
end