Commit d056407511404579f6c2d086d55e459feac01407
Committed by
Paulo Meireles
1 parent
63911c66
Exists in
master
and in
28 other branches
[Mezuro] Finished refactoring project model design.
Showing
7 changed files
with
64 additions
and
60 deletions
Show diff stats
plugins/mezuro/lib/mezuro_plugin/project_content.rb
| @@ -21,7 +21,7 @@ class MezuroPlugin::ProjectContent < Article | @@ -21,7 +21,7 @@ class MezuroPlugin::ProjectContent < Article | ||
| 21 | 21 | ||
| 22 | def project | 22 | def project |
| 23 | begin | 23 | begin |
| 24 | - @project ||= Kalibro::Client::ProjectClient.project(name) | 24 | + @project ||= Kalibro::Project.find_by_name(name) |
| 25 | rescue Exception => error | 25 | rescue Exception => error |
| 26 | errors.add_to_base(error.message) | 26 | errors.add_to_base(error.message) |
| 27 | end | 27 | end |
| @@ -55,13 +55,13 @@ client.first_result_after(name, date) | @@ -55,13 +55,13 @@ client.first_result_after(name, date) | ||
| 55 | end | 55 | end |
| 56 | 56 | ||
| 57 | after_save :send_project_to_service | 57 | after_save :send_project_to_service |
| 58 | - after_destroy :remove_project_from_service | 58 | + after_destroy :destroy_project_from_service |
| 59 | 59 | ||
| 60 | private | 60 | private |
| 61 | 61 | ||
| 62 | def validate_kalibro_project_name | 62 | def validate_kalibro_project_name |
| 63 | begin | 63 | begin |
| 64 | - existing = Kalibro::Client::ProjectClient.new.project_names | 64 | + existing = Kalibro::Project.all_names |
| 65 | rescue Exception => error | 65 | rescue Exception => error |
| 66 | errors.add_to_base(error.message) | 66 | errors.add_to_base(error.message) |
| 67 | end | 67 | end |
| @@ -79,7 +79,7 @@ client.first_result_after(name, date) | @@ -79,7 +79,7 @@ client.first_result_after(name, date) | ||
| 79 | 79 | ||
| 80 | def send_project_to_service | 80 | def send_project_to_service |
| 81 | begin | 81 | begin |
| 82 | - Kalibro::Client::ProjectClient.save(self) | 82 | + Kalibro::Project.create(self).save |
| 83 | Kalibro::Client::KalibroClient.process_project(name, periodicity_in_days) | 83 | Kalibro::Client::KalibroClient.process_project(name, periodicity_in_days) |
| 84 | rescue Exception => error | 84 | rescue Exception => error |
| 85 | errors.add_to_base(error.message) | 85 | errors.add_to_base(error.message) |
| @@ -87,13 +87,12 @@ client.first_result_after(name, date) | @@ -87,13 +87,12 @@ client.first_result_after(name, date) | ||
| 87 | 87 | ||
| 88 | end | 88 | end |
| 89 | 89 | ||
| 90 | - def remove_project_from_service | 90 | + def destroy_project_from_service |
| 91 | begin | 91 | begin |
| 92 | - Kalibro::Client::ProjectClient.remove(name) | 92 | + Kalibro::Project.destroy(name) |
| 93 | rescue Exception => error | 93 | rescue Exception => error |
| 94 | errors.add_to_base(error.message) | 94 | errors.add_to_base(error.message) |
| 95 | end | 95 | end |
| 96 | - | ||
| 97 | end | 96 | end |
| 98 | 97 | ||
| 99 | def module_result_client | 98 | def module_result_client |
plugins/mezuro/test/fixtures/project_fixtures.rb
| @@ -2,16 +2,28 @@ require File.dirname(__FILE__) + '/repository_fixtures' | @@ -2,16 +2,28 @@ require File.dirname(__FILE__) + '/repository_fixtures' | ||
| 2 | 2 | ||
| 3 | class ProjectFixtures | 3 | class ProjectFixtures |
| 4 | 4 | ||
| 5 | - def self.qt_calculator | ||
| 6 | - Kalibro::Project.new qt_calculator_hash | 5 | + def self.project |
| 6 | + Kalibro::Project.new project_hash | ||
| 7 | end | 7 | end |
| 8 | 8 | ||
| 9 | - def self.qt_calculator_hash | 9 | + def self.project_content |
| 10 | + content = MezuroPlugin::ProjectContent.new | ||
| 11 | + content.name = 'Qt-Calculator' | ||
| 12 | + content.license = 'GPL' | ||
| 13 | + content.description = 'Calculator for Qt' | ||
| 14 | + content.repository_type = RepositoryFixtures.repository_hash[:type] | ||
| 15 | + content.repository_url = RepositoryFixtures.repository_hash[:address] | ||
| 16 | + content.configuration_name = 'Kalibro for Java' | ||
| 17 | + content.periodicity_in_days = 1 | ||
| 18 | + content | ||
| 19 | + end | ||
| 20 | + | ||
| 21 | + def self.project_hash | ||
| 10 | { | 22 | { |
| 11 | :name => 'Qt-Calculator', | 23 | :name => 'Qt-Calculator', |
| 12 | :license => 'GPL', | 24 | :license => 'GPL', |
| 13 | :description => 'Calculator for Qt', | 25 | :description => 'Calculator for Qt', |
| 14 | - :repository => RepositoryFixtures.qt_calculator_hash, | 26 | + :repository => RepositoryFixtures.repository_hash, |
| 15 | :configuration_name => 'Kalibro for Java', | 27 | :configuration_name => 'Kalibro for Java', |
| 16 | :state => 'READY' | 28 | :state => 'READY' |
| 17 | } | 29 | } |
plugins/mezuro/test/fixtures/project_result_fixtures.rb
| @@ -6,7 +6,7 @@ class ProjectResultFixtures | @@ -6,7 +6,7 @@ class ProjectResultFixtures | ||
| 6 | 6 | ||
| 7 | def self.qt_calculator | 7 | def self.qt_calculator |
| 8 | result = Kalibro::Entities::ProjectResult.new | 8 | result = Kalibro::Entities::ProjectResult.new |
| 9 | - result.project = ProjectFixtures.qt_calculator | 9 | + result.project = ProjectFixtures.project |
| 10 | result.date = ModuleResultFixtures.create.date | 10 | result.date = ModuleResultFixtures.create.date |
| 11 | result.load_time = 14878 | 11 | result.load_time = 14878 |
| 12 | result.analysis_time = 1022 | 12 | result.analysis_time = 1022 |
| @@ -16,7 +16,7 @@ class ProjectResultFixtures | @@ -16,7 +16,7 @@ class ProjectResultFixtures | ||
| 16 | end | 16 | end |
| 17 | 17 | ||
| 18 | def self.qt_calculator_hash | 18 | def self.qt_calculator_hash |
| 19 | - {:project => ProjectFixtures.qt_calculator_hash, :date => ModuleResultFixtures.create_hash[:date], | 19 | + {:project => ProjectFixtures.project_hash, :date => ModuleResultFixtures.create_hash[:date], |
| 20 | :load_time => 14878, :analysis_time => 1022, :source_tree => ModuleNodeFixtures.qt_calculator_tree_hash, | 20 | :load_time => 14878, :analysis_time => 1022, :source_tree => ModuleNodeFixtures.qt_calculator_tree_hash, |
| 21 | :collect_time => 14878} | 21 | :collect_time => 14878} |
| 22 | end | 22 | end |
plugins/mezuro/test/fixtures/repository_fixtures.rb
| 1 | class RepositoryFixtures | 1 | class RepositoryFixtures |
| 2 | 2 | ||
| 3 | - def self.qt_calculator | ||
| 4 | - Kalibro::Repository.new qt_calculator_hash | 3 | + def self.repository |
| 4 | + Kalibro::Repository.new repository_hash | ||
| 5 | end | 5 | end |
| 6 | 6 | ||
| 7 | - def self.qt_calculator_hash | 7 | + def self.repository_hash |
| 8 | {:type => 'SUBVERSION', :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} | 8 | {:type => 'SUBVERSION', :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} |
| 9 | end | 9 | end |
| 10 | 10 |
plugins/mezuro/test/unit/kalibro/project_test.rb
| @@ -5,11 +5,18 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | @@ -5,11 +5,18 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | ||
| 5 | class ProjectTest < ActiveSupport::TestCase | 5 | class ProjectTest < ActiveSupport::TestCase |
| 6 | 6 | ||
| 7 | def setup | 7 | def setup |
| 8 | - @hash = ProjectFixtures.qt_calculator_hash | ||
| 9 | - @project = ProjectFixtures.qt_calculator | 8 | + @hash = ProjectFixtures.project_hash |
| 9 | + @project = ProjectFixtures.project | ||
| 10 | + @project_content = ProjectFixtures.project_content | ||
| 10 | end | 11 | end |
| 11 | 12 | ||
| 12 | - should 'get project by name' do | 13 | + should 'get all project names' do |
| 14 | + response_hash = {:project_name => [@project.name]} | ||
| 15 | + Kalibro::Project.expects(:request).with(:get_project_names).returns(response_hash) | ||
| 16 | + assert_equal response_hash[:project_name], Kalibro::Project.all_names | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + should 'find project by name' do | ||
| 13 | request_body = {:project_name => @project.name} | 20 | request_body = {:project_name => @project.name} |
| 14 | response_hash = {:project => @hash} | 21 | response_hash = {:project => @hash} |
| 15 | Kalibro::Project.expects(:new).with(@hash).returns(@project) | 22 | Kalibro::Project.expects(:new).with(@hash).returns(@project) |
| @@ -43,31 +50,24 @@ class ProjectTest < ActiveSupport::TestCase | @@ -43,31 +50,24 @@ class ProjectTest < ActiveSupport::TestCase | ||
| 43 | assert_raise Exception do Kalibro::Project.destroy(@project.name) end | 50 | assert_raise Exception do Kalibro::Project.destroy(@project.name) end |
| 44 | end | 51 | end |
| 45 | 52 | ||
| 46 | -=begin | ||
| 47 | - should 'not try to remove inexistent project from service' do | ||
| 48 | - @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'}) | ||
| 49 | - @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never | ||
| 50 | - Kalibro::Client::ProjectClient.remove(@project.name) | ||
| 51 | - end | ||
| 52 | - | ||
| 53 | - private | ||
| 54 | - | ||
| 55 | - def create_project_content_mock | ||
| 56 | - @project_content = mock | ||
| 57 | - @project_content.expects(:name).returns(@project.name) | ||
| 58 | - @project_content.expects(:license).returns(@project.license) | ||
| 59 | - @project_content.expects(:description).returns(@project.description) | ||
| 60 | - @project_content.expects(:repository_type).returns(@project.repository.type) | ||
| 61 | - @project_content.expects(:repository_url).returns(@project.repository.address) | ||
| 62 | - @project_content.expects(:configuration_name).returns(@project.configuration_name) | 53 | + should 'initialize new project from hash' do |
| 54 | + project = Kalibro::Project.new @hash | ||
| 55 | + assert_equal @project.name, project.name | ||
| 56 | + assert_equal @project.repository.type, project.repository.type | ||
| 63 | end | 57 | end |
| 64 | 58 | ||
| 65 | - should 'create project from hash' do | ||
| 66 | - assert_equal @project, Kalibro::Project.new(@hash) | 59 | + should 'create project' do |
| 60 | + project = Kalibro::Project.create @project_content | ||
| 61 | + assert_equal @project.name, project.name | ||
| 62 | + assert_equal @project.repository.type, project.repository.type | ||
| 67 | end | 63 | end |
| 68 | 64 | ||
| 69 | should 'convert project to hash' do | 65 | should 'convert project to hash' do |
| 70 | - assert_equal @hash, @project.to_hash | 66 | + hash = @project.to_hash |
| 67 | + assert_equal @hash[:name], hash[:name] | ||
| 68 | + assert_equal @hash[:configuration_name], hash[:configuration_name] | ||
| 69 | + assert_equal @hash[:repository], hash[:repository] | ||
| 70 | + assert_equal @hash[:state], hash[:state] | ||
| 71 | end | 71 | end |
| 72 | -=end | 72 | + |
| 73 | end | 73 | end |
plugins/mezuro/test/unit/kalibro/repository_test.rb
| @@ -5,8 +5,8 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" | @@ -5,8 +5,8 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" | ||
| 5 | class RepositoryTest < ActiveSupport::TestCase | 5 | class RepositoryTest < ActiveSupport::TestCase |
| 6 | 6 | ||
| 7 | def setup | 7 | def setup |
| 8 | - @hash = RepositoryFixtures.qt_calculator_hash | ||
| 9 | - @repository = RepositoryFixtures.qt_calculator | 8 | + @hash = RepositoryFixtures.repository_hash |
| 9 | + @repository = RepositoryFixtures.repository | ||
| 10 | end | 10 | end |
| 11 | 11 | ||
| 12 | should 'new repository from hash' do | 12 | should 'new repository from hash' do |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
| @@ -6,15 +6,8 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | @@ -6,15 +6,8 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | ||
| 6 | class ProjectContentTest < ActiveSupport::TestCase | 6 | class ProjectContentTest < ActiveSupport::TestCase |
| 7 | 7 | ||
| 8 | def setup | 8 | def setup |
| 9 | - @project = ProjectFixtures.qt_calculator | ||
| 10 | - @content = MezuroPlugin::ProjectContent.new | ||
| 11 | - @content.name = @project.name | ||
| 12 | - @content.license = @project.license | ||
| 13 | - @content.description = @project.description | ||
| 14 | - @content.repository_type = @project.repository.type | ||
| 15 | - @content.repository_url = @project.repository.address | ||
| 16 | - @content.configuration_name = @project.configuration_name | ||
| 17 | - @content.periodicity_in_days = 1 | 9 | + @project = ProjectFixtures.project |
| 10 | + @content = ProjectFixtures.project_content | ||
| 18 | end | 11 | end |
| 19 | 12 | ||
| 20 | should 'be an article' do | 13 | should 'be an article' do |
| @@ -34,7 +27,7 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -34,7 +27,7 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
| 34 | end | 27 | end |
| 35 | 28 | ||
| 36 | should 'get project from service' do | 29 | should 'get project from service' do |
| 37 | - Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project) | 30 | + Kalibro::Project.expects(:find_by_name).with(@content.name).returns(@project) |
| 38 | assert_equal @project, @content.project | 31 | assert_equal @project, @content.project |
| 39 | end | 32 | end |
| 40 | 33 | ||
| @@ -100,20 +93,20 @@ returns(module_result) | @@ -100,20 +93,20 @@ returns(module_result) | ||
| 100 | end | 93 | end |
| 101 | 94 | ||
| 102 | should 'send correct project to service' do | 95 | should 'send correct project to service' do |
| 103 | - Kalibro::Client::ProjectClient.expects(:save).with(@content) | 96 | + project = mock |
| 97 | + Kalibro::Project.expects(:create).with(@content).returns(project) | ||
| 98 | + project.expects(:save).returns(true) | ||
| 104 | Kalibro::Client::KalibroClient.expects(:process_project).with(@content.name, @content.periodicity_in_days) | 99 | Kalibro::Client::KalibroClient.expects(:process_project).with(@content.name, @content.periodicity_in_days) |
| 105 | @content.send :send_project_to_service | 100 | @content.send :send_project_to_service |
| 106 | end | 101 | end |
| 107 | 102 | ||
| 108 | - should 'remove project from service' do | ||
| 109 | - Kalibro::Client::ProjectClient.expects(:remove).with(@content.name) | ||
| 110 | - @content.send :remove_project_from_service | 103 | + should 'destroy project from service' do |
| 104 | + Kalibro::Project.expects(:destroy).with(@content.name) | ||
| 105 | + @content.send :destroy_project_from_service | ||
| 111 | end | 106 | end |
| 112 | 107 | ||
| 113 | should 'not save a project with an existing project name in kalibro' do | 108 | should 'not save a project with an existing project name in kalibro' do |
| 114 | - client = mock | ||
| 115 | - Kalibro::Client::ProjectClient.expects(:new).returns(client) | ||
| 116 | - client.expects(:project_names).returns([@content.name]) | 109 | + Kalibro::Project.expects(:all_names).returns([@content.name]) |
| 117 | @content.send :validate_kalibro_project_name | 110 | @content.send :validate_kalibro_project_name |
| 118 | assert_equal "Project name already exists in Kalibro", @content.errors.on_base | 111 | assert_equal "Project name already exists in Kalibro", @content.errors.on_base |
| 119 | end | 112 | end |
| @@ -121,7 +114,7 @@ returns(module_result) | @@ -121,7 +114,7 @@ returns(module_result) | ||
| 121 | private | 114 | private |
| 122 | 115 | ||
| 123 | def mock_project_client | 116 | def mock_project_client |
| 124 | - Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project) | 117 | + Kalibro::Project.expects(:find_by_name).with(@content.name).returns(@project) |
| 125 | end | 118 | end |
| 126 | 119 | ||
| 127 | def mock_project_result_client | 120 | def mock_project_result_client |