diff --git a/plugins/mezuro/lib/kalibro/client/kalibro_client.rb b/plugins/mezuro/lib/kalibro/client/kalibro_client.rb deleted file mode 100644 index e1c143d..0000000 --- a/plugins/mezuro/lib/kalibro/client/kalibro_client.rb +++ /dev/null @@ -1,39 +0,0 @@ -class Kalibro::Client::KalibroClient - - def self.process_project(project_name) - new.process_project(project_name) - end - - def initialize - @port = Kalibro::Client::Port.new('Kalibro') - end - - def supported_repository_types - @port.request(:get_supported_repository_types)[:repository_type].to_a - end - - def process_project(project_name) - @port.request(:process_project, {:project_name => project_name}) - end - - def self.process_project(project_name, days) - if days.to_i.zero? - new.process_project(project_name) - else - new.process_periodically(project_name, days) - end - end - - def process_periodically(project_name, period_in_days) - @port.request(:process_periodically, {:project_name => project_name, :period_in_days => period_in_days}) - end - - def process_period(project_name) - @port.request(:get_process_period, {:project_name => project_name})[:period] - end - - def cancel_periodic_process(project_name) - @port.request(:cancel_periodic_process, {:project_name => project_name}) - end - -end diff --git a/plugins/mezuro/lib/kalibro/kalibro.rb b/plugins/mezuro/lib/kalibro/kalibro.rb new file mode 100644 index 0000000..902ccb3 --- /dev/null +++ b/plugins/mezuro/lib/kalibro/kalibro.rb @@ -0,0 +1,22 @@ +class Kalibro::Kalibro < Kalibro::Model + + def self.repository_types + request("Kalibro", :get_supported_repository_types)[:repository_type].to_a + end + + def self.process_project(project_name, days = '0') + if days.to_i.zero? + request("Kalibro", :process_project, {:project_name => project_name}) + else + request("Kalibro", :process_periodically, {:project_name => project_name, :period_in_days => days}) + end + end + + def self.process_period(project_name) + request("Kalibro", :get_process_period, {:project_name => project_name})[:period] + end + + def self.cancel_periodic_process(project_name) + request("Kalibro", :cancel_periodic_process, {:project_name => project_name}) + end +end diff --git a/plugins/mezuro/lib/kalibro/model.rb b/plugins/mezuro/lib/kalibro/model.rb index e96e083..f276c11 100644 --- a/plugins/mezuro/lib/kalibro/model.rb +++ b/plugins/mezuro/lib/kalibro/model.rb @@ -38,4 +38,14 @@ class Kalibro::Model xml_name + "Xml" end + def self.client(endpoint) + service_address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml") + Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") + end + + def self.request(endpoint, action, request_body = nil) + response = client(endpoint).request(:kalibro, action) { soap.body = request_body } + response.to_hash["#{action}_response".to_sym] + end + end diff --git a/plugins/mezuro/lib/kalibro/project.rb b/plugins/mezuro/lib/kalibro/project.rb index 5f3f2c2..8d4d3d3 100644 --- a/plugins/mezuro/lib/kalibro/project.rb +++ b/plugins/mezuro/lib/kalibro/project.rb @@ -3,12 +3,12 @@ class Kalibro::Project < Kalibro::Model attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :error def self.all_names - request(:get_project_names)[:project_name] + request("Project", :get_project_names)[:project_name] end def self.find_by_name(project_name) begin - attributes = request(:get_project, :project_name => project_name)[:project] + attributes = request("Project", :get_project, :project_name => project_name)[:project] new attributes rescue Exception => error nil @@ -16,7 +16,7 @@ class Kalibro::Project < Kalibro::Model end def self.destroy(project_name) - request(:remove_project, {:project_name => project_name}) + request("Project", :remove_project, {:project_name => project_name}) end def self.create (content) @@ -34,7 +34,7 @@ class Kalibro::Project < Kalibro::Model def save begin - self.class.request(:save_project, {:project => to_hash}) + self.class.request("Project", :save_project, {:project => to_hash}) true rescue Exception => error false @@ -45,18 +45,5 @@ class Kalibro::Project < Kalibro::Model @repository = (value.kind_of?(Hash)) ? Kalibro::Repository.new(value) : value end - private - - def self.client - endpoint = "Project" - service_address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml") - Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") - end - - def self.request(action, request_body = nil) - response = client.request(:kalibro, action) { soap.body = request_body } - response.to_hash["#{action}_response".to_sym] - end - end diff --git a/plugins/mezuro/lib/mezuro_plugin/project_content.rb b/plugins/mezuro/lib/mezuro_plugin/project_content.rb index d0d5bfa..76bfbe1 100644 --- a/plugins/mezuro/lib/mezuro_plugin/project_content.rb +++ b/plugins/mezuro/lib/mezuro_plugin/project_content.rb @@ -80,7 +80,7 @@ client.first_result_after(name, date) def send_project_to_service begin Kalibro::Project.create(self).save - Kalibro::Client::KalibroClient.process_project(name, periodicity_in_days) + Kalibro::Kalibro.process_project(name, periodicity_in_days) rescue Exception => error errors.add_to_base(error.message) end diff --git a/plugins/mezuro/test/unit/kalibro/client/kalibro_client_test.rb b/plugins/mezuro/test/unit/kalibro/client/kalibro_client_test.rb deleted file mode 100644 index 4ef3417..0000000 --- a/plugins/mezuro/test/unit/kalibro/client/kalibro_client_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require "test_helper" - -class KalibroClientTest < ActiveSupport::TestCase - - def setup - @port = mock - Kalibro::Client::Port.expects(:new).with('Kalibro').returns(@port) - @client = Kalibro::Client::KalibroClient.new - end - - should 'get supported repository types' do - types = ['BAZAAR', 'GIT', 'SUBVERSION'] - @port.expects(:request).with(:get_supported_repository_types).returns({:repository_type => types}) - assert_equal types, @client.supported_repository_types - end - - should 'process project' do - name = 'KalibroClientTest' - @port.expects(:request).with(:process_project, {:project_name => name}) - @client.process_project(name) - end - - should 'instantiate for processing project' do - instance = mock - Kalibro::Client::KalibroClient.expects(:new).returns(instance) - instance.expects(:process_project).with('myproject') - Kalibro::Client::KalibroClient.process_project('myproject', 0) - end - - should 'process project with periodicity' do - name = 'KalibroClientTest' - @port.expects(:request).with(:process_periodically, {:project_name => name, :period_in_days => 30}) - @client.process_periodically(name, 30) - end - - should 'instantiate for processing project periodically' do - instance = mock - Kalibro::Client::KalibroClient.expects(:new).returns(instance) - instance.expects(:process_periodically).with('myproject', 30) - Kalibro::Client::KalibroClient.process_project('myproject', 30) - end - -end diff --git a/plugins/mezuro/test/unit/kalibro/kalibro_test.rb b/plugins/mezuro/test/unit/kalibro/kalibro_test.rb new file mode 100644 index 0000000..47d91ef --- /dev/null +++ b/plugins/mezuro/test/unit/kalibro/kalibro_test.rb @@ -0,0 +1,34 @@ +require "test_helper" + +class KalibroClientTest < ActiveSupport::TestCase + + def setup + @name = 'KalibroTest' + end + + should 'get supported repository types' do + types = ['BAZAAR', 'GIT', 'SUBVERSION'] + Kalibro::Kalibro.expects(:request).with('Kalibro', :get_supported_repository_types).returns({:repository_type => types}) + assert_equal types, Kalibro::Kalibro.repository_types + end + + should 'process project without days' do + Kalibro::Kalibro.expects(:request).with('Kalibro', :process_project, {:project_name => @name}) + Kalibro::Kalibro.process_project(@name) + end + + should 'process project with days' do + Kalibro::Kalibro.expects(:request).with('Kalibro', :process_periodically, {:project_name => @name, :period_in_days => "1"}) + Kalibro::Kalibro.process_project(@name, "1") + end + + should 'process period' do + Kalibro::Kalibro.expects(:request).with('Kalibro', :get_process_period, {:project_name => @name}).returns({:period => "1"}) + assert_equal "1", Kalibro::Kalibro.process_period(@name) + end + + should 'cancel periodic process' do + Kalibro::Kalibro.expects(:request).with("Kalibro", :cancel_periodic_process, {:project_name => @name}) + Kalibro::Kalibro.cancel_periodic_process(@name) + end +end diff --git a/plugins/mezuro/test/unit/kalibro/project_test.rb b/plugins/mezuro/test/unit/kalibro/project_test.rb index 9f5c31d..732bed1 100644 --- a/plugins/mezuro/test/unit/kalibro/project_test.rb +++ b/plugins/mezuro/test/unit/kalibro/project_test.rb @@ -12,7 +12,7 @@ class ProjectTest < ActiveSupport::TestCase should 'get all project names' do response_hash = {:project_name => [@project.name]} - Kalibro::Project.expects(:request).with(:get_project_names).returns(response_hash) + Kalibro::Project.expects(:request).with("Project", :get_project_names).returns(response_hash) assert_equal response_hash[:project_name], Kalibro::Project.all_names end @@ -20,33 +20,33 @@ class ProjectTest < ActiveSupport::TestCase request_body = {:project_name => @project.name} response_hash = {:project => @hash} Kalibro::Project.expects(:new).with(@hash).returns(@project) - Kalibro::Project.expects(:request).with(:get_project, request_body).returns(response_hash) + Kalibro::Project.expects(:request).with("Project", :get_project, request_body).returns(response_hash) assert_equal @project, Kalibro::Project.find_by_name(@project.name) end should 'raise error when project doesnt exist' do request_body = {:project_name => @project.name} - Kalibro::Project.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) + Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) assert_nil Kalibro::Project.find_by_name(@project.name) end should 'return true when project is saved successfully' do - Kalibro::Project.expects(:request).with(:save_project, {:project => @project.to_hash}) + Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}) assert @project.save end should 'return false when project is not saved successfully' do - Kalibro::Project.expects(:request).with(:save_project, {:project => @project.to_hash}).raises(Exception.new) + Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}).raises(Exception.new) assert !(@project.save) end should 'remove existent project from service' do - Kalibro::Project.expects(:request).with(:remove_project, {:project_name => @project.name}) + Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}) Kalibro::Project.destroy(@project.name) end should 'raise error when try to remove inexistent project from service' do - Kalibro::Project.expects(:request).with(:remove_project, {:project_name => @project.name}).raises(Exception.new) + Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}).raises(Exception.new) assert_raise Exception do Kalibro::Project.destroy(@project.name) end end diff --git a/plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb b/plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb index 6b7e707..4dc1e21 100644 --- a/plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb +++ b/plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb @@ -96,7 +96,7 @@ returns(module_result) project = mock Kalibro::Project.expects(:create).with(@content).returns(project) project.expects(:save).returns(true) - Kalibro::Client::KalibroClient.expects(:process_project).with(@content.name, @content.periodicity_in_days) + Kalibro::Kalibro.expects(:process_project).with(@content.name, @content.periodicity_in_days) @content.send :send_project_to_service end -- libgit2 0.21.2