virtuoso_plugin_admin_controller_test.rb
2.77 KB
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
require File.dirname(__FILE__) + '/../test_helper'
class VirtuosoPluginAdminControllerTest < ActionController::TestCase
attr_reader :environment
def setup
@environment = Environment.default
@profile = create_user('profile').person
login_as(@profile.identifier)
end
def mock_settings
{ :virtuoso_uri=>"http://virtuoso.noosfero.com",
:virtuoso_username=>"username",
:virtuoso_password=>"password",
:virtuoso_readonly_username=>"readonly_username",
:virtuoso_readonly_password=>"readonly_password",
:dspace_servers=>[
{"dspace_uri"=>"http://dspace1.noosfero.com"},
{"dspace_uri"=>"http://dspace2.noosfero.com"},
{"dspace_uri"=>"http://dspace3.noosfero.com"}
]
}
end
should 'save virtuoso plugin settings' do
post :index, :settings => mock_settings
@settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin)
assert_equal 'http://virtuoso.noosfero.com', @settings.settings[:virtuoso_uri]
assert_equal 'username', @settings.settings[:virtuoso_username]
assert_equal 'password', @settings.settings[:virtuoso_password]
assert_equal 'readonly_username', @settings.settings[:virtuoso_readonly_username]
assert_equal 'readonly_password', @settings.settings[:virtuoso_readonly_password]
assert_equal 'http://dspace1.noosfero.com', @settings.settings[:dspace_servers][0][:dspace_uri]
assert_equal 'http://dspace2.noosfero.com', @settings.settings[:dspace_servers][1][:dspace_uri]
assert_equal 'http://dspace3.noosfero.com', @settings.settings[:dspace_servers][2][:dspace_uri]
assert_redirected_to :action => 'index'
end
should 'redirect to index after save' do
post :index, :settings => mock_settings
assert_redirected_to :action => 'index'
end
should 'create delayed job to start harvest on force action' do
post :index, :settings => mock_settings
harvest = VirtuosoPlugin::DspaceHarvest.new(environment, "http://dspace1.noosfero.com")
assert !harvest.find_job.present?
get :force_harvest
assert harvest.find_job.present?
end
should 'force harvest from start' do
post :index, :settings => mock_settings
get :force_harvest, :from_start => true
harvest = VirtuosoPlugin::DspaceHarvest.new(environment, "http://dspace2.noosfero.com")
assert harvest.find_job.present?
assert_equal nil, harvest.settings.last_harvest
end
should 'not create delayed job to start harvest on force action without settings' do
post :index, :settings => mock_settings
harvest = VirtuosoPlugin::DspaceHarvest.new(environment, "http://dspace8.noosfero.com")
assert !harvest.find_job.present?, "testing if no job is running"
get :force_harvest
assert !harvest.find_job.present?, "testing if no job is running again"
end
end