Commit 0a3af84ee0e3458cb5274212a4d42f94297febd0
Committed by
João M. M. da Silva
1 parent
94e8959f
Exists in
staging
and in
42 other branches
[Mezuro] Finished refactoring project result model to processing model.
Showing
6 changed files
with
201 additions
and
223 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,49 @@ |
| 1 | +class Kalibro::Processing < Kalibro::Model | |
| 2 | + | |
| 3 | + attr_accessor :id, :date, :state, :error, :process_times, :results_root_id | |
| 4 | + | |
| 5 | + def self.has_processing(repository_id) | |
| 6 | + request('Processing', :has_processing, {:repository_id => repository_id})[:exists] | |
| 7 | + end | |
| 8 | + | |
| 9 | + def self.has_ready_processing(repository_id) | |
| 10 | + request('Processing', :has_ready_processing, {:repository_id => repository_id})[:exists] | |
| 11 | + end | |
| 12 | + | |
| 13 | + def self.has_processing_after(repository_id, date) | |
| 14 | + request('Processing', :has_processing_after, {:repository_id => repository_id, :date => date})[:exists] | |
| 15 | + end | |
| 16 | + | |
| 17 | + def self.has_processing_before(repository_id, date) | |
| 18 | + request('Processing', :has_processing_before, {:repository_id => repository_id, :date => date})[:exists] | |
| 19 | + end | |
| 20 | + | |
| 21 | + def self.last_processing_state_of(repository_id) | |
| 22 | + request('Processing', :last_processing_state, {:repository_id => repository_id})[:process_state] | |
| 23 | + end | |
| 24 | + | |
| 25 | + def self.last_ready_processing_of(repository_id) | |
| 26 | + new request('Processing', :last_ready_processing, {:repository_id => repository_id})[:processing] | |
| 27 | + end | |
| 28 | + | |
| 29 | + def self.first_processing_of(repository_id) | |
| 30 | + new request('Processing', :first_processing, {:repository_id => repository_id})[:processing] | |
| 31 | + end | |
| 32 | + | |
| 33 | + def self.last_processing_of(repository_id) | |
| 34 | + new request('Processing', :last_processing, {:repository_id => repository_id})[:processing] | |
| 35 | + end | |
| 36 | + | |
| 37 | + def self.first_processing_after(repository_id, date) | |
| 38 | + new request('Processing', :first_processing_after, {:repository_id => repository_id, :date => date})[:processing] | |
| 39 | + end | |
| 40 | + | |
| 41 | + def self.last_processing_before(repository_id, date) | |
| 42 | + new request('Processing', :last_processing_before, {:repository_id => repository_id, :date => date})[:processing] | |
| 43 | + end | |
| 44 | + | |
| 45 | + def date=(value) | |
| 46 | + @date = value.is_a?(String) ? DateTime.parse(value) : value | |
| 47 | + end | |
| 48 | + | |
| 49 | +end | ... | ... |
plugins/mezuro/lib/kalibro/project_result.rb
| ... | ... | @@ -1,100 +0,0 @@ |
| 1 | -class Kalibro::ProjectResult < Kalibro::Model | |
| 2 | - | |
| 3 | - attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time | |
| 4 | - | |
| 5 | - def self.last_result(project_name) | |
| 6 | - new request('ProjectResult', :get_last_result_of, {:project_name => project_name})[:project_result] | |
| 7 | - end | |
| 8 | - | |
| 9 | - def self.first_result(project_name) | |
| 10 | - new request('ProjectResult', :get_first_result_of, {:project_name => project_name})[:project_result] | |
| 11 | - end | |
| 12 | - | |
| 13 | - def self.first_result_after(project_name, date) | |
| 14 | - new request('ProjectResult', :get_first_result_after, {:project_name => project_name, :date => date})[:project_result] | |
| 15 | - end | |
| 16 | - | |
| 17 | - def self.last_result_before(project_name, date) | |
| 18 | - new request('ProjectResult', :get_last_result_before, {:project_name => project_name, :date => date})[:project_result] | |
| 19 | - end | |
| 20 | - | |
| 21 | - def self.has_results?(project_name) | |
| 22 | - request('ProjectResult', :has_results_for, {:project_name => project_name})[:has_results] | |
| 23 | - end | |
| 24 | - | |
| 25 | - def self.has_results_before?(project_name, date) | |
| 26 | - request('ProjectResult', :has_results_before, {:project_name => project_name, :date => date})[:has_results] | |
| 27 | - end | |
| 28 | - | |
| 29 | - def self.has_results_after?(project_name, date) | |
| 30 | - request('ProjectResult', :has_results_after, {:project_name => project_name, :date => date})[:has_results] | |
| 31 | - end | |
| 32 | - | |
| 33 | - def project=(value) | |
| 34 | - @project = (value.kind_of?(Hash)) ? Kalibro::Project.new(value) : value | |
| 35 | - end | |
| 36 | - | |
| 37 | - def date=(value) | |
| 38 | - @date = value.is_a?(String) ? DateTime.parse(value) : value | |
| 39 | - end | |
| 40 | - | |
| 41 | - def load_time=(value) | |
| 42 | - @load_time = value.to_i | |
| 43 | - end | |
| 44 | - | |
| 45 | - def collect_time=(value) | |
| 46 | - @collect_time = value.to_i | |
| 47 | - end | |
| 48 | - | |
| 49 | - def analysis_time=(value) | |
| 50 | - @analysis_time = value.to_i | |
| 51 | - end | |
| 52 | - | |
| 53 | - def source_tree=(value) | |
| 54 | - @source_tree = value.kind_of?(Hash) ? Kalibro::ModuleNode.new(value) : value | |
| 55 | - end | |
| 56 | - | |
| 57 | - def formatted_load_time | |
| 58 | - format_milliseconds(@load_time) | |
| 59 | - end | |
| 60 | - | |
| 61 | - def formatted_analysis_time | |
| 62 | - format_milliseconds(@analysis_time) | |
| 63 | - end | |
| 64 | - | |
| 65 | - def format_milliseconds(value) | |
| 66 | - seconds = value.to_i/1000 | |
| 67 | - hours = seconds/3600 | |
| 68 | - seconds -= hours * 3600 | |
| 69 | - minutes = seconds/60 | |
| 70 | - seconds -= minutes * 60 | |
| 71 | - "#{format(hours)}:#{format(minutes)}:#{format(seconds)}" | |
| 72 | - end | |
| 73 | - | |
| 74 | - def format(amount) | |
| 75 | - ('%2d' % amount).sub(/\s/, '0') | |
| 76 | - end | |
| 77 | - | |
| 78 | - def node(module_name) | |
| 79 | - if module_name.nil? or module_name == project.name | |
| 80 | - node = source_tree | |
| 81 | - else | |
| 82 | - path = Kalibro::Module.parent_names(module_name) | |
| 83 | - parent = @source_tree | |
| 84 | - path.each do |node_name| | |
| 85 | - parent = get_leaf_from(parent, node_name) | |
| 86 | - end | |
| 87 | - parent | |
| 88 | - end | |
| 89 | - end | |
| 90 | - | |
| 91 | - private | |
| 92 | - | |
| 93 | - def get_leaf_from(node, module_name) | |
| 94 | - node.children.each do |child_node| | |
| 95 | - return child_node if child_node.module.name == module_name | |
| 96 | - end | |
| 97 | - nil | |
| 98 | - end | |
| 99 | - | |
| 100 | -end |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +require File.dirname(__FILE__) + '/process_time_fixtures' | |
| 2 | + | |
| 3 | +class ProcessingFixtures | |
| 4 | + | |
| 5 | + def self.processing | |
| 6 | + Kalibro::Processing.new processing_hash | |
| 7 | + end | |
| 8 | + | |
| 9 | + def self.processing_hash | |
| 10 | + { | |
| 11 | + :id => 31, | |
| 12 | + :date => '2011-10-20T18:26:43.151+00:00', | |
| 13 | + :state => 'READY', | |
| 14 | + :process_times => [ProcessTimeFixtures.process_time_hash], | |
| 15 | + :results_root_id => 13 | |
| 16 | + } | |
| 17 | + end | |
| 18 | + | |
| 19 | +end | ... | ... |
plugins/mezuro/test/fixtures/project_result_fixtures.rb
| ... | ... | @@ -1,35 +0,0 @@ |
| 1 | -require File.dirname(__FILE__) + '/project_fixtures' | |
| 2 | -require File.dirname(__FILE__) + '/module_node_fixtures' | |
| 3 | -require File.dirname(__FILE__) + '/module_result_fixtures' | |
| 4 | - | |
| 5 | -class ProjectResultFixtures | |
| 6 | - | |
| 7 | - def self.project_result | |
| 8 | - Kalibro::ProjectResult.new project_result_hash | |
| 9 | - end | |
| 10 | - | |
| 11 | - def self.project_result_hash | |
| 12 | - { | |
| 13 | - :project => ProjectFixtures.project_hash, | |
| 14 | - :date => ModuleResultFixtures.module_result_hash[:date], | |
| 15 | - :load_time => 14878, | |
| 16 | - :analysis_time => 1022, | |
| 17 | - :source_tree => ModuleNodeFixtures.module_node_hash, | |
| 18 | - :collect_time => 14878, | |
| 19 | - :attributes! => | |
| 20 | - { | |
| 21 | - :source_tree => | |
| 22 | - { | |
| 23 | - "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", | |
| 24 | - "xsi:type"=>"kalibro:moduleNodeXml" | |
| 25 | - }, | |
| 26 | - :project => | |
| 27 | - { | |
| 28 | - "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", | |
| 29 | - "xsi:type"=>"kalibro:projectXml" | |
| 30 | - } | |
| 31 | - } | |
| 32 | - } | |
| 33 | - end | |
| 34 | - | |
| 35 | -end |
| ... | ... | @@ -0,0 +1,133 @@ |
| 1 | +require "test_helper" | |
| 2 | + | |
| 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/processing_fixtures" | |
| 4 | + | |
| 5 | +class ProcessingTest < ActiveSupport::TestCase | |
| 6 | + | |
| 7 | + def setup | |
| 8 | + @hash = ProcessingFixtures.processing_hash | |
| 9 | + @processing = ProcessingFixtures.processing | |
| 10 | + | |
| 11 | + @repository_id = 31 | |
| 12 | + | |
| 13 | +=begin | |
| 14 | + @project_name = @processing.project.name | |
| 15 | + @date = @processing.date | |
| 16 | + @flag = DateTime.now.sec % 2 == 0 #random choose between true or false | |
| 17 | + | |
| 18 | + @request = {:project_name => @project_name} | |
| 19 | + @request_with_date = {:project_name => @project_name, :date => @date} | |
| 20 | + @flag_response = {:has_results => @flag} | |
| 21 | + @result_response = {:processing => @processing.to_hash} | |
| 22 | +=end | |
| 23 | + end | |
| 24 | + | |
| 25 | + should 'create project result from hash' do | |
| 26 | + assert_equal @processing.results_root_id, Kalibro::Processing.new(@hash).results_root_id | |
| 27 | + end | |
| 28 | + | |
| 29 | + should 'convert project result to hash' do | |
| 30 | + assert_equal @hash, @processing.to_hash | |
| 31 | + end | |
| 32 | + | |
| 33 | + should 'verify if a repository has a processing' do | |
| 34 | + true_repository_id = 31 | |
| 35 | + false_repository_id = 32 | |
| 36 | + | |
| 37 | + Kalibro::Processing.expects(:request).with('Processing',:has_processing, {:repository_id => true_repository_id}).returns({:exists => true}) | |
| 38 | + Kalibro::Processing.expects(:request).with('Processing',:has_processing, {:repository_id => false_repository_id}).returns({:exists => false}) | |
| 39 | + | |
| 40 | + assert Kalibro::Processing.has_processing(true_repository_id) | |
| 41 | + assert !Kalibro::Processing.has_processing(false_repository_id) | |
| 42 | + end | |
| 43 | + | |
| 44 | + should 'verify if a repository has a ready processing' do | |
| 45 | + true_repository_id = 31 | |
| 46 | + false_repository_id = 32 | |
| 47 | + | |
| 48 | + Kalibro::Processing.expects(:request).with('Processing',:has_ready_processing, {:repository_id => true_repository_id}).returns({:exists => true}) | |
| 49 | + Kalibro::Processing.expects(:request).with('Processing',:has_ready_processing, {:repository_id => false_repository_id}).returns({:exists => false}) | |
| 50 | + | |
| 51 | + assert Kalibro::Processing.has_ready_processing(true_repository_id) | |
| 52 | + assert !Kalibro::Processing.has_ready_processing(false_repository_id) | |
| 53 | + end | |
| 54 | + | |
| 55 | + should 'verify if a repository has a processing after a date' do | |
| 56 | + true_repository_id = 31 | |
| 57 | + false_repository_id = 32 | |
| 58 | + | |
| 59 | + Kalibro::Processing.expects(:request).with('Processing',:has_processing_after, {:repository_id => true_repository_id, :date => @processing.date}).returns({:exists => true}) | |
| 60 | + Kalibro::Processing.expects(:request).with('Processing',:has_processing_after, {:repository_id => false_repository_id, :date => @processing.date}).returns({:exists => false}) | |
| 61 | + | |
| 62 | + assert Kalibro::Processing.has_processing_after(true_repository_id, @processing.date) | |
| 63 | + assert !Kalibro::Processing.has_processing_after(false_repository_id, @processing.date) | |
| 64 | + end | |
| 65 | + | |
| 66 | + should 'verify if a repository has a processing before a date' do | |
| 67 | + true_repository_id = 31 | |
| 68 | + false_repository_id = 32 | |
| 69 | + | |
| 70 | + Kalibro::Processing.expects(:request).with('Processing',:has_processing_before, {:repository_id => true_repository_id, :date => @processing.date}).returns({:exists => true}) | |
| 71 | + Kalibro::Processing.expects(:request).with('Processing',:has_processing_before, {:repository_id => false_repository_id, :date => @processing.date}).returns({:exists => false}) | |
| 72 | + | |
| 73 | + assert Kalibro::Processing.has_processing_before(true_repository_id, @processing.date) | |
| 74 | + assert !Kalibro::Processing.has_processing_before(false_repository_id, @processing.date) | |
| 75 | + end | |
| 76 | + | |
| 77 | + should 'get last processing state of a repository' do | |
| 78 | + Kalibro::Processing.expects(:request).with('Processing',:last_processing_state, {:repository_id => @repository_id}).returns({:process_state => @processing.state}) | |
| 79 | + assert_equal @processing.state, Kalibro::Processing.last_processing_state_of(@repository_id) | |
| 80 | + end | |
| 81 | + | |
| 82 | + should 'get last ready processing of a repository' do | |
| 83 | + Kalibro::Processing.expects(:request).with('Processing', :last_ready_processing, {:repository_id => @repository_id}).returns({:processing => @hash}) | |
| 84 | + assert_equal @processing.id, Kalibro::Processing.last_ready_processing_of(@repository_id).id | |
| 85 | + end | |
| 86 | + | |
| 87 | + should 'get first processing of a repository' do | |
| 88 | + Kalibro::Processing.expects(:request).with('Processing', :first_processing, {:repository_id => @repository_id}).returns({:processing => @hash}) | |
| 89 | + assert_equal @processing.id, Kalibro::Processing.first_processing_of(@repository_id).id | |
| 90 | + end | |
| 91 | + | |
| 92 | + should 'get last processing of a repository' do | |
| 93 | + Kalibro::Processing.expects(:request).with('Processing', :last_processing, {:repository_id => @repository_id}).returns({:processing => @hash}) | |
| 94 | + assert_equal @processing.id, Kalibro::Processing.last_processing_of(@repository_id).id | |
| 95 | + end | |
| 96 | + | |
| 97 | + should 'get first processing after a date of a repository' do | |
| 98 | + Kalibro::Processing.expects(:request).with('Processing', :first_processing_after, {:repository_id => @repository_id, :date => @processing.date}).returns({:processing => @hash}) | |
| 99 | + assert_equal @processing.id, Kalibro::Processing.first_processing_after(@repository_id, @processing.date).id | |
| 100 | + end | |
| 101 | + | |
| 102 | + should 'get last processing before a date of a repository' do | |
| 103 | + Kalibro::Processing.expects(:request).with('Processing', :last_processing_before, {:repository_id => @repository_id, :date => @processing.date}).returns({:processing => @hash}) | |
| 104 | + assert_equal @processing.id, Kalibro::Processing.last_processing_before(@repository_id, @processing.date).id | |
| 105 | + end | |
| 106 | + | |
| 107 | +=begin | |
| 108 | + | |
| 109 | + should 'retrieve formatted load time' do | |
| 110 | + assert_equal '00:00:14', @processing.formatted_load_time | |
| 111 | + end | |
| 112 | + | |
| 113 | + should 'retrieve formatted analysis time' do | |
| 114 | + assert_equal '00:00:01', @processing.formatted_analysis_time | |
| 115 | + end | |
| 116 | + | |
| 117 | + should 'retrive complex module' do | |
| 118 | + assert_equal @hash[:source_tree][:child][0][:child].first, @processing.node("org.Window").to_hash | |
| 119 | + end | |
| 120 | + | |
| 121 | + should 'return source tree node when nil is given' do | |
| 122 | + assert_equal @hash[:source_tree], @processing.node(nil).to_hash | |
| 123 | + end | |
| 124 | + | |
| 125 | + should 'return source tree node when project name is given' do | |
| 126 | + assert_equal @hash[:source_tree], @processing.node(@processing.project.name).to_hash | |
| 127 | + end | |
| 128 | + | |
| 129 | + should 'return correct node when module name is given' do | |
| 130 | + assert_equal @hash[:source_tree][:child][2], @processing.node("main").to_hash | |
| 131 | + end | |
| 132 | +=end | |
| 133 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/project_result_test.rb
| ... | ... | @@ -1,88 +0,0 @@ |
| 1 | -require "test_helper" | |
| 2 | - | |
| 3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | |
| 4 | - | |
| 5 | -class ProjectResultTest < ActiveSupport::TestCase | |
| 6 | - | |
| 7 | - def setup | |
| 8 | - @hash = ProjectResultFixtures.project_result_hash | |
| 9 | - @project_result = ProjectResultFixtures.project_result | |
| 10 | - | |
| 11 | - @project_name = @project_result.project.name | |
| 12 | - @date = @project_result.date | |
| 13 | - @flag = DateTime.now.sec % 2 == 0 #random choose between true or false | |
| 14 | - | |
| 15 | - @request = {:project_name => @project_name} | |
| 16 | - @request_with_date = {:project_name => @project_name, :date => @date} | |
| 17 | - @flag_response = {:has_results => @flag} | |
| 18 | - @result_response = {:project_result => @project_result.to_hash} | |
| 19 | - end | |
| 20 | - | |
| 21 | - should 'create project result from hash' do | |
| 22 | - assert_equal @project_result.analysis_time, Kalibro::ProjectResult.new(@hash).analysis_time | |
| 23 | - end | |
| 24 | - | |
| 25 | - should 'convert project result to hash' do | |
| 26 | - assert_equal @hash, @project_result.to_hash | |
| 27 | - end | |
| 28 | - | |
| 29 | - should 'get last result' do | |
| 30 | - Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_of, @request).returns(@result_response) | |
| 31 | - assert_equal @project_result.analysis_time , Kalibro::ProjectResult.last_result(@project_name).analysis_time | |
| 32 | - end | |
| 33 | - | |
| 34 | - should 'get first result' do | |
| 35 | - Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_first_result_of, @request).returns(@result_response) | |
| 36 | - assert_equal @project_result.analysis_time, Kalibro::ProjectResult.first_result(@project_name).analysis_time | |
| 37 | - end | |
| 38 | - | |
| 39 | - should 'get first result after date' do | |
| 40 | - Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_first_result_after, @request_with_date).returns(@result_response) | |
| 41 | - assert_equal @project_result.analysis_time, Kalibro::ProjectResult.first_result_after(@project_name, @date).analysis_time | |
| 42 | - end | |
| 43 | - | |
| 44 | - should 'get last result before date' do | |
| 45 | - Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_before, @request_with_date).returns(@result_response) | |
| 46 | - assert_equal @project_result.analysis_time, Kalibro::ProjectResult.last_result_before(@project_name, @date).analysis_time | |
| 47 | - end | |
| 48 | - | |
| 49 | - should 'verify if project has results' do | |
| 50 | - Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_for, @request).returns(@flag_response) | |
| 51 | - assert_equal @flag, Kalibro::ProjectResult.has_results?(@project_name) | |
| 52 | - end | |
| 53 | - | |
| 54 | - should 'verify if project has results before date' do | |
| 55 | - Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_before, @request_with_date).returns(@flag_response) | |
| 56 | - assert_equal @flag, Kalibro::ProjectResult.has_results_before?(@project_name, @date) | |
| 57 | - end | |
| 58 | - | |
| 59 | - should 'verify if project has results after date' do | |
| 60 | - Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_after, @request_with_date).returns(@flag_response) | |
| 61 | - assert_equal @flag, Kalibro::ProjectResult.has_results_after?(@project_name, @date) | |
| 62 | - end | |
| 63 | - | |
| 64 | - should 'retrieve formatted load time' do | |
| 65 | - assert_equal '00:00:14', @project_result.formatted_load_time | |
| 66 | - end | |
| 67 | - | |
| 68 | - should 'retrieve formatted analysis time' do | |
| 69 | - assert_equal '00:00:01', @project_result.formatted_analysis_time | |
| 70 | - end | |
| 71 | - | |
| 72 | - should 'retrive complex module' do | |
| 73 | - assert_equal @hash[:source_tree][:child][0][:child].first, @project_result.node("org.Window").to_hash | |
| 74 | - end | |
| 75 | - | |
| 76 | - should 'return source tree node when nil is given' do | |
| 77 | - assert_equal @hash[:source_tree], @project_result.node(nil).to_hash | |
| 78 | - end | |
| 79 | - | |
| 80 | - should 'return source tree node when project name is given' do | |
| 81 | - assert_equal @hash[:source_tree], @project_result.node(@project_result.project.name).to_hash | |
| 82 | - end | |
| 83 | - | |
| 84 | - should 'return correct node when module name is given' do | |
| 85 | - assert_equal @hash[:source_tree][:child][2], @project_result.node("main").to_hash | |
| 86 | - end | |
| 87 | - | |
| 88 | -end |