Module: SlingTest

Defined in:
lib/nakamura/test.rb

Constant Summary collapse

@@log_level =
Logger::DEBUG

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setLogLevel(level) ⇒ Object



13
14
15
# File 'lib/nakamura/test.rb', line 13

def SlingTest.setLogLevel(level)
  @@log_level = level
end

Instance Method Details

#create_file_node(path, fieldname, filename, data, content_type = "text/plain") ⇒ Object



48
49
50
51
52
# File 'lib/nakamura/test.rb', line 48

def create_file_node(path, fieldname, filename, data, content_type="text/plain")
  res = @s.create_file_node(path, fieldname, filename, data, content_type)
  @created_nodes << path unless @created_nodes.include?(path)
  return res
end

#create_group(groupname, title = nil) ⇒ Object



81
82
83
84
85
86
# File 'lib/nakamura/test.rb', line 81

def create_group(groupname, title = nil)
  g = @um.create_group(groupname, title)
  assert_not_nil(g, "Expected group to be created: #{groupname}")
  @created_groups << groupname
  return g
end

#create_node(path, props = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/nakamura/test.rb', line 40

def create_node(path, props={})
  #puts "Path is #{path}"
  res = @s.create_node(path, props)
  assert_not_equal("500", res.code, "Expected to be able to create node "+res.body)
  @created_nodes << path
  return path
end

#create_pooled_content(filename, content, props = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nakamura/test.rb', line 54

def create_pooled_content(filename, content, props={})
  res = @fm.upload_pooled_file(filename,{},'text/plain')
  assert_not_nil(res)
  assert_equal(true, res.code.to_i >= 200 && res.code.to_i < 300, "Expected to be able to create node #{res.body}")
  json = JSON.parse(res.body)
  assert_not_nil(json[filename])
  assert_not_nil(json[filename]['poolId'])

  path = "/p/#{json[filename]['poolId']}"
  @created_nodes << path unless @created_nodes.include?(path)
  return path
end

#create_test_user(i) ⇒ Object



74
75
76
77
78
79
# File 'lib/nakamura/test.rb', line 74

def create_test_user(i)
  u = @um.create_test_user(i)
  assert_not_nil(u, "Expected user to be created: #{i}")
  @created_users << u
  return u
end

#create_user(username, firstname = nil, lastname = nil) ⇒ Object



67
68
69
70
71
72
# File 'lib/nakamura/test.rb', line 67

def create_user(username, firstname = nil, lastname = nil)
  u = @um.create_user(username, firstname, lastname)
  assert_not_nil(u, "Expected user to be created: #{username}")
  @created_users << u
  return u
end

#setupObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nakamura/test.rb', line 17

def setup
  @s = SlingInterface::Sling.new()
  @um = SlingUsers::UserManager.new(@s)
  @search = SlingSearch::SearchManager.new(@s)
  @fm = SlingFile::FileManager.new(@s)

  @created_nodes = []
  @created_users = []
  @created_groups = []
  @delete = true
  @log = Logger.new(STDOUT)
  @log.level = @@log_level
end

#teardownObject



31
32
33
34
35
36
37
38
# File 'lib/nakamura/test.rb', line 31

def teardown
  if ( @delete ) then
    @s.switch_user(SlingUsers::User.admin_user)
    @created_nodes.reverse.each { |n| @s.delete_node(n) }
    @created_groups.each { |g| @um.delete_group(g) }
    @created_users.each { |u| @um.delete_user(u.name) }
  end
end

#uniquenessObject



88
89
90
# File 'lib/nakamura/test.rb', line 88

def uniqueness()
  Time.now.to_f.to_s.gsub(".", "")
end

#wait_for_indexerObject



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
# File 'lib/nakamura/test.rb', line 92

def wait_for_indexer()
  magic_content = "#{uniqueness()}_#{rand(1000).to_s}"
  current_user = @s.get_user()
  path = "~#{current_user.name}/private/wait_for_indexer_#{magic_content}"
  urlpath = @s.url_for(path)
  res = @s.execute_post(urlpath, {
    "sling:resourceType" => "sakai/widget-data",
    "sakai:indexed-fields" => "foo",
    "foo" => magic_content
  })
  assert(res.code.to_i >= 200 && res.code.to_i < 300, "Expected to be able to create node #{res.body}")
  # Give the indexer up to 20 seconds to catch up, but stop waiting early if
  # we find our test item has landed in the index.
  20.times do
    res = @s.execute_get(@s.url_for("/var/search/pool/all.json?q=#{magic_content}"))
    if JSON.parse(res.body)["total"] != 0
        break
    end
    sleep(1)
  end
  res = @s.execute_post(urlpath, {
    ":operation" => "delete"
  })
  assert(res.code.to_i >= 200 && res.code.to_i < 300, "Expected to be able to delete node #{res.body}")
end