File: package_live.rb

package info (click to toggle)
ruby-zoom 0.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 296 kB
  • ctags: 99
  • sloc: ansic: 680; xml: 262; ruby: 254; makefile: 2
file content (106 lines) | stat: -rw-r--r-- 3,030 bytes parent folder | download | duplicates (6)
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
class PackageLiveTest < Test::Unit::TestCase

  # test z39.50 instance that supports extended services by connecting to 
  # zebra instance
  #
  # important: you won't be able to run these tests if port 99999 isn't
  # available 
  
  def test_crud_record
    
    #start the zebra server if it's not already started
    Dir.chdir("test/zebra") do
      @pid = fork do
        STDERR.close
        exec "zebrasrv tcp:@:99999 -l live_test.log"
      end
    end
    
    #ensure that the server has time to get up
    sleep 1
    
    @id = '14055446'
    @record = File.read('test/zebra/records/programming_ruby.xml')
    @record_update = File.read('test/zebra/records/programming_ruby_update.xml')

    #make clean before test
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      p = conn.package
      p.wait_action = 'waitIfPossible'      
      p.action = 'recordDelete'
      p.record = @record_update
      p.send('update')
      p.send('commit')
    end

    
    # create
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      p = conn.package
      p.wait_action = 'waitIfPossible'
      p.action = 'specialUpdate'
      p.record = @record
      p.send('update')
      p.send('commit')     
    end
    
    # make sure it's there
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      conn.preferred_record_syntax = 'XML'
      result_set = conn.search("@attr 1=12 \"#{@id}\"")
      assert_equal 1, result_set.length
    end

    #make sure can search by author
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      conn.preferred_record_syntax = 'XML'
      result_set = conn.search("@attr 1=1 David")
      assert_equal 1, result_set.length
    end

    # update
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      p = conn.package
      p.wait_action = 'waitIfPossible'      
      p.action = 'specialUpdate'
      p.record = @record_update
      p.send('update')
      p.send('commit')
    end
    
    # confirm update record is there
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      conn.preferred_record_syntax = 'XML'
      result_set = conn.search("@attr 1=1 Jason")
      assert_equal 1, result_set.length
    end

    # confirm original record has been written over
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      conn.preferred_record_syntax = 'XML'
      result_set = conn.search("@attr 1=1 David")
      assert_equal 0, result_set.length
    end

    # cleanup
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      p = conn.package
      p.wait_action = 'waitIfPossible'
      p.action = 'recordDelete'
      p.record = @record_update
      p.send('update')
      p.send('commit')
    end
    
    # make sure the file has been destroyed
    ZOOM::Connection.open('localhost:99999/test') do |conn|
      conn.preferred_record_syntax = 'XML'
      result_set = conn.search("@attr 1=12 \"#{@id}\"")
      assert_equal 0, result_set.length
    end
    
   Process.kill('TERM', @pid)
   
  end
 
end