Commit 11b8fd73ec92e3c91d119684f33430dab750e033

Authored by Paulo Meireles
2 parents f241c072 6df08cce

Merge branch 'mezuro-dev' into mezuro

Conflicts:
	plugins/mezuro/public/javascripts/project_content.js
Showing 192 changed files with 3654 additions and 3072 deletions   Show diff stats
features/step_definitions/mezuro_steps.rb
... ... @@ -32,3 +32,17 @@ Then /^I should see "([^\"]*)" inside an alert$/ do |message|
32 32 selenium.get_alert.should eql(message)
33 33 selenium.chooseOkOnNextConfirmation();
34 34 end
  35 +
  36 +When /^I have a Mezuro project with the following data$/ do |fields|
  37 + item = {}
  38 + fields.rows_hash.each do |name, value|
  39 + if(name=="community")
  40 + item.merge!(:profile=>Profile[value])
  41 + else
  42 + item.merge!(name => value)
  43 + end
  44 + end
  45 + result = MezuroPlugin::ProjectContent.new(item)
  46 + result.save!
  47 +end
  48 +
... ...
features/step_definitions/noosfero_steps.rb
... ... @@ -761,3 +761,9 @@ Given /^there are no pending jobs$/ do
761 761 Delayed::Worker.new.work_off
762 762 end
763 763 end
  764 +
  765 +When /^I confirm the "(.*)" dialog$/ do |confirmation|
  766 + a = page.driver.browser.switch_to.alert
  767 + assert_equal confirmation, a.text
  768 + a.accept
  769 +end
... ...
features/support/hooks.rb
... ... @@ -1,4 +0,0 @@
1   -Before('@mezuro') do |scenario|
2   - command = "#{RAILS_ROOT}/plugins/mezuro/features/initialize_monkey_server.sh \"#{scenario.name}\""
3   - system command
4   -end
plugins/mezuro/controllers/myprofile/mezuro_plugin_base_tool_controller.rb
... ... @@ -1,10 +0,0 @@
1   -class MezuroPluginBaseToolController < MezuroPluginMyprofileController
2   -
3   - append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4   -
5   - def choose_metric
6   - @configuration_content = profile.articles.find(params[:id])
7   - @base_tools = Kalibro::BaseTool.all
8   - end
9   -
10   -end
plugins/mezuro/controllers/myprofile/mezuro_plugin_metric_configuration_controller.rb
... ... @@ -2,96 +2,108 @@ class MezuroPluginMetricConfigurationController &lt; MezuroPluginMyprofileControlle
2 2  
3 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4 4  
5   - def new_metric_configuration
  5 + def choose_metric
6 6 @configuration_content = profile.articles.find(params[:id])
7   - @metric = Kalibro::BaseTool.find_by_name(params[:base_tool]).metric params[:metric_name]
  7 + @base_tools = Kalibro::BaseTool.all
8 8 end
9 9  
10   - def new_compound_metric_configuration
  10 + def new_native
11 11 @configuration_content = profile.articles.find(params[:id])
12   - @metric_configurations = @configuration_content.metric_configurations
13   - if configuration_content_has_errors?
14   - redirect_to_error_page @configuration_content.errors[:base]
15   - end
  12 + @reading_group_names_and_ids = reading_group_names_and_ids
  13 + @metric = Kalibro::BaseTool.find_by_name(params[:base_tool_name]).metric params[:metric_name]
  14 + @metric_configuration = Kalibro::MetricConfiguration.new :base_tool_name => params[:base_tool_name], :metric => @metric
16 15 end
17 16  
18   - def edit_metric_configuration
19   - @configuration_content = profile.articles.find(params[:id])
20   - @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name])
21   - @metric = @metric_configuration.metric
  17 + def edit_native
  18 + params_to_edit_view
22 19 end
23 20  
24   - def edit_compound_metric_configuration
  21 + def new_compound
25 22 @configuration_content = profile.articles.find(params[:id])
26   - @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name])
27 23 @metric_configurations = @configuration_content.metric_configurations
28   - @metric = @metric_configuration.metric
29   - end
30   -
31   - def create_metric_configuration
32   - id = params[:id]
33   - metric_name = params[:metric_configuration][:metric][:name]
34   - metric_configuration = Kalibro::MetricConfiguration.new(params[:metric_configuration])
35   - metric_configuration.save
36   - if metric_configuration_has_errors? metric_configuration
37   - redirect_to_error_page metric_configuration.errors[0].message
38   - else
39   - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/metric_configuration/edit_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}"
  24 + @reading_group_names_and_ids = reading_group_names_and_ids
  25 + metric = Kalibro::Metric.new :compound => true
  26 + @metric_configuration = Kalibro::MetricConfiguration.new :metric => metric
  27 + if configuration_content_has_errors?
  28 + redirect_to_error_page @configuration_content.errors[:base]
40 29 end
41 30 end
42 31  
43   - def create_compound_metric_configuration
44   - id = params[:id]
45   - metric_name = params[:metric_configuration][:metric][:name]
46   - metric_configuration = Kalibro::MetricConfiguration.new(params[:metric_configuration])
47   - metric_configuration.save
48   - if metric_configuration_has_errors? metric_configuration
49   - redirect_to_error_page metric_configuration.errors[0].message
50   - else
51   - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/metric_configuration/edit_compound_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}"
52   - end
  32 + def edit_compound
  33 + params_to_edit_view
53 34 end
54 35  
55   - def update_metric_configuration
56   - @configuration_content = profile.articles.find(params[:id])
57   - metric_name = params[:metric_configuration][:metric][:name]
58   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name)
59   - metric_configuration.update_attributes params[:metric_configuration]
  36 + def create
  37 + configuration_content = profile.articles.find(params[:id])
  38 + metric_configuration = Kalibro::MetricConfiguration.create(params[:metric_configuration])
  39 +
60 40 if metric_configuration_has_errors? metric_configuration
61 41 redirect_to_error_page metric_configuration.errors[0].message
62 42 else
63   - redirect_to "/#{profile.identifier}/#{@configuration_content.slug}"
  43 + redirect_to(metric_configuration_url(configuration_content, metric_configuration.id))
64 44 end
65 45 end
66 46  
67   - def update_compound_metric_configuration
  47 + def update
68 48 @configuration_content = profile.articles.find(params[:id])
69   - metric_name = params[:metric_configuration][:metric][:name]
70   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name)
  49 + metric_configurations = @configuration_content.metric_configurations
  50 + metric_configuration = find_metric_configuration(metric_configurations, params[:metric_configuration][:id].to_i)
71 51 metric_configuration.update_attributes params[:metric_configuration]
72 52 if metric_configuration_has_errors? metric_configuration
73 53 redirect_to_error_page metric_configuration.errors[0].message
74 54 else
75   - redirect_to "/#{profile.identifier}/#{@configuration_content.slug}"
  55 + redirect_to @configuration_content.view_url
76 56 end
77 57 end
78 58  
79   - def remove_metric_configuration
  59 + def remove
80 60 configuration_content = profile.articles.find(params[:id])
81   - metric_name = params[:metric_name]
82   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name)
  61 + configuration_id = configuration_content.configuration_id
  62 + metric_configuration = Kalibro::MetricConfiguration.new({:id => params[:metric_configuration_id].to_i})
83 63 metric_configuration.destroy
84 64 if metric_configuration_has_errors? metric_configuration
85 65 redirect_to_error_page metric_configuration.errors[0].message
86 66 else
87   - redirect_to "/#{profile.identifier}/#{configuration_content.slug}"
  67 + redirect_to configuration_content.view_url
88 68 end
89 69 end
90   -
  70 +
91 71 private
92   -
  72 +
  73 + def find_metric_configuration (metric_configurations, metric_configuration_id)
  74 + metric_configurations.select {|metric_configuration| metric_configuration.id == metric_configuration_id }.first
  75 + end
  76 +
  77 + def reading_group_names_and_ids
  78 + array = Kalibro::ReadingGroup.all.map { |reading_group| [reading_group.name, reading_group.id] }
  79 + array.sort { |x,y| x.first.downcase <=> y.first.downcase }
  80 + end
  81 +
  82 + def metric_configuration_has_errors? metric_configuration
  83 + not metric_configuration.errors.empty?
  84 + end
  85 +
93 86 def configuration_content_has_errors?
94 87 not @configuration_content.errors[:base].nil?
95 88 end
96   -
  89 +
  90 + def metric_configuration_url(configuration_content, metric_configuration_id)
  91 + url = configuration_content.view_url
  92 + url[:controller] = controller_name
  93 + url[:id] = configuration_content.id
  94 + url[:metric_configuration_id] = metric_configuration_id
  95 + url[:action] = (params[:metric_configuration][:metric][:compound] == "true" ? "edit_compound" : "edit_native")
  96 + url
  97 + end
  98 +
  99 + def params_to_edit_view
  100 + @configuration_content = profile.articles.find(params[:id])
  101 + @metric_configurations = @configuration_content.metric_configurations
  102 + @metric_configuration = find_metric_configuration(@metric_configurations, params[:metric_configuration_id].to_i)
  103 + @metric = @metric_configuration.metric
  104 + @reading_group_names_and_ids = reading_group_names_and_ids
  105 + @ranges = Kalibro::Range.ranges_of(@metric_configuration.id)
  106 + end
  107 +
97 108 end
  109 +
... ...
plugins/mezuro/controllers/myprofile/mezuro_plugin_myprofile_controller.rb
... ... @@ -2,27 +2,15 @@ class MezuroPluginMyprofileController &lt; ProfileController #MyprofileController?
2 2  
3 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4 4  
5   - rescue_from Exception do |exception|
6   - @message = process_error_message exception.message
7   - render :partial => "error_page"
8   - end
  5 +# rescue_from Exception do |exception|
  6 +# @message = process_error_message exception.message
  7 +# render :partial => "error_page"
  8 +# end
9 9  
10 10 def error_page
11 11 @message = params[:message]
12 12 end
13 13  
14   - def choose_base_tool
15   - @configuration_content = profile.articles.find(params[:id])
16   - @base_tools = Kalibro::BaseTool.all_names
17   - end
18   -
19   - def choose_metric
20   - @configuration_content = profile.articles.find(params[:id])
21   - @base_tool = params[:base_tool]
22   - base_tool = Kalibro::BaseTool.find_by_name(@base_tool)
23   - @supported_metrics = base_tool.nil? ? [] : base_tool.supported_metrics
24   - end
25   -
26 14 protected
27 15  
28 16 def redirect_to_error_page(message)
... ... @@ -30,11 +18,7 @@ class MezuroPluginMyprofileController &lt; ProfileController #MyprofileController?
30 18 redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}"
31 19 end
32 20  
33   - def metric_configuration_has_errors? metric_configuration
34   - not metric_configuration.errors.empty?
35   - end
36   -
37   - def process_error_message message
  21 + def process_error_message message #FIXME
38 22 if message =~ /bla/
39 23 message
40 24 else
... ...
plugins/mezuro/controllers/myprofile/mezuro_plugin_range_controller.rb
... ... @@ -2,65 +2,65 @@ class MezuroPluginRangeController &lt; MezuroPluginMyprofileController
2 2  
3 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4 4  
5   - def new_range
6   - @content_id = params[:id]
7   - @metric_name = params[:metric_name]
8   - @range = Kalibro::Range.new
9   - @range_color = "#000000"
  5 + def new
  6 + params_to_range_form
  7 + params_to_redirect
10 8 end
11 9  
12   - def edit_range
13   - @beginning_id = params[:beginning_id]
14   - @content_id = params[:id]
15   - configuration_name = profile.articles.find(@content_id).name
16   - @metric_name = params[:metric_name]
17   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_name, @metric_name)
18   - @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" }
19   - @range_color = "#" + @range.color.to_s.gsub(/^ff/, "")
  10 + def edit
  11 + params_to_range_form
  12 + ranges = Kalibro::Range.ranges_of params[:metric_configuration_id].to_i
  13 + @range = (ranges.select { |range| range.id == params[:range_id].to_i }).first
20 14 end
21 15  
22   - def create_range
23   - @configuration_content = profile.articles.find(params[:id])
24   - @range = Kalibro::Range.new params[:range]
25   - metric_name = params[:metric_name]
26   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name)
27   - metric_configuration.add_range(@range)
28   - metric_configuration.save
29   - if metric_configuration_has_errors? metric_configuration
30   - @error = metric_configuration.errors[0].message
31   - end
  16 + def create
  17 + params_to_redirect
  18 + save_range
32 19 end
33 20  
34   - def update_range
35   - configuration_content = profile.articles.find(params[:id])
36   - metric_name = params[:metric_name]
37   - beginning_id = params[:beginning_id]
38   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name)
39   - index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" }
40   - metric_configuration.ranges[index] = Kalibro::Range.new params[:range]
41   - metric_configuration.save
42   - if metric_configuration_has_errors? metric_configuration
43   - @error = metric_configuration.errors[0].message
44   - end
  21 + def update
  22 + save_range
45 23 end
46 24  
47   - def remove_range
  25 + def remove
48 26 configuration_content = profile.articles.find(params[:id])
49   - metric_name = params[:metric_name]
50   - beginning_id = params[:beginning_id]
51   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name)
52   - metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" }
53   - metric_configuration.save
54   - if metric_configuration_has_errors? metric_configuration
55   - redirect_to_error_page metric_configuration.errors[0].message
56   - else
57   - formatted_metric_name = metric_name.gsub(/\s/, '+')
58   - if metric_configuration.metric.class == Kalibro::CompoundMetric
59   - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/metric_configuration/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}"
60   - else
61   - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/metric_configuration/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}"
62   - end
  27 + Kalibro::Range.new({:id => params[:range_id].to_i}).destroy
  28 + redirect_to(metric_configuration_url(configuration_content))
  29 + end
  30 +
  31 + private
  32 +
  33 + def metric_configuration_url configuration_content
  34 + url = configuration_content.view_url
  35 + url[:controller] = "mezuro_plugin_metric_configuration"
  36 + url[:id] = configuration_content.id
  37 + url[:metric_configuration_id] = params[:metric_configuration_id].to_i
  38 + url[:action] = (params[:compound] ? "edit_compound" : "edit_native")
  39 + url
  40 + end
  41 +
  42 + def reading_labels_and_ids
  43 + Kalibro::Reading.readings_of(params[:reading_group_id].to_i).map { |reading| [reading.label, reading.id] }
  44 + end
  45 +
  46 + def save_range
  47 + metric_configuration_id = params[:metric_configuration_id].to_i
  48 + @range = Kalibro::Range.new params[:range]
  49 + @range.save metric_configuration_id
  50 + if !@range.errors.empty?
  51 + @error = @range.errors[0].message
63 52 end
64 53 end
65 54  
  55 + def params_to_range_form
  56 + @content_id = params[:id].to_i
  57 + @metric_configuration_id = params[:metric_configuration_id].to_i
  58 + @reading_labels_and_ids = reading_labels_and_ids
  59 + end
  60 +
  61 + def params_to_redirect
  62 + @reading_group_id = params[:reading_group_id].to_i
  63 + @compound = params[:compound]
  64 + end
  65 +
66 66 end
... ...
plugins/mezuro/controllers/myprofile/mezuro_plugin_reading_controller.rb 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +class MezuroPluginReadingController < MezuroPluginMyprofileController
  2 +
  3 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  4 +
  5 + def new
  6 + @reading_group_content = profile.articles.find(params[:id])
  7 + end
  8 +
  9 + def save
  10 + reading_group_content = profile.articles.find(params[:id])
  11 + reading = Kalibro::Reading.new params[:reading]
  12 +
  13 + if( reading.save(reading_group_content.reading_group_id) )
  14 + redirect_to reading_group_content.view_url
  15 + else
  16 + redirect_to_error_page reading.errors[0].message
  17 + end
  18 + end
  19 +
  20 + def edit
  21 + @reading_group_content = profile.articles.find(params[:id])
  22 + @reading = Kalibro::Reading.find params[:reading_id]
  23 + end
  24 +
  25 + def destroy
  26 + reading_group_content = profile.articles.find(params[:id])
  27 + reading = Kalibro::Reading.find params[:reading_id]
  28 + reading.destroy
  29 + if( reading.errors.empty? )
  30 + redirect_to reading_group_content.view_url
  31 + else
  32 + redirect_to_error_page reading.errors[0].message
  33 + end
  34 + end
  35 +
  36 +end
... ...
plugins/mezuro/controllers/profile/mezuro_plugin_module_controller.rb
... ... @@ -1,62 +0,0 @@
1   -class MezuroPluginModuleController < MezuroPluginProfileController
2   -
3   - append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4   -
5   - def module_result
6   - @content = profile.articles.find(params[:id])
7   - @module_result = @content.module_result(params)
8   - @module = @module_result.module
9   - @module_label = "#{@module.name} (#{@module.granularity})"
10   - if project_content_has_errors?
11   - redirect_to_error_page(@content.errors[:base])
12   - else
13   - render :partial => 'module_result'
14   - end
15   - end
16   -
17   - def module_metrics_history
18   - metric_name = params[:metric_name]
19   - @content = profile.articles.find(params[:id])
20   - module_history = @content.result_history(params[:module_name])
21   - if project_content_has_errors?
22   - redirect_to_error_page(@content.errors[:base])
23   - else
24   - @score_history = filtering_metric_history(metric_name, module_history)
25   - render :partial => 'score_history'
26   - end
27   - end
28   -
29   - def module_grade_history
30   - @content = profile.articles.find(params[:id])
31   - modules_results = @content.result_history(params[:module_name])
32   - if project_content_has_errors?
33   - redirect_to_error_page(@content.errors[:base])
34   - else
35   - @score_history = modules_results.map do |module_result|
36   - [module_result.grade, format_date_to_simple_form(module_result.date)]
37   - end
38   - render :partial => 'score_history'
39   - end
40   - end
41   -
42   - private
43   -
44   - def filtering_metric_history(metric_name, module_history)
45   - metrics_history = module_history.map do |module_result|
46   - [module_result.metric_results, format_date_to_simple_form(module_result.date)]
47   - end
48   - metric_history = metrics_history.map do |metric_results_with_date|
49   - [(metric_results_with_date.first.select do |metric_result|
50   - metric_result.metric.name.delete("() ") == metric_name
51   - end).first, metric_results_with_date.last]
52   - end
53   - metric_history.map do |metric_result_with_date|
54   - [metric_result_with_date.first.value, metric_result_with_date.last]
55   - end
56   - end
57   -
58   - def format_date_to_simple_form date
59   - date.to_s[0..9]
60   - end
61   -
62   -end
plugins/mezuro/controllers/profile/mezuro_plugin_module_result_controller.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +class MezuroPluginModuleResultController < MezuroPluginProfileController
  2 +
  3 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  4 +
  5 + def module_result
  6 + @module_result = Kalibro::ModuleResult.find(params[:module_result_id].to_i)
  7 + @metric_results = Kalibro::MetricResult.metric_results_of(@module_result.id)
  8 + render :partial => 'module_result'
  9 + end
  10 +
  11 + def metric_result_history
  12 + @history = Kalibro::MetricResult.history_of(params[:metric_name], params[:module_result_id].to_i)
  13 + render :partial => 'score_history'
  14 + end
  15 +
  16 + def module_result_history
  17 + @history = Kalibro::ModuleResult.history_of(params[:module_result_id].to_i)
  18 + render :partial => 'score_history'
  19 + end
  20 +
  21 +end
... ...
plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +class MezuroPluginProcessingController < MezuroPluginProfileController
  2 +
  3 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  4 +
  5 + def state
  6 + processing = processing_for_date(params[:repository_id].to_i, params[:date])
  7 + if processing.error.nil?
  8 + render :text => processing.state
  9 + else
  10 + render :text => 'ERROR'
  11 + end
  12 + end
  13 +
  14 + def processing
  15 + @processing = processing_for_date(params[:repository_id].to_i, params[:date])
  16 + if @processing.error.nil?
  17 + render :partial => 'processing'
  18 + else
  19 + render :partial => 'processing_error'
  20 + end
  21 + end
  22 +
  23 + private
  24 +
  25 + def processing_for_date(repository_id, date = nil)
  26 + processing_class = Kalibro::Processing
  27 + if date.nil?
  28 + processing_class.processing_of(repository_id)
  29 + else
  30 + processing_class.processing_with_date_of(repository_id, date)
  31 + end
  32 + end
  33 +
  34 +end
... ...
plugins/mezuro/controllers/profile/mezuro_plugin_profile_controller.rb
  1 +#TODO Ver quais metodos precisam estar aqui e fazer os testes
1 2 class MezuroPluginProfileController < ProfileController
2 3  
3 4 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4 5  
  6 +=begin
5 7 rescue_from Exception do |exception|
6 8 @message = process_error_message exception.message
7 9 render :partial => "error_page"
... ... @@ -10,7 +12,7 @@ class MezuroPluginProfileController &lt; ProfileController
10 12 def error_page
11 13 @message = params[:message]
12 14 end
13   -
  15 +=end
14 16 protected
15 17  
16 18 def process_error_message message
... ... @@ -24,6 +26,11 @@ class MezuroPluginProfileController &lt; ProfileController
24 26 def project_content_has_errors?
25 27 not @content.errors[:base].nil?
26 28 end
  29 +
  30 + def redirect_to_error_page(message)
  31 + message = URI.escape(CGI.escape(process_error_message(message)),'.')
  32 + redirect_to "/profile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}"
  33 + end
27 34  
28 35 end
29 36  
... ...
plugins/mezuro/controllers/profile/mezuro_plugin_project_controller.rb
... ... @@ -1,50 +0,0 @@
1   -class MezuroPluginProjectController < MezuroPluginProfileController
2   -
3   - append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4   -
5   - def project_state
6   - @content = profile.articles.find(params[:id])
7   - project = @content.project
8   - if project_content_has_errors?
9   - redirect_to_error_page(@content.errors[:base])
10   - else
11   - state = project.kalibro_error.nil? ? project.state : "ERROR"
12   - render :text => state
13   - end
14   - end
15   -
16   - def project_error
17   - @content = profile.articles.find(params[:id])
18   - @project = @content.project
19   - if project_content_has_errors?
20   - redirect_to_error_page(@content.errors[:base])
21   - else
22   - render :partial => 'project_error'
23   - end
24   - end
25   -
26   - def project_result
27   - @content = profile.articles.find(params[:id])
28   - date = params[:date]
29   - @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date)
30   - if project_content_has_errors?
31   - redirect_to_error_page(@content.errors[:base])
32   - else
33   - render :partial => 'project_result'
34   - end
35   - end
36   -
37   - def project_tree
38   - @content = profile.articles.find(params[:id])
39   - date = params[:date]
40   - project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date)
41   - @project_name = @content.project.name if not @content.project.nil?
42   - if project_content_has_errors?
43   - redirect_to_error_page(@content.errors[:base])
44   - else
45   - @source_tree = project_result.node(params[:module_name])
46   - render :partial =>'source_tree'
47   - end
48   - end
49   -
50   -end
plugins/mezuro/controllers/profile/mezuro_plugin_repository_controller.rb 0 → 100644
... ... @@ -0,0 +1,67 @@
  1 +class MezuroPluginRepositoryController < MezuroPluginProfileController
  2 +
  3 + append_view_path File.join(File.dirname(__FILE__) + '/../../views')
  4 +
  5 + def new
  6 + params_repository_form
  7 + end
  8 +
  9 + def edit
  10 + params_repository_form
  11 + @repository = @project_content.repositories.select{ |repository| repository.id.to_s == params[:repository_id] }.first
  12 + end
  13 +
  14 + def save
  15 + project_content = profile.articles.find(params[:id])
  16 +
  17 + repository = Kalibro::Repository.new( params[:repository] )
  18 + repository.save(project_content.project_id)
  19 +
  20 + if( repository.errors.empty? )
  21 + repository.process
  22 + redirect_to(repository_url(project_content, repository.id))
  23 + else
  24 + redirect_to_error_page repository.errors[0].message
  25 + end
  26 + end
  27 +
  28 + def show
  29 + @project_content = profile.articles.find(params[:id])
  30 + @repository = @project_content.repositories.select{ |repository| repository.id == params[:repository_id].to_i }.first
  31 + @configuration_name = Kalibro::Configuration.configuration_of(@repository.id).name
  32 + end
  33 +
  34 + def destroy
  35 + project_content = profile.articles.find(params[:id])
  36 + repository = Kalibro::Repository.new :id => params[:repository_id]
  37 + repository.destroy
  38 + if( repository.errors.empty? )
  39 + redirect_to project_content.view_url
  40 + else
  41 + redirect_to_error_page repository.errors[0].message
  42 + end
  43 + end
  44 +
  45 + private
  46 +
  47 + def repository_url(project_content, repository_id)
  48 + url = project_content.view_url
  49 + url[:controller] = controller_name
  50 + url[:id] = project_content.id
  51 + url[:repository_id] = repository_id
  52 + url[:action] = "show"
  53 + url
  54 + end
  55 +
  56 + def params_repository_form
  57 + @project_content = profile.articles.find(params[:id])
  58 + @repository_types = Kalibro::Repository.repository_types
  59 +
  60 + configurations = Kalibro::Configuration.all
  61 + configurations = [] if (configurations.nil?)
  62 + @configuration_select = configurations.map do |configuration|
  63 + [configuration.name,configuration.id]
  64 + end
  65 + end
  66 +
  67 +end
... ...
plugins/mezuro/features/adding_metric_configuration.feature
1   -@mezuro
2 1 Feature: Add metric configuration to a configuration
3 2 As a mezuro user
4 3 I want to add metric configurations to a Kalibro configuration
... ...
plugins/mezuro/features/adding_ranges.feature
1   -@mezuro
2 1 Feature: Add range to a metric configuration
3 2 As a mezuro user
4 3 I want to add ranges to a Kalibro metric configuration
... ...
plugins/mezuro/features/creating_configuration.feature
1   -@mezuro
2 1 Feature: Create configuration
3 2 As a mezuro user
4 3 I want to create a Mezuro configuration
... ...
plugins/mezuro/features/creating_project.feature
... ... @@ -1,54 +0,0 @@
1   -@mezuro
2   -Feature: Create project
3   - As a mezuro user
4   - I want to create a Mezuro project
5   -
6   - Background:
7   - Given the following users
8   - | login | name |
9   - | joaosilva | Joao Silva |
10   - And I am logged in as "joaosilva"
11   - And "Mezuro" plugin is enabled
12   - And the following community
13   - | identifier | name |
14   - | mycommunity | My Community |
15   - And "Joao Silva" is admin of "My Community"
16   -
17   - Scenario: I see Mezuro project's input form
18   - Given I am on My Community's control panel
19   - When I follow "Mezuro Project"
20   - Then I should see "Title"
21   - And I should see "License"
22   - And I should see "Repository type"
23   - And I should see "GIT"
24   - And I should see "REMOTE_ZIP"
25   - And I should see "REMOTE_TARBALL"
26   - And I should see "SUBVERSION"
27   - And I should see "Repository url"
28   - And I should see "Configuration"
29   - And I should see "Kalibro for Java"
30   -
31   - Scenario: I create a Mezuro project with valid attributes
32   - Given I am on My Community's control panel
33   - When I create a Mezuro project with the following data
34   - | Title | Sample Project |
35   - | License | GNU General Public License version 2.0 (GPL-2.0) |
36   - | Repository type | SUBVERSION |
37   - | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator |
38   - | Configuration | Kalibro for Java |
39   - Then I should see "Sample Project"
40   - And I should see "GNU General Public License version 2.0 (GPL-2.0)"
41   - And I should see "SUBVERSION"
42   - And I should see "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator"
43   - And I should see "Kalibro for Java"
44   -
45   - Scenario: I can't create a Mezuro project with invalid attributes
46   - Given I am on My Community's control panel
47   - When I create a Mezuro project with the following data
48   - | Title | |
49   - | License | GNU General Public License version 2.0 (GPL-2.0) |
50   - | Repository type | SUBVERSION |
51   - | Repository url | |
52   - | Configuration | Kalibro for Java |
53   - Then I should see "The highlighted fields are mandatory."
54   - And I should see "Repository URL is mandatory"
plugins/mezuro/features/editing_configuration.feature
1   -@mezuro
2 1 Feature: editing a configuration
3 2 As a mezuro user
4 3 I want to edit a Mezuro configuration
... ...
plugins/mezuro/features/initialize_monkey_server.sh
... ... @@ -1,9 +0,0 @@
1   -#!/bin/bash
2   -
3   -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4   -MEZURO_HOME="$DIR/.."
5   -
6   -# Ignore errors from all commands
7   -trap "" ERR
8   -
9   -
plugins/mezuro/features/project.feature 0 → 100644
... ... @@ -0,0 +1,68 @@
  1 +Feature: Project
  2 + As a mezuro user
  3 + I want to create, edit and remove a Mezuro project
  4 +
  5 + Background:
  6 + Given the following users
  7 + | login | name |
  8 + | joaosilva | Joao Silva |
  9 + And I am logged in as "joaosilva"
  10 + And "Mezuro" plugin is enabled
  11 + And the following community
  12 + | identifier | name |
  13 + | mycommunity | My Community |
  14 + And "Joao Silva" is admin of "My Community"
  15 +
  16 + Scenario: I see Mezuro project's input form
  17 + Given I am on mycommunity's control panel
  18 + When I follow "Mezuro project"
  19 + Then I should see "Title"
  20 + And I should see "Description"
  21 +
  22 + Scenario: I create a Mezuro project with valid attributes
  23 + Given I am on mycommunity's control panel
  24 + When I create a Mezuro project with the following data
  25 + | Title | Sample Project |
  26 + | Description | Sample Description |
  27 + Then I should see "Sample Project"
  28 + And I should see "Sample Description"
  29 + And I should see "Add Repository"
  30 +
  31 + @selenium
  32 + Scenario: I edit a Mezuro project
  33 + When I have a Mezuro project with the following data
  34 + | name | Sample Project |
  35 + | description | Sample Description |
  36 + | community | mycommunity |
  37 + And I am on article "Sample Project"
  38 + And I should be on /mycommunity/sample-project
  39 + Then I should see "Sample Project"
  40 + And I should see "Sample Description"
  41 + And I should see "Add Repository"
  42 + When I follow "Edit"
  43 + # Not complete
  44 +
  45 +# @selenium
  46 +# Scenario: I delete a Mezuro project that belongs to me
  47 +# Given the following Mezuro project
  48 +# | name | description | owner |
  49 +# | Sample Project | Sample Description | joaosilva |
  50 +# And I am on article "Sample Project"
  51 +# And I should be on /joaosilva/sample-project
  52 +# When I follow "Delete"
  53 +# And I confirm the "Are you sure that you want to remove the item "Sample Project"?" dialog
  54 +# Then I go to /joaosilva/sample-project
  55 +# And I should see "There is no such page: /joaosilva/sample-project"
  56 +#
  57 +# @selenium
  58 +# Scenario: I cannot delete a Mezuro project that doesn't belong to me
  59 +# Given the following Mezuro project
  60 +# | name | description | owner |
  61 +# | Sample Project | Sample Description | joaosilva |
  62 +# And I am on article "Sample Project"
  63 +# And I should be on /joaosilva/sample-project
  64 +# When I follow "Delete"
  65 +# And I confirm the "Are you sure that you want to remove the item "Sample Project"?" dialog
  66 +# Then I go to /joaosilva/sample-project
  67 +# And I should see "There is no such page: /joaosilva/sample-project"
  68 +
... ...
plugins/mezuro/features/removing_metric_configuration.feature
1   -@mezuro
2 1 Feature: Remove a metric configuration from a configuration
3 2 As a mezuro user
4 3 I want to remove metric configurations from a configuration
... ...
plugins/mezuro/lib/kalibro/base_tool.rb
1 1 class Kalibro::BaseTool < Kalibro::Model
2 2  
3   - attr_accessor :name, :description, :supported_metric
4   -
5   - def self.all_names
6   - request("BaseTool", :get_base_tool_names)[:base_tool_name].to_a
7   - end
  3 + attr_accessor :name, :description, :collector_class_name, :supported_metric
8 4  
9 5 def self.find_by_name(base_tool_name)
10   - new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool]
  6 + new request(:get_base_tool, {:base_tool_name => base_tool_name})[:base_tool]
11 7 end
12 8  
13 9 def self.all
14 10 basetools = all_names
15 11 basetools.map{ |name| find_by_name(name) }
16   - end
  12 + end
  13 +
  14 + def self.all_names
  15 + request(:all_base_tool_names)[:base_tool_name].to_a
  16 + end
17 17  
18 18 def supported_metric=(value)
19   - @supported_metric = Kalibro::NativeMetric.to_objects_array value
  19 + @supported_metric = Kalibro::Metric.to_objects_array value
20 20 end
21 21  
22 22 def supported_metrics
... ...
plugins/mezuro/lib/kalibro/compound_metric.rb
... ... @@ -1,5 +0,0 @@
1   -class Kalibro::CompoundMetric < Kalibro::Metric
2   -
3   - attr_accessor :script
4   -
5   -end
plugins/mezuro/lib/kalibro/compound_metric_with_error.rb
... ... @@ -1,13 +0,0 @@
1   -class Kalibro::CompoundMetricWithError < Kalibro::Model
2   -
3   - attr_accessor :metric, :error
4   -
5   - def metric=(value)
6   - @metric = Kalibro::CompoundMetric.to_object value
7   - end
8   -
9   - def error=(value)
10   - @error = Kalibro::Error.to_object value
11   - end
12   -
13   -end
plugins/mezuro/lib/kalibro/configuration.rb
1 1 class Kalibro::Configuration < Kalibro::Model
2 2  
3   - attr_accessor :name, :description, :metric_configuration
  3 + attr_accessor :id, :name, :description
4 4  
5   - def metric_configuration=(value)
6   - @metric_configuration = Kalibro::MetricConfiguration.to_objects_array value
  5 + def id=(value)
  6 + @id = value.to_i
7 7 end
8 8  
9   - def metric_configurations
10   - @metric_configuration.nil? ? [] : @metric_configuration
  9 + def self.configuration_of(repository_id)
  10 + new request(:configuration_of, {:repository_id => repository_id})[:configuration]
11 11 end
12 12  
13   - def metric_configurations=(metric_configurations)
14   - @metric_configuration = metric_configurations
  13 + def self.all
  14 + response = request(:all_configurations)[:configuration]
  15 + response = [] if response.nil?
  16 + response = [response] if response.is_a?(Hash)
  17 + response.map {|configuration| new configuration}
15 18 end
16 19  
17   - def self.find_by_name(configuration_name)
18   - new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration]
19   - end
20   -
21   - def self.all_names
22   - request("Configuration", :get_configuration_names)[:configuration_name]
23   - end
24   -
25   - def update_attributes(attributes={})
26   - attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
27   - save
28   - end
29   -
30   - def metric_configurations_hash
31   - self.to_hash[:metric_configuration]
32   - end
33 20 end
... ...
plugins/mezuro/lib/kalibro/date_metric_result.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class Kalibro::DateMetricResult < Kalibro::Model
  2 +
  3 + attr_accessor :date, :metric_result
  4 +
  5 + def date=(value)
  6 + @date = value.is_a?(String) ? DateTime.parse(value) : value
  7 + end
  8 +
  9 + def metric_result=(value)
  10 + @metric_result = Kalibro::MetricResult.to_object value
  11 + end
  12 +
  13 + def result
  14 + @metric_result.value
  15 + end
  16 +end
... ...
plugins/mezuro/lib/kalibro/date_module_result.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class Kalibro::DateModuleResult < Kalibro::Model
  2 +
  3 + attr_accessor :date, :module_result
  4 +
  5 + def date=(value)
  6 + @date = value.is_a?(String) ? DateTime.parse(value) : value
  7 + end
  8 +
  9 + def module_result=(value)
  10 + @module_result = Kalibro::ModuleResult.to_object value
  11 + end
  12 +
  13 + def result
  14 + @module_result.grade
  15 + end
  16 +
  17 +end
... ...
plugins/mezuro/lib/kalibro/error.rb
... ... @@ -1,21 +0,0 @@
1   -class Kalibro::Error < Kalibro::Model
2   -
3   - attr_accessor :error_class, :message, :stack_trace_element, :cause
4   -
5   - def stack_trace_element=(value)
6   - @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value
7   - end
8   -
9   - def stack_trace
10   - @stack_trace_element
11   - end
12   -
13   - def stack_trace=(stack_trace)
14   - @stack_trace_element = stack_trace
15   - end
16   -
17   - def cause=(cause_value)
18   - @cause = Kalibro::Error.to_object cause_value
19   - end
20   -
21   -end
plugins/mezuro/lib/kalibro/errors/record_not_found.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class Kalibro::Errors::RecordNotFound < Kalibro::Errors::Standard
  2 +end
0 3 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/errors/standard.rb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +#Inspired on:
  2 +#https://github.com/rails/rails/blob/master/activerecord/lib/active_record/errors.rb
  3 +class Kalibro::Errors::Standard < StandardError
  4 +end
0 5 \ No newline at end of file
... ...
plugins/mezuro/lib/kalibro/metric.rb
1 1 class Kalibro::Metric < Kalibro::Model
2 2  
3   - attr_accessor :name, :scope, :description
  3 + attr_accessor :name, :compound, :scope, :description, :script, :language
  4 +
  5 + def languages
  6 + @language
  7 + end
  8 +
  9 + def languages=(languages)
  10 + @language = languages
  11 + end
  12 +
  13 + def language=(value)
  14 + @language = Kalibro::Model.to_objects_array value
  15 + end
4 16  
5 17 end
... ...
plugins/mezuro/lib/kalibro/metric_configuration.rb
1 1 class Kalibro::MetricConfiguration < Kalibro::Model
2 2  
3   - NATIVE_TYPE='native'
4   - COMPOUND_TYPE='compound'
  3 + attr_accessor :id, :code, :metric, :base_tool_name, :weight, :aggregation_form, :reading_group_id, :configuration_id
  4 +
  5 + def id=(value)
  6 + @id = value.to_i
  7 + end
5 8  
6   - attr_accessor :metric, :code, :weight, :aggregation_form, :range, :configuration_name
  9 + def reading_group_id=(value)
  10 + @reading_group_id = value.to_i
  11 + end
7 12  
8 13 def metric=(value)
9   - if value.kind_of?(Hash)
10   - @metric = native?(value) ? Kalibro::NativeMetric.to_object(value) : Kalibro::CompoundMetric.to_object(value)
11   - else
12   - @metric = value
13   - end
  14 + @metric = Kalibro::Metric.to_object(value)
14 15 end
15 16  
16 17 def weight=(value)
17 18 @weight = value.to_f
18 19 end
19 20  
20   - def range=(value)
21   - @range = Kalibro::Range.to_objects_array value
22   - end
23   -
24   - def add_range(new_range)
25   - @range = [] if @range.nil?
26   - @range << new_range
27   - end
28   -
29   - def ranges
30   - @range
31   - end
32   -
33   - def ranges=(ranges)
34   - @range = ranges
35   - end
36   -
37 21 def update_attributes(attributes={})
38 22 attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
39 23 save
40 24 end
41 25  
42   - def self.find_by_configuration_name_and_metric_name(configuration_name, metric_name)
43   - metric_configuration = new request("MetricConfiguration", :get_metric_configuration, {
44   - :configuration_name => configuration_name,
45   - :metric_name => metric_name
46   - })[:metric_configuration]
47   - metric_configuration.configuration_name = configuration_name
48   - metric_configuration
  26 + def to_hash
  27 + super :except => [:configuration_id]
49 28 end
50 29  
51   - def destroy
52   - begin
53   - self.class.request("MetricConfiguration", :remove_metric_configuration, {
54   - :configuration_name => configuration_name,
55   - :metric_name=> metric.name
56   - })
57   - rescue Exception => exception
58   - add_error exception
59   - end
60   - end
61   -
62   - def to_hash
63   - super :except => [:configuration_name]
  30 + def self.metric_configurations_of(configuration_id)
  31 + response = request(:metric_configurations_of, {:configuration_id => configuration_id})[:metric_configuration]
  32 + response = [] if response.nil?
  33 + response = [response] if response.is_a?(Hash)
  34 + response.map { |metric_configuration| new metric_configuration }
64 35 end
65 36  
66 37 private
67 38  
68   - def native?(value)
69   - value.has_key?(:origin) ? true : false
70   - end
71   -
72 39 def save_params
73   - {:metric_configuration => to_hash, :configuration_name => configuration_name}
  40 + {:metric_configuration => self.to_hash, :configuration_id => self.configuration_id}
74 41 end
75 42  
76 43 end
... ...
plugins/mezuro/lib/kalibro/metric_configuration_snapshot.rb 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +class Kalibro::MetricConfigurationSnapshot < Kalibro::Model
  2 +
  3 + attr_accessor :code, :weight, :aggregation_form, :metric, :base_tool_name, :range
  4 +
  5 + def weight=(value)
  6 + @weight = value.to_f
  7 + end
  8 +
  9 + def metric=(value)
  10 + if value.kind_of?(Hash)
  11 + @metric = Kalibro::Metric.to_object(value)
  12 + else
  13 + @metric = value
  14 + end
  15 + end
  16 +
  17 + def range=(value)
  18 + value.to_a
  19 + @range = []
  20 +
  21 + value.each do |range_snapshot|
  22 + @range << Kalibro::RangeSnapshot.to_object(range_snapshot)
  23 + end
  24 +
  25 + end
  26 +
  27 + def range_snapshot
  28 + range
  29 + end
  30 +
  31 + def to_hash
  32 + hash = super
  33 + hash[:attributes!][:range] = {'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
  34 + 'xsi:type' => 'kalibro:rangeSnapshotXml' }
  35 + hash
  36 + end
  37 +
  38 +end
... ...
plugins/mezuro/lib/kalibro/metric_result.rb
1 1 class Kalibro::MetricResult < Kalibro::Model
2 2  
3   - attr_accessor :metric, :value, :range, :descendent_result, :weight
4   -
5   - def metric=(value)
6   - if value.kind_of?(Hash)
7   - @metric = native?(value) ? Kalibro::NativeMetric.to_object(value) : Kalibro::CompoundMetric.to_object(value)
8   - else
9   - @metric = value
  3 + attr_accessor :id, :configuration, :value, :error
  4 +
  5 + def initialize(attributes={})
  6 + value = attributes[:value]
  7 + @value = (value == "NaN") ? attributes[:aggregated_value].to_f : value.to_f
  8 + attributes.each do |field, value|
  9 + if field!= :value and field!= :aggregated_value and self.class.is_valid?(field)
  10 + send("#{field}=", value)
  11 + end
10 12 end
  13 + @errors = []
11 14 end
12 15  
13   - def value=(value)
14   - @value = value.to_f
  16 + def id=(value)
  17 + @id = value.to_i
15 18 end
16 19  
17   - def range=(value)
18   - @range = Kalibro::Range.to_object value
  20 + def configuration=(value)
  21 + @configuration = Kalibro::MetricConfigurationSnapshot.to_object value
19 22 end
20 23  
21   - def descendent_result=(value)
22   - array = value.kind_of?(Array) ? value : [value]
23   - @descendent_result = array.collect {|element| element.to_f}
  24 + def metric_configuration_snapshot
  25 + configuration
24 26 end
25 27  
26   - def descendent_results
27   - @descendent_result
  28 + def error=(value)
  29 + @error = Kalibro::Throwable.to_object value
  30 + end
  31 +
  32 + def descendant_results
  33 + self.class.request(:descendant_results_of, {:metric_result_id => self.id})[:descendant_result].to_a
28 34 end
29 35  
30   - def descendent_results=(descendent_results)
31   - @descendent_result = descendent_results
  36 + def self.metric_results_of(module_result_id)
  37 + response = request(:metric_results_of, {:module_result_id => module_result_id})[:metric_result]
  38 + response = [] if response.nil?
  39 + response = [response] if response.is_a?(Hash)
  40 + response.map {|metric_result| new metric_result}
32 41 end
33   -
34   - private
35   -
36   - def native?(value)
37   - value.has_key?(:origin) ? true : false
  42 +
  43 + def self.history_of(metric_name, module_result_id)
  44 + response = self.request(:history_of_metric, {:metric_name => metric_name, :module_result_id => module_result_id})[:date_metric_result]
  45 + response = [] if response.nil?
  46 + response = [response] if response.is_a?(Hash)
  47 + response.map {|date_metric_result| Kalibro::DateMetricResult.new date_metric_result}
38 48 end
39 49  
40 50 end
... ...
plugins/mezuro/lib/kalibro/model.rb
... ... @@ -7,20 +7,21 @@ class Kalibro::Model
7 7 @errors = []
8 8 end
9 9  
  10 +
10 11 def to_hash(options={})
11 12 hash = Hash.new
12   - excepts = !options[:except].nil? ? options[:except] : []
  13 + excepts = options[:except].nil? ? [] : options[:except]
13 14 excepts << :errors
14 15 fields.each do |field|
15 16 if(!excepts.include?(field))
16 17 field_value = send(field)
17 18 if !field_value.nil?
18   - hash[field] = convert_to_hash(field_value)
  19 + hash[field] = convert_to_hash(field_value)
19 20 if field_value.is_a?(Kalibro::Model)
20 21 hash = {:attributes! => {}}.merge(hash)
21 22 hash[:attributes!][field.to_sym] = {
22 23 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
23   - 'xsi:type' => 'kalibro:' + xml_class_name(field_value) }
  24 + 'xsi:type' => 'kalibro:' + xml_instance_class_name(field_value) }
24 25 end
25 26 end
26 27 end
... ... @@ -28,7 +29,7 @@ class Kalibro::Model
28 29 hash
29 30 end
30 31  
31   - def self.request(endpoint, action, request_body = nil)
  32 + def self.request(action, request_body = nil)
32 33 response = client(endpoint).request(:kalibro, action) { soap.body = request_body }
33 34 response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method
34 35 end
... ... @@ -40,17 +41,25 @@ class Kalibro::Model
40 41  
41 42 def self.to_object value
42 43 value.kind_of?(Hash) ? new(value) : value
43   - end
44   -
  44 + end
  45 +
45 46 def self.create(attributes={})
46 47 new_model = new attributes
47 48 new_model.save
48 49 new_model
49 50 end
50 51  
  52 + def self.find(id)
  53 + if(exists?(id))
  54 + new request(find_action, id_params(id))["#{class_name.underscore}".to_sym]
  55 + else
  56 + raise Kalibro::Errors::RecordNotFound
  57 + end
  58 + end
  59 +
51 60 def save
52 61 begin
53   - self.class.request(save_endpoint, save_action, save_params)
  62 + self.id = self.class.request(save_action, save_params)["#{instance_class_name.underscore}_id".to_sym]
54 63 true
55 64 rescue Exception => exception
56 65 add_error exception
... ... @@ -60,12 +69,16 @@ class Kalibro::Model
60 69  
61 70 def destroy
62 71 begin
63   - self.class.request(destroy_endpoint, destroy_action, destroy_params)
  72 + self.class.request(destroy_action, destroy_params)
64 73 rescue Exception => exception
65 74 add_error exception
66 75 end
67 76 end
68 77  
  78 + def self.exists?(id)
  79 + request(exists_action, id_params(id))[:exists]
  80 + end
  81 +
69 82 protected
70 83  
71 84 def fields
... ... @@ -76,13 +89,13 @@ class Kalibro::Model
76 89 return value if value.nil?
77 90 return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array)
78 91 return value.to_hash if value.is_a?(Kalibro::Model)
79   - return self.class.date_with_milliseconds(value) if value.is_a?(DateTime)
  92 + return self.class.date_with_milliseconds(value) if value.is_a?(DateTime)
80 93 return 'INF' if value.is_a?(Float) and value.infinite? == 1
81 94 return '-INF' if value.is_a?(Float) and value.infinite? == -1
82   - value
  95 + value.to_s
83 96 end
84 97  
85   - def xml_class_name(object)
  98 + def xml_instance_class_name(object)
86 99 xml_name = object.class.name
87 100 xml_name["Kalibro::"] = ""
88 101 xml_name[0..0] = xml_name[0..0].downcase
... ... @@ -97,38 +110,50 @@ class Kalibro::Model
97 110 def self.is_valid?(field)
98 111 field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil?
99 112 end
100   -
  113 +
101 114 def self.date_with_milliseconds(date)
102 115 milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s
103 116 date.to_s[0..18] + milliseconds + date.to_s[19..-1]
104 117 end
105   -
106   - def class_name
  118 +
  119 + def instance_class_name
107 120 self.class.name.gsub(/Kalibro::/,"")
108 121 end
109   -
110   - def save_endpoint
  122 +
  123 + def self.endpoint
111 124 class_name
112 125 end
113   -
  126 +
114 127 def save_action
115   - "save_#{class_name.underscore}".to_sym
  128 + "save_#{instance_class_name.underscore}".to_sym
116 129 end
117   -
  130 +
118 131 def save_params
119   - {class_name.underscore.to_sym => self.to_hash}
  132 + {instance_class_name.underscore.to_sym => self.to_hash}
120 133 end
121   -
122   - def destroy_endpoint
123   - class_name
124   - end
125   -
  134 +
126 135 def destroy_action
127   - "remove_#{class_name.underscore}".to_sym
  136 + "delete_#{instance_class_name.underscore}".to_sym
128 137 end
129   -
  138 +
130 139 def destroy_params
131   - {"#{class_name.underscore}_name".to_sym => self.name}
  140 + {"#{instance_class_name.underscore}_id".to_sym => self.id}
  141 + end
  142 +
  143 + def self.class_name
  144 + self.name.gsub(/Kalibro::/,"")
  145 + end
  146 +
  147 + def self.exists_action
  148 + "#{class_name.underscore}_exists".to_sym
  149 + end
  150 +
  151 + def self.id_params(id)
  152 + {"#{class_name.underscore}_id".to_sym => id}
  153 + end
  154 +
  155 + def self.find_action
  156 + "get_#{class_name.underscore}".to_sym
132 157 end
133 158  
134 159 def add_error(exception)
... ...
plugins/mezuro/lib/kalibro/module.rb
... ... @@ -2,17 +2,4 @@ class Kalibro::Module &lt; Kalibro::Model
2 2  
3 3 attr_accessor :name, :granularity
4 4  
5   - def self.parent_names(name)
6   - path = []
7   - ancestors = []
8   - name.split(".").each do |token|
9   - path << token
10   - ancestors << path.join(".")
11   - end
12   - ancestors
13   - end
14   -
15   - def ancestor_names
16   - self.class.parent_names(@name)
17   - end
18 5 end
... ...
plugins/mezuro/lib/kalibro/module_node.rb
... ... @@ -1,21 +0,0 @@
1   -class Kalibro::ModuleNode < Kalibro::Model
2   -
3   - attr_accessor :module, :child
4   -
5   - def module=(value)
6   - @module = Kalibro::Module.to_object value
7   - end
8   -
9   - def child=(value)
10   - @child = Kalibro::ModuleNode.to_objects_array value
11   - end
12   -
13   - def children
14   - @child
15   - end
16   -
17   - def children=(children)
18   - @child = children
19   - end
20   -
21   -end
plugins/mezuro/lib/kalibro/module_result.rb
1 1 class Kalibro::ModuleResult < Kalibro::Model
2 2  
3   - attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error
  3 + attr_accessor :id, :module, :grade, :parent_id
4 4  
5   - def self.find_by_project_name_and_module_name_and_date(project_name, module_name, date)
6   - new request(
7   - 'ModuleResult',
8   - :get_module_result,
9   - {
10   - :project_name => project_name,
11   - :module_name => module_name,
12   - :date => date_with_milliseconds(date)
13   - })[:module_result]
  5 + def self.find(id)
  6 + new request(:get_module_result, { :module_result_id => id })[:module_result]
14 7 end
15   -
16   - def self.all_by_project_name_and_module_name(project_name, module_name)
17   - response = request(
18   - 'ModuleResult',
19   - :get_result_history,
20   - {
21   - :project_name => project_name,
22   - :module_name => module_name
23   - })[:module_result]
24   - Kalibro::ModuleResult.to_objects_array(response)
  8 +
  9 + def children
  10 + response = self.class.request(:children_of, {:module_result_id => id})[:module_result]
  11 + response = [] if response.nil?
  12 + response = [response] if response.is_a?(Hash)
  13 + response.map {|module_result| Kalibro::ModuleResult.new module_result}
25 14 end
26 15  
27   - def module=(value)
28   - @module = Kalibro::Module.to_object value
  16 + def parents
  17 + if parent_id.nil?
  18 + []
  19 + else
  20 + parent = self.class.find(parent_id)
  21 + parent.parents << parent
  22 + end
29 23 end
30 24  
31   - def date=(value)
32   - @date = value.is_a?(String) ? DateTime.parse(value) : value
33   - end
34   -
35   - def grade=(value)
36   - @grade = value.to_f
  25 + def id=(value)
  26 + @id = value.to_i
37 27 end
38 28  
39   - def metric_result=(value)
40   - @metric_result = Kalibro::MetricResult.to_objects_array value
41   - end
42   -
43   - def metric_results
44   - @metric_result
45   - end
46   -
47   - def metric_results=(metric_results)
48   - @metric_result = metric_results
  29 + def module=(value)
  30 + @module = Kalibro::Module.to_object value
49 31 end
50 32  
51   - def compound_metric_with_error=(value)
52   - @compound_metric_with_error = Kalibro::CompoundMetricWithError.to_objects_array value
  33 + def grade=(value)
  34 + @grade = value.to_f
53 35 end
54 36  
55   - def compound_metrics_with_error
56   - @compound_metric_with_error
  37 + def parent_id=(value)
  38 + @parent_id = value.to_i
57 39 end
58 40  
59   - def compound_metrics_with_error=(compound_metrics_with_error)
60   - @compound_metric_with_error = compound_metrics_with_error
  41 + def self.history_of(module_result_id)
  42 + response = self.request(:history_of_module, {:module_result_id => module_result_id})[:date_module_result]
  43 + response = [] if response.nil?
  44 + response = [response] if response.is_a?(Hash)
  45 + response.map {|date_module_result| Kalibro::DateModuleResult.new date_module_result}
61 46 end
62 47  
63 48 end
... ...
plugins/mezuro/lib/kalibro/native_metric.rb
... ... @@ -1,17 +0,0 @@
1   -class Kalibro::NativeMetric < Kalibro::Metric
2   -
3   - attr_accessor :origin, :language
4   -
5   - def languages
6   - @language
7   - end
8   -
9   - def languages=(languages)
10   - @language = languages
11   - end
12   -
13   - def language=(value)
14   - @language = Kalibro::Model.to_objects_array value
15   - end
16   -
17   -end
plugins/mezuro/lib/kalibro/process_time.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class Kalibro::ProcessTime < Kalibro::Model
  2 +
  3 + attr_accessor :state, :time
  4 +
  5 + def time=(time)
  6 + @time = time.to_i
  7 + end
  8 +
  9 +end
... ...
plugins/mezuro/lib/kalibro/processing.rb 0 → 100644
... ... @@ -0,0 +1,94 @@
  1 +class Kalibro::Processing < Kalibro::Model
  2 +
  3 + attr_accessor :id, :date, :state, :error, :process_time, :results_root_id
  4 +
  5 + def self.processing_of(repository_id)
  6 + if has_ready_processing(repository_id)
  7 + last_ready_processing_of(repository_id)
  8 + else #always exists a processing, we send a requisition to kalibro to process repository
  9 + last_processing_of(repository_id)
  10 + end
  11 + end
  12 +
  13 + def self.processing_with_date_of(repository_id, date)
  14 + date = date.is_a?(String) ? DateTime.parse(date) : date
  15 + if has_processing_after(repository_id, date)
  16 + first_processing_after(repository_id, date)
  17 + elsif has_processing_before(repository_id, date)
  18 + last_processing_before(repository_id, date)
  19 + else
  20 + last_processing_of(repository_id)
  21 + end
  22 + end
  23 +
  24 + def id=(value)
  25 + @id = value.to_i
  26 + end
  27 +
  28 + def date=(value)
  29 + @date = value.is_a?(String) ? DateTime.parse(value) : value
  30 + end
  31 +
  32 + def process_times=(value)
  33 + process_time=value
  34 + end
  35 +
  36 + def process_time=(value)
  37 + @process_time = Kalibro::ProcessTime.to_objects_array value
  38 + end
  39 +
  40 + def process_times
  41 + process_time
  42 + end
  43 +
  44 + def error=(value)
  45 + @error = Kalibro::Throwable.to_object value
  46 + end
  47 +
  48 + def results_root_id=(value)
  49 + @results_root_id = value.to_i
  50 + end
  51 +
  52 + private
  53 +
  54 + def self.has_processing(repository_id)
  55 + request(:has_processing, {:repository_id => repository_id})[:exists]
  56 + end
  57 +
  58 + def self.has_ready_processing(repository_id)
  59 + request(:has_ready_processing, {:repository_id => repository_id})[:exists]
  60 + end
  61 +
  62 + def self.has_processing_after(repository_id, date)
  63 + request(:has_processing_after, {:repository_id => repository_id, :date => date})[:exists]
  64 + end
  65 +
  66 + def self.has_processing_before(repository_id, date)
  67 + request(:has_processing_before, {:repository_id => repository_id, :date => date})[:exists]
  68 + end
  69 +
  70 + def self.last_processing_state_of(repository_id)
  71 + request(:last_processing_state, {:repository_id => repository_id})[:process_state]
  72 + end
  73 +
  74 + def self.last_ready_processing_of(repository_id)
  75 + new request(:last_ready_processing, {:repository_id => repository_id})[:processing]
  76 + end
  77 +
  78 + def self.first_processing_of(repository_id)
  79 + new request(:first_processing, {:repository_id => repository_id})[:processing]
  80 + end
  81 +
  82 + def self.last_processing_of(repository_id)
  83 + new request(:last_processing, {:repository_id => repository_id})[:processing]
  84 + end
  85 +
  86 + def self.first_processing_after(repository_id, date)
  87 + new request(:first_processing_after, {:repository_id => repository_id, :date => date})[:processing]
  88 + end
  89 +
  90 + def self.last_processing_before(repository_id, date)
  91 + new request(:last_processing_before, {:repository_id => repository_id, :date => date})[:processing]
  92 + end
  93 +
  94 +end
... ...
plugins/mezuro/lib/kalibro/project.rb
1 1 class Kalibro::Project < Kalibro::Model
2 2  
3   - attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :kalibro_error
  3 + attr_accessor :id, :name, :description
4 4  
5   - def self.all_names
6   - response = request("Project", :get_project_names)[:project_name]
7   - response = [] if response.nil?
8   - response
9   - end
10   -
11   - def self.find_by_name(project_name)
12   - new request("Project", :get_project, :project_name => project_name)[:project]
13   - end
14   -
15   - def repository=(value)
16   - @repository = Kalibro::Repository.to_object value
  5 + def id=(value)
  6 + @id = value.to_i
17 7 end
18 8  
19   - def error=(value)
20   - @kalibro_error = Kalibro::Error.to_object value
21   - end
22   -
23   - def process_project(days = '0')
24   - begin
25   - if days.to_i.zero?
26   - self.class.request("Kalibro", :process_project, {:project_name => name})
27   - else
28   - self.class.request("Kalibro", :process_periodically, {:project_name => name, :period_in_days => days})
29   - end
30   - rescue Exception => exception
31   - add_error exception
32   - end
33   - end
34   -
35   - def process_period
36   - begin
37   - self.class.request("Kalibro", :get_process_period, {:project_name => name})[:period]
38   - rescue Exception => exception
39   - add_error exception
40   - end
  9 + def self.all
  10 + response = request(:all_projects)[:project]
  11 + response = [] if response.nil?
  12 + response = [response] if response.is_a?(Hash)
  13 + response.map {|project| new project}
41 14 end
42 15  
43   - def cancel_periodic_process
44   - begin
45   - self.class.request("Kalibro", :cancel_periodic_process, {:project_name => name})
46   - rescue Exception => exception
47   - add_error exception
48   - end
  16 + def self.project_of(repository_id)
  17 + new request(:project_of, :repository_id => repository_id)[:project]
49 18 end
50 19  
51 20 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
plugins/mezuro/lib/kalibro/range.rb
1 1 class Kalibro::Range < Kalibro::Model
2 2  
3   - attr_accessor :beginning, :end, :label, :grade, :color, :comments
  3 + attr_accessor :id, :beginning, :end, :reading_id, :comments
  4 +
  5 + def id=(value)
  6 + @id = value.to_i
  7 + end
4 8  
5 9 def beginning=(value)
6 10 @beginning = value.to_f
... ... @@ -30,12 +34,45 @@ class Kalibro::Range &lt; Kalibro::Model
30 34 end
31 35 end
32 36  
33   - def grade=(value)
34   - @grade = value.to_f
  37 + def reading_id=(value)
  38 + @reading_id = value.to_i
  39 + end
  40 +
  41 + def label
  42 + reading.label
35 43 end
36 44  
37   - def mezuro_color
38   - @color.nil? ? "e4ca2d" : @color.gsub(/^ff/, "")
39   - end
  45 + def grade
  46 + reading.grade
  47 + end
  48 +
  49 + def color
  50 + reading.color
  51 + end
  52 +
  53 + def self.ranges_of( metric_configuration_id )
  54 + response = request(:ranges_of, {:metric_configuration_id => metric_configuration_id} )[:range]
  55 + response = [] if response.nil?
  56 + response = [response] if response.is_a?(Hash)
  57 + response.map { |range| new range }
  58 + end
  59 +
  60 + def save( metric_configuration_id )
  61 + begin
  62 + self.id = self.class.request(:save_range, {:range => self.to_hash, :metric_configuration_id => metric_configuration_id})[:range_id]
  63 + true
  64 + rescue Exception => exception
  65 + add_error exception
  66 + false
  67 + end
  68 + end
  69 +
  70 + private
  71 +
  72 + def reading
  73 + @reading ||= Kalibro::Reading.find(reading_id)
  74 + @reading
  75 + end
40 76  
41 77 end
  78 +
... ...
plugins/mezuro/lib/kalibro/range_snapshot.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +class Kalibro::RangeSnapshot < Kalibro::Model
  2 +
  3 + attr_accessor :beginning, :end, :label, :grade, :color, :comments
  4 +
  5 + def beginning=(value)
  6 + @beginning = ((value == "-INF") ? -1.0/0 : value.to_f)
  7 + end
  8 +
  9 + def end=(value)
  10 + @end = ((value == "INF") ? 1.0/0 : value.to_f)
  11 + end
  12 +
  13 + def grade=(value)
  14 + @grade = value.to_f
  15 + end
  16 +
  17 +end
... ...
plugins/mezuro/lib/kalibro/reading.rb 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +class Kalibro::Reading < Kalibro::Model
  2 +
  3 + attr_accessor :id, :label, :grade, :color
  4 +
  5 + def self.find(id)
  6 + new request(:get_reading, {:reading_id => id})[:reading]
  7 + end
  8 +
  9 + def self.readings_of( group_id )
  10 + response = request(:readings_of, {:group_id => group_id})[:reading]
  11 + response = [] if response.nil?
  12 + response = [response] if response.is_a?(Hash)
  13 + response.map { |reading| new reading }
  14 + end
  15 +
  16 + def self.reading_of( range_id )
  17 + new request(:reading_of, {:range_id => range_id} )[:reading]
  18 + end
  19 +
  20 + def id=(value)
  21 + @id = value.to_i
  22 + end
  23 +
  24 + def grade=(value)
  25 + @grade = value.to_f
  26 + end
  27 +
  28 + def save(reading_group_id)
  29 + begin
  30 + self.id = self.class.request(:save_reading, {:reading => self.to_hash, :group_id => reading_group_id})[:reading_id]
  31 + true
  32 + rescue Exception => exception
  33 + add_error exception
  34 + false
  35 + end
  36 + end
  37 +
  38 +end
... ...
plugins/mezuro/lib/kalibro/reading_group.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +class Kalibro::ReadingGroup < Kalibro::Model
  2 +
  3 + attr_accessor :id, :name, :description
  4 +
  5 + def id=(value)
  6 + @id = value.to_i
  7 + end
  8 +
  9 + def self.all
  10 + response = request(:all_reading_groups)[:reading_group]
  11 + response = [] if response.nil?
  12 + response = [response] if response.is_a?(Hash)
  13 + response.map { |reading_group| new reading_group }
  14 + end
  15 +
  16 + def self.reading_group_of( metric_configuration_id )
  17 + new request(:reading_group_of, {:metric_configuration_id => metric_configuration_id} )[:reading_group]
  18 + end
  19 +
  20 + private
  21 +
  22 + def self.id_params(id)
  23 + {:group_id => id}
  24 + end
  25 +
  26 + def destroy_params
  27 + {:group_id => self.id}
  28 + end
  29 +
  30 +end
... ...
plugins/mezuro/lib/kalibro/repository.rb
1 1 class Kalibro::Repository < Kalibro::Model
2 2  
3   - attr_accessor :type, :address, :username, :password
  3 + attr_accessor :id, :name, :description, :license, :process_period, :type, :address, :configuration_id
4 4  
5 5 def self.repository_types
6   - request("Kalibro", :get_supported_repository_types)[:repository_type].to_a
  6 + request(:supported_repository_types)[:supported_type].to_a
  7 + end
  8 +
  9 + def self.repository_of(processing_id)
  10 + new request(:repository_of, {:processing_id => processing_id})[:repository]
  11 + end
  12 +
  13 + def self.repositories_of(project_id)
  14 + response = request(:repositories_of, {:project_id => project_id})[:repository]
  15 + response = [] if response.nil?
  16 + response = [response] if response.is_a?(Hash)
  17 + response.map {|repository| new repository}
  18 + end
  19 +
  20 + def id=(value)
  21 + @id = value.to_i
  22 + end
  23 +
  24 + def process_period=(value)
  25 + @process_period = value.to_i
  26 + end
  27 +
  28 + def configuration_id=(value)
  29 + @configuration_id = value.to_i
  30 + end
  31 +
  32 + def process
  33 + self.class.request(:process_repository, {:repository_id => self.id})
  34 + end
  35 +
  36 + def cancel_processing_of_repository
  37 + self.class.request(:cancel_processing_of_repository, {:repository_id => self.id})
  38 + end
  39 +
  40 + def save(project_id)
  41 + begin
  42 + self.id = self.class.request(:save_repository, {:repository => self.to_hash, :project_id => project_id})[:repository_id]
  43 + true
  44 + rescue Exception => exception
  45 + add_error exception
  46 + false
  47 + end
7 48 end
8 49  
9 50 end
... ...
plugins/mezuro/lib/kalibro/throwable.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +class Kalibro::Throwable < Kalibro::Model
  2 +
  3 + attr_accessor :target_string, :message, :cause, :stack_trace_element
  4 +
  5 + def stack_trace_element=(value)
  6 + @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value
  7 + end
  8 +
  9 + def stack_trace
  10 + @stack_trace_element
  11 + end
  12 +
  13 + def stack_trace=(stack_trace)
  14 + @stack_trace_element = stack_trace
  15 + end
  16 +
  17 + def cause=(cause_value)
  18 + @cause = Kalibro::Throwable.to_object cause_value
  19 + end
  20 +
  21 +end
... ...
plugins/mezuro/lib/mezuro_plugin.rb
... ... @@ -18,7 +18,8 @@ class MezuroPlugin &lt; Noosfero::Plugin
18 18 if context.profile.is_a?(Community)
19 19 MezuroPlugin::ProjectContent
20 20 else
21   - MezuroPlugin::ConfigurationContent
  21 + [MezuroPlugin::ConfigurationContent,
  22 + MezuroPlugin::ReadingGroupContent]
22 23 end
23 24 end
24 25  
... ... @@ -26,7 +27,8 @@ class MezuroPlugin &lt; Noosfero::Plugin
26 27 if context.profile.is_a?(Community)
27 28 {:title => _('Mezuro project'), :url => {:controller => 'cms', :action => 'new', :profile => context.profile.identifier, :type => 'MezuroPlugin::ProjectContent'}, :icon => 'mezuro' }
28 29 else
29   - {:title => _('Mezuro configuration'), :url => {:controller => 'cms', :action => 'new', :profile => context.profile.identifier, :type => 'MezuroPlugin::ConfigurationContent'}, :icon => 'mezuro' }
  30 + [{:title => _('Mezuro configuration'), :url => {:controller => 'cms', :action => 'new', :profile => context.profile.identifier, :type => 'MezuroPlugin::ConfigurationContent'}, :icon => 'mezuro' },
  31 + {:title => _('Mezuro Reading Group'), :url => {:controller => 'cms', :action => 'new', :profile => context.profile.identifier, :type => 'MezuroPlugin::ReadingGroupContent'}, :icon => 'mezuro' }]
30 32 end
31 33 end
32 34  
... ...
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
1 1 class MezuroPlugin::ConfigurationContent < Article
2   - validate_on_create :validate_kalibro_configuration_name
  2 + validate_on_create :validate_configuration_name
3 3  
4   - settings_items :description, :configuration_to_clone_name
  4 + settings_items :configuration_id
5 5  
6   - after_save :send_kalibro_configuration_to_service
7   - after_destroy :remove_kalibro_configuration_from_service
  6 + before_save :send_configuration_to_service
  7 + after_destroy :remove_configuration_from_service
8 8  
9 9 def self.short_description
10 10 'Mezuro configuration'
11 11 end
12 12  
13 13 def self.description
14   - 'Sets of thresholds to interpret metrics'
  14 + 'Set of metric configurations to interpret a Kalibro project'
15 15 end
16 16  
17 17 include ActionView::Helpers::TagHelper
... ... @@ -21,77 +21,118 @@ class MezuroPlugin::ConfigurationContent &lt; Article
21 21 end
22 22 end
23 23  
24   - def kalibro_configuration
  24 + def kalibro_configuration #Can't be just "configuration", method name exists somewhere in noosfero
25 25 begin
26   - @kalibro_configuration ||= Kalibro::Configuration.find_by_name(self.name)
  26 + @configuration ||= Kalibro::Configuration.find(self.configuration_id)
27 27 rescue Exception => exception
28 28 errors.add_to_base(exception.message)
  29 + @configuration = nil
29 30 end
30   - @kalibro_configuration
  31 + @configuration
31 32 end
32 33  
33   - def metric_configurations
34   - kalibro_configuration.metric_configurations
  34 + def configuration_names_and_ids
  35 + begin
  36 + all_configurations = Kalibro::Configuration.all
  37 + all_names_and_ids = all_configurations.map { |configuration| [configuration.name, configuration.id] }
  38 + [["None", -1]] + (all_names_and_ids.sort { |x,y| x.first.downcase <=> y.first.downcase })
  39 + rescue Exception => exception
  40 + errors.add_to_base(exception.message)
  41 + [["None", -1]]
  42 + end
  43 +
35 44 end
36 45  
37   - def kalibro_configuration_names
  46 + def description=(value)
  47 + @description=value
  48 + end
  49 +
  50 + def description
38 51 begin
39   - all_configuration_names = Kalibro::Configuration.all_names
40   - if all_configuration_names.nil?
41   - ["None"]
42   - else
43   - ["None"] + all_configuration_names.sort
44   - end
  52 + @description ||= kalibro_configuration.description
  53 + rescue
  54 + @description = ""
  55 + end
  56 + @description
  57 + end
  58 +
  59 + def configuration_to_clone_id
  60 + begin
  61 + @configuration_to_clone_id
45 62 rescue Exception => exception
46   - errors.add_to_base(exception.message)
47   - ["None"]
  63 + nil
  64 + end
  65 + end
  66 +
  67 + def configuration_to_clone_id=(value)
  68 + @configuration_to_clone_id = (value == -1) ? nil : value
  69 + end
  70 +
  71 + def metric_configurations
  72 + begin
  73 + @metric_configurations ||= Kalibro::MetricConfiguration.metric_configurations_of(configuration_id)
  74 + rescue Exception => error
  75 + errors.add_to_base(error.message)
  76 + @metric_configurations = []
48 77 end
  78 + @metric_configurations
  79 + end
  80 +
  81 + def metric_configurations=(value)
  82 + @metric_configurations = value.kind_of?(Array) ? value : [value]
  83 + @metric_configurations = @metric_configurations.map { |element| to_metric_configuration(element) }
49 84 end
50 85  
51 86 private
52 87  
53   - def validate_kalibro_configuration_name
54   - existing = kalibro_configuration_names.map { |a| a.downcase}
  88 + def self.to_metric_configuration value
  89 + value.kind_of?(Hash) ? Kalibro::MetricConfiguration.new(value) : value
  90 + end
  91 +
  92 + def validate_configuration_name
  93 + existing = configuration_names_and_ids.map { |a| a.first.downcase}
55 94  
56 95 if existing.include?(name.downcase)
57 96 errors.add_to_base("Configuration name already exists in Kalibro")
58 97 end
59 98 end
60 99  
61   - def send_kalibro_configuration_to_service
62   - if editing_kalibro_configuration?
63   - kalibro_configuration.update_attributes({:description => description})
64   - else
65   - create_kalibro_configuration
66   - end
67   - end
68   -
69   - def remove_kalibro_configuration_from_service
  100 + def remove_configuration_from_service
70 101 kalibro_configuration.destroy unless kalibro_configuration.nil?
71 102 end
72 103  
73   - def create_kalibro_configuration
74   - attributes = {:name => name, :description => description}
75   - if cloning_kalibro_configuration?
76   - attributes[:metric_configuration] = configuration_to_clone.metric_configurations_hash
77   - end
78   - Kalibro::Configuration.create attributes
  104 + def send_configuration_to_service
  105 + attributes = {:id => configuration_id, :name => name, :description => description}
  106 + created_configuration = Kalibro::Configuration.create attributes
  107 + self.configuration_id = created_configuration.id
  108 + clone_configuration if cloning_configuration?
79 109 end
80   -
81   - def editing_kalibro_configuration?
82   - kalibro_configuration.present?
  110 +
  111 + def cloning_configuration?
  112 + !configuration_to_clone_id.nil?
83 113 end
84   -
85   - def configuration_to_clone
86   - @configuration_to_clone ||= find_configuration_to_clone
  114 +
  115 + def clone_configuration
  116 + metric_configurations_to_clone ||= Kalibro::MetricConfiguration.metric_configurations_of(configuration_to_clone_id)
  117 + clone_metric_configurations metric_configurations_to_clone
87 118 end
88   -
89   - def find_configuration_to_clone
90   - (configuration_to_clone_name == "None") ? nil : Kalibro::Configuration.find_by_name(configuration_to_clone_name)
  119 +
  120 + def clone_metric_configurations metric_configurations_to_clone
  121 + metric_configurations_to_clone.each do |metric_configuration|
  122 + clonned_metric_configuration_id = metric_configuration.id
  123 + metric_configuration.id = nil
  124 + metric_configuration.configuration_id = self.configuration_id
  125 + metric_configuration.save
  126 + clone_ranges clonned_metric_configuration_id, metric_configuration.id
  127 + end
91 128 end
92   -
93   - def cloning_kalibro_configuration?
94   - configuration_to_clone.present?
  129 +
  130 + def clone_ranges clonned_metric_configuration_id, new_metric_configuration_id
  131 + Kalibro::Range.ranges_of(clonned_metric_configuration_id).each do |range|
  132 + range.id = nil
  133 + range.save new_metric_configuration_id
  134 + end
95 135 end
96 136  
97 137 end
  138 +
... ...
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
... ... @@ -6,24 +6,26 @@ class MezuroPlugin::Helpers::ContentViewerHelper
6 6 sprintf("%.2f", grade.to_f)
7 7 end
8 8  
9   - def self.create_periodicity_options
10   - [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]]
  9 + def self.periodicity_options
  10 + [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweekly", 15], ["Monthly", 30]]
11 11 end
12 12  
13   - def self.create_license_options
  13 + def self.periodicity_option(periodicity)
  14 + periodicity_options.select {|x| x.last == periodicity}.first.first
  15 + end
  16 +
  17 + def self.license_options
14 18 options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yml")
15 19 options = options.split(";")
16   - formated_options = []
17   - options.each { |option| formated_options << [option, option] }
18   - formated_options
  20 + options
19 21 end
20 22  
21 23 def self.generate_chart(score_history)
22 24 values = []
23 25 labels = []
24 26 score_history.each do |score_data|
25   - values << score_data.first
26   - labels << score_data.last
  27 + values << score_data.result
  28 + labels << score_data.date
27 29 end
28 30 labels = discretize_array labels
29 31 Gchart.line(
... ... @@ -39,20 +41,22 @@ class MezuroPlugin::Helpers::ContentViewerHelper
39 41 )
40 42 end
41 43  
42   - def self.get_periodicity_option(index)
43   - options = [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]]
44   - selected_option = options.find { |option| option.last == index.to_i }
45   - selected_option.first
  44 + def self.format_name(metric_configuration_snapshot)
  45 + metric_configuration_snapshot.metric.name.delete("() ")
  46 + end
  47 +
  48 + def self.format_time(miliseconds)
  49 + seconds = miliseconds/1000
  50 + MezuroPluginModuleResultController.helpers.distance_of_time_in_words(0, seconds, include_seconds = true)
46 51 end
47 52  
48   - def self.format_name(metric_result)
49   - metric_result.metric.name.delete("() ")
  53 + def self.aggregation_options
  54 + [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
  55 + ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]]
50 56 end
51 57  
52   - def self.get_license_option(selected)
53   - options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yml")
54   - options.split(";")
55   - selected_option = options.find { |license| license == selected }
  58 + def self.scope_options
  59 + [["Software", "SOFTWARE"], ["Package", "PACKAGE"], ["Class", "CLASS"], ["Method", "METHOD"]]
56 60 end
57 61  
58 62 private
... ...
plugins/mezuro/lib/mezuro_plugin/helpers/module_result_helper.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class MezuroPlugin::Helpers::ModuleResultHelper
  2 +
  3 + def self.module_name name
  4 + name.is_a?(Array) ? name.last : name
  5 + end
  6 +
  7 +end
... ...
plugins/mezuro/lib/mezuro_plugin/project_content.rb
1 1 class MezuroPlugin::ProjectContent < Article
2 2 include ActionView::Helpers::TagHelper
3 3  
4   - settings_items :project_license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days
  4 + settings_items :project_id
5 5  
6   - validate_on_create :validate_kalibro_project_name
7   - validate_on_create :validate_repository_url
  6 + before_save :send_project_to_service
  7 + after_destroy :destroy_project_from_service
8 8  
9 9 def self.short_description
10 10 'Mezuro project'
... ... @@ -22,90 +22,70 @@ class MezuroPlugin::ProjectContent &lt; Article
22 22  
23 23 def project
24 24 begin
25   - @project ||= Kalibro::Project.find_by_name(name)
  25 + @project ||= Kalibro::Project.find(project_id)
26 26 rescue Exception => error
27 27 errors.add_to_base(error.message)
28 28 end
29 29 @project
30 30 end
31 31  
32   - def project_result
33   - begin
34   - @project_result ||= Kalibro::ProjectResult.last_result(name)
35   - rescue Exception => error
36   - errors.add_to_base(error.message)
37   - end
38   - @project_result
39   - end
40   -
41   - def project_result_with_date(date)
  32 + def repositories
42 33 begin
43   - @project_result ||= Kalibro::ProjectResult.has_results_before?(name, date) ? Kalibro::ProjectResult.last_result_before(name, date) :
44   -Kalibro::ProjectResult.first_result_after(name, date)
  34 + @repositories ||= Kalibro::Repository.repositories_of(project_id)
45 35 rescue Exception => error
46 36 errors.add_to_base(error.message)
  37 + @repositories = []
47 38 end
48   - @project_result
  39 + @repositories
49 40 end
50 41  
51   - def module_result(attributes)
52   - module_name = attributes[:module_name].nil? ? project.name : attributes[:module_name]
53   - date = attributes[:date].nil? ? project_result.date : project_result_with_date(attributes[:date]).date
54   - begin
55   - @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, module_name, date)
56   - rescue Exception => error
57   - errors.add_to_base(error.message)
58   - end
59   - @module_result
  42 + def description=(value)
  43 + @description=value
60 44 end
61   -
62   - def result_history(module_name)
  45 +
  46 + def description
63 47 begin
64   - @result_history ||= Kalibro::ModuleResult.all_by_project_name_and_module_name(name, module_name)
65   - rescue Exception => error
66   - errors.add_to_base(error.message)
  48 + @description ||= project.description
  49 + rescue
  50 + @description = ""
67 51 end
  52 + @description
68 53 end
69 54  
70   - after_save :send_project_to_service
71   - after_destroy :destroy_project_from_service
  55 + def repositories=(value)
  56 + @repositories = value.kind_of?(Array) ? value : [value]
  57 + @repositories = @repositories.map { |element| to_repository(element) }
  58 + end
72 59  
73 60 private
74   -
75   - def validate_kalibro_project_name
76   - begin
77   - existing = Kalibro::Project.all_names
78   - rescue Exception => error
79   - errors.add_to_base(error.message)
80   - existing = []
81   - end
82   -
83   - if existing.any?{|existing_name| existing_name.casecmp(name)==0} # existing.include?(name) + case insensitive
84   - errors.add_to_base("Project name already exists in Kalibro")
85   - end
86   - end
87 61  
88   - def validate_repository_url
89   - if(repository_url.nil? || repository_url == "")
90   - errors.add_to_base("Repository URL is mandatory")
  62 + def self.to_repository value
  63 + value.kind_of?(Hash) ? Kalibro::Repository.new(value) : value
  64 + end
  65 +
  66 + def validate_repository_address
  67 + repositories.each do |repository|
  68 + if (!repository.nil?)
  69 + address = repository.address
  70 + if(address.nil? || address == "")
  71 + errors.add_to_base("Repository Address is mandatory")
  72 + end
  73 + else
  74 + errors.add_to_base("Repository is mandatory")
  75 + end
91 76 end
92 77 end
93   -
  78 +
94 79 def send_project_to_service
95 80 created_project = create_kalibro_project
96   - created_project.process_project(periodicity_in_days)
  81 + self.project_id = created_project.id
97 82 end
98 83  
99 84 def create_kalibro_project
100 85 Kalibro::Project.create(
101 86 :name => name,
102   - :license => project_license,
103 87 :description => description,
104   - :repository => {
105   - :type => repository_type,
106   - :address => repository_url
107   - },
108   - :configuration_name => configuration_name
  88 + :id => self.project_id
109 89 )
110 90 end
111 91  
... ...
plugins/mezuro/lib/mezuro_plugin/reading_group_content.rb 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +class MezuroPlugin::ReadingGroupContent < Article
  2 + include ActionView::Helpers::TagHelper
  3 +
  4 + settings_items :reading_group_id
  5 +
  6 + before_save :send_reading_group_to_service
  7 + after_destroy :destroy_reading_group_from_service
  8 +
  9 + def self.short_description
  10 + 'Mezuro reading group'
  11 + end
  12 +
  13 + def self.description
  14 + 'Set of thresholds to interpret metric results'
  15 + end
  16 +
  17 + def to_html(options = {})
  18 + lambda do
  19 + render :file => 'content_viewer/show_reading_group.rhtml'
  20 + end
  21 + end
  22 +
  23 + def reading_group
  24 + begin
  25 + @reading_group ||= Kalibro::ReadingGroup.find(reading_group_id)
  26 + rescue Exception => error
  27 + errors.add_to_base(error.message)
  28 + end
  29 + @reading_group
  30 + end
  31 +
  32 + def readings
  33 + begin
  34 + @readings ||= Kalibro::Reading.readings_of(reading_group_id)
  35 + rescue Exception => error
  36 + errors.add_to_base(error.message)
  37 + @readings = []
  38 + end
  39 + @readings
  40 + end
  41 +
  42 + def description=(value)
  43 + @description=value
  44 + end
  45 +
  46 + def description
  47 + begin
  48 + @description ||= reading_group.description
  49 + rescue
  50 + @description = ""
  51 + end
  52 + @description
  53 + end
  54 +
  55 + def readings=(value)
  56 + @readings = value.kind_of?(Array) ? value : [value]
  57 + @readings = @readings.map { |element| to_reading(element) }
  58 + end
  59 +
  60 + private
  61 +
  62 + def self.to_reading value
  63 + value.kind_of?(Hash) ? Kalibro::Reading.new(value) : value
  64 + end
  65 +
  66 + def send_reading_group_to_service
  67 + created_reading_group = create_kalibro_reading_group
  68 + self.reading_group_id = created_reading_group.id
  69 + end
  70 +
  71 + def create_kalibro_reading_group
  72 + Kalibro::ReadingGroup.create(
  73 + :name => name,
  74 + :description => description,
  75 + :id => self.reading_group_id
  76 + )
  77 + end
  78 +
  79 + def destroy_reading_group_from_service
  80 + reading_group.destroy unless reading_group.nil?
  81 + end
  82 +
  83 +end
... ...
plugins/mezuro/public/javascripts/colorPicker/LICENSE
... ... @@ -1,22 +0,0 @@
1   -Copyright (c) 2012 Lakshan Perera
2   -
3   -Permission is hereby granted, free of charge, to any person
4   -obtaining a copy of this software and associated documentation
5   -files (the "Software"), to deal in the Software without
6   -restriction, including without limitation the rights to use,
7   -copy, modify, merge, publish, distribute, sublicense, and/or sell
8   -copies of the Software, and to permit persons to whom the
9   -Software is furnished to do so, subject to the following
10   -conditions:
11   -
12   -The above copyright notice and this permission notice shall be
13   -included in all copies or substantial portions of the Software.
14   -
15   -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16   -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17   -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18   -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19   -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20   -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21   -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22   -OTHER DEALINGS IN THE SOFTWARE.
plugins/mezuro/public/javascripts/colorPicker/jquery.colorPicker.js
... ... @@ -1,328 +0,0 @@
1   -/**
2   - * Really Simple Color Picker in jQuery
3   - *
4   - * Licensed under the MIT (MIT-LICENSE.txt) licenses.
5   - *
6   - * Copyright (c) 2008-2012
7   - * Lakshan Perera (www.laktek.com) & Daniel Lacy (daniellacy.com)
8   - *
9   - * Permission is hereby granted, free of charge, to any person obtaining a copy
10   - * of this software and associated documentation files (the "Software"), to
11   - * deal in the Software without restriction, including without limitation the
12   - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13   - * sell copies of the Software, and to permit persons to whom the Software is
14   - * furnished to do so, subject to the following conditions:
15   - *
16   - * The above copyright notice and this permission notice shall be included in
17   - * all copies or substantial portions of the Software.
18   - *
19   - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20   - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21   - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22   - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23   - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24   - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25   - * IN THE SOFTWARE.
26   - */
27   -
28   -(function ($) {
29   - /**
30   - * Create a couple private variables.
31   - **/
32   - var selectorOwner,
33   - activePalette,
34   - cItterate = 0,
35   - templates = {
36   - control : $('<div class="colorPicker-picker">&nbsp;</div>'),
37   - palette : $('<div id="colorPicker_palette" class="colorPicker-palette" />'),
38   - swatch : $('<div class="colorPicker-swatch">&nbsp;</div>'),
39   - hexLabel: $('<label for="colorPicker_hex">Hex</label>'),
40   - hexField: $('<input type="text" id="colorPicker_hex" />')
41   - },
42   - transparent = "transparent",
43   - lastColor;
44   -
45   - /**
46   - * Create our colorPicker function
47   - **/
48   - $.fn.colorPicker = function (options) {
49   -
50   - return this.each(function () {
51   - // Setup time. Clone new elements from our templates, set some IDs, make shortcuts, jazzercise.
52   - var element = $(this),
53   - opts = $.extend({}, $.fn.colorPicker.defaults, options),
54   - defaultColor = $.fn.colorPicker.toHex(
55   - (element.val().length > 0) ? element.val() : opts.pickerDefault
56   - ),
57   - newControl = templates.control.clone(),
58   - newPalette = templates.palette.clone().attr('id', 'colorPicker_palette-' + cItterate),
59   - newHexLabel = templates.hexLabel.clone(),
60   - newHexField = templates.hexField.clone(),
61   - paletteId = newPalette[0].id,
62   - swatch;
63   -
64   -
65   - /**
66   - * Build a color palette.
67   - **/
68   - $.each(opts.colors, function (i) {
69   - swatch = templates.swatch.clone();
70   -
71   - if (opts.colors[i] === transparent) {
72   - swatch.addClass(transparent).text('X');
73   - $.fn.colorPicker.bindPalette(newHexField, swatch, transparent);
74   - } else {
75   - swatch.css("background-color", "#" + this);
76   - $.fn.colorPicker.bindPalette(newHexField, swatch);
77   - }
78   - swatch.appendTo(newPalette);
79   - });
80   -
81   - newHexLabel.attr('for', 'colorPicker_hex-' + cItterate);
82   -
83   - newHexField.attr({
84   - 'id' : 'colorPicker_hex-' + cItterate,
85   - 'value' : defaultColor
86   - });
87   -
88   - newHexField.bind("keydown", function (event) {
89   - if (event.keyCode === 13) {
90   - var hexColor = $.fn.colorPicker.toHex($(this).val());
91   - $.fn.colorPicker.changeColor(hexColor ? hexColor : element.val());
92   - }
93   - if (event.keyCode === 27) {
94   - $.fn.colorPicker.hidePalette();
95   - }
96   - });
97   -
98   - newHexField.bind("keyup", function (event) {
99   - var hexColor = $.fn.colorPicker.toHex($(event.target).val());
100   - $.fn.colorPicker.previewColor(hexColor ? hexColor : element.val());
101   - });
102   -
103   - $('<div class="colorPicker_hexWrap" />').append(newHexLabel).appendTo(newPalette);
104   -
105   - newPalette.find('.colorPicker_hexWrap').append(newHexField);
106   -
107   - $("body").append(newPalette);
108   -
109   - newPalette.hide();
110   -
111   -
112   - /**
113   - * Build replacement interface for original color input.
114   - **/
115   - newControl.css("background-color", defaultColor);
116   -
117   - newControl.bind("click", function () {
118   - $.fn.colorPicker.togglePalette($('#' + paletteId), $(this));
119   - });
120   -
121   - if( options && options.onColorChange ) {
122   - newControl.data('onColorChange', options.onColorChange);
123   - } else {
124   - newControl.data('onColorChange', function() {} );
125   - }
126   - element.after(newControl);
127   -
128   - element.bind("change", function () {
129   - element.next(".colorPicker-picker").css(
130   - "background-color", $.fn.colorPicker.toHex($(this).val())
131   - );
132   - });
133   -
134   - // Hide the original input.
135   - element.val(defaultColor).hide();
136   -
137   - cItterate++;
138   - });
139   - };
140   -
141   - /**
142   - * Extend colorPicker with... all our functionality.
143   - **/
144   - $.extend(true, $.fn.colorPicker, {
145   - /**
146   - * Return a Hex color, convert an RGB value and return Hex, or return false.
147   - *
148   - * Inspired by http://code.google.com/p/jquery-color-utils
149   - **/
150   - toHex : function (color) {
151   - // If we have a standard or shorthand Hex color, return that value.
152   - if (color.match(/[0-9A-F]{6}|[0-9A-F]{3}$/i)) {
153   - return (color.charAt(0) === "#") ? color : ("#" + color);
154   -
155   - // Alternatively, check for RGB color, then convert and return it as Hex.
156   - } else if (color.match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/)) {
157   - var c = ([parseInt(RegExp.$1, 10), parseInt(RegExp.$2, 10), parseInt(RegExp.$3, 10)]),
158   - pad = function (str) {
159   - if (str.length < 2) {
160   - for (var i = 0, len = 2 - str.length; i < len; i++) {
161   - str = '0' + str;
162   - }
163   - }
164   -
165   - return str;
166   - };
167   -
168   - if (c.length === 3) {
169   - var r = pad(c[0].toString(16)),
170   - g = pad(c[1].toString(16)),
171   - b = pad(c[2].toString(16));
172   -
173   - return '#' + r + g + b;
174   - }
175   -
176   - // Otherwise we wont do anything.
177   - } else {
178   - return false;
179   -
180   - }
181   - },
182   -
183   - /**
184   - * Check whether user clicked on the selector or owner.
185   - **/
186   - checkMouse : function (event, paletteId) {
187   - var selector = activePalette,
188   - selectorParent = $(event.target).parents("#" + selector.attr('id')).length;
189   -
190   - if (event.target === $(selector)[0] || event.target === selectorOwner[0] || selectorParent > 0) {
191   - return;
192   - }
193   -
194   - $.fn.colorPicker.hidePalette();
195   - },
196   -
197   - /**
198   - * Hide the color palette modal.
199   - **/
200   - hidePalette : function () {
201   - $(document).unbind("mousedown", $.fn.colorPicker.checkMouse);
202   -
203   - $('.colorPicker-palette').hide();
204   - },
205   -
206   - /**
207   - * Show the color palette modal.
208   - **/
209   - showPalette : function (palette) {
210   - var hexColor = selectorOwner.prev("input").val();
211   -
212   - palette.css({
213   - top: selectorOwner.offset().top + (selectorOwner.outerHeight()),
214   - left: selectorOwner.offset().left
215   - });
216   -
217   - $("#color_value").val(hexColor);
218   -
219   - palette.show();
220   -
221   - $(document).bind("mousedown", $.fn.colorPicker.checkMouse);
222   - },
223   -
224   - /**
225   - * Toggle visibility of the colorPicker palette.
226   - **/
227   - togglePalette : function (palette, origin) {
228   - // selectorOwner is the clicked .colorPicker-picker.
229   - if (origin) {
230   - selectorOwner = origin;
231   - }
232   -
233   - activePalette = palette;
234   -
235   - if (activePalette.is(':visible')) {
236   - $.fn.colorPicker.hidePalette();
237   -
238   - } else {
239   - $.fn.colorPicker.showPalette(palette);
240   -
241   - }
242   - },
243   -
244   - /**
245   - * Update the input with a newly selected color.
246   - **/
247   - changeColor : function (value) {
248   - selectorOwner.css("background-color", value);
249   - selectorOwner.prev("input").val(value).change();
250   -
251   - $.fn.colorPicker.hidePalette();
252   -
253   - selectorOwner.data('onColorChange').call(selectorOwner, $(selectorOwner).prev("input").attr("id"), value);
254   - },
255   -
256   -
257   - /**
258   - * Preview the input with a newly selected color.
259   - **/
260   - previewColor : function (value) {
261   - selectorOwner.css("background-color", value);
262   - },
263   -
264   - /**
265   - * Bind events to the color palette swatches.
266   - */
267   - bindPalette : function (paletteInput, element, color) {
268   - color = color ? color : $.fn.colorPicker.toHex(element.css("background-color"));
269   -
270   - element.bind({
271   - click : function (ev) {
272   - lastColor = color;
273   -
274   - $.fn.colorPicker.changeColor(color);
275   - },
276   - mouseover : function (ev) {
277   - lastColor = paletteInput.val();
278   -
279   - $(this).css("border-color", "#598FEF");
280   -
281   - paletteInput.val(color);
282   -
283   - $.fn.colorPicker.previewColor(color);
284   - },
285   - mouseout : function (ev) {
286   - $(this).css("border-color", "#000");
287   -
288   - paletteInput.val(selectorOwner.css("background-color"));
289   -
290   - paletteInput.val(lastColor);
291   -
292   - $.fn.colorPicker.previewColor(lastColor);
293   - }
294   - });
295   - }
296   - });
297   -
298   - /**
299   - * Default colorPicker options.
300   - *
301   - * These are publibly available for global modification using a setting such as:
302   - *
303   - * $.fn.colorPicker.defaults.colors = ['151337', '111111']
304   - *
305   - * They can also be applied on a per-bound element basis like so:
306   - *
307   - * $('#element1').colorPicker({pickerDefault: 'efefef', transparency: true});
308   - * $('#element2').colorPicker({pickerDefault: '333333', colors: ['333333', '111111']});
309   - *
310   - **/
311   - $.fn.colorPicker.defaults = {
312   - // colorPicker default selected color.
313   - pickerDefault : "FFFFFF",
314   -
315   - // Default color set.
316   - colors : [
317   - '000000', '993300', '333300', '000080', '333399', '333333', '800000', 'FF6600',
318   - '808000', '008000', '008080', '0000FF', '666699', '808080', 'FF0000', 'FF9900',
319   - '99CC00', '339966', '33CCCC', '3366FF', '800080', '999999', 'FF00FF', 'FFCC00',
320   - 'FFFF00', '00FF00', '00FFFF', '00CCFF', '993366', 'C0C0C0', 'FF99CC', 'FFCC99',
321   - 'FFFF99', 'CCFFFF', '99CCFF', 'FFFFFF'
322   - ],
323   -
324   - // If we want to simply add more colors to the default set, use addColors.
325   - addColors : []
326   - };
327   -
328   -})(jQuery);
plugins/mezuro/public/javascripts/colorPicker/jquery.colorPicker.min.js
... ... @@ -1,26 +0,0 @@
1   -/**
2   - * Really Simple Color Picker in jQuery
3   - *
4   - * Licensed under the MIT (MIT-LICENSE.txt) licenses.
5   - *
6   - * Copyright (c) 2008-2012
7   - * Lakshan Perera (www.laktek.com) & Daniel Lacy (daniellacy.com)
8   - *
9   - * Permission is hereby granted, free of charge, to any person obtaining a copy
10   - * of this software and associated documentation files (the "Software"), to
11   - * deal in the Software without restriction, including without limitation the
12   - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13   - * sell copies of the Software, and to permit persons to whom the Software is
14   - * furnished to do so, subject to the following conditions:
15   - *
16   - * The above copyright notice and this permission notice shall be included in
17   - * all copies or substantial portions of the Software.
18   - *
19   - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20   - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21   - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22   - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23   - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24   - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25   - * IN THE SOFTWARE.
26   - */(function(a){var b,c,d=0,e={control:a('<div class="colorPicker-picker">&nbsp;</div>'),palette:a('<div id="colorPicker_palette" class="colorPicker-palette" />'),swatch:a('<div class="colorPicker-swatch">&nbsp;</div>'),hexLabel:a('<label for="colorPicker_hex">Hex</label>'),hexField:a('<input type="text" id="colorPicker_hex" />')},f="transparent",g;a.fn.colorPicker=function(b){return this.each(function(){var c=a(this),g=a.extend({},a.fn.colorPicker.defaults,b),h=a.fn.colorPicker.toHex(c.val().length>0?c.val():g.pickerDefault),i=e.control.clone(),j=e.palette.clone().attr("id","colorPicker_palette-"+d),k=e.hexLabel.clone(),l=e.hexField.clone(),m=j[0].id,n;a.each(g.colors,function(b){n=e.swatch.clone(),g.colors[b]===f?(n.addClass(f).text("X"),a.fn.colorPicker.bindPalette(l,n,f)):(n.css("background-color","#"+this),a.fn.colorPicker.bindPalette(l,n)),n.appendTo(j)}),k.attr("for","colorPicker_hex-"+d),l.attr({id:"colorPicker_hex-"+d,value:h}),l.bind("keydown",function(b){if(b.keyCode===13){var d=a.fn.colorPicker.toHex(a(this).val());a.fn.colorPicker.changeColor(d?d:c.val())}b.keyCode===27&&a.fn.colorPicker.hidePalette()}),l.bind("keyup",function(b){var d=a.fn.colorPicker.toHex(a(b.target).val());a.fn.colorPicker.previewColor(d?d:c.val())}),a('<div class="colorPicker_hexWrap" />').append(k).appendTo(j),j.find(".colorPicker_hexWrap").append(l),a("body").append(j),j.hide(),i.css("background-color",h),i.bind("click",function(){a.fn.colorPicker.togglePalette(a("#"+m),a(this))}),b&&b.onColorChange?i.data("onColorChange",b.onColorChange):i.data("onColorChange",function(){}),c.after(i),c.bind("change",function(){c.next(".colorPicker-picker").css("background-color",a.fn.colorPicker.toHex(a(this).val()))}),c.val(h).hide(),d++})},a.extend(!0,a.fn.colorPicker,{toHex:function(a){if(a.match(/[0-9A-F]{6}|[0-9A-F]{3}$/i))return a.charAt(0)==="#"?a:"#"+a;if(!a.match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/))return!1;var b=[parseInt(RegExp.$1,10),parseInt(RegExp.$2,10),parseInt(RegExp.$3,10)],c=function(a){if(a.length<2)for(var b=0,c=2-a.length;b<c;b++)a="0"+a;return a};if(b.length===3){var d=c(b[0].toString(16)),e=c(b[1].toString(16)),f=c(b[2].toString(16));return"#"+d+e+f}},checkMouse:function(d,e){var f=c,g=a(d.target).parents("#"+f.attr("id")).length;if(d.target===a(f)[0]||d.target===b[0]||g>0)return;a.fn.colorPicker.hidePalette()},hidePalette:function(){a(document).unbind("mousedown",a.fn.colorPicker.checkMouse),a(".colorPicker-palette").hide()},showPalette:function(c){var d=b.prev("input").val();c.css({top:b.offset().top+b.outerHeight(),left:b.offset().left}),a("#color_value").val(d),c.show(),a(document).bind("mousedown",a.fn.colorPicker.checkMouse)},togglePalette:function(d,e){e&&(b=e),c=d,c.is(":visible")?a.fn.colorPicker.hidePalette():a.fn.colorPicker.showPalette(d)},changeColor:function(c){b.css("background-color",c),b.prev("input").val(c).change(),a.fn.colorPicker.hidePalette(),b.data("onColorChange").call(b,a(b).prev("input").attr("id"),c)},previewColor:function(a){b.css("background-color",a)},bindPalette:function(c,d,e){e=e?e:a.fn.colorPicker.toHex(d.css("background-color")),d.bind({click:function(b){g=e,a.fn.colorPicker.changeColor(e)},mouseover:function(b){g=c.val(),a(this).css("border-color","#598FEF"),c.val(e),a.fn.colorPicker.previewColor(e)},mouseout:function(d){a(this).css("border-color","#000"),c.val(b.css("background-color")),c.val(g),a.fn.colorPicker.previewColor(g)}})}}),a.fn.colorPicker.defaults={pickerDefault:"FFFFFF",colors:["000000","993300","333300","000080","333399","333333","800000","FF6600","808000","008000","008080","0000FF","666699","808080","FF0000","FF9900","99CC00","339966","33CCCC","3366FF","800080","999999","FF00FF","FFCC00","FFFF00","00FF00","00FFFF","00CCFF","993366","C0C0C0","FF99CC","FFCC99","FFFF99","CCFFFF","99CCFF","FFFFFF"],addColors:[]}})(jQuery)
27 0 \ No newline at end of file
plugins/mezuro/public/javascripts/processing.js 0 → 100644
... ... @@ -0,0 +1,133 @@
  1 +var processingTree = false;
  2 +var metricName;
  3 +jQuery(function (){
  4 + jQuery('.source-tree-link').live("click", reloadModule);
  5 + jQuery('[show-metric-history]').live("click", display_metric_history);
  6 + jQuery('[show-grade-history]').live("click", display_grade_history);
  7 + jQuery('#project_date_submit').live("click", reloadProcessingWithDate);
  8 + showLoadingProcess(true);
  9 + showProcessing();
  10 +});
  11 +
  12 +function showProcessing() {
  13 + repository_id = processingData('repository-id');
  14 + callAction('processing', 'state', {repository_id: repository_id}, showProcessingFor);
  15 +}
  16 +
  17 +function display_metric_history() {
  18 + var module_result_id = jQuery(this).attr('data-module-id');
  19 + var formatted_name = jQuery(this).attr('show-metric-history');
  20 + var metric_name = jQuery(this).attr('data-metric-name');
  21 + toggle_mezuro("." + formatted_name);
  22 + metricName = formatted_name;
  23 + callAction('module_result', 'metric_result_history', {metric_name: metric_name, module_result_id: module_result_id}, show_metrics);
  24 + return false;
  25 +}
  26 +
  27 +function display_grade_history() {
  28 + var module_result_id = jQuery(this).attr('data-module-id');
  29 + toggle_mezuro("#historical-grade");
  30 + callAction('module_result', 'module_result_history', {module_result_id: module_result_id}, show_grades);
  31 + return false;
  32 +}
  33 +
  34 +function show_metrics(content) {
  35 + jQuery('#historical-' + metricName).html(content);
  36 +}
  37 +
  38 +function show_grades(content) {
  39 + jQuery('#historical-grade').html(content);
  40 +}
  41 +
  42 +function toggle_mezuro(element){
  43 + jQuery(element).toggle();
  44 + return false;
  45 +}
  46 +
  47 +function reloadModule(){
  48 + var module_result_id = jQuery(this).attr('data-module-id');
  49 + showLoadingProcess(false);
  50 + processingTree = true;
  51 + callAction('module_result', 'module_result', {module_result_id: module_result_id}, showModuleResult);
  52 + return false;
  53 +}
  54 +
  55 +function reloadProcessingWithDate(date){
  56 + reloadProcessing(date + "T00:00:00+00:00");
  57 + return false;
  58 +}
  59 +
  60 +function reloadProcessing(date){
  61 + repository_id = processingData('repository-id');
  62 + showLoadingProcess(true);
  63 +
  64 + callAction('processing', 'processing', {date: date, repository_id: repository_id}, function(content){
  65 + showReadyProcessing(content);
  66 + var module_result_id = jQuery("#module_result_root_id").attr('module_result_root_id');
  67 + callAction('module_result', 'module_result', {module_result_id: module_result_id}, showModuleResult);
  68 + }
  69 + );
  70 +}
  71 +
  72 +function showProcessingFor(state){
  73 + repository_id = processingData('repository-id');
  74 + if (state == 'ERROR') {
  75 + jQuery('#processing-state').html('<div style="color:Red">ERROR</div>');
  76 + callAction('processing', 'processing', {repository_id: repository_id}, showReadyProcessing);
  77 + showModuleResult('');
  78 + }
  79 + else if (state == 'READY') {
  80 + jQuery('#msg-time').html('');
  81 + jQuery('#processing-state').html('<div style="color:Green">READY</div>');
  82 + callAction('processing', 'processing', {repository_id: repository_id}, function(content){
  83 + showReadyProcessing(content);
  84 + var module_result_id = jQuery("#module_result_root_id").attr('module_result_root_id');
  85 + callAction('module_result', 'module_result', {module_result_id: module_result_id}, showModuleResult);
  86 + }
  87 + );
  88 + }
  89 + else if (state.endsWith("ING")) {
  90 + jQuery('#processing-state').html('<div style="color:DarkGoldenRod">'+ state +'</div>');
  91 + jQuery('#msg-time').html("The project analysis may take long. <br/> You'll receive an e-mail when it's ready!");
  92 + showProcessingAfter(20);
  93 + }
  94 +}
  95 +
  96 +function showProcessingAfter(seconds){
  97 + if (seconds > 0){
  98 + setTimeout(function() { showProcessingAfter(seconds - 10);}, 10000);
  99 + } else {
  100 + showProcessing();
  101 + }
  102 +}
  103 +
  104 +function showReadyProcessing(content) {
  105 + jQuery('#processing').html(content);
  106 +}
  107 +
  108 +function showModuleResult(content){
  109 + jQuery('#module-result').html(content);
  110 +}
  111 +
  112 +function callAction(controller, action, params, callback){
  113 + var profile = processingData('profile');
  114 + var content = processingData('content');
  115 + var endpoint = '/profile/' + profile + '/plugin/mezuro/' + controller + '/' + action + '/' + content;
  116 + jQuery.get(endpoint, params, callback);
  117 +}
  118 +
  119 +function processingData(data){
  120 + return jQuery('#processing').attr('data-' + data);
  121 +}
  122 +
  123 +function showLoadingProcess(firstLoad){
  124 + if(firstLoad)
  125 + showReadyProcessing("<img src='/images/loading-small.gif'/>");
  126 + showModuleResult("<img src='/images/loading-small.gif'/>");
  127 +}
  128 +
  129 +function sourceNodeToggle(id){
  130 + var suffixes = ['_hidden', '_plus', '_minus'];
  131 + for (var i in suffixes)
  132 + jQuery('#' + id + suffixes[i]).toggle();
  133 +}
... ...
plugins/mezuro/public/javascripts/validations.js
... ... @@ -40,18 +40,15 @@ function IsNotInfinite(value){
40 40 }
41 41  
42 42 function validate_new_range_configuration(event){
43   - var label = jQuery("#range_label").val();
44 43 var beginning = jQuery("#range_beginning").val();
45 44 var end = jQuery("#range_end").val();
46   - var color = jQuery("#range_color").val();
47   - var grade = jQuery("#range_grade").val();
48 45  
49   - if (is_null(label) || is_null(beginning) || is_null(end) || is_null(color) || is_null(grade))
  46 + if (is_null(beginning) || is_null(end))
50 47 {
51 48 alert("Please fill all fields marked with (*).");
52 49 return false;
53 50 }
54   - if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)) || IsNotNumeric(grade))
  51 + if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)))
55 52 {
56 53 alert("Beginning, End and Grade must be numeric values.");
57 54 return false;
... ...
plugins/mezuro/test/fixtures/base_tool_fixtures.rb
1   -require File.dirname(__FILE__) + '/native_metric_fixtures'
  1 +require File.dirname(__FILE__) + '/metric_fixtures'
2 2  
3 3 class BaseToolFixtures
4 4  
... ... @@ -6,10 +6,14 @@ class BaseToolFixtures
6 6 Kalibro::BaseTool.new base_tool_hash
7 7 end
8 8  
9   - def self.base_tool_hash
10   - {:name => 'Analizo', :supported_metric => [
11   - NativeMetricFixtures.total_cof_hash,
12   - NativeMetricFixtures.amloc_hash]}
  9 + def self.base_tool_hash
  10 + {
  11 + :name => 'Analizo',
  12 + :supported_metric => [
  13 + MetricFixtures.total_cof_hash,
  14 + MetricFixtures.amloc_hash],
  15 + :collector_class_name => "org.analizo.AnalizoMetricCollector"
  16 + }
13 17 end
14 18  
15 19 end
... ...
plugins/mezuro/test/fixtures/compound_metric_fixtures.rb
... ... @@ -1,11 +0,0 @@
1   -class CompoundMetricFixtures
2   -
3   - def self.compound_metric
4   - Kalibro::CompoundMetric.new compound_metric_hash
5   - end
6   -
7   - def self.compound_metric_hash
8   - {:name => 'Structural Complexity', :scope => 'CLASS', :script => 'return 42;', :description => 'Calculate the Structural Complexity of the Code'}
9   - end
10   -
11   -end
plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures.rb
... ... @@ -1,20 +0,0 @@
1   -require File.dirname(__FILE__) + '/error_fixtures'
2   -require File.dirname(__FILE__) + '/compound_metric_fixtures'
3   -
4   -class CompoundMetricWithErrorFixtures
5   -
6   - def self.compound_metric_with_error
7   - Kalibro::CompoundMetricWithError.new compound_metric_with_error_hash
8   - end
9   -
10   - def self.compound_metric_with_error_hash
11   - {:metric => CompoundMetricFixtures.compound_metric_hash, :error => ErrorFixtures.error_hash,
12   - :attributes! => {:metric => {
13   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
14   - 'xsi:type' => 'kalibro:compoundMetricXml' },
15   - :error => {
16   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
17   - 'xsi:type' => 'kalibro:errorXml' }}}
18   - end
19   -
20   -end
plugins/mezuro/test/fixtures/configuration_content_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +class ConfigurationContentFixtures
  2 +
  3 + def self.configuration_content
  4 + MezuroPlugin::ConfigurationContent.new configuration_content_hash
  5 + end
  6 +
  7 + def self.created_configuration_content
  8 + MezuroPlugin::ConfigurationContent.new( {
  9 + :name => 'Sample Configuration',
  10 + :description => 'Kalibro configuration for Java projects.',
  11 + :configuration_id => nil
  12 + } )
  13 + end
  14 +
  15 + def self.configuration_content_hash
  16 + {
  17 + :name => 'Sample Configuration',
  18 + :description => 'Kalibro configuration for Java projects.',
  19 + :configuration_id => "42"
  20 + }
  21 + end
  22 +
  23 +end
... ...
plugins/mezuro/test/fixtures/configuration_fixtures.rb
... ... @@ -6,23 +6,23 @@ class ConfigurationFixtures
6 6 Kalibro::Configuration.new configuration_hash
7 7 end
8 8  
  9 + def self.created_configuration
  10 + Kalibro::Configuration.new({
  11 + :name => 'Created Sample Configuration',
  12 + :description => 'Kalibro configuration for Java projects.'
  13 + })
  14 + end
  15 +
9 16 def self.configuration_hash
10 17 {
  18 + :id => "42",
11 19 :name => 'Sample Configuration',
12   - :description => 'Kalibro configuration for Java projects.',
13   - :metric_configuration => [
14   - MetricConfigurationFixtures.amloc_metric_configuration_hash,
15   - MetricConfigurationFixtures.sc_metric_configuration_hash
16   - ]
  20 + :description => 'Kalibro configuration for Java projects.'
17 21 }
18 22 end
19 23  
20   - def self.configuration_content(clone_configuration)
21   - MezuroPlugin::ConfigurationContent.new({
22   - :name => 'Sample Configuration',
23   - :description => 'Kalibro configuration for Java projects.',
24   - :configuration_to_clone_name => clone_configuration
25   - })
  24 + def self.all
  25 + [configuration]
26 26 end
27 27  
28 28 end
... ...
plugins/mezuro/test/fixtures/date_metric_result_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +require File.dirname(__FILE__) + '/metric_result_fixtures'
  2 +
  3 +class DateMetricResultFixtures
  4 +
  5 + def self.date_metric_result
  6 + Kalibro::DateMetricResult.new date_metric_result_hash
  7 + end
  8 +
  9 + def self.date_metric_result_hash
  10 + {
  11 + :date => '2011-10-20T18:26:43.151+00:00',
  12 + :metric_result => MetricResultFixtures.native_metric_result_hash,
  13 + :attributes! =>
  14 + {
  15 + :metric_result =>
  16 + {
  17 + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
  18 + "xsi:type"=>"kalibro:metricResultXml"
  19 + }
  20 + }
  21 + }
  22 + end
  23 +
  24 + def self.score_history
  25 + result = []
  26 + result << date_metric_result
  27 + newer_date_metric_result = date_metric_result
  28 + newer_date_metric_result.date = '2011-10-25T18:26:43.151+00:00'
  29 + newer_date_metric_result.metric_result.value = 5.0
  30 + result << newer_date_metric_result
  31 + end
  32 +
  33 +end
... ...
plugins/mezuro/test/fixtures/date_module_result_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require File.dirname(__FILE__) + '/module_result_fixtures'
  2 +
  3 +class DateModuleResultFixtures
  4 +
  5 + def self.date_module_result
  6 + Kalibro::DateModuleResult.new date_module_result_hash
  7 + end
  8 +
  9 + def self.date_module_result_hash
  10 + {
  11 + :date => '2011-10-20T18:26:43.151+00:00',
  12 + :module_result => ModuleResultFixtures.module_result_hash,
  13 + :attributes! =>
  14 + {
  15 + :module_result =>
  16 + {
  17 + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
  18 + "xsi:type"=>"kalibro:moduleResultXml"
  19 + }
  20 + }
  21 + }
  22 + end
  23 +
  24 +end
... ...
plugins/mezuro/test/fixtures/error_fixtures.rb
... ... @@ -1,20 +0,0 @@
1   -require File.dirname(__FILE__) + '/stack_trace_element_fixtures'
2   -
3   -class ErrorFixtures
4   -
5   - def self.error
6   - Kalibro::Error.new error_hash
7   - end
8   -
9   - def self.error_hash
10   - {
11   - :error_class => 'java.lang.Exception',
12   - :message => 'Error message from ErrorTest',
13   - :stack_trace_element => [
14   - StackTraceElementFixtures.stack_trace_element_hash('my method 1', 42),
15   - StackTraceElementFixtures.stack_trace_element_hash('my method 2', 84)
16   - ]
17   - }
18   - end
19   -
20   -end
plugins/mezuro/test/fixtures/metric_configuration_fixtures.rb
1   -require File.dirname(__FILE__) + '/compound_metric_fixtures'
2   -require File.dirname(__FILE__) + '/native_metric_fixtures'
3   -require File.dirname(__FILE__) + '/range_fixtures'
  1 +require File.dirname(__FILE__) + '/metric_fixtures'
4 2  
5 3 class MetricConfigurationFixtures
6 4  
7 5 def self.amloc_metric_configuration
8 6 amloc = Kalibro::MetricConfiguration.new amloc_metric_configuration_hash
9   - amloc.configuration_name = "Sample Configuration"
10   - amloc
11   - end
12   -
13   - def self.metric_configuration_without_ranges
14   - amloc = Kalibro::MetricConfiguration.new
15   - {
16   - :metric => NativeMetricFixtures.amloc_hash,
17   - :code => 'amloc',
18   - :weight => 1.0,
19   - :aggregation_form => 'AVERAGE'
20   - }
21   - amloc.configuration_name = "Sample Configuration"
  7 + amloc.configuration_id = "13"
22 8 amloc
23 9 end
24 10  
25 11 def self.sc_metric_configuration
26 12 sc = Kalibro::MetricConfiguration.new sc_metric_configuration_hash
27   - sc.configuration_name = "Sample Configuration"
  13 + sc.configuration_id = "13"
28 14 sc
29 15 end
  16 +
  17 + def self.created_metric_configuration
  18 + Kalibro::MetricConfiguration.new({
  19 + :code => 'amloc',
  20 + :metric => MetricFixtures.amloc_hash,
  21 + :base_tool_name => "Analizo",
  22 + :weight => "1.0",
  23 + :aggregation_form => 'AVERAGE',
  24 + :reading_group_id => "31",
  25 + :configuration_id => "13"
  26 + })
  27 + end
30 28  
31 29 def self.amloc_metric_configuration_hash
32   - {:metric => NativeMetricFixtures.amloc_hash, :code => 'amloc', :weight => 1.0,
  30 + {
  31 + :id => "42",
  32 + :code => 'amloc',
  33 + :metric => MetricFixtures.amloc_hash,
  34 + :base_tool_name => "Analizo",
  35 + :weight => "1.0",
33 36 :aggregation_form => 'AVERAGE',
34   - :range => [RangeFixtures.range_excellent_hash, RangeFixtures.range_bad_hash],
  37 + :reading_group_id => "31",
35 38 :attributes! => {:metric => {
36 39 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
37   - 'xsi:type' => 'kalibro:nativeMetricXml' }}}
  40 + 'xsi:type' => 'kalibro:metricXml' }}
  41 + }
38 42 end
39 43  
40 44 def self.sc_metric_configuration_hash
41   - {:metric => CompoundMetricFixtures.compound_metric_hash, :code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE',
  45 + {
  46 + :id => "42",
  47 + :code => 'sc',
  48 + :metric => MetricFixtures.compound_metric_hash,
  49 + :weight => "1.0",
  50 + :aggregation_form => 'AVERAGE',
  51 + :reading_group_id => "31",
42 52 :attributes! => {:metric => {
43 53 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
44   - 'xsi:type' => 'kalibro:compoundMetricXml' }}}
  54 + 'xsi:type' => 'kalibro:metricXml' }}
  55 + }
45 56 end
46 57  
47 58 end
... ...
plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,62 @@
  1 +require File.dirname(__FILE__) + '/metric_fixtures'
  2 +require File.dirname(__FILE__) + '/range_snapshot_fixtures'
  3 +
  4 +class MetricConfigurationSnapshotFixtures
  5 +
  6 + def self.metric_configuration_snapshot
  7 + Kalibro::MetricConfigurationSnapshot.new metric_configuration_snapshot_hash
  8 + end
  9 +
  10 + def self.metric_configuration_snapshot_hash
  11 + {
  12 + :code => "code",
  13 + :weight => "1.0",
  14 + :aggregation_form => 'AVERAGE',
  15 + :metric => MetricFixtures.amloc_hash,
  16 + :base_tool_name => "Analizo",
  17 + :range => [RangeSnapshotFixtures.range_snapshot_hash],
  18 + :attributes! => {
  19 + :metric => {
  20 + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
  21 + 'xsi:type' => 'kalibro:metricXml' },
  22 + :range => {
  23 + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
  24 + 'xsi:type' => 'kalibro:rangeSnapshotXml' }
  25 + }
  26 + }
  27 + end
  28 +
  29 + def self.metric_configuration_snapshot_with_2_elements
  30 + Kalibro::MetricConfigurationSnapshot.new metric_configuration_snapshot_hash_with_2_elements
  31 + end
  32 +
  33 + def self.metric_configuration_snapshot_hash_with_2_elements
  34 + hash = self.metric_configuration_snapshot_hash
  35 + hash[:range] << RangeSnapshotFixtures.range_snapshot_hash
  36 + hash
  37 + end
  38 +
  39 + def self.compound_metric_configuration_snapshot
  40 + Kalibro::MetricConfigurationSnapshot.new compound_metric_configuration_snapshot_hash
  41 + end
  42 +
  43 + def self.compound_metric_configuration_snapshot_hash
  44 + {
  45 + :code => "code",
  46 + :weight => "1.0",
  47 + :aggregation_form => 'AVERAGE',
  48 + :metric => MetricFixtures.compound_metric,
  49 + :base_tool_name => "Analizo",
  50 + :range => [RangeSnapshotFixtures.range_snapshot_hash],
  51 + :attributes! => {
  52 + :metric => {
  53 + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
  54 + 'xsi:type' => 'kalibro:metricXml' },
  55 + :range => {
  56 + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
  57 + 'xsi:type' => 'kalibro:rangeSnapshotXml' }
  58 + }
  59 + }
  60 + end
  61 +
  62 +end
... ...
plugins/mezuro/test/fixtures/metric_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class MetricFixtures
  2 +
  3 + def self.compound_metric
  4 + Kalibro::Metric.new compound_metric_hash
  5 + end
  6 +
  7 + def self.compound_metric_hash
  8 + {:name => 'Structural Complexity', :compound => "true", :scope => 'CLASS', :script => 'return 42;', :description => 'Calculate the Structural Complexity of the Code'}
  9 + end
  10 +
  11 + def self.total_cof
  12 + Kalibro::Metric.new total_cof_hash
  13 + end
  14 +
  15 + def self.total_cof_hash
  16 + {:name => 'Total Coupling Factor', :compound => "false", :scope => 'APPLICATION', :language => ['JAVA']}
  17 + end
  18 +
  19 + def self.amloc
  20 + Kalibro::Metric.new amloc_hash
  21 + end
  22 +
  23 + def self.amloc_hash
  24 + {:name => 'Average Method LOC', :compound => "false", :scope => 'CLASS', :language => ['JAVA']}
  25 + end
  26 +
  27 +end
... ...
plugins/mezuro/test/fixtures/metric_result_fixtures.rb
1   -require File.dirname(__FILE__) + '/compound_metric_fixtures'
2   -require File.dirname(__FILE__) + '/native_metric_fixtures'
3   -require File.dirname(__FILE__) + '/range_fixtures'
  1 +require File.dirname(__FILE__) + '/metric_configuration_snapshot_fixtures'
  2 +require File.dirname(__FILE__) + '/throwable_fixtures'
4 3  
5 4 class MetricResultFixtures
6 5  
... ... @@ -12,32 +11,42 @@ class MetricResultFixtures
12 11 Kalibro::MetricResult.new compound_metric_result_hash
13 12 end
14 13  
  14 + def self.metric_result_with_error_hash
  15 + {
  16 + :id => "41",
  17 + :configuration => MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash,
  18 + :error => ThrowableFixtures.throwable_hash
  19 + }
  20 + end
  21 +
15 22 def self.native_metric_result_hash
16 23 {
17   - :metric => NativeMetricFixtures.amloc_hash,
18   - :value => 0.0,
19   - :descendent_result => [40.0, 42.0],
20   - :range => RangeFixtures.range_excellent_hash,
21   - :attributes! => {
22   - :metric => {
23   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
24   - 'xsi:type' => 'kalibro:nativeMetricXml' },
25   - :range => {
26   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
27   - 'xsi:type' => 'kalibro:rangeXml' }
  24 + :id => "42",
  25 + :configuration => MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash,
  26 + :value => "0.0",
  27 + :attributes! =>
  28 + {
  29 + :configuration =>
  30 + {
  31 + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
  32 + "xsi:type"=>"kalibro:metricConfigurationSnapshotXml"
  33 + }
28 34 }
29 35 }
30 36 end
31 37  
32 38 def self.compound_metric_result_hash
33 39 {
34   - :metric => CompoundMetricFixtures.compound_metric_hash,
35   - :value => 1.0,
36   - :descendent_result => [2.0, 42.0],
37   - :attributes! => {
38   - :metric => {
39   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
40   - 'xsi:type' => 'kalibro:compoundMetricXml' }
  40 + :id => "43",
  41 + :configuration => MetricConfigurationSnapshotFixtures.compound_metric_configuration_snapshot_hash,
  42 + :value => "1.0",
  43 + :attributes! =>
  44 + {
  45 + :configuration =>
  46 + {
  47 + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
  48 + "xsi:type"=>"kalibro:metricConfigurationSnapshotXml"
  49 + }
41 50 }
42 51 }
43 52 end
... ...
plugins/mezuro/test/fixtures/module_node_fixtures.rb
... ... @@ -1,47 +0,0 @@
1   -require File.dirname(__FILE__) + '/module_fixtures'
2   -
3   -class ModuleNodeFixtures
4   -
5   - def self.module_node
6   - Kalibro::ModuleNode.new module_node_hash
7   - end
8   -
9   - def self.module_node_hash
10   - {
11   - :module => ModuleFixtures.module_hash,:attributes! => {:module => {
12   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
13   - 'xsi:type' => 'kalibro:moduleXml' }},
14   - :child => [{
15   - :module => {
16   - :name => 'org',
17   - :granularity => 'PACKAGE'
18   - },:attributes! => {:module => {
19   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
20   - 'xsi:type' => 'kalibro:moduleXml' }},
21   - :child => [{
22   - :module => {
23   - :name => 'org.Window',
24   - :granularity => 'CLASS'
25   - },:attributes! => {:module => {
26   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
27   - 'xsi:type' => 'kalibro:moduleXml' }}
28   - }]
29   - },{
30   - :module => {
31   - :name => 'Dialog',
32   - :granularity => 'CLASS'
33   - },:attributes! => {:module => {
34   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
35   - 'xsi:type' => 'kalibro:moduleXml' }}
36   - },{
37   - :module => {
38   - :name => 'main',
39   - :granularity => 'CLASS'
40   - },:attributes! => {:module => {
41   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
42   - 'xsi:type' => 'kalibro:moduleXml' }}
43   - }]
44   - }
45   - end
46   -
47   -end
plugins/mezuro/test/fixtures/module_result_fixtures.rb
1 1 require File.dirname(__FILE__) + '/module_fixtures'
2   -require File.dirname(__FILE__) + '/metric_result_fixtures'
3   -require File.dirname(__FILE__) + '/compound_metric_with_error_fixtures'
4 2  
5 3 class ModuleResultFixtures
6 4  
... ... @@ -10,19 +8,37 @@ class ModuleResultFixtures
10 8  
11 9 def self.module_result_hash
12 10 {
  11 + :id => "42",
13 12 :module => ModuleFixtures.module_hash,
14   - :date => '2011-10-20T18:26:43.151+00:00',
15   - :grade => 10.0,
16   - :metric_result => [
17   - MetricResultFixtures.native_metric_result_hash,
18   - MetricResultFixtures.compound_metric_result_hash],
19   - :compound_metric_with_error => [CompoundMetricWithErrorFixtures.compound_metric_with_error_hash],
20   - :attributes! => {
21   - :module => {
22   - 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
23   - 'xsi:type' => 'kalibro:moduleXml' }
  13 + :grade => "10.0",
  14 + :parent_id => "31",
  15 + :attributes! =>
  16 + {
  17 + :module =>
  18 + {
  19 + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
  20 + "xsi:type"=>"kalibro:moduleXml"
  21 + }
24 22 }
25 23 }
26 24 end
27 25  
  26 + def self.parent_module_result_hash
  27 + {
  28 + :id => "31",
  29 + :module => {
  30 + :name => 'Qt-Calculator Parent',
  31 + :granularity => 'APPLICATION'
  32 + },
  33 + :grade => "10.0",
  34 + :attributes! =>
  35 + {
  36 + :module =>
  37 + {
  38 + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance",
  39 + "xsi:type"=>"kalibro:moduleXml"
  40 + }
  41 + }
  42 + }
  43 + end
28 44 end
... ...
plugins/mezuro/test/fixtures/native_metric_fixtures.rb
... ... @@ -1,19 +0,0 @@
1   -class NativeMetricFixtures
2   -
3   - def self.total_cof
4   - Kalibro::NativeMetric.new total_cof_hash
5   - end
6   -
7   - def self.total_cof_hash
8   - {:name => 'Total Coupling Factor', :scope => 'APPLICATION', :origin => 'Analizo', :language => ['JAVA']}
9   - end
10   -
11   - def self.amloc
12   - Kalibro::NativeMetric.new amloc_hash
13   - end
14   -
15   - def self.amloc_hash
16   - {:name => 'Average Method LOC', :scope => 'CLASS', :origin => 'Analizo', :language => ['JAVA']}
17   - end
18   -
19   -end
plugins/mezuro/test/fixtures/process_time_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class ProcessTimeFixtures
  2 +
  3 + def self.process_time
  4 + Kalibro::ProcessTime.new process_time_hash
  5 + end
  6 +
  7 + def self.process_time_hash
  8 + {:state => "Ready", :time => "1"}
  9 + end
  10 +
  11 +end
... ...
plugins/mezuro/test/fixtures/processing_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +require File.dirname(__FILE__) + '/process_time_fixtures'
  2 +require File.dirname(__FILE__) + '/throwable_fixtures'
  3 +
  4 +class ProcessingFixtures
  5 +
  6 + def self.processing
  7 + Kalibro::Processing.new processing_hash
  8 + end
  9 +
  10 + def self.processing_hash
  11 + {
  12 + :id => "31",
  13 + :date => '2011-10-20T18:26:43.151+00:00',
  14 + :state => 'READY',
  15 + :process_time => [ProcessTimeFixtures.process_time_hash],
  16 + :results_root_id => "13"
  17 + }
  18 + end
  19 +
  20 + def self.processing_with_error_hash
  21 + {
  22 + :id => "31",
  23 + :date => '2011-10-20T18:26:43.151+00:00',
  24 + :state => 'ERROR',
  25 + :process_time => [ProcessTimeFixtures.process_time_hash],
  26 + :error => ThrowableFixtures.throwable_hash
  27 + }
  28 + end
  29 +
  30 +end
... ...
plugins/mezuro/test/fixtures/project_content_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class ProjectContentFixtures
  2 +
  3 + def self.project_content
  4 + content = MezuroPlugin::ProjectContent.new
  5 + content.project_id = 42
  6 + content
  7 + end
  8 +
  9 +end
... ...
plugins/mezuro/test/fixtures/project_fixtures.rb
... ... @@ -6,35 +6,15 @@ class ProjectFixtures
6 6 Kalibro::Project.new project_hash
7 7 end
8 8  
  9 + def self.created_project
  10 + Kalibro::Project.new :name => 'Qt-Calculator', :description => 'Calculator for Qt'
  11 + end
  12 +
9 13 def self.project_hash
10 14 {
  15 + :id => "42",
11 16 :name => 'Qt-Calculator',
12   - :license => 'GPL',
13   - :description => 'Calculator for Qt',
14   - :repository => RepositoryFixtures.repository_hash,
15   - :configuration_name => 'Kalibro for Java',
16   - :state => 'READY',
17   - :attributes! =>
18   - {
19   - :repository=>
20   - {
21   - "xsi:type"=>"kalibro:repositoryXml",
22   - "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance"
23   - }
24   - }
  17 + :description => 'Calculator for Qt'
25 18 }
26 19 end
27   -
28   - def self.project_content
29   - content = MezuroPlugin::ProjectContent.new
30   - content.name = 'Qt-Calculator'
31   - content.project_license = 'GPL'
32   - content.description = 'Calculator for Qt'
33   - content.repository_type = RepositoryFixtures.repository_hash[:type]
34   - content.repository_url = RepositoryFixtures.repository_hash[:address]
35   - content.configuration_name = 'Kalibro for Java'
36   - content.periodicity_in_days = 1
37   - content
38   - end
39   -
40 20 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
plugins/mezuro/test/fixtures/range_fixtures.rb
1 1 class RangeFixtures
2 2  
3   - Infinity = 1.0/0.0
4   -
5   - def self.range_excellent
6   - Kalibro::Range.new range_excellent_hash
  3 + def self.range
  4 + Kalibro::Range.new range_hash
7 5 end
8 6  
9   - def self.range_bad
10   - Kalibro::Range.new range_bad_hash
  7 + def self.created_range
  8 + Kalibro::Range.new created_range_hash
11 9 end
12   -
13   - def self.range_excellent_hash
14   - {:beginning => 0.0, :end => 7.0, :label => 'Excellent', :grade => 10.0, :color => 'ff00ff00'}
  10 +
  11 + def self.created_range_hash
  12 + {:beginning => "19.5", :end => "INF", :reading_id => "1", :comments => "Test range 1"}
15 13 end
16 14  
17   - def self.range_bad_hash
18   - {:beginning => 19.5, :end => "INF", :label => 'Bad',:grade => 0.0, :color => 'ffff0000'}
  15 + def self.range_hash
  16 + {:id => "1", :beginning => "19.5", :end => "INF", :reading_id => "1", :comments => "Test range 1"}
19 17 end
20 18  
21 19 end
... ...
plugins/mezuro/test/fixtures/range_snapshot_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +class RangeSnapshotFixtures
  2 +
  3 + def self.range_snapshot
  4 + Kalibro::RangeSnapshot.new range_snapshot_hash
  5 + end
  6 +
  7 + def self.range_snapshot_with_infinite_range
  8 + Kalibro::RangeSnapshot.new range_snapshot_with_infinite_range_hash
  9 + end
  10 +
  11 + def self.range_snapshot_hash
  12 + { :beginning => "1.1", :end => "5.1", :label => "snapshot", :grade => "10.1", :color => "FF2284", :comments => "comment" }
  13 + end
  14 +
  15 + def self.range_snapshot_with_infinite_range_hash
  16 + { :beginning => "-INF", :end => "INF", :label => "snapshot", :grade => "10.1", :color => "FF2284", :comments => "comment" }
  17 + end
  18 +
  19 +end
... ...
plugins/mezuro/test/fixtures/reading_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class ReadingFixtures
  2 +
  3 + def self.reading
  4 + Kalibro::Reading.new reading_hash
  5 + end
  6 +
  7 + def self.created_reading # A created object has no id before being sent to kalibro
  8 + Kalibro::Reading.new :label => "Reading Test Label", :grade => "10.5", :color => "AABBCC"
  9 + end
  10 +
  11 + def self.reading_hash
  12 + {:id => "42", :label => "Reading Test Label", :grade => "10.5", :color => "AABBCC" }
  13 + end
  14 +
  15 +end
  16 +
... ...
plugins/mezuro/test/fixtures/reading_group_content_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class ReadingGroupContentFixtures
  2 +
  3 + def self.reading_group_content
  4 + content = MezuroPlugin::ReadingGroupContent.new
  5 + content.reading_group_id = 42
  6 + content
  7 + end
  8 +
  9 +end
... ...
plugins/mezuro/test/fixtures/reading_group_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +class ReadingGroupFixtures
  2 +
  3 + def self.reading_group
  4 + Kalibro::ReadingGroup.new reading_group_hash
  5 + end
  6 +
  7 + def self.created_reading_group # A created object has no id before being sent to kalibro
  8 + Kalibro::ReadingGroup.new :name => "Reading Group Test", :description => "Reading group in the fixtures"
  9 + end
  10 +
  11 + def self.reading_group_hash
  12 + {:id => "42", :name => "Reading Group Test", :description => "Reading group in the fixtures"}
  13 + end
  14 +
  15 +end
... ...
plugins/mezuro/test/fixtures/repository_fixtures.rb
... ... @@ -4,8 +4,24 @@ class RepositoryFixtures
4 4 Kalibro::Repository.new repository_hash
5 5 end
6 6  
  7 + def self.created_repository
  8 + Kalibro::Repository.new({
  9 + :name => "test created repository",
  10 + :description => "test description",
  11 + :license => "GPL",
  12 + :process_period => "1",
  13 + :type => 'SUBVERSION',
  14 + :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator',
  15 + :configuration_id => "31"
  16 + })
  17 + end
  18 +
7 19 def self.repository_hash
8   - {:type => 'SUBVERSION', :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'}
  20 + {:id => "42", :name => "test repository", :description => "test description", :license => "GPL", :process_period => "1", :type => 'SUBVERSION', :address => "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator", :configuration_id => "31"}
  21 + end
  22 +
  23 + def self.types
  24 + ["SUBVERSION", "GIT"]
9 25 end
10 26  
11 27 end
... ...
plugins/mezuro/test/fixtures/stack_trace_element_fixtures.rb
1 1 class StackTraceElementFixtures
2 2  
3   - def self.stack_trace_element(method_name = 'my method name', line_number = 42)
4   - Kalibro::StackTraceElement.new stack_trace_element_hash(method_name, line_number)
  3 + def self.stack_trace_element
  4 + Kalibro::StackTraceElement.new stack_trace_element_hash
5 5 end
6 6  
7   - def self.stack_trace_element_hash(method_name = 'my method name', line_number = 42)
  7 + def self.stack_trace_element_hash
8 8 {
9 9 :declaring_class => 'my.declaring.Class',
10   - :method_name => method_name,
  10 + :method_name => 'my method name',
11 11 :file_name => 'MyFile.java',
12   - :line_number => line_number
  12 + :line_number => '42'
13 13 }
14 14 end
15 15  
... ...
plugins/mezuro/test/fixtures/throwable_fixtures.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +require File.dirname(__FILE__) + '/stack_trace_element_fixtures'
  2 +
  3 +class ThrowableFixtures
  4 +
  5 + def self.throwable
  6 + Kalibro::Throwable.new throwable_hash
  7 + end
  8 +
  9 + def self.throwable_hash
  10 + {
  11 + :target_string => 'Target String',
  12 + :message => 'Throwable message from ThrowableTest',
  13 + :stack_trace_element => [
  14 + StackTraceElementFixtures.stack_trace_element_hash, StackTraceElementFixtures.stack_trace_element_hash
  15 + ]
  16 + }
  17 + end
  18 +
  19 +end
... ...
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
... ... @@ -1,56 +0,0 @@
1   -require 'test_helper'
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
5   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures"
6   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures"
7   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
8   -
9   -class MezuroPluginMyprofileControllerTest < ActionController::TestCase
10   -
11   - def setup
12   - @controller = MezuroPluginMyprofileController.new
13   - @request = ActionController::TestRequest.new
14   - @response = ActionController::TestResponse.new
15   - @profile = fast_create(Community)
16   -
17   - @base_tool = BaseToolFixtures.base_tool
18   - @base_tool_hash = BaseToolFixtures.base_tool_hash
19   - @metric = NativeMetricFixtures.amloc
20   - @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration
21   - @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash
22   - @compound_metric_configuration = MetricConfigurationFixtures.sc_metric_configuration
23   - @compound_metric_configuration_hash = MetricConfigurationFixtures.sc_metric_configuration_hash
24   - @configuration = ConfigurationFixtures.configuration
25   - @configuration_hash = ConfigurationFixtures.configuration_hash
26   -
27   - Kalibro::Configuration.expects(:all_names).returns([])
28   - @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name)
29   - @content.expects(:send_kalibro_configuration_to_service).returns(nil)
30   - @content.stubs(:solr_save)
31   - @content.save
32   -
33   - @native_hash = @metric_configuration.to_hash.merge({:configuration_name => @metric_configuration.configuration_name})
34   - @native_hash.delete :attributes!
35   - @compound_hash = @compound_metric_configuration.to_hash.merge({:configuration_name => @compound_metric_configuration.configuration_name})
36   - @compound_hash.delete :attributes!
37   - end
38   -
39   - should 'test choose base tool' do
40   - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name})
41   - get :choose_base_tool, :profile => @profile.identifier, :id => @content.id
42   - assert_equal [@base_tool.name], assigns(:base_tools)
43   - assert_equal @content, assigns(:configuration_content)
44   - assert_response 200
45   - end
46   -
47   - should 'test choose metric' do
48   - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash})
49   - get :choose_metric, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name
50   - assert_equal @content, assigns(:configuration_content)
51   - assert_equal @base_tool.name, assigns(:base_tool)
52   - assert_equal @base_tool.supported_metric[0].name, assigns(:supported_metrics)[0].name
53   - assert_response 200
54   - end
55   -
56   -end
plugins/mezuro/test/functional/myprofile/mezuro_plugin_base_tool_controller_test.rb
... ... @@ -1,34 +0,0 @@
1   -require 'test_helper'
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
5   -
6   -class MezuroPluginBaseToolControllerTest < ActionController::TestCase
7   -
8   - def setup
9   - @controller = MezuroPluginBaseToolController.new
10   - @request = ActionController::TestRequest.new
11   - @response = ActionController::TestResponse.new
12   - @profile = fast_create(Community)
13   -
14   - @base_tool = BaseToolFixtures.base_tool
15   - @base_tool_hash = BaseToolFixtures.base_tool_hash
16   - @configuration = ConfigurationFixtures.configuration
17   -
18   - Kalibro::Configuration.expects(:all_names).returns([])
19   - @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name)
20   - @content.expects(:send_kalibro_configuration_to_service).returns(nil)
21   - @content.stubs(:solr_save)
22   - @content.save
23   - end
24   -
25   - should 'test choose metric' do
26   - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name})
27   - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash})
28   - get :choose_metric, :profile => @profile.identifier, :id => @content.id
29   - assert_equal @base_tool.name, assigns(:base_tools).first.name
30   - assert_equal @content, assigns(:configuration_content)
31   - assert_response 200
32   - end
33   -
34   -end
plugins/mezuro/test/functional/myprofile/mezuro_plugin_metric_configuration_controller_test.rb
1 1 require 'test_helper'
2 2  
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_fixtures"
5 5 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures"
6 6 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
  7 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_group_fixtures"
  8 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures"
  9 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_fixtures"
7 10  
8 11 class MezuroPluginMetricConfigurationControllerTest < ActionController::TestCase
9 12  
... ... @@ -11,131 +14,111 @@ class MezuroPluginMetricConfigurationControllerTest &lt; ActionController::TestCase
11 14 @controller = MezuroPluginMetricConfigurationController.new
12 15 @request = ActionController::TestRequest.new
13 16 @response = ActionController::TestResponse.new
14   - @profile = fast_create(Community)
  17 + @profile = fast_create(Profile)
  18 +
  19 + @configuration = ConfigurationFixtures.configuration
  20 + @created_configuration = ConfigurationFixtures.created_configuration
  21 + @configuration_hash = ConfigurationFixtures.configuration_hash
  22 +
  23 + @configuration_content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name, :configuration_id => 42)
  24 + @configuration_content.expects(:send_configuration_to_service).returns(nil)
  25 + @configuration_content.expects(:validate_configuration_name).returns(true)
  26 + @configuration_content.stubs(:solr_save)
  27 + @configuration_content.save
15 28  
16 29 @base_tool = BaseToolFixtures.base_tool
17 30 @base_tool_hash = BaseToolFixtures.base_tool_hash
18   - @metric = NativeMetricFixtures.amloc
19   - @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration
20   - @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash
  31 +
  32 + @metric = MetricFixtures.amloc
  33 +
  34 + @reading_group = ReadingGroupFixtures.reading_group
  35 + @range = RangeFixtures.range
  36 + @reading = ReadingFixtures.reading
  37 +
  38 + @native_metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration
  39 + @native_metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash
  40 + @created_metric_configuration = MetricConfigurationFixtures.created_metric_configuration
21 41 @compound_metric_configuration = MetricConfigurationFixtures.sc_metric_configuration
22 42 @compound_metric_configuration_hash = MetricConfigurationFixtures.sc_metric_configuration_hash
23   - @configuration = ConfigurationFixtures.configuration
24   - @configuration_hash = ConfigurationFixtures.configuration_hash
  43 + end
25 44  
26   - Kalibro::Configuration.expects(:all_names).returns([])
27   - @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name)
28   - @content.expects(:send_kalibro_configuration_to_service).returns(nil)
29   - @content.stubs(:solr_save)
30   - @content.save
31   -
32   - @native_hash = @metric_configuration.to_hash.merge({:configuration_name => @metric_configuration.configuration_name})
33   - @native_hash.delete :attributes!
34   - @compound_hash = @compound_metric_configuration.to_hash.merge({:configuration_name => @compound_metric_configuration.configuration_name})
35   - @compound_hash.delete :attributes!
36   -
  45 + should 'choose metric' do
  46 + Kalibro::BaseTool.expects(:all).returns([@base_tool])
  47 + get :choose_metric, :profile => @profile.identifier, :id => @configuration_content.id
  48 + assert_equal @configuration_content, assigns(:configuration_content)
  49 + assert_equal [@base_tool], assigns(:base_tools)
  50 + assert_response :success
37 51 end
38   -
39   - should 'test new metric configuration' do
40   - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash})
41   - get :new_metric_configuration, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name, :metric_name => @metric.name
42   - assert_equal @content, assigns(:configuration_content)
  52 +
  53 + should 'initialize native' do
  54 + Kalibro::BaseTool.expects(:find_by_name).with(@base_tool.name).returns(@base_tool)
  55 + Kalibro::ReadingGroup.expects(:all).returns([@reading_group])
  56 + get :new_native, :profile => @profile.identifier, :id => @configuration_content.id, :base_tool_name => @base_tool.name, :metric_name => @metric.name
  57 + assert_equal @configuration_content, assigns(:configuration_content)
43 58 assert_equal @metric.name, assigns(:metric).name
44   - assert_response 200
  59 + assert_equal @base_tool.name, assigns(:metric_configuration).base_tool_name
  60 + assert_equal [[@reading_group.name,@reading_group.id]], assigns(:reading_group_names_and_ids)
  61 + assert_response :success
45 62 end
46   -
47   -
48   - should 'test new compound metric configuration' do
49   - Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, {
50   - :configuration_name => @content.name}).returns({:configuration => @configuration_hash})
51   - get :new_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id
52   - assert_equal @content, assigns(:configuration_content)
53   - assert_equal @configuration.metric_configuration[0].code, assigns(:metric_configurations)[0].code
54   - assert_response 200
  63 +
  64 + should 'edit native' do
  65 + Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@native_metric_configuration])
  66 + Kalibro::ReadingGroup.expects(:all).returns([@reading_group])
  67 + Kalibro::Range.expects(:ranges_of).with(@native_metric_configuration.id).returns([@range])
  68 + Kalibro::Reading.expects(:find).with(@range.reading_id).returns(@reading)
  69 + get :edit_native, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration_id => @native_metric_configuration.id
  70 + assert_equal @configuration_content, assigns(:configuration_content)
  71 + assert_equal @native_metric_configuration.code, assigns(:metric_configuration).code
  72 + assert_equal @native_metric_configuration.metric.name, assigns(:metric).name
  73 + assert_equal [[@reading_group.name,@reading_group.id]], assigns(:reading_group_names_and_ids)
  74 + assert_equal [@range], assigns(:ranges)
  75 + assert_response :success
55 76 end
56 77  
57   - should 'test edit metric configuration' do
58   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
59   - :configuration_name => @content.name,
60   - :metric_name => @metric_configuration.metric.name}).returns({:metric_configuration => @metric_configuration_hash})
61   - get :edit_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name
62   - assert_equal @content, assigns(:configuration_content)
63   - assert_equal @metric_configuration.code, assigns(:metric_configuration).code
64   - assert_equal @metric_configuration.metric.name, assigns(:metric).name
65   - assert_response 200
  78 + should 'initialize compound' do
  79 + Kalibro::ReadingGroup.expects(:all).returns([@reading_group])
  80 + Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration_content.configuration_id).returns([@compound_metric_configuration])
  81 + get :new_compound, :profile => @profile.identifier, :id => @configuration_content.id
  82 + assert_equal @configuration_content, assigns(:configuration_content)
  83 + assert_equal @compound_metric_configuration.code, assigns(:metric_configurations).first.code
  84 + assert_equal [[@reading_group.name,@reading_group.id]], assigns(:reading_group_names_and_ids)
  85 + assert_response :success
66 86 end
67   -
68   - should 'test edit compound metric configuration' do
69   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
70   - :configuration_name => @content.name,
71   - :metric_name => @compound_metric_configuration.metric.name}).returns({:metric_configuration => @compound_metric_configuration_hash})
72   - Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, {:configuration_name => @content.name}).returns({:configuration => @configuration_hash})
73   - get :edit_compound_metric_configuration,
74   - :profile => @profile.identifier,
75   - :id => @content.id,
76   - :metric_name => @compound_metric_configuration.metric.name
77   - assert_equal @content, assigns(:configuration_content)
  87 +
  88 + should 'edit compound' do
  89 + Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@compound_metric_configuration])
  90 + Kalibro::ReadingGroup.expects(:all).returns([@reading_group])
  91 + Kalibro::Range.expects(:ranges_of).with(@compound_metric_configuration.id).returns([@range])
  92 + Kalibro::Reading.expects(:find).with(@range.reading_id).returns(@reading)
  93 + get :edit_compound, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration_id => @compound_metric_configuration.id
  94 + assert_equal @configuration_content, assigns(:configuration_content)
78 95 assert_equal @compound_metric_configuration.code, assigns(:metric_configuration).code
79 96 assert_equal @compound_metric_configuration.metric.name, assigns(:metric).name
80   - assert_equal @configuration.metric_configuration[0].code, assigns(:metric_configurations)[0].code
81   - assert_response 200
82   - end
83   -
84   - should 'test create native metric configuration' do
85   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {
86   - :metric_configuration => @metric_configuration.to_hash,
87   - :configuration_name => @metric_configuration.configuration_name})
88   - get :create_metric_configuration,
89   - :profile => @profile.identifier,
90   - :id => @content.id,
91   - :metric_configuration => @native_hash
92   - assert_response 302
93   - end
94   -
95   - should 'test compound metric creation' do
96   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {
97   - :metric_configuration => @compound_metric_configuration.to_hash,
98   - :configuration_name => @compound_metric_configuration.configuration_name})
99   - get :create_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id,
100   - :metric_configuration => @compound_hash
101   - assert_response 302
  97 + assert_equal [@compound_metric_configuration], assigns(:metric_configurations)
  98 + assert_equal [[@reading_group.name,@reading_group.id]], assigns(:reading_group_names_and_ids)
  99 + assert_equal [@range], assigns(:ranges)
  100 + assert_response :success
102 101 end
103 102  
104   - should 'test update native metric configuration' do
105   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
106   - :configuration_name => @content.name,
107   - :metric_name => @metric_configuration.metric.name}).returns({:metric_configuration => @metric_configuration_hash})
108   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {
109   - :metric_configuration => @metric_configuration.to_hash,
110   - :configuration_name => @metric_configuration.configuration_name})
111   - get :update_metric_configuration, :profile => @profile.identifier, :id => @content.id,
112   - :metric_configuration => @native_hash
113   - assert_equal @content, assigns(:configuration_content)
114   - assert_response 302
  103 + should 'create' do
  104 + Kalibro::MetricConfiguration.expects(:create).returns(@compound_metric_configuration) #FIXME need .with(some_hash), should it mock the request?.
  105 + get :create, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration => @compound_metric_configuration_hash
  106 + assert_response :redirect
115 107 end
116 108  
117   - should 'test update compound metric configuration' do
118   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
119   - :configuration_name => @content.name,
120   - :metric_name => @compound_metric_configuration.metric.name}).returns({:metric_configuration => @compound_metric_configuration_hash})
121   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {
122   - :metric_configuration => @compound_metric_configuration.to_hash,
123   - :configuration_name => @compound_metric_configuration.configuration_name})
124   - get :update_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id,
125   - :metric_configuration => @compound_hash
126   - assert_equal @content, assigns(:configuration_content)
127   - assert_response 302
  109 + should 'update' do
  110 + Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration_content.configuration_id).returns([@native_metric_configuration])
  111 + @native_metric_configuration.expects(:update_attributes).returns(true) #FIXME need .with(some_hash), should it mock the request?.
  112 + get :update, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration => @native_metric_configuration_hash
  113 + assert_equal @configuration_content, assigns(:configuration_content)
  114 + assert_response :redirect
128 115 end
129 116  
130   - should 'test remove metric configuration' do
131   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
132   - :configuration_name => @content.name,
133   - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash})
134   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :remove_metric_configuration, {
135   - :metric_name => @metric.name,
136   - :configuration_name => @metric_configuration.configuration_name})
137   - get :remove_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name
138   - assert_response 302
  117 + should 'remove' do
  118 + Kalibro::MetricConfiguration.expects(:new).with({:id => @native_metric_configuration.id}).returns(@native_metric_configuration)
  119 + @native_metric_configuration.expects(:destroy).returns()
  120 + get :remove, :profile => @profile.identifier, :id => @configuration_content.id, :metric_configuration_id => @native_metric_configuration.id
  121 + assert_response :redirect
139 122 end
140 123  
141 124 end
... ...
plugins/mezuro/test/functional/myprofile/mezuro_plugin_range_controller_test.rb
1 1 require 'test_helper'
2 2  
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures"
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_fixtures"
4 4 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures"
5 5 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
6 6 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures"
  7 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_fixtures"
7 8  
8 9 class MezuroPluginRangeControllerTest < ActionController::TestCase
9 10  
... ... @@ -11,87 +12,73 @@ class MezuroPluginRangeControllerTest &lt; ActionController::TestCase
11 12 @controller = MezuroPluginRangeController.new
12 13 @request = ActionController::TestRequest.new
13 14 @response = ActionController::TestResponse.new
14   - @profile = fast_create(Community)
  15 + @profile = fast_create(Profile)
15 16  
16   - @metric = NativeMetricFixtures.amloc
17 17 @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration
18 18 @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash
19 19 @configuration = ConfigurationFixtures.configuration
20 20  
21   - Kalibro::Configuration.expects(:all_names).returns([])
22   - @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name)
23   - @content.expects(:send_kalibro_configuration_to_service).returns(nil)
  21 + @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name, :configuration_id => 42)
  22 + @content.expects(:send_configuration_to_service).returns(nil)
  23 + @content.expects(:validate_configuration_name).returns(true)
24 24 @content.stubs(:solr_save)
25 25 @content.save
26 26  
27   - @range = RangeFixtures.range_excellent
28   - @range_hash = RangeFixtures.range_excellent_hash
  27 + @created_range = RangeFixtures.created_range
  28 + @range = RangeFixtures.range
  29 + @created_range_hash = RangeFixtures.created_range_hash
  30 + @range_hash = RangeFixtures.range_hash
  31 +
  32 + @reading = ReadingFixtures.reading
29 33 end
30 34  
31   - should 'test new range' do
32   - get :new_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name
33   - assert_equal @content.id.to_s, assigns(:content_id)
34   - assert_equal @metric.name, assigns(:metric_name)
35   - assert_response 200
  35 + should 'set correct attributes to create a new range' do
  36 + Kalibro::Reading.expects(:readings_of).with(@metric_configuration.reading_group_id).returns([@reading])
  37 + get :new, :profile => @profile.identifier, :id => @content.id, :metric_configuration_id => @metric_configuration.id, :reading_group_id => @metric_configuration.reading_group_id, :compound => @metric_configuration.metric.compound
  38 + assert_equal @content.id, assigns(:content_id)
  39 + assert_equal @metric_configuration.id, assigns(:metric_configuration_id)
  40 + assert_equal [[@reading.label,@reading.id]], assigns(:reading_labels_and_ids)
  41 + assert_equal @metric_configuration.reading_group_id, assigns(:reading_group_id)
  42 + assert_equal @metric_configuration.metric.compound, assigns(:compound)
  43 + assert_response :success
36 44 end
37 45  
38   - should 'test edit range' do
39   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
40   - :configuration_name => @content.name,
41   - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash})
42   - get :edit_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name, :beginning_id => @range.beginning
43   - assert_equal @content.id.to_s, assigns(:content_id)
44   - assert_equal @metric.name, assigns(:metric_name)
45   - assert_equal @range.beginning, assigns(:beginning_id)
46   - assert_equal @range.end, assigns(:range).end
47   - assert_response 200
  46 + should 'set correct attributes to edit a range' do
  47 + Kalibro::Reading.expects(:readings_of).with(@metric_configuration.reading_group_id).returns([@reading])
  48 + Kalibro::Range.expects(:ranges_of).with(@metric_configuration.id).returns([@range])
  49 + get :edit, :profile => @profile.identifier, :id => @content.id, :metric_configuration_id => @metric_configuration.id, :range_id => @range.id, :reading_group_id => @metric_configuration.reading_group_id
  50 + assert_equal @content.id, assigns(:content_id)
  51 + assert_equal @metric_configuration.id, assigns(:metric_configuration_id)
  52 + assert_equal [[@reading.label,@reading.id]], assigns(:reading_labels_and_ids)
  53 + assert_equal @range, assigns(:range)
  54 + assert_response :success
48 55 end
49 56  
50 57 should 'test create instance range' do
51   - metric_configuration = @metric_configuration
52   - metric_configuration.add_range(@range)
53   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
54   - :configuration_name => @content.name,
55   - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash})
56   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {
57   - :metric_configuration => metric_configuration.to_hash,
58   - :configuration_name => metric_configuration.configuration_name})
59   - get :create_range, :profile => @profile.identifier, :range => @range_hash, :id => @content.id, :metric_name => @metric.name
60   - assert_equal @content, assigns(:configuration_content)
61   - assert_equal @range.end, assigns(:range).end
62   - assert_response 200
  58 + Kalibro::Range.expects(:request).with(:save_range, {
  59 + :metric_configuration_id => @metric_configuration.id,
  60 + :range => @created_range.to_hash}).returns(:range_id => @range.id)
  61 + Kalibro::Reading.expects(:find).with(@created_range.reading_id).returns(@reading)
  62 + get :create, :profile => @profile.identifier, :range => @created_range_hash, :metric_configuration_id => @metric_configuration.id, :reading_group_id => @metric_configuration.reading_group_id, :compound => @metric_configuration.metric.compound
  63 + assert_equal @range.id, assigns(:range).id
  64 + assert_equal @metric_configuration.reading_group_id, assigns(:reading_group_id)
  65 + assert_equal @metric_configuration.metric.compound, assigns(:compound)
  66 + assert_response :success
63 67 end
64 68  
65 69 should 'test update range' do
66   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
67   - :configuration_name => @content.name,
68   - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash})
69   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {
70   - :metric_configuration => @metric_configuration.to_hash,
71   - :configuration_name => @metric_configuration.configuration_name})
72   - get :update_range,
73   - :profile => @profile.identifier,
74   - :range => @range_hash,
75   - :id => @content.id,
76   - :metric_name => @metric.name,
77   - :beginning_id => @range.beginning
78   - assert_response 200
  70 + Kalibro::Range.expects(:request).with(:save_range, {
  71 + :metric_configuration_id => @metric_configuration.id,
  72 + :range => @range.to_hash}).returns(:range_id => @range.id)
  73 + get :update, :profile => @profile.identifier, :range => @range_hash, :metric_configuration_id => @metric_configuration.id
  74 + assert_equal @range.id, assigns(:range).id
  75 + assert_response :success
79 76 end
80 77  
81   - should 'test remove range' do
82   - metric_configuration = @metric_configuration
83   - metric_configuration.ranges.delete_if { |range| range.beginning == @range.beginning.to_f }
84   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, {
85   - :configuration_name => @content.name,
86   - :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash})
87   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {
88   - :metric_configuration => metric_configuration.to_hash,
89   - :configuration_name => metric_configuration.configuration_name})
90   - get :remove_range,
91   - :profile => @profile.identifier,
92   - :id => @content.id,
93   - :metric_name => @metric.name,
94   - :beginning_id => @range.beginning
95   - assert_response 302
  78 + should 'test remove range in native metric configuration' do
  79 + Kalibro::Range.expects(:new).with({:id => @range.id}).returns(@range)
  80 + @range.expects(:destroy).with().returns()
  81 + get :remove, :profile => @profile.identifier, :id => @content.id, :metric_configuration_id => @metric_configuration.id, :range_id => @range.id, :compound => false
  82 + assert_response :redirect
96 83 end
97 84 end
... ...
plugins/mezuro/test/functional/myprofile/mezuro_plugin_reading_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,74 @@
  1 +require 'test_helper'
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_group_content_fixtures"
  5 +
  6 +class MezuroPluginReadingControllerTest < ActionController::TestCase
  7 +
  8 + def setup
  9 + @controller = MezuroPluginReadingController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + @profile = fast_create(Profile)
  13 +
  14 + @reading = ReadingFixtures.reading
  15 + @created_reading = ReadingFixtures.created_reading
  16 + @reading_hash = ReadingFixtures.hash
  17 + @content = MezuroPlugin::ReadingGroupContent.new(:profile => @profile, :name => name)
  18 + @content.expects(:send_reading_group_to_service).returns(nil)
  19 + @content.stubs(:solr_save)
  20 + @content.save
  21 + end
  22 +
  23 + should 'set variables to create a new reading' do
  24 + get :new, :profile => @profile.identifier, :id => @content.id
  25 + assert_equal @content.id, assigns(:reading_group_content).id
  26 + assert_response :success
  27 + end
  28 +
  29 + should 'create a reading' do
  30 + Kalibro::Reading.expects(:new).with(@reading_hash.to_s).returns(@created_reading)
  31 + @created_reading.expects(:save).with(@content.reading_group_id).returns(true)
  32 + get :save, :profile => @profile.identifier, :id => @content.id, :reading => @reading_hash
  33 + assert @created_reading.errors.empty?
  34 + assert_response :redirect
  35 + end
  36 +
  37 + should 'put an Exception in reading when an error occurs in create action' do
  38 + @created_reading.errors = [Exception.new]
  39 + Kalibro::Reading.expects(:new).with(@reading_hash.to_s).returns(@created_reading)
  40 + @created_reading.expects(:save).with(@content.reading_group_id).returns(false)
  41 + get :save, :profile => @profile.identifier, :id => @content.id, :reading => @reading_hash
  42 + assert !@created_reading.errors.empty?
  43 + assert_response :redirect
  44 + end
  45 +
  46 + should 'set variables to edit a reading' do
  47 + Kalibro::Reading.expects(:find).with(@reading.id.to_s).returns(@reading)
  48 + get :edit, :profile => @profile.identifier, :id => @content.id, :reading_id => @reading.id
  49 + assert_equal @content.id, assigns(:reading_group_content).id
  50 + assert_equal @reading, assigns(:reading)
  51 + assert_response :success
  52 + end
  53 +
  54 + should 'destroy a reading' do
  55 + @reading.expects(:destroy)
  56 + Kalibro::Reading.expects(:find).with(@reading.id.to_s).returns(@reading)
  57 +
  58 + get :destroy, :profile => @profile.identifier, :id => @content.id, :reading_id => @reading.id
  59 +
  60 + assert @reading.errors.empty?
  61 + assert_response :redirect
  62 + end
  63 +
  64 + should 'put an Exception in reading when an error occurs in destroy action' do
  65 + @reading.errors = [Exception.new]
  66 + @reading.expects(:destroy)
  67 + Kalibro::Reading.expects(:find).with(@reading.id.to_s).returns(@reading)
  68 +
  69 + get :destroy, :profile => @profile.identifier, :id => @content.id, :reading_id => @reading.id
  70 +
  71 + assert !@reading.errors.empty?
  72 + assert_response :redirect
  73 + end
  74 +end
... ...
plugins/mezuro/test/functional/profile/mezuro_plugin_module_controller_test.rb
... ... @@ -1,74 +0,0 @@
1   -require 'test_helper'
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
5   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures"
6   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures"
7   -
8   -class MezuroPluginModuleControllerTest < ActionController::TestCase
9   -
10   - def setup
11   - @controller = MezuroPluginModuleController.new
12   - @request = ActionController::TestRequest.new
13   - @response = ActionController::TestResponse.new
14   - @profile = fast_create(Community)
15   -
16   - @project_result = ProjectResultFixtures.project_result
17   - @module_result = ModuleResultFixtures.module_result
18   - @repository_url = RepositoryFixtures.repository.address
19   - @project = @project_result.project
20   - @date = "2012-04-13T20:39:41+04:00"
21   -
22   - Kalibro::Project.expects(:all_names).returns([])
23   - @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url)
24   - @content.expects(:send_project_to_service).returns(nil)
25   - @content.save
26   - end
27   -
28   -
29   - should 'get module result without date' do
30   - date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date)
31   - Kalibro::ProjectResult.expects(:request).
32   - with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).
33   - returns({:project_result => @project_result.to_hash})
34   - Kalibro::ModuleResult.expects(:request).
35   - with("ModuleResult", :get_module_result, {:project_name => @project.name, :module_name => @project.name, :date => date_with_milliseconds}).
36   - returns({:module_result => @module_result.to_hash})
37   - get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil
38   - assert_equal @content, assigns(:content)
39   - assert_equal @module_result.grade, assigns(:module_result).grade
40   - assert_response 200
41   - assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')
42   - end
43   -
44   - should 'get module result with a specific date' do
45   - date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date)
46   - request_body = {:project_name => @project.name, :date => @project_result.date}
47   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true})
48   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})
49   - Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_module_result, {:project_name => @project.name, :module_name => @project.name, :date => date_with_milliseconds}).returns({:module_result => @module_result.to_hash})
50   - get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date
51   - assert_equal @content, assigns(:content)
52   - assert_equal @module_result.grade, assigns(:module_result).grade
53   - assert_response 200
54   - assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')
55   - end
56   -
57   - should 'test module metrics history' do
58   - Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result})
59   - get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name,
60   - :metric_name => @module_result.metric_result.first.metric.name.delete("() ")
61   - assert_equal @content, assigns(:content)
62   - assert_equal [[@module_result.metric_result[0].value, @module_result.date.to_s[0..9]]], assigns(:score_history)
63   - assert_response 200
64   - end
65   -
66   - should 'test grade history' do
67   - Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result})
68   - get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name
69   - assert_equal @content, assigns(:content)
70   - assert_equal [[@module_result.grade, @module_result.date.to_s[0..9]]], assigns(:score_history)
71   - assert_response 200
72   - end
73   -
74   -end
plugins/mezuro/test/functional/profile/mezuro_plugin_module_result_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +require 'test_helper'
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures"
  6 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures"
  7 +
  8 +class MezuroPluginModuleResultControllerTest < ActionController::TestCase
  9 +
  10 + def setup
  11 + @controller = MezuroPluginModuleResultController.new
  12 + @request = ActionController::TestRequest.new
  13 + @response = ActionController::TestResponse.new
  14 + @profile = fast_create(Community)
  15 +
  16 + @module_result_hash = ModuleResultFixtures.module_result_hash
  17 + @metric_result_hash = MetricResultFixtures.native_metric_result_hash
  18 + @date_metric_result_hash = DateMetricResultFixtures.date_metric_result_hash
  19 + @date_module_result_hash = DateModuleResultFixtures.date_module_result_hash
  20 + end
  21 +
  22 + should 'find module result on kalibro' do
  23 + parent_module_result = ModuleResultFixtures.parent_module_result_hash
  24 + Kalibro::ModuleResult.expects(:request).with(:get_module_result, { :module_result_id => @module_result_hash[:id].to_i }).
  25 + returns({:module_result => @module_result_hash})
  26 + Kalibro::MetricResult.expects(:request).with(:metric_results_of, { :module_result_id => @module_result_hash[:id].to_i }).
  27 + returns({:metric_result => @metric_result_hash})
  28 + Kalibro::ModuleResult.expects(:request).with(:get_module_result, { :module_result_id => @module_result_hash[:parent_id].to_i }).
  29 + returns({:module_result => parent_module_result})
  30 + Kalibro::ModuleResult.expects(:request).with(:children_of, {:module_result_id => @module_result_hash[:id].to_i}).
  31 + returns({:module_result => nil})
  32 + get :module_result, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id]
  33 + assert_equal @module_result_hash[:grade].to_f, assigns(:module_result).grade
  34 + assert_equal @metric_result_hash[:value].to_f, assigns(:metric_results).first.value
  35 + assert_response :success
  36 + #TODO assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)')
  37 + end
  38 +
  39 + should 'get metric result history' do
  40 + metric_name = @metric_result_hash[:configuration][:metric][:name]
  41 + Kalibro::MetricResult.expects(:request).with(:history_of_metric, { :metric_name => metric_name, :module_result_id => @module_result_hash[:id].to_i }).
  42 + returns({:date_metric_result => @date_metric_result_hash})
  43 + get :metric_result_history, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id], :metric_name => metric_name
  44 + assert_equal DateTime.parse(@date_metric_result_hash[:date]), assigns(:history).first.date
  45 + assert_response :success
  46 + #TODO assert_select
  47 + end
  48 +
  49 + should 'get module result history' do
  50 + Kalibro::ModuleResult.expects(:request).with(:history_of_module, { :module_result_id => @module_result_hash[:id].to_i }).
  51 + returns({:date_module_result => @date_module_result_hash})
  52 + get :module_result_history, :profile => @profile.identifier, :module_result_id => @module_result_hash[:id]
  53 + assert_equal DateTime.parse(@date_module_result_hash[:date]), assigns(:history).first.date
  54 + assert_response :success
  55 + #TODO assert_select
  56 + end
  57 +
  58 +end
... ...
plugins/mezuro/test/functional/profile/mezuro_plugin_processing_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,60 @@
  1 +require 'test_helper'
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/processing_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/throwable_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures"
  6 +
  7 +
  8 +class MezuroPluginProcessingControllerTest < ActionController::TestCase
  9 + def setup
  10 + @controller = MezuroPluginProcessingController.new
  11 + @request = ActionController::TestRequest.new
  12 + @response = ActionController::TestResponse.new
  13 + @profile = fast_create(Community)
  14 +
  15 + @repository_id = RepositoryFixtures.repository.id
  16 + @processing = ProcessingFixtures.processing
  17 + @processing_hash = ProcessingFixtures.processing_hash
  18 + @processing_with_error_hash = ProcessingFixtures.processing_with_error_hash
  19 + end
  20 +
  21 + should 'render last processing state' do
  22 + Kalibro::Processing.expects(:processing_of).with(@repository_id).returns(@processing)
  23 + get :state, :profile => @profile.identifier, :repository_id => @repository_id
  24 + assert_response :success
  25 + assert_equal @processing.state, @response.body
  26 + end
  27 +
  28 + should 'render a processing state in a specific date' do
  29 + Kalibro::Processing.expects(:processing_with_date_of).with(@repository_id, @processing.date).returns(@processing)
  30 + get :state, :profile => @profile.identifier, :repository_id => @repository_id, :date => @processing.date
  31 + assert_response :success
  32 + assert_equal @processing.state, @response.body
  33 + end
  34 +
  35 + should 'render processing with error' do
  36 + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => @repository_id}).returns({:exists => false})
  37 + Kalibro::Processing.expects(:request).with(:last_processing, :repository_id => @repository_id).returns({:processing => @processing_with_error_hash})
  38 + get :processing, :profile => @profile.identifier, :repository_id => @repository_id
  39 + assert_response :success
  40 + assert_equal @processing_with_error_hash[:state], assigns(:processing).state
  41 + #TODO How to assert from view? assert_select('h3', 'ERROR')
  42 + end
  43 +
  44 + should 'test project result without date' do
  45 + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => @repository_id}).returns({:exists => true})
  46 + Kalibro::Processing.expects(:request).with(:last_ready_processing, {:repository_id => @repository_id}).returns({:processing => @processing_hash})
  47 + get :processing, :profile => @profile.identifier, :repository_id => @repository_id
  48 + assert_response :success
  49 + assert_select('h4', 'Last Result')
  50 + end
  51 +
  52 + should 'test project results from a specific date' do
  53 + Kalibro::Processing.expects(:request).with(:has_processing_after, {:repository_id => @repository_id, :date => @processing.date}).returns({:exists => true})
  54 + Kalibro::Processing.expects(:request).with(:first_processing_after, :repository_id => @repository_id, :date => @processing.date).returns({:processing => @processing_hash})
  55 + get :processing, :profile => @profile.identifier, :repository_id => @repository_id, :date => @processing.date
  56 + assert_response :success
  57 + assert_select('h4', 'Last Result')
  58 + end
  59 +
  60 +end
... ...
plugins/mezuro/test/functional/profile/mezuro_plugin_project_controller_test.rb
... ... @@ -1,92 +0,0 @@
1   -require 'test_helper'
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures"
5   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures"
6   -
7   -class MezuroPluginProjectControllerTest < ActionController::TestCase
8   - def setup
9   - @controller = MezuroPluginProjectController.new
10   - @request = ActionController::TestRequest.new
11   - @response = ActionController::TestResponse.new
12   - @profile = fast_create(Community)
13   -
14   - @project_result = ProjectResultFixtures.project_result
15   - @repository_url = RepositoryFixtures.repository.address
16   - @project = @project_result.project
17   - @date = "2012-04-13T20:39:41+04:00"
18   -
19   - Kalibro::Project.expects(:all_names).returns([])
20   - @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url)
21   - @content.expects(:send_project_to_service).returns(nil)
22   - @content.save
23   - end
24   -
25   - should 'test project state without kalibro_error' do
26   - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
27   - get :project_state, :profile => @profile.identifier, :id => @content.id
28   - assert_response 200
29   - assert_equal @content, assigns(:content)
30   - end
31   -
32   - should 'test project state with kalibro_error' do
33   - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})})
34   - get :project_state, :profile => @profile.identifier, :id => @content.id
35   - assert_response 200
36   - assert_equal "ERROR", @response.body
37   - assert_equal @content, assigns(:content)
38   - end
39   -
40   - should 'test project error' do
41   - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})})
42   - get :project_error, :profile => @profile.identifier, :id => @content.id
43   - assert_response 200
44   - assert_select('h3', 'ERROR')
45   - assert_equal @content, assigns(:content)
46   - assert_equal @project.name, assigns(:project).name
47   - end
48   -
49   - should 'test project result without date' do
50   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})
51   - get :project_result, :profile => @profile.identifier, :id => @content.id, :date => nil
52   - assert_equal @content, assigns(:content)
53   - assert_equal @project_result.project.name, assigns(:project_result).project.name
54   - assert_response 200
55   - assert_select('h4', 'Last Result')
56   - end
57   -
58   - should 'test project results from a specific date' do
59   - request_body = {:project_name => @project.name, :date => @date}
60   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true})
61   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})
62   - get :project_result, :profile => @profile.identifier, :id => @content.id, :date => @date
63   - assert_equal @content, assigns(:content)
64   - assert_equal @project_result.project.name, assigns(:project_result).project.name
65   - assert_response 200
66   - assert_select('h4', 'Last Result')
67   - end
68   -
69   - should 'test project tree without date' do
70   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})
71   - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
72   - get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil
73   - assert_equal @content, assigns(:content)
74   - assert_equal @project.name, assigns(:project_name)
75   - assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name
76   - assert_response 200
77   - assert_select('h2', /Qt-Calculator/)
78   - end
79   -
80   - should 'test project tree with a specific date' do
81   - request_body = {:project_name => @project.name, :date => @project_result.date}
82   - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
83   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true})
84   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})
85   - get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date
86   - assert_equal @content, assigns(:content)
87   - assert_equal @project.name, assigns(:project_name)
88   - assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name
89   - assert_response 200
90   - end
91   -
92   -end
plugins/mezuro/test/functional/profile/mezuro_plugin_repository_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,104 @@
  1 +require 'test_helper'
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/processing_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/throwable_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures"
  6 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_content_fixtures"
  7 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
  8 +
  9 +class MezuroPluginRepositoryControllerTest < ActionController::TestCase
  10 +
  11 + def setup
  12 + @controller = MezuroPluginRepositoryController.new
  13 + @request = ActionController::TestRequest.new
  14 + @response = ActionController::TestResponse.new
  15 + @profile = fast_create(Community)
  16 +
  17 + @configuration = ConfigurationFixtures.configuration
  18 + @repository_types = RepositoryFixtures.types
  19 + @all_configurations = ConfigurationFixtures.all
  20 + @repository = RepositoryFixtures.repository
  21 + @repository_hash = RepositoryFixtures.hash
  22 + @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => name)
  23 + @content.expects(:send_project_to_service).returns(nil)
  24 + @content.stubs(:solr_save)
  25 + @content.save
  26 + end
  27 +
  28 + should 'set variables to create a new repository' do
  29 + Kalibro::Repository.expects(:repository_types).returns(@repository_types)
  30 + Kalibro::Configuration.expects(:all).returns(@all_configurations)
  31 +
  32 + get :new, :profile => @profile.identifier, :id => @content.id
  33 +
  34 + assert_equal @content.id, assigns(:project_content).id
  35 + assert_equal @repository_types, assigns(:repository_types)
  36 + assert_equal @all_configurations.first.name, assigns(:configuration_select).first.first
  37 + assert_equal @all_configurations.first.id, assigns(:configuration_select).first.last
  38 + assert_response :success
  39 + end
  40 +
  41 + should 'save a repository' do
  42 + Kalibro::Repository.expects(:new).returns(@repository)
  43 + @repository.expects(:save).with(@content.project_id).returns(true)
  44 + @repository.expects(:process)
  45 + get :save, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash
  46 + assert @repository.errors.empty?
  47 + assert_response :redirect
  48 + end
  49 +
  50 + should 'not save a repository' do
  51 + @repository.errors = [Exception.new]
  52 + Kalibro::Repository.expects(:new).returns(@repository)
  53 + @repository.expects(:save).with(@content.project_id).returns(false)
  54 + get :save, :profile => @profile.identifier, :id => @content.id, :repository => @repository_hash
  55 + assert !@repository.errors.empty?
  56 + assert_response :redirect
  57 + end
  58 +
  59 + should 'set variables to edit a repository' do
  60 + Kalibro::Repository.expects(:repository_types).returns(@repository_types)
  61 + Kalibro::Configuration.expects(:all).returns(@all_configurations)
  62 + Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository])
  63 +
  64 + get :edit, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id
  65 +
  66 + assert_equal @content.id, assigns(:project_content).id
  67 + assert_equal @repository_types, assigns(:repository_types)
  68 + assert_equal @all_configurations.first.name, assigns(:configuration_select).first.first
  69 + assert_equal @all_configurations.first.id, assigns(:configuration_select).first.last
  70 + assert_equal @repository, assigns(:repository)
  71 + assert_response :success
  72 + end
  73 +
  74 + should 'set variables to show a repository' do
  75 + Kalibro::Repository.expects(:repositories_of).with(@content.project_id).returns([@repository])
  76 + Kalibro::Configuration.expects(:configuration_of).with(@repository.id).returns(@configuration)
  77 +
  78 + get :show, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id
  79 +
  80 + assert_equal @content.id, assigns(:project_content).id
  81 + assert_equal @repository, assigns(:repository)
  82 + assert_equal @configuration.name, assigns(:configuration_name)
  83 + assert_response :success
  84 + end
  85 +
  86 + should 'destroy a repository' do
  87 + Kalibro::Repository.expects(:new).with(:id => @repository.id.to_s).returns(@repository)
  88 + @repository.expects(:destroy)
  89 + get :destroy, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id
  90 +
  91 + assert @repository.errors.empty?
  92 + assert_response :redirect
  93 + end
  94 +
  95 + should 'not destroy a repository' do
  96 + @repository.errors = [Exception.new]
  97 + Kalibro::Repository.expects(:new).with(:id => @repository.id.to_s).returns(@repository)
  98 + @repository.expects(:destroy)
  99 + get :destroy, :profile => @profile.identifier, :id => @content.id, :repository_id => @repository.id
  100 +
  101 + #TODO verify if it is redirected to the right page
  102 + assert_response :redirect
  103 + end
  104 +end
... ...
plugins/mezuro/test/run_acceptance_tests.sh 0 → 100755
... ... @@ -0,0 +1,42 @@
  1 +#!/bin/bash
  2 +
  3 +TEST_FILE=$1
  4 +PROFILE=$2
  5 +
  6 +if [ -z "$PROFILE" ]; then
  7 + PROFILE='default'
  8 +fi
  9 +
  10 +# where are your .kalibro dir?
  11 +KALIBRO_HOME='/usr/share/tomcat6/.kalibro'
  12 +
  13 +# create a kalibro test dir
  14 +echo "--> Creating tests directory"
  15 +sudo mkdir $KALIBRO_HOME/tests
  16 +echo "--> Copying test settings"
  17 +sudo cp $KALIBRO_HOME/kalibro_tests.settings $KALIBRO_HOME/tests/kalibro.settings
  18 +echo "--> Changing owner of tests directory to tomcat6"
  19 +sudo chown -R tomcat6:tomcat6 $KALIBRO_HOME/tests
  20 +
  21 +# you must restart tomcat6
  22 +#if you are using a tomcat installed from apt-get, for example:
  23 +sudo service tomcat6 restart
  24 +
  25 +#if you are using a tomcat installed a specific dir, for exemple:
  26 +#~/tomcat6/bin/shoutdown.sh
  27 +#~/tomcat6/bin/startup.sh
  28 +
  29 +# run test
  30 +cucumber $TEST_FILE -p $PROFILE
  31 +
  32 +#back to normal mode
  33 +echo "--> Removing tests directory"
  34 +sudo rm -rf $KALIBRO_HOME/tests
  35 +
  36 +# you must restart tomcat6 again
  37 +sudo service tomcat6 restart
  38 +
  39 +#or some thing like that...
  40 +#~/tomcat6/bin/shoutdown.sh
  41 +#~/tomcat6/bin/startup.sh
  42 +
... ...
plugins/mezuro/test/unit/kalibro/base_tool_test.rb
1 1 require "test_helper"
2   -
3 2 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures"
4 3  
5 4 class BaseToolTest < ActiveSupport::TestCase
... ... @@ -10,27 +9,19 @@ class BaseToolTest &lt; ActiveSupport::TestCase
10 9 end
11 10  
12 11 should 'create base tool from hash' do
13   - assert_equal @base_tool.name, Kalibro::BaseTool.new(@hash).name
14   - end
15   -
16   - should 'convert base tool to hash' do
17   - assert_equal @hash, @base_tool.to_hash
  12 + assert_equal @hash[:name], Kalibro::BaseTool.new(@hash).name
18 13 end
19   -
  14 +
20 15 should 'get base tool names' do
21 16 names = ['Analizo', 'Checkstyle']
22   - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => names})
  17 + Kalibro::BaseTool.expects(:request).with(:all_base_tool_names).returns({:base_tool_name => names})
23 18 assert_equal names, Kalibro::BaseTool.all_names
24 19 end
25 20  
26 21 should 'get base tool by name' do
27 22 request_body = {:base_tool_name => @base_tool.name}
28   - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, request_body).returns({:base_tool => @hash})
  23 + Kalibro::BaseTool.expects(:request).with(:get_base_tool, request_body).returns({:base_tool => @hash})
29 24 assert_equal @base_tool.name, Kalibro::BaseTool.find_by_name(@base_tool.name).name
30 25 end
31 26  
32   - should 'get base tool metrics' do
33   - assert_equal @base_tool.supported_metrics[0].name, @base_tool.metric('Total Coupling Factor').name
34   - end
35   -
36 27 end
... ...
plugins/mezuro/test/unit/kalibro/compound_metric_test.rb
... ... @@ -1,20 +0,0 @@
1   -require "test_helper"
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_fixtures"
4   -
5   -class CompoundMetricTest < ActiveSupport::TestCase
6   -
7   - def setup
8   - @hash = CompoundMetricFixtures.compound_metric_hash
9   - @metric = CompoundMetricFixtures.compound_metric
10   - end
11   -
12   - should 'create compound metric from hash' do
13   - assert_equal @hash[:script], Kalibro::CompoundMetric.new(@hash).script
14   - end
15   -
16   - should 'convert compound metric to hash' do
17   - assert_equal @hash, @metric.to_hash
18   - end
19   -
20   -end
plugins/mezuro/test/unit/kalibro/compound_metric_with_error_test.rb
... ... @@ -1,20 +0,0 @@
1   -require "test_helper"
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures"
4   -
5   -class CompoundMetricWithErrorTest < ActiveSupport::TestCase
6   -
7   - def setup
8   - @hash = CompoundMetricWithErrorFixtures.compound_metric_with_error_hash
9   - @compound_metric_with_error = CompoundMetricWithErrorFixtures.compound_metric_with_error
10   - end
11   -
12   - should 'create error from hash' do
13   - assert_equal @hash[:error][:message], Kalibro::CompoundMetricWithError.new(@hash).error.message
14   - end
15   -
16   - should 'convert error to hash' do
17   - assert_equal @hash, @compound_metric_with_error.to_hash
18   - end
19   -
20   -end
plugins/mezuro/test/unit/kalibro/configuration_test.rb
... ... @@ -7,7 +7,7 @@ class ConfigurationTest &lt; ActiveSupport::TestCase
7 7 def setup
8 8 @hash = ConfigurationFixtures.configuration_hash
9 9 @configuration = ConfigurationFixtures.configuration
10   - @configuration_content = ConfigurationFixtures.configuration_content([])
  10 + @created_configuration = ConfigurationFixtures.created_configuration
11 11 end
12 12  
13 13 should 'initialize configuration' do
... ... @@ -18,39 +18,49 @@ class ConfigurationTest &lt; ActiveSupport::TestCase
18 18 assert_equal @hash, @configuration.to_hash
19 19 end
20 20  
21   - should 'return true when configuration is saved successfully' do
22   - Kalibro::Configuration.expects(:request).with("Configuration", :save_configuration, {:configuration => @configuration.to_hash})
23   - assert @configuration.save
  21 + should 'answer if configuration exists in kalibro' do
  22 + Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => true})
  23 + assert Kalibro::Configuration.exists?(@configuration.id)
24 24 end
25 25  
26   - should 'return false when configuration is not saved successfully' do
27   - Kalibro::Configuration.expects(:request).with("Configuration", :save_configuration, {:configuration => @configuration.to_hash}).raises(Exception.new)
28   - assert !(@configuration.save)
  26 + should 'find configuration' do
  27 + Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => true})
  28 + Kalibro::Configuration.expects(:request).with(:get_configuration, {:configuration_id => @configuration.id}).returns(:configuration => @hash)
  29 + assert_equal @hash[:name], Kalibro::Configuration.find(@configuration.id).name
  30 + end
  31 +
  32 + should 'return exception when configuration doesnt exist' do
  33 + Kalibro::Configuration.expects(:request).with(:configuration_exists, {:configuration_id => @configuration.id}).returns({:exists => false})
  34 + assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Configuration.find(@configuration.id)}
  35 + end
  36 +
  37 + should 'get configuration of a repository' do
  38 + repository_id = 31
  39 + Kalibro::Configuration.expects(:request).with(:configuration_of, {:repository_id => repository_id}).returns({:configuration => @hash})
  40 + assert_equal @hash[:name], Kalibro::Configuration.configuration_of(repository_id).name
29 41 end
30   -
31   - should 'get all configuration names' do
32   - names = ['Kalibro for Java', 'ConfigurationClientTest configuration']
33   - Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration_names).returns({:configuration_name => names})
34   - assert_equal names, Kalibro::Configuration.all_names
  42 +
  43 + should 'get all configuration' do
  44 + Kalibro::Configuration.expects(:request).with(:all_configurations).returns({:configuration => [@hash]})
  45 + assert_equal @hash[:name], Kalibro::Configuration.all.first.name
35 46 end
36 47  
37   - should 'find configuration by name' do
38   - request_body = {:configuration_name => @configuration.name}
39   - response_hash = {:configuration => @configuration.to_hash}
40   - Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).returns(response_hash)
41   - assert_equal @configuration.name, Kalibro::Configuration.find_by_name(@configuration.name).name
  48 + should 'return true when configuration is saved successfully' do
  49 + id_from_kalibro = 1
  50 + Kalibro::Configuration.expects(:request).with(:save_configuration, {:configuration => @created_configuration.to_hash}).returns(:configuration_id => id_from_kalibro)
  51 + assert @created_configuration.save
  52 + assert_equal id_from_kalibro, @created_configuration.id
42 53 end
43 54  
44   - should 'return nil when configuration doesnt exist' do
45   - request_body = {:configuration_name => @configuration.name}
46   - Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).raises(Exception.new)
47   - assert_raise Exception do
48   - Kalibro::Configuration.find_by_name(@configuration.name)
49   - end
  55 + should 'return false when configuration is not saved successfully' do
  56 + Kalibro::Configuration.expects(:request).with(:save_configuration, {:configuration => @created_configuration.to_hash}).raises(Exception.new)
  57 + assert !(@created_configuration.save)
  58 + assert_nil @created_configuration.id
50 59 end
51 60  
52   - should 'destroy configuration by name' do
53   - Kalibro::Configuration.expects(:request).with("Configuration", :remove_configuration, {:configuration_name => @configuration.name})
  61 + should 'remove existent configuration from service' do
  62 + Kalibro::Configuration.expects(:request).with(:delete_configuration, {:configuration_id => @configuration.id})
54 63 @configuration.destroy
55 64 end
  65 +
56 66 end
... ...
plugins/mezuro/test/unit/kalibro/date_metric_result_test.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures"
  4 +
  5 +class DateMetricResultTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = DateMetricResultFixtures.date_metric_result_hash
  9 + @date_metric_result = DateMetricResultFixtures.date_metric_result
  10 + end
  11 +
  12 + should 'create date_metric_result from hash' do
  13 + assert_equal @hash[:metric_result][:id].to_i, Kalibro::DateMetricResult.new(@hash).metric_result.id
  14 + end
  15 +
  16 + should 'convert date_metric_result to hash' do
  17 + assert_equal @hash, @date_metric_result.to_hash
  18 + end
  19 +
  20 +end
... ...
plugins/mezuro/test/unit/kalibro/date_module_result_test.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures"
  4 +
  5 +class DateModuleResultTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = DateModuleResultFixtures.date_module_result_hash
  9 + @date_module_result = DateModuleResultFixtures.date_module_result
  10 + end
  11 +
  12 + should 'create date_module_result from hash' do
  13 + assert_equal @hash[:module_result][:id].to_i, Kalibro::DateModuleResult.new(@hash).module_result.id
  14 + end
  15 +
  16 + should 'convert date_module_result to hash' do
  17 + assert_equal @hash, @date_module_result.to_hash
  18 + end
  19 +
  20 +end
... ...
plugins/mezuro/test/unit/kalibro/error_test.rb
... ... @@ -1,20 +0,0 @@
1   -require "test_helper"
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures"
4   -
5   -class ErrorTest < ActiveSupport::TestCase
6   -
7   - def setup
8   - @hash = ErrorFixtures.error_hash
9   - @error = ErrorFixtures.error
10   - end
11   -
12   - should 'create error from hash' do
13   - assert_equal @hash[:message], Kalibro::Error.new(@hash).message
14   - end
15   -
16   - should 'convert error to hash' do
17   - assert_equal @hash, @error.to_hash
18   - end
19   -
20   -end
plugins/mezuro/test/unit/kalibro/metric_configuration_snapshot_test.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures"
  4 +
  5 +class MetricConfigurationSnapshotTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash
  9 + @hash2 = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_hash_with_2_elements
  10 + @metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot
  11 + @metric_configuration_snapshot2 = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot_with_2_elements
  12 + end
  13 +
  14 + should 'create and convert metric configuration snapshot from hash' do
  15 + assert_equal @hash[:code], Kalibro::MetricConfigurationSnapshot.new(@hash).code
  16 + assert_equal @hash[:weight].to_f, @metric_configuration_snapshot.weight
  17 + end
  18 +
  19 + should 'create and convert metric configuration snapshot from hash with 2 elements' do
  20 + assert_equal @hash2[:code], Kalibro::MetricConfigurationSnapshot.new(@hash2).code
  21 + assert_equal @hash2, @metric_configuration_snapshot2.to_hash
  22 + end
  23 +
  24 +end
... ...
plugins/mezuro/test/unit/kalibro/metric_configuration_test.rb
1 1 require "test_helper"
2 2  
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures"
5 4  
6 5 class MetricConfigurationTest < ActiveSupport::TestCase
7 6  
8 7 def setup
9 8 @native_metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration
10 9 @native_metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash
11   - @compound_metric_configuration = MetricConfigurationFixtures.sc_metric_configuration
12   - @metric_configuration_without_ranges = MetricConfigurationFixtures.metric_configuration_without_ranges
13   - @excellent_range = RangeFixtures.range_excellent
14   - @bad_range = RangeFixtures.range_bad
  10 + @created_metric_configuration = MetricConfigurationFixtures.created_metric_configuration
15 11 end
16 12  
17 13 should 'create metric configuration from hash' do
18   - assert_equal @native_metric_configuration_hash[:code], Kalibro::MetricConfiguration.new(@native_metric_configuration_hash).code
  14 + metric_configuration = Kalibro::MetricConfiguration.new(@native_metric_configuration_hash)
  15 + assert_equal @native_metric_configuration_hash[:code], metric_configuration.code
  16 + assert_equal @native_metric_configuration_hash[:id].to_i, metric_configuration.id
  17 + assert_equal @native_metric_configuration_hash[:reading_group_id].to_i, metric_configuration.reading_group_id
19 18 end
20 19  
21 20 should 'convert metric configuration to hash' do
22   - assert_equal @native_metric_configuration_hash, @native_metric_configuration.to_hash()
  21 + assert_equal @native_metric_configuration_hash, @native_metric_configuration.to_hash
23 22 end
24 23  
25   - should 'create appropriate metric type' do
26   - assert @native_metric_configuration.metric.instance_of?(Kalibro::NativeMetric)
27   - assert @compound_metric_configuration.metric.instance_of?(Kalibro::CompoundMetric)
  24 + should 'get all metric configurations of a configuration' do
  25 + configuration_id = 13
  26 + request_body = { :configuration_id => configuration_id }
  27 + response_hash = {:metric_configuration => [@native_metric_configuration_hash]}
  28 + Kalibro::MetricConfiguration.expects(:request).with(:metric_configurations_of, request_body).returns(response_hash)
  29 + assert_equal @native_metric_configuration.code, Kalibro::MetricConfiguration.metric_configurations_of(configuration_id).first.code
28 30 end
29 31  
30   - should 'add a range to an empty range list' do
31   - @metric_configuration_without_ranges.add_range @excellent_range
32   - assert_equal @metric_configuration_without_ranges.ranges, [@excellent_range]
33   - end
34   -
35   - should 'add a range to an non-empty range list' do
36   - @metric_configuration_without_ranges.ranges = [@excellent_range]
37   - @metric_configuration_without_ranges.add_range @bad_range
38   - assert_equal @metric_configuration_without_ranges.ranges, [@excellent_range, @bad_range]
39   - end
40   -
41   - should 'save metric configuration' do
42   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, {
43   - :metric_configuration => @native_metric_configuration_hash,
44   - :configuration_name => @native_metric_configuration.configuration_name
45   - })
46   - @native_metric_configuration.save
  32 + should 'return true when metric configuration is saved successfully' do
  33 + id_from_kalibro = 1
  34 + configuration_id = @created_metric_configuration.configuration_id
  35 + Kalibro::MetricConfiguration.expects(:request).with(:save_metric_configuration, {:metric_configuration => @created_metric_configuration.to_hash, :configuration_id => configuration_id}).returns(:metric_configuration_id => id_from_kalibro)
  36 + assert @created_metric_configuration.save
  37 + assert_equal id_from_kalibro, @created_metric_configuration.id
47 38 end
48 39  
49   - should 'get metric configuration by name and configuration name' do
50   - request_body = {
51   - :configuration_name => @native_metric_configuration.configuration_name,
52   - :metric_name => @native_metric_configuration.metric.name
53   - }
54   - response_hash = {:metric_configuration => @native_metric_configuration_hash}
55   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, request_body).returns(response_hash)
56   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@native_metric_configuration.configuration_name,
57   - @native_metric_configuration.metric.name)
58   - assert_equal @native_metric_configuration.code, metric_configuration.code
  40 + should 'return false when metric configuration is not saved successfully' do
  41 + configuration_id = @created_metric_configuration.configuration_id
  42 + Kalibro::MetricConfiguration.expects(:request).with(:save_metric_configuration, {:metric_configuration => @created_metric_configuration.to_hash, :configuration_id => configuration_id}).raises(Exception.new)
  43 + assert !(@created_metric_configuration.save)
  44 + assert_nil @created_metric_configuration.id
59 45 end
60 46  
61   - should 'destroy metric configuration by name' do
62   - request_body = {
63   - :configuration_name => @native_metric_configuration.configuration_name,
64   - :metric_name => @native_metric_configuration.metric.name
65   - }
66   - Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :remove_metric_configuration, request_body)
  47 + should 'destroy metric configuration' do
  48 + Kalibro::MetricConfiguration.expects(:request).with(:delete_metric_configuration, :metric_configuration_id => @native_metric_configuration.id)
67 49 @native_metric_configuration.destroy
68 50 end
69 51  
... ...
plugins/mezuro/test/unit/kalibro/metric_result_test.rb
1 1 require "test_helper"
2 2  
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures"
4 5  
5 6 class MetricResultTest < ActiveSupport::TestCase
6 7  
7 8 def setup
8   - @hash = MetricResultFixtures.native_metric_result_hash
  9 + @native_hash = MetricResultFixtures.native_metric_result_hash
  10 + @compound_hash = MetricResultFixtures.compound_metric_result_hash
9 11 @result = MetricResultFixtures.native_metric_result
10 12 end
11 13  
12 14 should 'create metric result from hash' do
13   - assert_equal @hash[:metric][:name], Kalibro::MetricResult.new(@hash).metric.name
  15 + metric_result = Kalibro::MetricResult.new(@native_hash)
  16 + assert_equal @native_hash[:configuration][:code], metric_result.configuration.code
  17 + assert_equal @native_hash[:id].to_i, metric_result.id
  18 + assert_equal @native_hash[:value].to_f, metric_result.value
14 19 end
15 20  
16   - should 'convert metric result to hash' do
17   - assert_equal @hash, @result.to_hash
  21 + should 'create metric result with aggregated value from hash' do
  22 + hash = @native_hash
  23 + hash[:aggregated_value] = "2.0"
  24 + hash[:value] = "NaN"
  25 + metric_result = Kalibro::MetricResult.new(hash)
  26 + assert_equal @native_hash[:aggregated_value].to_f, metric_result.value
18 27 end
19 28  
20   - should 'create appropriate metric type' do
21   - assert MetricResultFixtures.native_metric_result.metric.instance_of?(Kalibro::NativeMetric)
22   - assert MetricResultFixtures.compound_metric_result.metric.instance_of?(Kalibro::CompoundMetric)
  29 + should 'convert metric result to hash' do
  30 + assert_equal @native_hash, @result.to_hash
23 31 end
24 32  
25   - should 'convert single descendent result to array' do
26   - @result.descendent_result = 1
27   - assert_equal [1], @result.descendent_results
  33 + should 'return descendant results of a metric result' do
  34 + descendant = [31, 13]
  35 + Kalibro::MetricResult.expects(:request).with(:descendant_results_of, {:metric_result_id => @result.id}).returns({:descendant_result => descendant})
  36 + assert_equal descendant, @result.descendant_results
28 37 end
29 38  
  39 + should 'return metric results of a module result' do
  40 + id = 31
  41 + Kalibro::MetricResult.expects(:request).with(:metric_results_of, {:module_result_id => id}).returns(:metric_result => [@native_hash, @compound_hash])
  42 + assert_equal @native_hash[:id].to_i, Kalibro::MetricResult.metric_results_of(id).first.id
  43 + end
  44 +
  45 + should 'return history of a metric with a module result id' do
  46 + module_result_id = 31
  47 + Kalibro::MetricResult.expects(:request).with(:history_of_metric, {:metric_name => @result.configuration.metric.name, :module_result_id => module_result_id}).returns({:date_metric_result => DateMetricResultFixtures.date_metric_result_hash})
  48 + assert_equal DateMetricResultFixtures.date_metric_result_hash[:metric_result][:id].to_i, Kalibro::MetricResult.history_of(@result.configuration.metric.name, module_result_id).first.metric_result.id
  49 + end
  50 +
30 51 end
... ...
plugins/mezuro/test/unit/kalibro/metric_test.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require "test_helper"
  2 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_fixtures"
  3 +
  4 +class MetricTest < ActiveSupport::TestCase
  5 +
  6 + def setup
  7 + @native_hash = MetricFixtures.amloc_hash
  8 + @native = MetricFixtures.amloc
  9 + @compound_hash = MetricFixtures.compound_metric_hash
  10 + @compound = MetricFixtures.compound_metric
  11 + end
  12 +
  13 + should 'create native metric from hash' do
  14 + assert_equal @native_hash[:name], Kalibro::Metric.new(@native_hash).name
  15 + end
  16 +
  17 + should 'convert native metric to hash' do
  18 + assert_equal @native_hash, @native.to_hash
  19 + end
  20 +
  21 + should 'create compound metric from hash' do
  22 + assert_equal @compound_hash[:script], Kalibro::Metric.new(@compound_hash).script
  23 + end
  24 +
  25 + should 'convert compound metric to hash' do
  26 + assert_equal @compound_hash, @compound.to_hash
  27 + end
  28 +
  29 +end
... ...
plugins/mezuro/test/unit/kalibro/module_node_test.rb
... ... @@ -1,19 +0,0 @@
1   -require "test_helper"
2   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_node_fixtures"
3   -
4   -class ModuleNodeTest < ActiveSupport::TestCase
5   -
6   - def setup
7   - @hash = ModuleNodeFixtures.module_node_hash
8   - @node = ModuleNodeFixtures.module_node
9   - end
10   -
11   - should 'create module node from hash' do
12   - assert_equal( @node.child[0].module.name, Kalibro::ModuleNode.new(@hash).child[0].module.name)
13   - end
14   -
15   - should 'convert children hash to array of ModuleNode' do
16   - assert_equal @hash, @node.to_hash
17   - end
18   -
19   -end
plugins/mezuro/test/unit/kalibro/module_result_test.rb
1 1 require "test_helper"
2 2  
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_module_result_fixtures"
4 5  
5 6 class ModuleResultTest < ActiveSupport::TestCase
6 7  
... ... @@ -8,8 +9,12 @@ class ModuleResultTest &lt; ActiveSupport::TestCase
8 9 @hash = ModuleResultFixtures.module_result_hash
9 10 @module_result = ModuleResultFixtures.module_result
10 11 end
  12 +
11 13 should 'create module result' do
12   - assert_equal @module_result.date.to_s , Kalibro::ModuleResult.new(@hash).date.to_s
  14 + module_result = Kalibro::ModuleResult.new(@hash)
  15 + assert_equal @hash[:id].to_i , module_result.id
  16 + assert_equal @hash[:grade].to_f , module_result.grade
  17 + assert_equal @hash[:parent_id].to_i , module_result.parent_id
13 18 end
14 19  
15 20 should 'convert module result to hash' do
... ... @@ -17,22 +22,29 @@ class ModuleResultTest &lt; ActiveSupport::TestCase
17 22 end
18 23  
19 24 should 'find module result' do
20   - date = DateTime.parse(@module_result.date.to_s)
21   - name = @module_result.module.name
22   - request_body = {:project_name => name, :module_name => name, :date => '2011-10-20T18:26:43.0+00:00'}
23 25 response = {:module_result => @hash}
24   - Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_module_result, request_body).returns(response)
25   - assert_equal @module_result.grade, Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, name, date).grade
  26 + Kalibro::ModuleResult.expects(:request).with(:get_module_result, {:module_result_id => @module_result.id}).returns(response)
  27 + assert_equal @module_result.grade, Kalibro::ModuleResult.find(@module_result.id).grade
26 28 end
27 29  
28   - should 'find all module results' do
29   - name = @module_result.module.name
30   - request_body = {:project_name => name, :module_name => name}
31   - response = {:module_result => @hash}
32   - Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_result_history, request_body).returns(response)
33   - response_array = Kalibro::ModuleResult.all_by_project_name_and_module_name(name, name)
34   - assert_equal [@module_result].class, response_array.class
35   - assert_equal @module_result.grade, response_array[0].grade
  30 + should 'return children of a module result' do
  31 + response = {:module_result => [@hash]}
  32 + Kalibro::ModuleResult.expects(:request).with(:children_of, {:module_result_id => @module_result.id}).returns(response)
  33 + assert @hash[:id], @module_result.children.first.id
  34 + end
  35 +
  36 + should 'return parents of a module result' do
  37 + parent_module_result = ModuleResultFixtures.parent_module_result_hash
  38 + response = {:module_result => parent_module_result}
  39 + Kalibro::ModuleResult.expects(:request).with(:get_module_result, {:module_result_id => @module_result.parent_id}).returns(response)
  40 + parents = @module_result.parents
  41 + assert parent_module_result[:module][:name], parents.first.module.name
  42 + assert parent_module_result[:module][:name], parents.last.module.name
  43 + end
  44 +
  45 + should 'return history of a module result' do
  46 + Kalibro::ModuleResult.expects(:request).with(:history_of_module, {:module_result_id => @module_result.id}).returns({:date_module_result => [DateModuleResultFixtures.date_module_result_hash]})
  47 + assert_equal DateModuleResultFixtures.date_module_result_hash[:module_result][:id].to_i, Kalibro::ModuleResult.history_of(@module_result.id).first.module_result.id
36 48 end
37 49  
38 50 end
... ...
plugins/mezuro/test/unit/kalibro/module_test.rb
... ... @@ -12,19 +12,9 @@ class ModuleTest &lt; ActiveSupport::TestCase
12 12 should 'create module from hash' do
13 13 assert_equal @hash[:name], Kalibro::Module.new(@hash).name
14 14 end
15   -
  15 +
16 16 should 'convert module to hash' do
17 17 assert_equal @hash, @module.to_hash
18 18 end
19 19  
20   - should 'list ancestor names' do
21   - @module.name = "org.kalibro.core"
22   - assert_equal ["org", "org.kalibro", "org.kalibro.core"], @module.ancestor_names
23   - end
24   -
25   - should 'list ancestor with one name' do
26   - @module.name = "org"
27   - assert_equal ["org"], @module.ancestor_names
28   - end
29   -
30 20 end
... ...
plugins/mezuro/test/unit/kalibro/native_metric_test.rb
... ... @@ -1,20 +0,0 @@
1   -require "test_helper"
2   -
3   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures"
4   -
5   -class NativeMetricTest < ActiveSupport::TestCase
6   -
7   - def setup
8   - @hash = NativeMetricFixtures.amloc_hash
9   - @metric = NativeMetricFixtures.amloc
10   - end
11   -
12   - should 'create native metric from hash' do
13   - assert_equal @hash[:name], Kalibro::NativeMetric.new(@hash).name
14   - end
15   -
16   - should 'convert native metric to hash' do
17   - assert_equal @hash, @metric.to_hash
18   - end
19   -
20   -end
plugins/mezuro/test/unit/kalibro/process_time_test.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/process_time_fixtures"
  4 +
  5 +class ProcessTimeTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = ProcessTimeFixtures.process_time_hash
  9 + @process_time = ProcessTimeFixtures.process_time
  10 + end
  11 +
  12 + should 'create process time from hash' do
  13 + assert_equal @hash[:state], Kalibro::ProcessTime.new(@hash).state
  14 + assert_equal @hash[:time].to_i, Kalibro::ProcessTime.new(@hash).time
  15 + end
  16 +
  17 + should 'convert process time to hash' do
  18 + assert_equal @hash, @process_time.to_hash
  19 + end
  20 +
  21 + should 'get time as an integer' do
  22 + assert_equal 1.class, @process_time.time.class
  23 + end
  24 +
  25 +end
... ...
plugins/mezuro/test/unit/kalibro/processing_test.rb 0 → 100644
... ... @@ -0,0 +1,98 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/processing_fixtures"
  4 +class ProcessingTest < ActiveSupport::TestCase
  5 +
  6 + def setup
  7 + @hash = ProcessingFixtures.processing_hash
  8 + @processing = ProcessingFixtures.processing
  9 +
  10 + @repository_id = 31
  11 + end
  12 +
  13 + should 'create processing from hash' do
  14 + processing = Kalibro::Processing.new(@hash)
  15 + assert_equal @hash[:results_root_id].to_i, processing.results_root_id
  16 + assert_equal @hash[:process_time].first[:state], processing.process_times.first.state
  17 + assert_equal @hash[:id].to_i, processing.id
  18 + end
  19 +
  20 + should 'convert processing to hash' do
  21 + assert_equal @hash, @processing.to_hash
  22 + end
  23 +
  24 + should 'verify if a repository has a processing' do
  25 + true_repository_id = 31
  26 + false_repository_id = 32
  27 +
  28 + Kalibro::Processing.expects(:request).with(:has_processing, {:repository_id => true_repository_id}).returns({:exists => true})
  29 + Kalibro::Processing.expects(:request).with(:has_processing, {:repository_id => false_repository_id}).returns({:exists => false})
  30 +
  31 + assert Kalibro::Processing.has_processing(true_repository_id)
  32 + assert !Kalibro::Processing.has_processing(false_repository_id)
  33 + end
  34 +
  35 + should 'verify if a repository has a ready processing' do
  36 + true_repository_id = 31
  37 + false_repository_id = 32
  38 +
  39 + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => true_repository_id}).returns({:exists => true})
  40 + Kalibro::Processing.expects(:request).with(:has_ready_processing, {:repository_id => false_repository_id}).returns({:exists => false})
  41 +
  42 + assert Kalibro::Processing.has_ready_processing(true_repository_id)
  43 + assert !Kalibro::Processing.has_ready_processing(false_repository_id)
  44 + end
  45 +
  46 + should 'verify if a repository has a processing after a date' do
  47 + true_repository_id = 31
  48 + false_repository_id = 32
  49 +
  50 + Kalibro::Processing.expects(:request).with(:has_processing_after, {:repository_id => true_repository_id, :date => @processing.date}).returns({:exists => true})
  51 + Kalibro::Processing.expects(:request).with(:has_processing_after, {:repository_id => false_repository_id, :date => @processing.date}).returns({:exists => false})
  52 +
  53 + assert Kalibro::Processing.has_processing_after(true_repository_id, @processing.date)
  54 + assert !Kalibro::Processing.has_processing_after(false_repository_id, @processing.date)
  55 + end
  56 +
  57 + should 'verify if a repository has a processing before a date' do
  58 + true_repository_id = 31
  59 + false_repository_id = 32
  60 +
  61 + Kalibro::Processing.expects(:request).with(:has_processing_before, {:repository_id => true_repository_id, :date => @processing.date}).returns({:exists => true})
  62 + Kalibro::Processing.expects(:request).with(:has_processing_before, {:repository_id => false_repository_id, :date => @processing.date}).returns({:exists => false})
  63 +
  64 + assert Kalibro::Processing.has_processing_before(true_repository_id, @processing.date)
  65 + assert !Kalibro::Processing.has_processing_before(false_repository_id, @processing.date)
  66 + end
  67 +
  68 + should 'get last processing state of a repository' do
  69 + Kalibro::Processing.expects(:request).with(:last_processing_state, {:repository_id => @repository_id}).returns({:process_state => @processing.state})
  70 + assert_equal @processing.state, Kalibro::Processing.last_processing_state_of(@repository_id)
  71 + end
  72 +
  73 + should 'get last ready processing of a repository' do
  74 + Kalibro::Processing.expects(:request).with(:last_ready_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
  75 + assert_equal @processing.id, Kalibro::Processing.last_ready_processing_of(@repository_id).id
  76 + end
  77 +
  78 + should 'get first processing of a repository' do
  79 + Kalibro::Processing.expects(:request).with(:first_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
  80 + assert_equal @processing.id, Kalibro::Processing.first_processing_of(@repository_id).id
  81 + end
  82 +
  83 + should 'get last processing of a repository' do
  84 + Kalibro::Processing.expects(:request).with(:last_processing, {:repository_id => @repository_id}).returns({:processing => @hash})
  85 + assert_equal @processing.id, Kalibro::Processing.last_processing_of(@repository_id).id
  86 + end
  87 +
  88 + should 'get first processing after a date of a repository' do
  89 + Kalibro::Processing.expects(:request).with(:first_processing_after, {:repository_id => @repository_id, :date => @processing.date}).returns({:processing => @hash})
  90 + assert_equal @processing.id, Kalibro::Processing.first_processing_after(@repository_id, @processing.date).id
  91 + end
  92 +
  93 + should 'get last processing before a date of a repository' do
  94 + Kalibro::Processing.expects(:request).with(:last_processing_before, {:repository_id => @repository_id, :date => @processing.date}).returns({:processing => @hash})
  95 + assert_equal @processing.id, Kalibro::Processing.last_processing_before(@repository_id, @processing.date).id
  96 + end
  97 +
  98 +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
plugins/mezuro/test/unit/kalibro/project_test.rb
... ... @@ -7,82 +7,75 @@ class ProjectTest &lt; ActiveSupport::TestCase
7 7 def setup
8 8 @hash = ProjectFixtures.project_hash
9 9 @project = ProjectFixtures.project
10   - @project_content = ProjectFixtures.project_content
  10 + @created_project = ProjectFixtures.created_project
11 11 end
12   -
13   - should 'get all project names' do
14   - response_hash = {:project_name => [@project.name]}
15   - Kalibro::Project.expects(:request).with("Project", :get_project_names).returns(response_hash)
16   - assert_equal response_hash[:project_name], Kalibro::Project.all_names
  12 +
  13 + should 'initialize new project from hash' do
  14 + project = Kalibro::Project.new @hash
  15 + assert_equal @hash[:name], project.name
  16 + assert_equal @hash[:id].to_i, project.id
17 17 end
18 18  
19   - should 'return empty when there are no projects' do
20   - response_hash = {:project_name => nil}
21   - Kalibro::Project.expects(:request).with("Project", :get_project_names).returns(response_hash)
22   - assert_equal [], Kalibro::Project.all_names
  19 + should 'convert project to hash' do
  20 + hash = @project.to_hash
  21 + assert_equal @project.name, hash[:name]
23 22 end
24 23  
25   - should 'find project by name' do
26   - request_body = {:project_name => @project.name}
27   - response_hash = {:project => @hash}
28   - Kalibro::Project.expects(:new).with(@hash).returns(@project)
29   - Kalibro::Project.expects(:request).with("Project", :get_project, request_body).returns(response_hash)
30   - assert_equal @project, Kalibro::Project.find_by_name(@project.name)
  24 + should 'answer if project exists in kalibro' do
  25 + Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => true})
  26 + assert Kalibro::Project.exists?(@project.id)
31 27 end
32 28  
33   - should 'raise error when project doesnt exist' do
34   - request_body = {:project_name => @project.name}
35   - Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name))
36   - assert_raise Exception do Kalibro::Project.find_by_name(@project.name) end
  29 + should 'find project' do
  30 + Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => true})
  31 + Kalibro::Project.expects(:request).with(:get_project, {:project_id => @project.id}).returns(:project => @hash)
  32 + assert_equal @hash[:name], Kalibro::Project.find(@project.id).name
37 33 end
38 34  
39   - should 'return true when project is saved successfully' do
40   - Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash})
41   - assert @project.save
  35 + should 'raise RecordNotFound exception when project doesnt exist' do
  36 + Kalibro::Project.expects(:request).with(:project_exists, {:project_id => @project.id}).returns({:exists => false})
  37 + assert_raise(Kalibro::Errors::RecordNotFound){Kalibro::Project.find(@project.id)}
42 38 end
43 39  
44   - should 'return false when project is not saved successfully' do
45   - Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}).raises(Exception.new)
46   - assert !(@project.save)
  40 + should 'get project of a repository' do
  41 + repository_id = 31
  42 + Kalibro::Project.expects(:request).with(:project_of, {:repository_id => repository_id}).returns({:project => @hash})
  43 + assert_equal @hash[:name], Kalibro::Project.project_of(repository_id).name
47 44 end
48 45  
49   - should 'remove existent project from service' do
50   - Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name})
51   - @project.destroy
52   - end
53   -
54   - should 'initialize new project from hash' do
55   - project = Kalibro::Project.new @hash
56   - assert_equal @project.name, project.name
57   - assert_equal @project.repository.type, project.repository.type
  46 + should 'get all projects when there is only one project' do
  47 + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => @hash})
  48 + assert_equal @hash[:name], Kalibro::Project.all.first.name
58 49 end
59 50  
60   - should 'convert project to hash' do
61   - hash = @project.to_hash
62   - assert_equal @hash[:name], hash[:name]
63   - assert_equal @hash[:configuration_name], hash[:configuration_name]
64   - assert_equal @hash[:repository], hash[:repository]
65   - assert_equal @hash[:state], hash[:state]
  51 + should 'get all projects when there are many projects' do
  52 + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => [@hash, @hash]})
  53 + projects = Kalibro::Project.all
  54 + assert_equal @hash[:name], projects.first.name
  55 + assert_equal @hash[:name], projects.last.name
66 56 end
67   -
68   - should 'process project without days' do
69   - Kalibro::Project.expects(:request).with('Kalibro', :process_project, {:project_name => @project.name})
70   - @project.process_project
  57 +
  58 + should 'return empty when there are no projects' do
  59 + Kalibro::Project.expects(:request).with(:all_projects).returns({:project => nil})
  60 + assert_equal [], Kalibro::Project.all
71 61 end
72 62  
73   - should 'process project with days' do
74   - Kalibro::Project.expects(:request).with('Kalibro', :process_periodically, {:project_name => @project.name, :period_in_days => "1"})
75   - @project.process_project "1"
  63 + should 'return true when project is saved successfully' do
  64 + id_from_kalibro = 1
  65 + Kalibro::Project.expects(:request).with(:save_project, {:project => @created_project.to_hash}).returns(:project_id => id_from_kalibro)
  66 + assert @created_project.save
  67 + assert_equal id_from_kalibro, @created_project.id
76 68 end
77 69  
78   - should 'process period' do
79   - Kalibro::Project.expects(:request).with('Kalibro', :get_process_period, {:project_name => @project.name}).returns({:period => "1"})
80   - assert_equal "1", @project.process_period
  70 + should 'return false when project is not saved successfully' do
  71 + Kalibro::Project.expects(:request).with(:save_project, {:project => @created_project.to_hash}).raises(Exception.new)
  72 + assert !(@created_project.save)
  73 + assert_nil @created_project.id
81 74 end
82   -
83   - should 'cancel periodic process' do
84   - Kalibro::Project.expects(:request).with("Kalibro", :cancel_periodic_process, {:project_name => @project.name})
85   - @project.cancel_periodic_process
  75 +
  76 + should 'remove existent project from service' do
  77 + Kalibro::Project.expects(:request).with(:delete_project, {:project_id => @project.id})
  78 + @project.destroy
86 79 end
87 80  
88 81 end
... ...
plugins/mezuro/test/unit/kalibro/range_snapshot_test.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_snapshot_fixtures"
  4 +
  5 +class RangeSnapshotTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = RangeSnapshotFixtures.range_snapshot_hash
  9 + @range_snapshot_with_infinite_range_hash = RangeSnapshotFixtures.range_snapshot_with_infinite_range_hash
  10 + @range_snapshot = RangeSnapshotFixtures.range_snapshot
  11 + @range_snapshot_with_infinite_range = RangeSnapshotFixtures.range_snapshot_with_infinite_range
  12 + end
  13 +
  14 + should 'create range_snapshot from hash' do
  15 + range_snapshot = Kalibro::RangeSnapshot.new(@hash)
  16 + assert_equal @hash[:comments], range_snapshot.comments
  17 + assert_equal @hash[:beginning].to_f, range_snapshot.beginning
  18 + assert_equal @hash[:end].to_f, range_snapshot.end
  19 + assert_equal @hash[:grade].to_f, range_snapshot.grade
  20 + end
  21 +
  22 + should 'create range_snapshot from hash with infinity values' do
  23 + range_snapshot = Kalibro::RangeSnapshot.new(@range_snapshot_with_infinite_range_hash)
  24 + assert_equal -1.0/0, range_snapshot.beginning
  25 + assert_equal 1.0/0, range_snapshot.end
  26 + end
  27 +
  28 + should 'convert range_snapshot to hash' do
  29 + assert_equal @hash, @range_snapshot.to_hash
  30 + end
  31 +
  32 +end
... ...
plugins/mezuro/test/unit/kalibro/range_test.rb
... ... @@ -5,24 +5,43 @@ require &quot;#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures&quot;
5 5 class RangeTest < ActiveSupport::TestCase
6 6  
7 7 def setup
8   - @hash = RangeFixtures.range_bad_hash
9   - @range = RangeFixtures.range_bad
  8 + @hash = RangeFixtures.range_hash
  9 + @range = RangeFixtures.range
  10 + @created_range = RangeFixtures.created_range
10 11 end
11 12  
12 13 should 'create range from hash' do
13   - assert_equal @hash[:label], Kalibro::Range.new(@hash).label
  14 + assert_equal @hash[:comments], Kalibro::Range.new(@hash).comments
14 15 end
15 16  
16 17 should 'convert range to hash' do
17 18 assert_equal @hash, @range.to_hash
18 19 end
19 20  
20   - should 'create a default color for new range' do
21   - assert_equal "e4ca2d", Kalibro::Range.new.mezuro_color
22   - end
23   -
24   - should "convert color from 'ff' to '#'" do
25   - assert_equal "ff0000", @range.mezuro_color
26   - end
  21 + should 'get ranges of a metric configuration' do
  22 + metric_configuration_id = 31
  23 + Kalibro::Range.expects(:request).with(:ranges_of, {:metric_configuration_id => metric_configuration_id}).returns({:range => [@hash]})
  24 + assert_equal @hash[:comments], Kalibro::Range.ranges_of(metric_configuration_id).first.comments
  25 + end
  26 +
  27 + should 'return true when range is saved successfully' do
  28 + id_from_kalibro = 1
  29 + metric_configuration_id = 2
  30 + Kalibro::Range.expects(:request).with(:save_range, {:range => @created_range.to_hash, :metric_configuration_id => metric_configuration_id}).returns(:range_id => id_from_kalibro)
  31 + assert @created_range.save(metric_configuration_id)
  32 + assert_equal id_from_kalibro, @created_range.id
  33 + end
  34 +
  35 + should 'return false when range is not saved successfully' do
  36 + metric_configuration_id = 2
  37 + Kalibro::Range.expects(:request).with(:save_range, {:range => @created_range.to_hash, :metric_configuration_id => metric_configuration_id}).raises(Exception.new)
  38 + assert !(@created_range.save(metric_configuration_id))
  39 + assert_nil @created_range.id
  40 + end
  41 +
  42 + should 'destroy range by id' do
  43 + Kalibro::Range.expects(:request).with(:delete_range, {:range_id => @range.id})
  44 + @range.destroy
  45 + end
27 46  
28 47 end
... ...
plugins/mezuro/test/unit/kalibro/reading_group_test.rb 0 → 100644
... ... @@ -0,0 +1,78 @@
  1 +require "test_helper"
  2 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_group_fixtures"
  3 +
  4 +class ReadingGroupTest < ActiveSupport::TestCase
  5 +
  6 + def setup
  7 + @hash = ReadingGroupFixtures.reading_group_hash
  8 + @reading_group = ReadingGroupFixtures.reading_group
  9 + @created_reading_group = ReadingGroupFixtures.created_reading_group
  10 + end
  11 +
  12 + should 'create reading group from hash' do
  13 + assert_equal @hash[:name], Kalibro::ReadingGroup.new(@hash).name
  14 + assert_equal @hash[:id].to_i, Kalibro::ReadingGroup.new(@hash).id
  15 + end
  16 +
  17 + should 'convert reading group to hash' do
  18 + assert_equal @hash, @reading_group.to_hash
  19 + end
  20 +
  21 + should 'verify existence of reading group' do
  22 + fake_id = 0
  23 + Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => fake_id}).returns({:exists => false})
  24 + Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => @hash[:id].to_i}).returns({:exists => true})
  25 + assert !Kalibro::ReadingGroup.exists?(fake_id)
  26 + assert Kalibro::ReadingGroup.exists?(@hash[:id].to_i)
  27 + end
  28 +
  29 + should 'get reading group' do
  30 + Kalibro::ReadingGroup.expects(:request).with(:reading_group_exists, {:group_id => @hash[:id]}).returns({:exists => true})
  31 + Kalibro::ReadingGroup.expects(:request).with(:get_reading_group, {:group_id => @hash[:id]}).
  32 + returns({:reading_group => @hash})
  33 + assert_equal @hash[:name], Kalibro::ReadingGroup.find(@hash[:id]).name
  34 + end
  35 +
  36 + should 'get all reading groups when there is only one reading group' do
  37 + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => @hash})
  38 + assert_equal @hash[:name], Kalibro::ReadingGroup.all.first.name
  39 + end
  40 +
  41 + should 'get all reading groups when there are many reading groups' do
  42 + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => [@hash, @hash]})
  43 + reading_groups = Kalibro::ReadingGroup.all
  44 + assert_equal @hash[:name], reading_groups.first.name
  45 + assert_equal @hash[:name], reading_groups.last.name
  46 + end
  47 +
  48 + should 'return empty when there are no reading groups' do
  49 + Kalibro::ReadingGroup.expects(:request).with(:all_reading_groups).returns({:reading_group => nil})
  50 + assert_equal [], Kalibro::ReadingGroup.all
  51 + end
  52 +
  53 + should 'get reading group of a metric configuration' do
  54 + id = 31
  55 + Kalibro::ReadingGroup.expects(:request).with(:reading_group_of, {:metric_configuration_id => id}).returns({:reading_group => @hash})
  56 + assert_equal @hash[:name], Kalibro::ReadingGroup.reading_group_of(id).name
  57 + end
  58 +
  59 + should 'return true when reading group is saved successfully' do
  60 + id_from_kalibro = 1
  61 + Kalibro::ReadingGroup.expects(:request).with(:save_reading_group, {:reading_group => @created_reading_group.to_hash}).returns(:reading_group_id => id_from_kalibro)
  62 + assert @created_reading_group.save
  63 + assert_equal id_from_kalibro, @created_reading_group.id
  64 + end
  65 +
  66 + should 'return false when reading group is not saved successfully' do
  67 + Kalibro::ReadingGroup.expects(:request).with(:save_reading_group, {:reading_group => @created_reading_group.to_hash}).raises(Exception.new)
  68 + assert !(@created_reading_group.save)
  69 + assert_nil @created_reading_group.id
  70 + end
  71 +
  72 + should 'destroy reading group by id' do
  73 + Kalibro::ReadingGroup.expects(:request).with(:delete_reading_group, {:group_id => @reading_group.id})
  74 + @reading_group.destroy
  75 + end
  76 +
  77 +end
  78 +
... ...
plugins/mezuro/test/unit/kalibro/reading_test.rb 0 → 100644
... ... @@ -0,0 +1,61 @@
  1 +require "test_helper"
  2 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_fixtures"
  3 +
  4 +class ReadingTest < ActiveSupport::TestCase
  5 +
  6 + def setup
  7 + @hash = ReadingFixtures.reading_hash
  8 + @reading = ReadingFixtures.reading
  9 + @created_reading = ReadingFixtures.created_reading
  10 + end
  11 +
  12 + should 'create reading from hash' do
  13 + assert_equal @hash[:label], Kalibro::Reading.new(@hash).label
  14 + assert_equal @hash[:id].to_i, Kalibro::Reading.new(@hash).id
  15 + assert_equal @hash[:grade].to_f, Kalibro::Reading.new(@hash).grade
  16 + end
  17 +
  18 + should 'convert reading to hash' do
  19 + assert_equal @hash, @reading.to_hash
  20 + end
  21 +
  22 + should 'get reading' do
  23 + Kalibro::Reading.expects(:request).with(:get_reading, {:reading_id => @hash[:id]}).
  24 + returns({:reading => @hash})
  25 + assert_equal @hash[:label], Kalibro::Reading.find(@hash[:id]).label
  26 + end
  27 +
  28 + should 'get reading of a range' do
  29 + range_id = 31
  30 + Kalibro::Reading.expects(:request).with(:reading_of, {:range_id => range_id}).returns({:reading => @hash})
  31 + assert_equal @hash[:label], Kalibro::Reading.reading_of(range_id).label
  32 + end
  33 +
  34 + should 'get readings of a reading group' do
  35 + reading_group_id = 31
  36 + Kalibro::Reading.expects(:request).with(:readings_of, {:group_id => reading_group_id}).returns({:reading => [@hash]})
  37 + assert_equal @hash[:label], Kalibro::Reading.readings_of(reading_group_id).first.label
  38 + end
  39 +
  40 + should 'return true when reading is saved successfully' do
  41 + reading_group_id = 31
  42 + id_from_kalibro = 1
  43 + Kalibro::Reading.expects(:request).with(:save_reading, {:group_id => reading_group_id, :reading => @created_reading.to_hash}).returns(:reading_id => id_from_kalibro)
  44 + assert @created_reading.save reading_group_id
  45 + assert_equal id_from_kalibro, @created_reading.id
  46 + end
  47 +
  48 + should 'return false when reading is not saved successfully' do
  49 + reading_group_id = 31
  50 + Kalibro::Reading.expects(:request).with(:save_reading, {:group_id => reading_group_id, :reading => @created_reading.to_hash}).raises(Exception.new)
  51 + assert !(@created_reading.save reading_group_id)
  52 + assert_nil @created_reading.id
  53 + end
  54 +
  55 + should 'destroy reading by id' do
  56 + Kalibro::Reading.expects(:request).with(:delete_reading, {:reading_id => @reading.id})
  57 + @reading.destroy
  58 + end
  59 +
  60 +end
  61 +
... ...
plugins/mezuro/test/unit/kalibro/repository_test.rb
... ... @@ -7,10 +7,15 @@ class RepositoryTest &lt; ActiveSupport::TestCase
7 7 def setup
8 8 @hash = RepositoryFixtures.repository_hash
9 9 @repository = RepositoryFixtures.repository
  10 + @created_repository = RepositoryFixtures.created_repository
10 11 end
11 12  
12 13 should 'new repository from hash' do
13   - assert_equal @repository.type, Kalibro::Repository.new(@hash).type
  14 + repository = Kalibro::Repository.new(@hash)
  15 + assert_equal @hash[:type], repository.type
  16 + assert_equal @hash[:id].to_i, repository.id
  17 + assert_equal @hash[:process_period].to_i, repository.process_period
  18 + assert_equal @hash[:configuration_id].to_i, repository.configuration_id
14 19 end
15 20  
16 21 should 'convert repository to hash' do
... ... @@ -19,8 +24,50 @@ class RepositoryTest &lt; ActiveSupport::TestCase
19 24  
20 25 should 'get supported repository types' do
21 26 types = ['BAZAAR', 'GIT', 'SUBVERSION']
22   - Kalibro::Repository.expects(:request).with('Kalibro', :get_supported_repository_types).returns({:repository_type => types})
  27 + Kalibro::Repository.expects(:request).with(:supported_repository_types).returns({:supported_type => types})
23 28 assert_equal types, Kalibro::Repository.repository_types
24 29 end
25 30  
  31 + should 'get repository of a precessing' do
  32 + id = 31
  33 + Kalibro::Repository.expects(:request).with(:repository_of, {:processing_id => id}).returns({:repository => @hash})
  34 + assert_equal @hash[:name], Kalibro::Repository.repository_of(id).name
  35 + end
  36 +
  37 + should 'get repositories of a project' do
  38 + project_id = 31
  39 + Kalibro::Repository.expects(:request).with(:repositories_of, {:project_id => project_id}).returns({:repository => [@hash]})
  40 + assert_equal @hash[:name], Kalibro::Repository.repositories_of(project_id).first.name
  41 + end
  42 +
  43 + should 'return true when repository is saved successfully' do
  44 + id_from_kalibro = 1
  45 + project_id = 56
  46 + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => project_id}).returns(:repository_id => id_from_kalibro)
  47 + assert @created_repository.save(project_id)
  48 + assert_equal id_from_kalibro, @created_repository.id
  49 + end
  50 +
  51 + should 'return false when repository is not saved successfully' do
  52 + project_id = 56
  53 + Kalibro::Repository.expects(:request).with(:save_repository, {:repository => @created_repository.to_hash, :project_id => project_id}).raises(Exception.new)
  54 + assert !(@created_repository.save(project_id))
  55 + assert_nil @created_repository.id
  56 + end
  57 +
  58 + should 'destroy repository by id' do
  59 + Kalibro::Repository.expects(:request).with(:delete_repository, {:repository_id => @repository.id})
  60 + @repository.destroy
  61 + end
  62 +
  63 + should 'process repository' do
  64 + Kalibro::Repository.expects(:request).with(:process_repository, {:repository_id => @repository.id});
  65 + @repository.process
  66 + end
  67 +
  68 + should 'cancel processing of a repository' do
  69 + Kalibro::Repository.expects(:request).with(:cancel_processing_of_repository, {:repository_id => @repository.id});
  70 + @repository.cancel_processing_of_repository
  71 + end
  72 +
26 73 end
... ...
plugins/mezuro/test/unit/kalibro/throwable_test.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/throwable_fixtures"
  4 +
  5 +class ThrowableTest < ActiveSupport::TestCase
  6 +
  7 + def setup
  8 + @hash = ThrowableFixtures.throwable_hash
  9 + @throwable = ThrowableFixtures.throwable
  10 + end
  11 +
  12 + should 'create throwable from hash' do
  13 + assert_equal @hash[:message], Kalibro::Throwable.new(@hash).message
  14 + end
  15 +
  16 + should 'convert throwable to hash' do
  17 + assert_equal @hash, @throwable.to_hash
  18 + end
  19 +
  20 +end
... ...
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb
1 1 require "test_helper"
2 2  
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_content_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures"
  6 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures"
4 7  
5 8 class ConfigurationContentTest < ActiveSupport::TestCase
6 9  
7 10 def setup
8 11 @configuration = ConfigurationFixtures.configuration
9   - @content = ConfigurationFixtures.configuration_content("None")
  12 + @content = ConfigurationContentFixtures.configuration_content
  13 + @created_configuration = ConfigurationFixtures.created_configuration
  14 + @content_hash = ConfigurationContentFixtures.configuration_content_hash
  15 + @configuration_hash = {:name => @content_hash[:name], :description => @content_hash[:description], :id => @content_hash[:configuration_id]}
  16 + @created_content = ConfigurationContentFixtures.created_configuration_content
  17 +
  18 + @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration
  19 + @range = RangeFixtures.range
10 20 end
11 21  
12 22 should 'be an article' do
... ... @@ -18,7 +28,7 @@ class ConfigurationContentTest &lt; ActiveSupport::TestCase
18 28 end
19 29  
20 30 should 'provide proper description' do
21   - assert_equal 'Sets of thresholds to interpret metrics', MezuroPlugin::ConfigurationContent.description
  31 + assert_equal 'Set of metric configurations to interpret a Kalibro project', MezuroPlugin::ConfigurationContent.description
22 32 end
23 33  
24 34 should 'have an html view' do
... ... @@ -26,52 +36,56 @@ class ConfigurationContentTest &lt; ActiveSupport::TestCase
26 36 end
27 37  
28 38 should 'not save a configuration with an existing cofiguration name in kalibro' do
29   - Kalibro::Configuration.expects(:all_names).returns([@content.name.upcase])
30   - @content.send :validate_kalibro_configuration_name
  39 + Kalibro::Configuration.expects(:all).returns([@configuration])
  40 + @content.send :validate_configuration_name
31 41 assert_equal "Configuration name already exists in Kalibro", @content.errors.on_base
32 42 end
33 43  
34 44 should 'get configuration from service' do
35   - Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration)
  45 + Kalibro::Configuration.expects(:find).with(@content.configuration_id).returns(@configuration)
36 46 assert_equal @configuration, @content.kalibro_configuration
37 47 end
38 48  
39 49 should 'send configuration to service after saving' do
40   - @content.expects :send_kalibro_configuration_to_service
  50 + @content.expects :send_configuration_to_service
41 51 @content.stubs(:solr_save)
42   - @content.run_callbacks :after_save
  52 + @content.run_callbacks :before_save
43 53 end
44 54  
45 55 should 'create new configuration' do
46   - Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description)
47   - Kalibro::Configuration.expects(:find_by_name).with(@content.name)
48   - @content.send :send_kalibro_configuration_to_service
  56 + Kalibro::Configuration.expects(:create).with(:name => @created_content.name, :description => @created_content.description, :id => nil).returns(@configuration)
  57 + @created_content.send :send_configuration_to_service
  58 + assert_equal @configuration.id, @created_content.configuration_id
49 59 end
50   -
  60 +
51 61 should 'clone configuration' do
52   - @content.configuration_to_clone_name = 'clone name'
53   - Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description, :metric_configuration => @configuration.metric_configurations_hash)
54   - Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(nil)
55   - Kalibro::Configuration.expects(:find_by_name).with('clone name').returns(@configuration)
56   - @content.send :send_kalibro_configuration_to_service
  62 + clone_id = @configuration.id
  63 + @content.configuration_to_clone_id = clone_id
  64 + Kalibro::Configuration.expects(:create).with(:id => @content.configuration_id, :name => @content.name, :description => @content.description).returns(@configuration)
  65 + Kalibro::MetricConfiguration.expects(:metric_configurations_of).with(@configuration.id).returns([@metric_configuration])
  66 + Kalibro::MetricConfiguration.expects(:request).returns(:metric_configuration_id => @metric_configuration.id)
  67 + Kalibro::Range.expects(:ranges_of).with(@metric_configuration.id).returns([@range])
  68 + @range.expects(:save).with(@metric_configuration.id).returns(true)
  69 + @content.send :send_configuration_to_service
57 70 end
58 71  
59 72 should 'edit configuration' do
60   - Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration)
61   - @configuration.expects(:update_attributes).with(:description => @content.description)
62   - @content.send :send_kalibro_configuration_to_service
  73 + Kalibro::Configuration.expects(:new).with(@configuration_hash).returns(@configuration)
  74 + @configuration.expects(:save).returns(true)
  75 + @content.send :send_configuration_to_service
  76 + assert_equal @configuration.id, @content.configuration_id
63 77 end
64 78  
65 79 should 'send correct configuration to service but comunication fails' do
66   - Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration)
67   - @configuration.expects(:save).returns(false)
68   - @content.send :send_kalibro_configuration_to_service
  80 + Kalibro::Configuration.expects(:new).with(@configuration_hash).returns(@created_configuration)
  81 + @created_configuration.expects(:save).returns(false)
  82 + @content.send :send_configuration_to_service
69 83 end
70 84  
71 85 should 'remove configuration from service' do
72   - Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration)
  86 + Kalibro::Configuration.expects(:find).with(@content.configuration_id).returns(@configuration)
73 87 @configuration.expects(:destroy)
74   - @content.send :remove_kalibro_configuration_from_service
  88 + @content.send :remove_configuration_from_service
75 89 end
76 90  
77 91 end
... ...
plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb
1 1 require "test_helper"
2   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures"
  2 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_snapshot_fixtures"
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures"
3 4  
4 5 class ContentViewerHelperTest < ActiveSupport::TestCase
5 6  
  7 + def setup
  8 + @helper = MezuroPlugin::Helpers::ContentViewerHelper
  9 + end
  10 +
6 11 should 'get the number rounded by two decimal points' do
7   - assert_equal '4.22', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.22344')
8   - assert_equal '4.10', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.1')
9   - assert_equal '4.00', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4')
  12 + assert_equal '4.22', @helper.format_grade('4.22344')
  13 + assert_equal '4.10', @helper.format_grade('4.1')
  14 + assert_equal '4.00', @helper.format_grade('4')
10 15 end
11 16  
12 17 should 'create the periodicity options array' do
13   - assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]], MezuroPlugin::Helpers::ContentViewerHelper.create_periodicity_options
  18 + assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweekly", 15], ["Monthly", 30]], @helper.periodicity_options
  19 + end
  20 +
  21 + should 'return the correct string for a given periodicity' do
  22 + assert_equal "Not Periodically", @helper.periodicity_option(0)
  23 + assert_equal "1 day", @helper.periodicity_option(1)
  24 + assert_equal "2 days", @helper.periodicity_option(2)
  25 + assert_equal "Weekly", @helper.periodicity_option(7)
  26 + assert_equal "Biweekly", @helper.periodicity_option(15)
  27 + assert_equal "Monthly", @helper.periodicity_option(30)
  28 + end
  29 +
  30 + should 'create the license options array' do
  31 + options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yml")
  32 + options = options.split(";")
  33 + assert_equal options, @helper.license_options
14 34 end
15 35  
16   - should 'format metric name for module result' do
17   - metric_result = MetricResultFixtures.native_metric_result
18   - assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result)
  36 + should 'generate chart from metric result history' do
  37 + chart = "http://chart.apis.google.com/chart?chxt=y,x&chco=c4a000&chf=bg,ls,90,efefef,0.2,ffffff,0.2&chd=s:A9&chl=2011-10-20T18%3A26%3A43%2B00%3A00|2011-10-25T18%3A26%3A43%2B00%3A00&cht=lc&chs=600x180&chxr=0,0.0,5.0"
  38 + metric_history = DateMetricResultFixtures.score_history
  39 +
  40 + assert_equal chart, @helper.generate_chart(metric_history)
  41 + end
  42 +
  43 + should 'format time to show a sentence' do
  44 + assert_equal 'less than 5 seconds', @helper.format_time(0)
  45 + assert_equal 'less than 5 seconds', @helper.format_time(4999)
  46 + assert_equal 'less than 10 seconds', @helper.format_time(5000)
  47 + assert_equal '1 minute', @helper.format_time(70000)
  48 + assert_equal 'about 2 hours', @helper.format_time(7000000)
  49 + end
  50 +
  51 + should 'format metric name for metric configuration snapshot' do
  52 + metric_configuration_snapshot = MetricConfigurationSnapshotFixtures.metric_configuration_snapshot
  53 + assert_equal 'AverageMethodLOC', @helper.format_name(metric_configuration_snapshot)
  54 + end
  55 +
  56 + should 'create aggregation options array' do
  57 + assert_equal [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
  58 + ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]], @helper.aggregation_options
  59 + end
  60 +
  61 + should 'create scope options' do
  62 + assert_equal [["Software", "SOFTWARE"], ["Package", "PACKAGE"], ["Class", "CLASS"], ["Method", "METHOD"]], @helper.scope_options
19 63 end
  64 +
20 65 end
... ...
plugins/mezuro/test/unit/mezuro_plugin/helpers/module_result_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +require "test_helper"
  2 +
  3 +class ModuleResultHelperTest < ActiveSupport::TestCase
  4 +
  5 + should 'return last module name when receive a string' do
  6 + name = 'Class'
  7 + assert_equal name, MezuroPlugin::Helpers::ModuleResultHelper.module_name(name)
  8 + end
  9 +
  10 + should 'return last module name when receive an array of strings' do
  11 + name = ['Class', 'Module']
  12 + assert_equal name.last, MezuroPlugin::Helpers::ModuleResultHelper.module_name(name)
  13 + end
  14 +
  15 +end
... ...
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
1 1 require "test_helper"
2 2  
3 3 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures"
4   -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_content_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/processing_fixtures"
5 6 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures"
6 7 require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures"
  8 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/date_metric_result_fixtures"
7 9  
8 10 class ProjectContentTest < ActiveSupport::TestCase
9 11  
10 12 def setup
  13 + @project_content = ProjectContentFixtures.project_content
11 14 @project = ProjectFixtures.project
12   - @content = ProjectFixtures.project_content
13   - @project_result = ProjectResultFixtures.project_result
  15 + @repository = RepositoryFixtures.repository
  16 + @processing = ProcessingFixtures.processing
  17 + @date = @processing.date
14 18 @module = ModuleFixtures.module
15 19 @module_result = ModuleResultFixtures.module_result
  20 + @date_metric_result = DateMetricResultFixtures.date_metric_result
16 21 end
17 22  
18 23 should 'provide proper short description' do
... ... @@ -24,98 +29,31 @@ class ProjectContentTest &lt; ActiveSupport::TestCase
24 29 end
25 30  
26 31 should 'have an html view' do
27   - assert_not_nil @content.to_html
  32 + assert_not_nil @project_content.to_html
28 33 end
29 34  
30 35 should 'get project from service' do
31   - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
32   - assert_equal @project.name, @content.project.name
  36 + Kalibro::Project.expects(:find).with(@project.id).returns(@project)
  37 + assert_equal @project, @project_content.project
33 38 end
34 39  
35   - should 'get project result from service' do
36   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})
37   - assert_equal @project_result.load_time, @content.project_result.load_time
38   - end
39   -
40   - should 'get date result from service when has_result_before is true' do
41   - request_body = {:project_name => @project.name, :date => @project_result.date}
42   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true})
43   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash})
44   - assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time
45   - end
46   -
47   - should 'get date result from service when has_result_before is false' do
48   - request_body = {:project_name => @project.name, :date => @project_result.date}
49   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false})
50   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash})
51   - assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time
52   - end
53   -
54   - should 'get module result from service without date' do
55   - date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date)
56   - Kalibro::ProjectResult.expects(:request).with('ProjectResult', :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash})
57   - Kalibro::ModuleResult.expects(:request).with(
58   - 'ModuleResult',
59   - :get_module_result,
60   - {
61   - :project_name => @project.name,
62   - :module_name => @module.name,
63   - :date => date_with_milliseconds
64   - }).returns({:module_result => @module_result.to_hash})
65   - assert_equal @module_result.grade, @content.module_result({:module_name => @module.name}).grade
66   - end
67   -
68   - should 'get module result from service with date' do
69   - date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date)
70   - request_body = {:project_name => @project.name, :date => @project_result.date}
71   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false})
72   - Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash})
73   - Kalibro::ModuleResult.expects(:request).with(
74   - 'ModuleResult',
75   - :get_module_result,
76   - {
77   - :project_name => @project.name,
78   - :module_name => @module.name,
79   - :date => date_with_milliseconds
80   - }).returns({:module_result => @module_result.to_hash})
81   - assert_equal @module_result.grade, @content.module_result({:module_name => @module.name, :date => @project_result.date}).grade
  40 + should 'add error to base when the project does not exist' do
  41 + Kalibro::Project.expects(:find).with(@project.id).raises(Kalibro::Errors::RecordNotFound)
  42 + assert_nil @project_content.errors[:base]
  43 + @project_content.project
  44 + assert_not_nil @project_content.errors[:base]
82 45 end
83 46  
84   - should 'get result history' do
85   - Kalibro::ModuleResult.expects(:request).with(
86   - 'ModuleResult',
87   - :get_result_history,
88   - {
89   - :project_name => @project.name,
90   - :module_name => @module.name
91   - }).returns({:module_result => @module_result.to_hash})
92   - @content.result_history(@module.name)
  47 + should 'get repositories of the project from service' do
  48 + Kalibro::Repository.expects(:repositories_of).with(@project.id).returns([@repository])
  49 + assert_equal [@repository], @project_content.repositories
93 50 end
94   -
95   - should 'send project to service after saving' do
96   - @content.expects :send_project_to_service
97   - @content.run_callbacks :after_save
98   - end
99   -
100   - should 'send correct project to service' do
101   - hash = ProjectFixtures.project_hash
102   - hash.delete(:attributes!)
103   - hash.delete(:state)
104   - Kalibro::Project.expects(:create).with(hash).returns(@project)
105   - @project.expects(:process_project).with(@content.periodicity_in_days)
106   - @content.send :send_project_to_service
  51 +
  52 + should 'add error to base when getting the repositories of a project that does not exist' do
  53 + Kalibro::Repository.expects(:repositories_of).with(@project.id).raises(Kalibro::Errors::RecordNotFound)
  54 + assert_nil @project_content.errors[:base]
  55 + @project_content.repositories
  56 + assert_not_nil @project_content.errors[:base]
107 57 end
108 58  
109   - should 'destroy project from service' do
110   - Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
111   - Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name})
112   - @content.send :destroy_project_from_service
113   - end
114   -
115   - should 'not save a project with an existing project name in kalibro' do
116   - Kalibro::Project.expects(:all_names).returns([@content.name])
117   - @content.send :validate_kalibro_project_name
118   - assert_equal "Project name already exists in Kalibro", @content.errors.on_base
119   - end
120   -
121 59 end
... ...
plugins/mezuro/test/unit/mezuro_plugin/reading_group_content_test.rb 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +require "test_helper"
  2 +
  3 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_group_fixtures"
  4 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_fixtures"
  5 +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/reading_group_content_fixtures"
  6 +
  7 +class ReadingGroupContentTest < ActiveSupport::TestCase
  8 +
  9 + def setup
  10 + @reading_group_content = ReadingGroupContentFixtures.reading_group_content
  11 + @reading_group = ReadingGroupFixtures.reading_group
  12 + @reading = ReadingFixtures.reading
  13 + end
  14 +
  15 + should 'provide proper short description' do
  16 + assert_equal 'Mezuro reading group', MezuroPlugin::ReadingGroupContent.short_description
  17 + end
  18 +
  19 + should 'provide proper description' do
  20 + assert_equal 'Set of thresholds to interpret metric results', MezuroPlugin::ReadingGroupContent.description
  21 + end
  22 +
  23 + should 'have an html view' do
  24 + assert_not_nil @reading_group_content.to_html
  25 + end
  26 +
  27 + should 'get reading_group from service' do
  28 + Kalibro::ReadingGroup.expects(:find).with(@reading_group.id).returns(@reading_group)
  29 + assert_equal @reading_group, @reading_group_content.reading_group
  30 + end
  31 +
  32 + should 'add error to base when the reading_group does not exist' do
  33 + Kalibro::ReadingGroup.expects(:find).with(@reading_group.id).raises(Kalibro::Errors::RecordNotFound)
  34 + assert_nil @reading_group_content.errors[:base]
  35 + @reading_group_content.reading_group
  36 + assert_not_nil @reading_group_content.errors[:base]
  37 + end
  38 +
  39 + should 'get readings of the reading_group from service' do
  40 + Kalibro::Reading.expects(:readings_of).with(@reading_group.id).returns([@reading])
  41 + assert_equal [@reading], @reading_group_content.readings
  42 + end
  43 +
  44 + should 'add error to base when getting the readings of a reading_group that does not exist' do
  45 + Kalibro::Reading.expects(:readings_of).with(@reading_group.id).raises(Kalibro::Errors::RecordNotFound)
  46 + assert_nil @reading_group_content.errors[:base]
  47 + @reading_group_content.readings
  48 + assert_not_nil @reading_group_content.errors[:base]
  49 + end
  50 +
  51 +end
... ...
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
... ... @@ -2,27 +2,18 @@
2 2  
3 3 <%
4 4 kalibro_configuration = @article.title.nil? ? nil : @article.kalibro_configuration
5   - kalibro_configuration_names = @article.kalibro_configuration_names
  5 + configuration_names_and_ids = @article.configuration_names_and_ids
6 6 %>
7 7  
8 8 <%= error_messages_for 'kalibro_configuration' %>
9 9  
10   -<%= hidden_field_tag 'kalibro_configuration[profile_id]', profile.id %>
11   -<%= hidden_field_tag 'id', @article.id %>
12 10  
13   -
14   -<% selected = (kalibro_configuration.nil? ? "None" : @article.configuration_to_clone_name) %>
  11 +<%= hidden_field_tag 'configuration_content[profile_id]', profile.id %>
  12 +<%= hidden_field_tag 'configuration_id', @article.configuration_id %>
  13 +<%= render :partial => "cms/mezuro_plugin/mezuro_content_form", :locals => {:f => f} %>
15 14  
16   -<%= required_fields_message %>
17   -
18   -<%= required labelled_form_field _('Clone Configuration'),
19   -if !kalibro_configuration.nil? && !@article.id.nil?
20   - f.select(:configuration_to_clone_name, kalibro_configuration_names, {:selected => selected}, :disabled => 'true')
21   -else
22   - f.select(:configuration_to_clone_name, kalibro_configuration_names, {:selected => selected})
23   -end %>
24 15 <br/>
25   -
26   -<%= required f.text_field(:name, :disabled => !(kalibro_configuration.nil? || @article.id.nil?)) %>
27   -
28   -<%= f.text_field :description %><br/>
  16 +<%= if kalibro_configuration.nil?
  17 + required labelled_form_field _('Clone Configuration'),
  18 + f.select(:configuration_to_clone_id, configuration_names_and_ids)
  19 +end %>
... ...
plugins/mezuro/views/cms/mezuro_plugin/_mezuro_content_form.html.erb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +<%= hidden_field_tag 'id', @article.id %>
  2 +<%= required_fields_message %>
  3 +<%= required f.text_field(:name) %>
  4 +<%= f.text_field :description %><br/>
... ...
plugins/mezuro/views/cms/mezuro_plugin/_project_content.html.erb
... ... @@ -2,50 +2,10 @@
2 2  
3 3 <%
4 4 @project = @article.title.nil? ? nil : @article.project
5   - begin
6   - @repository_types = Kalibro::Repository.repository_types.sort
7   - @configuration_names = Kalibro::Configuration.all_names.sort
8   - rescue Exception => exception
9   - @article.errors.add_to_base(exception.message)
10   - @repository_types = []
11   - @configuration_names = []
12   - end
13 5 %>
14 6  
15 7 <%= error_messages_for 'project_content' %>
16 8  
17 9 <%= hidden_field_tag 'project_content[profile_id]', profile.id %>
18   -<%= hidden_field_tag 'id', @article.id %>
19   -
20   -<%= required_fields_message %>
21   -<% if !@project.nil? && !@article.id.nil? %>
22   - <%= required f.text_field(:name, :disabled => 'true') %>
23   -<% else %>
24   - <%= required f.text_field(:name) %>
25   -<% end %>
26   -
27   -<% selected = (@project.nil? ? "" : @project.license) %>
28   -<%= required labelled_form_field _('License'),
29   - f.select(:project_license, MezuroPlugin::Helpers::ContentViewerHelper.create_license_options ,{:selected => selected}) %><br/>
30   -
31   -<%= f.text_field :description %><br/>
32   -
33   -<% @selected = (@project.nil? ? @repository_types : @project.repository.type) %>
34   -<%= required labelled_form_field _('Repository type'),
35   - f.select(:repository_type, @repository_types, {:selected => @selected}) %><br/>
36   -
37   -<%= required f.text_field(:repository_url) %><br/>
38   -
39   -<% @selected = (@project.nil? ? @configuration_names[0] : @project.configuration_name) %>
40   -
41   -<% if !@project.nil? && !@article.id.nil? %>
42   - <%= required labelled_form_field _('Configuration') + " (Changing the configuration will erase your saved periodic avaliations)",
43   - f.select(:configuration_name, @configuration_names, {:selected => @selected}) %>
44   -<% else %>
45   - <%= required labelled_form_field _('Configuration'),
46   - f.select(:configuration_name, @configuration_names, {:selected => @selected}) %><br/>
47   -<% end %>
48   -
49   -<% selected = (@project.nil? ? 0 : @project.process_period.to_i) %>
50   -<%= required labelled_form_field _('Periodic Avaliation'),
51   - f.select(:periodicity_in_days, MezuroPlugin::Helpers::ContentViewerHelper.create_periodicity_options ,{:selected => selected}) %><br/>
  10 +<%= hidden_field_tag 'project_id', @article.project_id %>
  11 +<%= render :partial => "cms/mezuro_plugin/mezuro_content_form", :locals => {:f => f} %>
... ...
plugins/mezuro/views/cms/mezuro_plugin/_reading_group_content.html.erb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +<h1> <%= _(MezuroPlugin::ReadingGroupContent.short_description) %> </h1>
  2 +
  3 +<%
  4 + reading_group = @article.title.nil? ? nil : @article.reading_group
  5 +%>
  6 +
  7 +<%= error_messages_for 'reading_group_content' %>
  8 +
  9 +<%= hidden_field_tag 'reading_group_content[profile_id]', profile.id %>
  10 +<%= hidden_field_tag 'reading_group_id', (reading_group.id unless reading_group.nil?) %>
  11 +<%= render :partial => "cms/mezuro_plugin/mezuro_content_form", :locals => {:f => f} %>
... ...
plugins/mezuro/views/content_viewer/_metric_configuration_form.rhtml
... ... @@ -1,41 +0,0 @@
1   -<% form_for :metric_configuration, :url => {:action =>"update_metric_configuration", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
2   - <%= hidden_field_tag :id, @configuration_content.id %>
3   - <%= f.hidden_field :configuration_name, :value => @configuration_content.name %>
4   -
5   - <% f.fields_for :metric do |m| %>
6   -
7   - <% @metric.language.each do |language| %>
8   - <%= m.hidden_field :language, :multiple => true, :value => language %>
9   - <% end %>
10   -
11   - <%= m.hidden_field "scope", :value => @metric.scope %>
12   - <p>
13   - <b><%= m.label :origin, "Collector Name:" %></b>
14   - <%= @metric.origin %>
15   - <%= m.hidden_field "origin", :value => @metric.origin %>
16   - </p>
17   - <p>
18   - <b><%= m.label :metric_name, "Metric Name:" %></b>
19   - <%= @metric.name %>
20   - <%= m.hidden_field "name", :value => @metric.name %>
21   - </p>
22   - <% end %>
23   - <p>
24   - <b><%= f.label :code, "Code:" %></b>
25   - <%= @metric_configuration.code %>
26   - <%= f.hidden_field "code", :value => @metric_configuration.code %>
27   - </p>
28   - <p>
29   - <b><%= f.label :aggregation_form, "Aggregation Form:" %></b>
30   - <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
31   - ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %>
32   - </p>
33   - <p>
34   - <b><%= f.label :weight, "Weight:" %></b>
35   - <%= f.text_field "weight", :value => @metric_configuration.weight %>
36   - </p>
37   -
38   - <p>
39   - <%= f.submit "Save" %>
40   - </p>
41   -<% end %>
plugins/mezuro/views/content_viewer/_metric_configuration_view.rhtml
... ... @@ -1,15 +0,0 @@
1   -<p>
2   - <b>Collector Name:</b> <%= @metric.origin %>
3   -</p>
4   -<p>
5   - <b>Metric Name:</b> <%= @metric.name %>
6   -</p>
7   -<p>
8   - <b>Code:</b> <%= @metric_configuration.code %>
9   -</p>
10   -<p>
11   - <b>Aggregation Form:</b> <%= @metric_configuration.aggregation_form %>
12   -</p>
13   -<p>
14   - <b>Weight:</b> <%= @metric_configuration.weight %>
15   -</p>
plugins/mezuro/views/content_viewer/show_configuration.rhtml
1 1 <% @configuration_content = @page
2 2 @kalibro_configuration = @page.kalibro_configuration %>
  3 +<!-- #TODO check owner verification to remove or edit metric configuration -->
3 4 <% owner = (not user.nil?) && user.id == @profile.id %>
4   -
5 5 <% unless @page.errors[:base].nil? %>
6   - <% if @page.errors[:base] =~ /There is no configuration named/ %>
  6 + <% if @page.errors[:base] =~ /Kalibro::Errors::RecordNotFound/ %>
7 7 <h3>Warning:</h3>
8 8 <p>This Configuration doesn't exist on the Web Service.</p>
9 9 <% if owner %>
... ... @@ -28,7 +28,7 @@
28 28 <br/>
29 29  
30 30 <% if owner %>
31   - <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_base_tool",
  31 + <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_metric_configuration",
32 32 :profile => @page.profile.identifier,
33 33 :action => "choose_metric",
34 34 :id => @configuration_content.id %><br/>
... ... @@ -39,30 +39,36 @@
39 39 <td><h5>Metric Name</h5></td>
40 40 <td><h5>Collector Name</h5></td>
41 41 <td><h5>Metric Code</h5></td>
  42 + <td><h5>Weight</h5></td>
  43 + <td><h5>Aggregation Form</h5></td>
42 44 <td/>
43 45 </tr>
44   - <% @kalibro_configuration.metric_configurations.each do |metric_configuration| %>
  46 + <% @configuration_content.metric_configurations.each do |metric_configuration| %>
45 47 <tr class="metric">
46   - <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %>
47   - <td><%= link_to metric_configuration.metric.name, :controller => "mezuro_plugin_metric_configuration", :action => "edit_metric_configuration",
48   - :metric_name => metric_configuration.metric.name, :id => @configuration_content.id,
  48 + <% if metric_configuration.metric.compound
  49 + edit_action = "edit_compound"
  50 + else
  51 + edit_action = "edit_native"
  52 + end
  53 + %>
  54 + <td><%= link_to metric_configuration.metric.name, :controller => "mezuro_plugin_metric_configuration", :action => edit_action,
  55 + :metric_configuration_id => metric_configuration.id, :id => @configuration_content.id,
49 56 :profile => @page.profile.identifier %></td>
  57 + <% if metric_configuration.metric.compound %>
50 58 <td>
51   - <%= metric_configuration.metric.origin %>
  59 + Compound Metric
52 60 </td>
53   - <td><%= metric_configuration.code %></td>
54 61 <% else %>
55   - <td><%= link_to metric_configuration.metric.name, :controller => "mezuro_plugin_metric_configuration",
56   - :action => "edit_compound_metric_configuration", :metric_name => metric_configuration.metric.name,
57   - :id => @configuration_content.id, :profile => @page.profile.identifier %></td>
58 62 <td>
59   - Compound Metric
  63 + <%= metric_configuration.base_tool_name %>
60 64 </td>
61   - <td><%= metric_configuration.code %></td>
62 65 <% end %>
  66 + <td><%= metric_configuration.code %></td>
  67 + <td><%= metric_configuration.weight %></td>
  68 + <td><%= metric_configuration.aggregation_form %></td>
63 69 <% if owner %>
64   - <td><%= link_to "Remove", :controller => "mezuro_plugin_metric_configuration", :action => "remove_metric_configuration",
65   - :metric_name => metric_configuration.metric.name, :id => @configuration_content.id,
  70 + <td><%= link_to "Remove", :controller => "mezuro_plugin_metric_configuration", :action => "remove",
  71 + :metric_configuration_id => metric_configuration.id, :id => @configuration_content.id,
66 72 :profile => @page.profile.identifier %></td>
67 73 <% end %>
68 74 </tr>
... ...
plugins/mezuro/views/content_viewer/show_project.rhtml
1   -<script src="/plugins/mezuro/javascripts/project_content.js" type="text/javascript"></script>
2   -
3 1 <% @project = @page.project %>
4 2 <% unless @page.errors[:base].nil? %>
5   - <% if @page.errors[:base] =~ /There is no project named/ %>
  3 +<!-- #TODO add owner verification to remove or edit repository -->
  4 + <% if @page.errors[:base] == "Kalibro::Errors::RecordNotFound" %>
6 5 <h3>Warning:</h3>
7 6 <p>This project doesn't exist on the Web Service. Do you want to <%= link_to 'delete', :action => 'destroy', :controller => 'cms', :profile => @page.profile.identifier, :id => @page.id %> or <%= link_to 'save it again', :action => 'edit', :controller => 'cms', :profile => @page.profile.identifier, :id => @page.id %>?</p>
8 7 <% else %>
... ... @@ -16,44 +15,38 @@
16 15 <td><%= @project.name %></td>
17 16 </tr>
18 17 <tr>
19   - <td><%= _('License') %></td>
20   - <td><%= @project.license %></td>
21   - </tr>
22   - <tr>
23 18 <td><%= _('Description') %></td>
24 19 <td><%= @project.description %></td>
25 20 </tr>
  21 + </table>
  22 + <br/>
  23 + <h5><%= _('Repositories') %></h5>
  24 + <table>
  25 + <% @page.repositories.each do |repository| %>
26 26 <tr>
27   - <td><%= _('Repository type') %></td>
28   - <td><%= @project.repository.type %></td>
29   - </tr>
30   - <tr>
31   - <td><%= _('Repository address') %></td>
32   - <td><%= @project.repository.address %></td>
33   - </tr>
34   - <tr>
35   - <td><%= _('Configuration') %></td>
36   - <td><%= @project.configuration_name %></td>
37   - </tr>
38   - <tr>
39   - <td><%= _('Periodicity') %></td>
40   - <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td>
41   - </tr>
42   - <tr>
43   - <td><%= _('Status')%></td>
44   - <td>
45   - <div id="project-state" style="color:DarkGoldenRod"><%= @project.state %></div>
46   - <div id="msg-time"></div>
47   - </td>
48   - </tr>
  27 + <td><%= link_to repository.name, :controller => "mezuro_plugin_repository",
  28 + :profile => @page.profile.identifier,
  29 + :action => "show",
  30 + :id => @page.id,
  31 + :repository_id => repository.id %></td>
  32 + <td ><%= link_to _('Edit'), {:controller => "mezuro_plugin_repository",
  33 + :profile => @page.profile.identifier,
  34 + :action => "edit",
  35 + :id => @page.id,
  36 + :repository_id => repository.id}, :class=>"button with-text icon-edit" %></td>
  37 + <td ><%= link_to _('Remove'), {:controller => "mezuro_plugin_repository",
  38 + :profile => @page.profile.identifier,
  39 + :action => "destroy",
  40 + :id => @page.id,
  41 + :repository_id => repository.id}, :class=>"button with-text icon-delete" %></td>
  42 + </tr>
  43 + <% end %>
49 44 </table>
  45 +
  46 + <br>
  47 + <%= link_to "#{image_tag('/plugins/mezuro/images/plus.png')}Add Repository", :controller => "mezuro_plugin_repository",
  48 + :profile => @page.profile.identifier,
  49 + :action => "new",
  50 + :id => @page.id %><br/>
50 51  
51   - <br />
52   -
53   - <div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>"
54   - data-project-name="<%= @project.name %>">
55   - </div>
56   - <div id="project-tree"></div>
57   - <div id="module-result">
58   - </div>
59 52 <% end %>
... ...
plugins/mezuro/views/content_viewer/show_reading_group.rhtml 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +<% @reading_group = @page.reading_group %>
  2 +<!-- #TODO add owner verification to remove or edit reading group -->
  3 +<% unless @page.errors[:base].nil? %>
  4 + <% if @page.errors[:base] == "Kalibro::Errors::RecordNotFound" %>
  5 + <h3>Warning:</h3>
  6 + <p>This reading group doesn't exist on the Web Service. Do you want to <%= link_to 'delete', :action => 'destroy', :controller => 'cms', :profile => @page.profile.identifier, :id => @page.id %> or <%= link_to 'save it again', :action => 'edit', :controller => 'cms', :profile => @page.profile.identifier, :id => @page.id %>?</p>
  7 + <% else %>
  8 + <%= @page.errors[:base] %>
  9 + <% end %>
  10 +<% else %>
  11 +
  12 + <table>
  13 + <tr>
  14 + <td><%= _('Name') %></td>
  15 + <td><%= @reading_group.name %></td>
  16 + </tr>
  17 + <tr>
  18 + <td><%= _('Description') %></td>
  19 + <td><%= @reading_group.description %></td>
  20 + </tr>
  21 + </table>
  22 + <br/>
  23 + <h5><%= _('Readings') %></h5>
  24 + <table>
  25 + <% @page.readings.each do |reading| %>
  26 + <tr>
  27 + <td><%= link_to reading.label, :controller => "mezuro_plugin_reading",
  28 + :profile => @page.profile.identifier,
  29 + :action => "edit",
  30 + :id => @page.id,
  31 + :reading_id => reading.id %></td>
  32 + <td><%= reading.grade %></td>
  33 + <td bgcolor="#<%= reading.color %>"></td>
  34 + <td ><%= link_to _('Remove'), {:controller => "mezuro_plugin_reading",
  35 + :profile => @page.profile.identifier,
  36 + :action => "destroy",
  37 + :id => @page.id,
  38 + :reading_id => reading.id}, :class=>"button with-text icon-delete" %></td>
  39 + </tr>
  40 + <% end %>
  41 + </table>
  42 +
  43 + <br/>
  44 + <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Reading", :controller => "mezuro_plugin_reading",
  45 + :profile => @page.profile.identifier,
  46 + :action => "new",
  47 + :id => @page.id %><br/>
  48 +
  49 +<% end %>
... ...
plugins/mezuro/views/mezuro_plugin_base_tool/_error_page.html.erb
... ... @@ -1,2 +0,0 @@
1   -<h2> An error occured: </h2>
2   -<%= @message %>
plugins/mezuro/views/mezuro_plugin_base_tool/choose_metric.html.erb
... ... @@ -1,18 +0,0 @@
1   -<h2><%= @configuration_content.name%> Configuration</h2>
2   -
3   -<%= link_to "New Compound Metric", :controller => "mezuro_plugin_metric_configuration", :action => "new_compound_metric_configuration",
4   - :id => @configuration_content.id %>
5   -
6   -<h5>Base Tools:</h5>
7   -<% @base_tools.each do |base_tool| %>
8   - <h4><%= link_to base_tool.name, "#", :onclick => "jQuery(\"\##{base_tool.name}\").toggle();"%></h4>
9   - <hr/>
10   -
11   - <div id="<%=base_tool.name%>" style="display:none">
12   - <% base_tool.supported_metrics.each do |metric| %>
13   - &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<%= link_to metric.name, :controller => "mezuro_plugin_metric_configuration", :action => "new_metric_configuration",
14   - :metric_name => metric.name, :base_tool => base_tool.name, :id => @configuration_content.id %>
15   - <hr size="1" width="93%"/>
16   - <% end %>
17   - </div>
18   -<% end %>
plugins/mezuro/views/mezuro_plugin_metric_configuration/_compound_metric_configuration_form.html.erb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +<%= hidden_field_tag :id, @configuration_content.id %>
  2 +<%= f.hidden_field :configuration_id, :value => @configuration_content.configuration_id %>
  3 +
  4 +<% f.fields_for :metric do |m| %>
  5 + <%= m.hidden_field :compound, :value => "true" %>
  6 + <%= required labelled_form_field _('Metric Name:'), m.text_field(:name, :value => @metric_configuration.metric.name) %>
  7 + <%= labelled_form_field _('Description:'), m.text_field(:description, :value => @metric_configuration.metric.description) %>
  8 + <%= required labelled_form_field _('Script:'), m.text_area(:script, :rows => 5, :value => @metric_configuration.metric.script) %>
  9 + <%= required labelled_form_field _('Scope:'),
  10 + m.select(:scope, MezuroPlugin::Helpers::ContentViewerHelper.scope_options, :selected => @metric_configuration.metric.scope) %>
  11 +<% end %>
  12 +
  13 +<%= required labelled_form_field _('Code:'), f.text_field(:code) %>
  14 +<%= required labelled_form_field _('Aggregation Form:'),
  15 + f.select(:aggregation_form, MezuroPlugin::Helpers::ContentViewerHelper.aggregation_options) %>
  16 +<%= required labelled_form_field _('Weight:'), f.text_field(:weight) %>
  17 +<%= required labelled_form_field _('Reading Group:'), f.select(:reading_group_id, @reading_group_names_and_ids) %>
  18 +
  19 +<p><%= f.submit "Save" %></p>
... ...
plugins/mezuro/views/mezuro_plugin_metric_configuration/_native_metric_configuration_form.rhtml 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +<%= hidden_field_tag :id, @configuration_content.id %>
  2 +<%= f.hidden_field :configuration_id, :value => @configuration_content.configuration_id %>
  3 +
  4 +<%= labelled_form_field _('Collector Name:'), f.text_field(:base_tool_name, :readonly => true) %>
  5 +
  6 +<% f.fields_for :metric do |m| %>
  7 + <%= m.hidden_field :compound, :value => "false" %>
  8 + <% @metric_configuration.metric.language.each do |language| %>
  9 + <%= m.hidden_field :language, :multiple => true, :value => language %>
  10 + <% end %>
  11 + <%= m.hidden_field "scope", :value => @metric.scope %>
  12 + <%= required labelled_form_field _('Metric Name:'), m.text_field(:name, :readonly => true, :value => @metric.name) %>
  13 + <%= labelled_form_field _('Description:'), m.text_field(:description, :readonly => true, :value => @metric.description) %>
  14 +<% end %>
  15 +
  16 +<%= required labelled_form_field _('Code:'), f.text_field(:code) %>
  17 +
  18 +<%= required labelled_form_field _('Aggregation Form:'),
  19 +f.select(:aggregation_form, MezuroPlugin::Helpers::ContentViewerHelper.aggregation_options) %>
  20 +
  21 +<%= required labelled_form_field _('Weight:'), f.text_field(:weight) %>
  22 +
  23 +<%= required labelled_form_field _('Reading Group:'),
  24 +f.select(:reading_group_id, @reading_group_names_and_ids) %>
  25 +
  26 +<p><%= f.submit "Save" %></p>
... ...
plugins/mezuro/views/mezuro_plugin_metric_configuration/_native_metric_configuration_view.rhtml 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<p>
  2 + <b>Collector Name:</b> <%= @metric_configuration.base_tool_name %>
  3 +</p>
  4 +<p>
  5 + <b>Metric Name:</b> <%= @metric.name %>
  6 +</p>
  7 +<p>
  8 + <b>Code:</b> <%= @metric_configuration.code %>
  9 +</p>
  10 +<p>
  11 + <b>Aggregation Form:</b> <%= @metric_configuration.aggregation_form %>
  12 +</p>
  13 +<p>
  14 + <b>Weight:</b> <%= @metric_configuration.weight %>
  15 +</p>
... ...
plugins/mezuro/views/mezuro_plugin_metric_configuration/choose_metric.html.erb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +<h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2>
  2 +
  3 +<%= link_to "New Compound Metric", :controller => "mezuro_plugin_metric_configuration", :action => "new_compound",
  4 + :id => @configuration_content.id %>
  5 +
  6 +<h5>Base Tools:</h5>
  7 +<% @base_tools.each do |base_tool| %>
  8 + <h4><%= link_to base_tool.name, "#", :onclick => "jQuery(\"\##{base_tool.name}\").toggle();"%></h4>
  9 + <hr/>
  10 +
  11 + <div id="<%=base_tool.name%>" style="display:none">
  12 + <% base_tool.supported_metrics.each do |metric| %>
  13 + &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<%= link_to metric.name, :controller => "mezuro_plugin_metric_configuration", :action => "new_native",
  14 + :metric_name => metric.name, :base_tool_name => base_tool.name, :id => @configuration_content.id %>
  15 + <hr size="1" width="93%"/>
  16 + <% end %>
  17 + </div>
  18 +<% end %>
... ...
plugins/mezuro/views/mezuro_plugin_metric_configuration/edit_compound.html.erb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
  2 +<script src="/javascripts/colorpicker.js" type="text/javascript"></script>
  3 +<script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script>
  4 +
  5 +<h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2>
  6 +
  7 +<% owner = (not user.nil?) && user.id == @profile.id %>
  8 +
  9 +<% form_for :metric_configuration, :url => {:action =>"update", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
  10 + <%= f.hidden_field :id %>
  11 + <%= render :partial => "compound_metric_configuration_form", :locals => {:f => f} %>
  12 +<% end %>
  13 +
  14 +<%= render :partial => "mezuro_plugin_range/ranges", :locals => {:owner => owner} %>
  15 +<hr>
  16 +<%= render :partial => "metric_codes", :locals => {:metric_configurations => @metric_configurations} %>
... ...
plugins/mezuro/views/mezuro_plugin_metric_configuration/edit_compound_metric_configuration.html.erb
... ... @@ -1,81 +0,0 @@
1   -<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
2   -<script src="/javascripts/colorpicker.js" type="text/javascript"></script>
3   -<script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script>
4   -
5   -<h2><%= @configuration_content.name %> Configuration</h2>
6   -
7   -<% form_for :metric_configuration, :url => {:action =>"update_compound_metric_configuration", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
8   - <%= hidden_field_tag :id, @configuration_content.id %>
9   - <%= f.hidden_field :configuration_name, :value => @configuration_content.name %>
10   -
11   - <p>
12   - <%= "Metric Name:" + @metric.name %>
13   - </p>
14   - <% f.fields_for :metric do |m| %>
15   - <%= m.hidden_field :name, :value => @metric.name %>
16   - <p>
17   - <%= m.label :description, "Description:" %>
18   - <%= m.text_field "description", :value => @metric.description %>
19   - </p>
20   - <p>
21   - <%= m.label :scope, "Scope:" %>
22   - <%= m.select :scope, [["Class", "CLASS"]], :selected => @metric.scope %>
23   - </p>
24   - <p>
25   - <%= m.label :script, "Script:" %>
26   - <%= m.text_area "script", :value => @metric.script, :rows => 5 %>
27   - </p>
28   - <% end %>
29   - <p>
30   - <%= f.label :code, "Code:" %>
31   - <%= f.text_field "code" %>
32   - </p>
33   - <p>
34   - <%= f.label :aggregation_form, "Aggregation Form:" %>
35   - <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
36   - ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %>
37   - </p>
38   - <p>
39   - <%= f.label :weight, "Weight:" %>
40   - <%= f.text_field :weight %>
41   - </p>
42   - <p>
43   - <%= f.submit "Save" %>
44   - </p>
45   -<% end %>
46   -
47   -
48   -<h5> Ranges </h5><br/>
49   -
50   -<table id="ranges">
51   - <tr>
52   - <td>
53   - Label
54   - </td>
55   - <td>
56   - Beginning
57   - </td>
58   - <td>
59   - End
60   - </td>
61   - <td>
62   - Grade
63   - </td>
64   - <td>
65   - Color
66   - </td>
67   - </tr>
68   - <% if (@metric_configuration.ranges!=nil)
69   - @metric_configuration.ranges.each do |range| %>
70   - <%= render :partial => "mezuro_plugin_range/range", :locals => {:range => range, :id => @configuration_content.id,
71   - :metric_name => @metric_configuration.metric.name} %>
72   - <% end
73   - end %>
74   -</table>
75   -
76   -<br/>
77   -<%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_range", :id => @configuration_content.id, :metric_name => @metric.name} %>
78   -<div id="range_form" style="display:none"></div>
79   -
80   -<br/>
81   -<%= render :partial => "metric_codes", :locals => {:metric_configurations => @metric_configurations} %>
plugins/mezuro/views/mezuro_plugin_metric_configuration/edit_metric_configuration.html.erb
... ... @@ -1,50 +0,0 @@
1   -<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
2   -<script src="/javascripts/colorpicker.js" type="text/javascript"></script>
3   -<script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script>
4   -
5   -<h2><%= @configuration_content.name %> Configuration</h2>
6   -
7   -<% owner = (not user.nil?) && user.id == @profile.id %>
8   -
9   -<% if owner %>
10   - <%= render :partial => "content_viewer/metric_configuration_form" %>
11   -<% else %>
12   - <%= render :partial => "content_viewer/metric_configuration_view" %>
13   -<% end %>
14   -
15   -<h5> Ranges </h5><br/>
16   -
17   -<table id="ranges">
18   - <tr>
19   - <td>
20   - Label
21   - </td>
22   - <td>
23   - Beginning
24   - </td>
25   - <td>
26   - End
27   - </td>
28   - <td>
29   - Grade
30   - </td>
31   - <td>
32   - Color
33   - </td>
34   - <td></td>
35   - <td></td>
36   - </tr>
37   - <% if (@metric_configuration.ranges!=nil)
38   - @metric_configuration.ranges.each do |range| %>
39   - <%= render :partial => "mezuro_plugin_range/range", :locals => {:range => range, :id => @configuration_content.id,
40   - :metric_name => @metric.name} %>
41   - <% end
42   - end %>
43   -</table>
44   -
45   -<br/>
46   -<% if owner %>
47   - <%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_range", :id => @configuration_content.id, :metric_name => @metric.name} %>
48   -<% end %>
49   -<div id="range_form" style="display:none"></div>
50   -
plugins/mezuro/views/mezuro_plugin_metric_configuration/edit_native.html.erb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
  2 +<script src="/javascripts/colorpicker.js" type="text/javascript"></script>
  3 +<script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script>
  4 +
  5 +<h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2>
  6 +
  7 +<% owner = (not user.nil?) && user.id == @profile.id %>
  8 +
  9 +<% if owner %>
  10 + <% form_for :metric_configuration, :url => {:action =>"update", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
  11 + <%= f.hidden_field :id %>
  12 + <%= render :partial => "native_metric_configuration_form", :locals => {:f => f} %>
  13 + <% end %>
  14 +<% else %>
  15 + <%= render :partial => "native_metric_configuration_view" %>
  16 +<% end %>
  17 +
  18 +<%= render :partial => "mezuro_plugin_range/ranges", :locals => {:owner => owner} %>
... ...
plugins/mezuro/views/mezuro_plugin_metric_configuration/new_compound.html.erb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2>
  2 +
  3 +<% form_for :metric_configuration, :url => {:action =>"create", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
  4 + <%= render :partial => "compound_metric_configuration_form", :locals => {:f => f} %>
  5 +<% end %>
  6 +
  7 +<%= render :partial => "metric_codes", :locals => {:metric_configurations => @metric_configurations} %>
... ...
plugins/mezuro/views/mezuro_plugin_metric_configuration/new_compound_metric_configuration.html.erb
... ... @@ -1,44 +0,0 @@
1   -<h2><%= @configuration_content.name %> Configuration</h2>
2   -
3   -<% form_for :metric_configuration, :url => {:action =>"create_compound_metric_configuration",
4   -:controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
5   - <%= hidden_field_tag :id, @configuration_content.id %>
6   - <%= f.hidden_field :configuration_name, :value => @configuration_content.name %>
7   -
8   - <% f.fields_for :metric do |m| %>
9   - <p>
10   - <%= m.label :name, "Name:" %>
11   - <%= m.text_field "name" %>
12   - </p>
13   - <p>
14   - <%= m.label :description, "Description:" %>
15   - <%= m.text_field "description" %>
16   - </p>
17   - <p>
18   - <%= m.label :scope, "Scope:" %>
19   - <%= m.select :scope, [["Class", "CLASS"]] %>
20   - </p>
21   - <p>
22   - <%= m.label :script, "Script:" %>
23   - <%= m.text_area "script", :rows => 5 %>
24   - </p>
25   - <% end %>
26   - <p>
27   - <%= f.label :code, "Code:" %>
28   - <%= f.text_field "code" %>
29   - </p>
30   - <p>
31   - <%= f.label :aggregation_form, "Aggregation Form:" %>
32   - <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
33   - ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %>
34   - </p>
35   - <p>
36   - <%= f.label :weight, "Weight:" %>
37   - <%= f.text_field :weight %>
38   - </p>
39   - <p>
40   - <%= f.submit "Add" %>
41   - </p>
42   -<% end %>
43   -
44   -<%= render :partial => "metric_codes", :locals => {:metric_configurations => @metric_configurations} %>
plugins/mezuro/views/mezuro_plugin_metric_configuration/new_metric_configuration.html.erb
... ... @@ -1,51 +0,0 @@
1   -<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
2   -
3   -<h2><%= @configuration_content.name %> Configuration</h2>
4   -
5   -<% form_for :metric_configuration, :url => {:action =>"create_metric_configuration", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
6   - <%= hidden_field_tag :id, @configuration_content.id %>
7   - <%= f.hidden_field :configuration_name, :value => @configuration_content.name %>
8   -
9   - <% f.fields_for :metric do |m| %>
10   -
11   - <% @metric.language.each do |language| %>
12   - <%= m.hidden_field :language, :multiple => true, :value => language %>
13   - <% end %>
14   -
15   - <%= m.hidden_field "scope", :value => @metric.scope %>
16   - <p>
17   - <%= m.label :origin, "Collector Name:" %>
18   - <%= @metric.origin %>
19   - <%= m.hidden_field "origin", :value => @metric.origin %>
20   - </p>
21   - <p>
22   - <%= m.label :name, "Metric Name:" %>
23   - <%= @metric.name %>
24   - <%= m.hidden_field "name", :value => @metric.name %>
25   - </p>
26   - <!--<p>-->
27   - <% m.label :description, "Description:" %>
28   - <% @metric.description %>
29   - <% m.hidden_field "description", :value => @metric.description %>
30   - <!--</p>-->
31   - <% end %>
32   - <p>
33   - <%= f.label :code, "Code:" %>
34   - <%= f.text_field :code %>
35   - </p>
36   - <p>
37   - <%= f.label :aggregation_form, "Aggregation Form:" %>
38   - <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
39   - ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %>
40   - </p>
41   - <p>
42   - <%= f.label :weight, "Weight:" %>
43   - <%= f.text_field :weight %>
44   - </p>
45   -
46   - <p>
47   - <%= f.submit "Add" %>
48   - </p>
49   -
50   -<% end %>
51   -
plugins/mezuro/views/mezuro_plugin_metric_configuration/new_native.html.erb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
  2 +
  3 +<h2><%= link_to("#{@configuration_content.name} Configuration", @configuration_content.view_url) %></h2>
  4 +
  5 +<% form_for :metric_configuration, :url => {:action =>"create", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
  6 + <%= render :partial => "native_metric_configuration_form", :locals => {:f => f} %>
  7 +<% end %>
... ...
plugins/mezuro/views/mezuro_plugin_module/_error_page.html.erb
... ... @@ -1,2 +0,0 @@
1   -<h2> An error occured: </h2>
2   -<%= @message %>
plugins/mezuro/views/mezuro_plugin_module/_module_result.rhtml
... ... @@ -1,56 +0,0 @@
1   -<h5><%= _('Metric results for: ') + @module_label %> </h5>
2   -
3   -<hr/>
4   -<div class="zoomable-image">
5   -<table style="width: 100%">
6   - <thead>
7   - <tr>
8   - <th style="width: 74%">Metric</th>
9   - <th>Value</th>
10   - <th>Weight</th>
11   - <th>Threshold</th>
12   - </tr>
13   - </thead>
14   - <tbody>
15   - <% @module_result.metric_results.each do |metric_result| %>
16   - <% range = metric_result.range %>
17   - <% if !range.nil? %>
18   - <tr>
19   - <td style="width: 74%"><a href="#" show-metric-history="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" data-module-name="<%= @module.name %>"><%= metric_result.metric.name %></a></td>
20   - <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>
21   - <td><%= metric_result.weight %></td>
22   - <td style="background-color: #<%= range.color[2..-1] %>">
23   - <span title="<%= range.comments %>" >
24   - <%= range.label %>
25   - </span>
26   - </td>
27   - </tr>
28   - <tr class="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" style="display: none;">
29   - <td colspan="3">
30   - <div id='historical-<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>'>
31   - </div>
32   - </td>
33   - <td align="right">
34   - <%= range.comments.nil? ? '' : range.comments %>
35   - </td>
36   - </tr>
37   - <% end %>
38   - <% end %>
39   - </tbody>
40   - <tfoot>
41   - <tr>
42   - <td colspan = "3">
43   - <div id='historical-grade' style="display: none;"></div>
44   - </td>
45   - <td align = "right">
46   - <a href="#" show-grade-history="<%= @module_result.module.name %>" data-module-name="<%= @module.name%>" >
47   - <strong>
48   - <%= _('Grade:') %>
49   - <%= "%.02f" % @module_result.grade %>
50   - </strong>
51   - </a>
52   - </td>
53   - </tr>
54   - </tfoot>
55   -</table>
56   -</div>
plugins/mezuro/views/mezuro_plugin_module/_score_history.rhtml
... ... @@ -1 +0,0 @@
1   -<%= image_tag(MezuroPlugin::Helpers::ContentViewerHelper.generate_chart(@score_history)) %>
plugins/mezuro/views/mezuro_plugin_module_result/_error_page.html.erb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +<h2> An error occured: </h2>
  2 +<%= @message %>
... ...
plugins/mezuro/views/mezuro_plugin_module_result/_metric_results.rhtml 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +<thead>
  2 + <tr>
  3 + <th style="width: 74%">Metric</th>
  4 + <th>Value</th>
  5 + <th>Weight</th>
  6 + <th>Threshold</th>
  7 + </tr>
  8 +</thead>
  9 +<tbody>
  10 + <% @metric_results.each do |metric_result| %>
  11 + <% metric_configuration_snapshot = metric_result.metric_configuration_snapshot%>
  12 + <% range_snapshots = metric_configuration_snapshot.range_snapshot %>
  13 + <% metric_name = metric_configuration_snapshot.metric.name %>
  14 + <% formatted_name = metric_name.delete("() ") %>
  15 + <% if !range_snapshots.nil? %>
  16 + <tr>
  17 + <td style="width: 74%"><a href="#" show-metric-history="<%= formatted_name %>" data-metric-name="<%= metric_name %>" data-module-id="<%= @module_result.id %>"><%= metric_name %></a></td>
  18 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>
  19 + <td><%= metric_configuration_snapshot.weight %></td>
  20 + <% range_snapshots.each do |range_snapshot| %>
  21 + <% if range_snapshot.beginning <= metric_result.value and range_snapshot.end > metric_result.value %>
  22 + <td style="background-color: #<%= range_snapshot.color %>">
  23 + <span title="<%= range_snapshot.comments %>" >
  24 + <%= range_snapshot.label %>
  25 + </span>
  26 + </td>
  27 + </tr>
  28 + <tr class="<%= formatted_name %>" style="display: none;">
  29 + <td colspan="3">
  30 + <div id='historical-<%= formatted_name %>'>
  31 + </div>
  32 + </td>
  33 + <td align="right">
  34 + <%= range_snapshot.comments.nil? ? '' : range_snapshot.comments %>
  35 + </td>
  36 + </tr>
  37 + <% end %>
  38 + <% end %>
  39 + <% end %>
  40 + <% end %>
  41 +</tbody>
... ...
plugins/mezuro/views/mezuro_plugin_module_result/_module_result.rhtml 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +<%= render :partial => "source_tree", :locals => {:module_result => @module_result} %>
  2 +<h5><%= _"Metric results for: #{MezuroPlugin::Helpers::ModuleResultHelper.module_name(@module_result.module.name)} (#{@module_result.module.granularity})" %> </h5>
  3 +
  4 +<hr/>
  5 +<div class="zoomable-image">
  6 +<table style="width: 100%">
  7 + <%= render :partial => "metric_results", :locals => {:metric_results => @metric_results, :module_result_id => @module_result.id} %>
  8 + <tfoot>
  9 + <tr>
  10 + <td colspan = "3">
  11 + <div id='historical-grade' style="display: none;"></div>
  12 + </td>
  13 + <td align = "right">
  14 + <a href="#" show-grade-history="<%= @module_result.id %>" data-module-id="<%= @module_result.id %>" >
  15 + <strong>
  16 + <%= _('Grade:') %>
  17 + <%= "%.02f" % @module_result.grade %>
  18 + </strong>
  19 + </a>
  20 + </td>
  21 + </tr>
  22 + </tfoot>
  23 +</table>
  24 +</div>
... ...
plugins/mezuro/views/mezuro_plugin_module_result/_score_history.rhtml 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= image_tag(MezuroPlugin::Helpers::ContentViewerHelper.generate_chart(@history)) %>
... ...
plugins/mezuro/views/mezuro_plugin_module_result/_source_tree.rhtml 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +<h4><%= _('Source tree') %></h4>
  2 +<% helper = MezuroPlugin::Helpers::ModuleResultHelper %>
  3 +<% module_name = helper.module_name(module_result.module.name) %>
  4 +<% module_label = "#{module_name} (#{module_result.module.granularity})" %>
  5 +
  6 +<p>
  7 + <h2 class="path">
  8 + <% module_result.parents.each do |parent| %>
  9 + /<a href="#" class="source-tree-link" data-module-id="<%= parent.id %>">
  10 + <%= helper.module_name parent.module.name %>
  11 + </a>
  12 + <% end %>/ <%= helper.module_name module_name %>
  13 + </h2>
  14 +</p>
  15 +
  16 +<table border="0" class="source-tree">
  17 + <% module_result.children.each do |child| %>
  18 + <% if child.module.granularity=='PACKAGE' %>
  19 + <tr>
  20 + <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td>
  21 + <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-id="<%= child.id %>"><%= helper.module_name child.module.name %></a></td>
  22 + </tr>
  23 + <% else %>
  24 + <tr>
  25 + <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td>
  26 + <td class="source-tree-text">
  27 + <a href='#' class="source-tree-link" data-module-id="<%= child.id %>">
  28 + <%= helper.module_name child.module.name %>
  29 + </a>
  30 + </td>
  31 + </tr>
  32 + <% end %>
  33 + <% end %>
  34 +</table>
... ...
plugins/mezuro/views/mezuro_plugin_processing/_error_page.html.erb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +<h2> An error occured: </h2>
  2 +<%= @processing.error.message %>
... ...
plugins/mezuro/views/mezuro_plugin_processing/_processing.rhtml 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +<div id="current_processing_date" data-date="<%= @processing.date %>"/>
  2 +
  3 +<h4><%= _('Last Result') %></h4>
  4 +
  5 +<table>
  6 + <tr>
  7 + <td><%= _('Date') %></td>
  8 + <td><%= @processing.date.inspect %></td>
  9 + </tr>
  10 + <% @processing.process_time.each do |process_time| %>
  11 + <tr>
  12 + <td><%= _(process_time.state + ' time') %></td>
  13 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_time(process_time.time) %></td>
  14 + </tr>
  15 + <% end %>
  16 + <tr>
  17 + <td>Click to choose specific date:</td>
  18 + <td><%= link_to(image_tag('/images/calendar_date_select/calendar.png', :width => 20, :height => 20, :onClick => "$( 'datepicker' ).toggle();"), "javascript:void(0)") %></td>
  19 + </tr>
  20 +</table>
  21 +
  22 +<div id="datepicker"></div>
  23 +
  24 +<script>
  25 + jQuery(document).ready(function($) {
  26 + $("#datepicker").datepicker({
  27 + onSelect: function(dateText, inst) {
  28 + reloadProcessingWithDate(dateText) } });
  29 + $("#datepicker").toggle();
  30 + var date = jQuery("#current_processing_date").attr('data-date').substr(0,10);
  31 + $("#datepicker").datepicker( "setDate" , date.substr(5,2)+"/"+date.substr(8,2)+"/"+date.substr(0,4));
  32 +
  33 + });
  34 +</script>
  35 +
  36 +<span id="module_result_root_id" module_result_root_id="<%= @processing.results_root_id %>">
... ...
plugins/mezuro/views/mezuro_plugin_processing/_processing_error.rhtml 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<h3><%= _('ERROR') %></h3>
  2 +<p>
  3 + <%= "State when error ocurred: #{@processing.state}" %>
  4 + <br/>
  5 + <% error = @processing.error %>
  6 + <%= error.message %>
  7 +<ul>
  8 + <% error.stack_trace.each do |trace| %>
  9 + <li><%= "#{trace.declaring_class}.#{trace.method_name}(#{trace.file_name}:#{trace.line_number})" %></li>
  10 + <% end %>
  11 +</ul>
  12 +</p>
... ...
plugins/mezuro/views/mezuro_plugin_project/_error_page.html.erb
... ... @@ -1,2 +0,0 @@
1   -<h2> An error occured: </h2>
2   -<%= @message %>
plugins/mezuro/views/mezuro_plugin_project/_project_error.rhtml
... ... @@ -1,12 +0,0 @@
1   -<h3><%= _('ERROR') %></h3>
2   -<p>
3   - <%= "State when error ocurred: #{@project.state}" %>
4   - <br/>
5   - <% error = @project.kalibro_error %>
6   - <%= error.message %>
7   -<ul>
8   - <% error.stack_trace.each do |trace| %>
9   - <li><%= "#{trace.declaring_class}.#{trace.method_name}(#{trace.file_name}:#{trace.line_number})" %></li>
10   - <% end %>
11   -</ul>
12   -</p>
plugins/mezuro/views/mezuro_plugin_project/_project_result.rhtml
... ... @@ -1,41 +0,0 @@
1   -<% unless @content.errors[:base].nil? %>
2   - <%= @content.errors[:base] %>
3   -<% else %>
4   - <div id="current_project_date" data-date="<%= @project_result.date %>"/>
5   -
6   - <h4><%= _('Last Result') %></h4>
7   -
8   - <table>
9   - <tr>
10   - <td><%= _('Date') %></td>
11   - <td><%= @project_result.date %></td>
12   - </tr>
13   - <tr>
14   - <td><%= _('Load time') %></td>
15   - <td><%= @project_result.formatted_load_time %></td>
16   - </tr>
17   - <tr>
18   - <td><%= _('Analysis time') %></td>
19   - <td><%= @project_result.formatted_analysis_time %></td>
20   - </tr>
21   - <tr>
22   - <td>Click to choose specific date:</td>
23   - <td><%= link_to(image_tag('/images/calendar_date_select/calendar.png', :width => 20, :height => 20, :onClick => "$( 'datepicker' ).toggle();"), "javascript:void(0)") %></td>
24   - </tr>
25   - </table>
26   -
27   - <div id="datepicker"></div>
28   -
29   - <script>
30   - jQuery(document).ready(function($) {
31   - $("#datepicker").datepicker({
32   - onSelect: function(dateText, inst) {
33   - reloadProjectWithDate(dateText) } });
34   - $("#datepicker").toggle();
35   - var date = jQuery("#current_project_date").attr('data-date').substr(0,10);
36   - $("#datepicker").datepicker( "setDate" , date );
37   -
38   - });
39   - </script>
40   -
41   -<% end %>
plugins/mezuro/views/mezuro_plugin_project/_source_tree.rhtml
... ... @@ -1,45 +0,0 @@
1   -<% unless @content.errors[:base].nil? %>
2   - <%= @content.errors[:base] %>
3   -<% else %>
4   - <h4><%= _('Source tree') %></h4>
5   - <% module_name = @source_tree.module.name %>
6   - <% module_label = "#{module_name} (#{@source_tree.module.granularity})" %>
7   -
8   - <p><h2 class="path">
9   - <% if module_name != @project_name %>
10   - <a href="#" class="source-tree-link" data-module-name="<%= @project_name %>">
11   - <%= @project_name %>
12   - </a>
13   - <% end %>
14   -
15   -
16   - <% split_link = @source_tree.module.ancestor_names %>
17   - <% split_link.each do |link| %>
18   - /<a href="#" class="source-tree-link" data-module-name="<%= link %>">
19   - <%= link.split(".").last %>
20   - </a>
21   - <% end %>
22   - </h2></p>
23   -
24   - <% if @source_tree.children %>
25   - <table border="0" class="source-tree">
26   - <% @source_tree.children.each do |child| %>
27   - <% if child.module.granularity=='PACKAGE' %>
28   - <tr>
29   - <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td>
30   - <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"><%= child.module.name %></a></td>
31   - </tr>
32   - <% else %>
33   - <tr>
34   - <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td>
35   - <td class="source-tree-text">
36   - <a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>">
37   - <%= child.module.name %>
38   - </a>
39   - </td>
40   - </tr>
41   - <% end %>
42   - <% end %>
43   - </table>
44   - <% end %>
45   -<% end %>
plugins/mezuro/views/mezuro_plugin_range/_edit.html.erb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +<% remote_form_for :range, :url => {:action =>"update", :controller => "mezuro_plugin_range"}, :method => :get do |f| %>
  2 + <%= hidden_field_tag :beginning_id, @beginning_id %>
  3 + <%= render :partial => "form", :locals => {:f => f} %>
  4 +<% end %>
... ...
plugins/mezuro/views/mezuro_plugin_range/_edit_range.html.erb
... ... @@ -1,4 +0,0 @@
1   -<% remote_form_for :range, :url => {:action =>"update_range", :controller => "mezuro_plugin_range"}, :method => :get do |f| %>
2   - <%= hidden_field_tag :beginning_id, @beginning_id %>
3   - <%= render :partial => "range_form", :locals => {:f => f} %>
4   -<% end %>
plugins/mezuro/views/mezuro_plugin_range/_form.html.erb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +<%= hidden_field_tag :id, @content_id %>
  2 +<%= hidden_field_tag :metric_configuration_id, @metric_configuration_id %>
  3 +<%= hidden_field_tag :reading_group_id, @reading_group_id %>
  4 +<%= hidden_field_tag :compound, @compound %>
  5 +
  6 +<%= f.hidden_field :id %>
  7 +
  8 + <%= required labelled_form_field _('Label'),
  9 + f.select(:reading_id, @reading_labels_and_ids) %><br/>
  10 +<table>
  11 + <tr>
  12 + <td>
  13 + <%= f.label :beginning, "(*) Beginning:" %>
  14 + </td>
  15 + <td>
  16 + <%= required f.text_field :beginning, :id => "range_beginning" %>&nbsp;<%= link_to('-&#8734', 'javascript:void(0)', :onClick => "jQuery( '#range_beginning' ).val('-INF');") %>
  17 + </td>
  18 + </tr>
  19 + <tr>
  20 + <td>
  21 + <%= f.label :end, "(*) End:" %>
  22 + </td>
  23 + <td>
  24 + <%= required f.text_field(:end, :id => "range_end") %>&nbsp;<%= link_to('+&#8734', 'javascript:void(0)', :onClick => "jQuery( '#range_end' ).val('+INF');") %>
  25 + </td>
  26 + </tr>
  27 + <tr>
  28 + <td>
  29 + <%= f.label :comments, "(*) Comments:" %>
  30 + </td>
  31 + <td>
  32 + <%= required f.text_area :comments, :rows => 3 %>
  33 + </td>
  34 + </tr>
  35 +</table>
  36 +<br/>
  37 +<%= f.submit "Save Range" %>
... ...
plugins/mezuro/views/mezuro_plugin_range/_new.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<% remote_form_for :range, :url => {:action =>"create", :controller => "mezuro_plugin_range"}, :method => :get do |f| %>
  2 + <%= render :partial => "form", :locals => {:f => f} %>
  3 +<% end %>
... ...
plugins/mezuro/views/mezuro_plugin_range/_new_range.html.erb
... ... @@ -1,3 +0,0 @@
1   -<% remote_form_for :range, :url => {:action =>"create_range", :controller => "mezuro_plugin_range"}, :method => :get do |f| %>
2   - <%= render :partial => "range_form", :locals => {:f => f} %>
3   -<% end %>
plugins/mezuro/views/mezuro_plugin_range/_range.html.erb
... ... @@ -13,9 +13,9 @@
13 13 </td>
14 14 <td bgcolor="#<%= range.color %>"></td>
15 15 <% if (not user.nil?) && user.id == @profile.id %>
16   - <td><%= link_to_remote "Edit", :url => {:action =>"edit_range", :controller => "mezuro_plugin_range", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning} %>
  16 + <td><%= link_to_remote "Edit", :url => {:action =>"edit", :controller => "mezuro_plugin_range", :id => params[:id], :metric_configuration_id => params[:metric_configuration_id], :range_id => range.id, :reading_group_id => reading_group_id} %>
17 17 </td>
18   - <td><%= link_to "Remove", :action =>"remove_range", :controller => "mezuro_plugin_range", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning %>
  18 + <td><%= link_to "Remove", :action =>"remove", :controller => "mezuro_plugin_range", :id => params[:id], :metric_configuration_id => params[:metric_configuration_id], :range_id => range.id, :compound => compound %>
19 19 </td>
20 20 <% else %>
21 21 <td></td>
... ...
plugins/mezuro/views/mezuro_plugin_range/_range_form.html.erb
... ... @@ -1,54 +0,0 @@
1   -<%= hidden_field_tag :id, @content_id %>
2   -<%= hidden_field_tag :metric_name, @metric_name %>
3   -
4   -<table>
5   - <tr>
6   - <td>
7   - <%= f.label :label, "(*) Label:" %>
8   - </td>
9   - <td>
10   - <%= f.text_field :label %>
11   - </td>
12   - </tr>
13   - <tr>
14   - <td>
15   - <%= f.label :beginning, "(*) Beginning:" %>
16   - </td>
17   - <td>
18   - <%= f.text_field :beginning, :id => "range_beginning" %>&nbsp;<%= link_to('-&#8734', 'javascript:void(0)', :onClick => "jQuery( '#range_beginning' ).val('-INF');") %>
19   - </td>
20   - </tr>
21   - <tr>
22   - <td>
23   - <%= f.label :end, "(*) End:" %>
24   - </td>
25   - <td>
26   - <%= f.text_field(:end, :id => "range_end") %>&nbsp;<%= link_to('+&#8734', 'javascript:void(0)', :onClick => "jQuery( '#range_end' ).val('+INF');") %>
27   - </td>
28   - </tr>
29   - <tr>
30   - <td>
31   - <%= f.label :grade, "(*) Grade:" %>
32   - </td>
33   - <td>
34   - <%= f.text_field :grade %>
35   - </td>
36   - </tr>
37   - <tr>
38   - <td>
39   - <%= f.label :color, "(*) Color:" %>
40   - </td>
41   - <td>
42   - <%= colorpicker_field(:range, :color, :value => @range.mezuro_color) %>Click in the field to change Color
43   - </td>
44   - </tr>
45   - <tr>
46   - <td>
47   - <%= f.label :comments, "Comments:" %>
48   - </td>
49   - <td>
50   - <%= f.text_area :comments, :rows => 3 %>
51   - </td>
52   - </tr>
53   -</table>
54   -<%= f.submit "Save Range" %>
plugins/mezuro/views/mezuro_plugin_range/_ranges.html.erb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +<h5> Ranges </h5><br/>
  2 +
  3 +<table id="ranges">
  4 + <tr>
  5 + <td>
  6 + Label
  7 + </td>
  8 + <td>
  9 + Beginning
  10 + </td>
  11 + <td>
  12 + End
  13 + </td>
  14 + <td>
  15 + Grade
  16 + </td>
  17 + <td>
  18 + Color
  19 + </td>
  20 + </tr>
  21 + <% @ranges.each do |range| %>
  22 + <%= render :partial => "mezuro_plugin_range/range", :locals => {:range => range, :id => @configuration_content.id,
  23 + :metric_configuration_id => @metric_configuration.id, :reading_group_id => @metric_configuration.reading_group_id, :compound => @metric_configuration.metric.compound} %>
  24 + <% end %>
  25 +</table>
  26 +
  27 +<br/>
  28 +<% if owner %>
  29 + <%= link_to_remote "New Range", :url => {:action =>"new", :controller => "mezuro_plugin_range", :id => @configuration_content.id, :metric_configuration_id => @metric_configuration.id, :reading_group_id => @metric_configuration.reading_group_id, :compound => @metric_configuration.metric.compound} %>
  30 +<% end %>
  31 +<div id="form" style="display:none"></div>
... ...
plugins/mezuro/views/mezuro_plugin_range/create.rjs 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +if @error.nil?
  2 + page.visual_effect :toggle_slide, "form"
  3 + page.insert_html :bottom, "ranges", :partial => "range", :locals => {:range => @range, :reading_group_id => @reading_group_id, :compound => @compound}
  4 +else
  5 + page.alert @error
  6 +end
... ...
plugins/mezuro/views/mezuro_plugin_range/create_range.rjs
... ... @@ -1,6 +0,0 @@
1   -if @error.nil?
2   - page.visual_effect :toggle_slide, "range_form"
3   - page.insert_html :bottom, "ranges", :partial => "range", :locals => {:range => @range}
4   -else
5   - page.alert @error
6   -end
plugins/mezuro/views/mezuro_plugin_range/edit.rjs 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +page.replace_html 'form', :partial => "edit", :locals => {:range => @range}
  2 +page.visual_effect :slide_down, "form"
  3 +
... ...
plugins/mezuro/views/mezuro_plugin_range/edit_range.rjs
... ... @@ -1,3 +0,0 @@
1   -page.replace_html 'range_form', :partial => "edit_range", :locals => {:range => @range}
2   -page.visual_effect :slide_down, "range_form"
3   -
plugins/mezuro/views/mezuro_plugin_range/new.rjs 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +page.replace_html 'form', :partial => "new"
  2 +page.visual_effect :slide_down, "form"
  3 +
... ...
plugins/mezuro/views/mezuro_plugin_range/new_range.rjs
... ... @@ -1,3 +0,0 @@
1   -page.replace_html 'range_form', :partial => "new_range"
2   -page.visual_effect :slide_down, "range_form"
3   -
plugins/mezuro/views/mezuro_plugin_range/update.rjs 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +if @error.nil?
  2 + page.reload()
  3 +else
  4 + page.alert @error
  5 +end
... ...
plugins/mezuro/views/mezuro_plugin_range/update_range.rjs
... ... @@ -1,5 +0,0 @@
1   -if @error.nil?
2   - page.reload()
3   -else
4   - page.alert @error
5   -end
plugins/mezuro/views/mezuro_plugin_reading/_form.html.erb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +<%= hidden_field_tag :id, @reading_group_content.id %>
  2 +
  3 +<%= required labelled_form_field _('label:'), f.text_field(:label) %>
  4 +
  5 +<%= required labelled_form_field _('grade:'),
  6 +f.text_field(:grade) %>
  7 +
  8 +<%= required labelled_form_field _('color:'),
  9 +colorpicker_field(:reading, :color) %>Click in the field to change Color
  10 +
  11 +<p><%= f.submit "Save" %></p>
... ...
plugins/mezuro/views/mezuro_plugin_reading/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +<script src="/javascripts/colorpicker.js" type="text/javascript"></script>
  2 +<script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script>
  3 +<h2><%= link_to("#{@reading_group_content.name} Reading Group", @reading_group_content.view_url) %></h2>
  4 +
  5 +<% form_for :reading, :url => {:action =>"save", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %>
  6 + <%= f.hidden_field :id %>
  7 + <%= render :partial => "form", :locals => {:f => f} %>
  8 +<% end %>
... ...
plugins/mezuro/views/mezuro_plugin_reading/new.html.erb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<script src="/javascripts/colorpicker.js" type="text/javascript"></script>
  2 +<script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script>
  3 +<h2><%= link_to("#{@reading_group_content.name} Reading Group", @reading_group_content.view_url) %></h2>
  4 +
  5 +<% form_for :reading, :url => {:action =>"save", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %>
  6 + <%= render :partial => "form", :locals => {:f => f} %>
  7 +<% end %>
... ...
plugins/mezuro/views/mezuro_plugin_repository/_error_page.html.erb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +<h2> An error occured: </h2>
  2 +<%= @message %>
... ...
plugins/mezuro/views/mezuro_plugin_repository/_form.html.erb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +<h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2>
  2 +
  3 +<% form_for :repository, :url => {:action =>"save", :controller => "mezuro_plugin_repository"}, :method => :get do |f| %>
  4 + <%= f.hidden_field :id %>
  5 + <%= hidden_field_tag :id, @project_content.id %>
  6 +
  7 + <%= required labelled_form_field _('Name'), f.text_field(:name) %>
  8 +
  9 + <%= labelled_form_field _("Description"), f.text_field(:description) %>
  10 +
  11 + <%= required labelled_form_field _('License'),
  12 + f.select(:license, MezuroPlugin::Helpers::ContentViewerHelper.license_options) %>
  13 +
  14 + <%= required labelled_form_field _('Process Period'),
  15 + f.select(:process_period, MezuroPlugin::Helpers::ContentViewerHelper.periodicity_options) %>
  16 +
  17 + <%= required labelled_form_field _('Type'),
  18 + f.select(:type, @repository_types) %>
  19 +
  20 + <%= required labelled_form_field _('Address'),
  21 + f.text_field(:address) %>
  22 +
  23 + <%= required labelled_form_field _('Configuration'),
  24 + f.select(:configuration_id, @configuration_select) %>
  25 +
  26 + <p> <%= f.submit "Add" %> </p>
  27 +
  28 +<% end %>
... ...
plugins/mezuro/views/mezuro_plugin_repository/edit.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => "form" %>
... ...
plugins/mezuro/views/mezuro_plugin_repository/new.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => "form" %>
... ...
plugins/mezuro/views/mezuro_plugin_repository/show.html.erb 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +<script src="/plugins/mezuro/javascripts/processing.js" type="text/javascript"></script>
  2 +<h2><%= link_to("#{@project_content.name} Project", @project_content.view_url) %></h2>
  3 +
  4 +<table>
  5 + <tr>
  6 + <td><%= _('Name') %></td>
  7 + <td><%= @repository.name %></td>
  8 + </tr>
  9 + <tr>
  10 + <td><%= _('Description') %></td>
  11 + <td><%= @repository.description %></td>
  12 + </tr>
  13 + <tr>
  14 + <td><%= _('License') %></td>
  15 + <td><%= @repository.license %></td>
  16 + </tr>
  17 + <tr>
  18 + <td><%= _('Process Period') %></td>
  19 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.periodicity_option(@repository.process_period.to_i) %></td>
  20 + </tr>
  21 + <tr>
  22 + <td><%= _('Type') %></td>
  23 + <td><%= @repository.type %></td>
  24 + </tr>
  25 + <tr>
  26 + <td><%= _('Address') %></td>
  27 + <td><%= @repository.address %></td>
  28 + </tr>
  29 + <tr>
  30 + <td><%= _('Configuration') %></td>
  31 + <td><%= @configuration_name %></td>
  32 + </tr>
  33 + <tr>
  34 + <td><%= _('Status')%></td>
  35 + <td>
  36 + <div id="processing-state" style="color:DarkGoldenRod">Retrieving</div>
  37 + <div id="msg-time"></div>
  38 + </td>
  39 + </tr>
  40 +</table>
  41 +<br />
  42 +
  43 +<div id="processing" data-profile="<%= @project_content.profile.identifier %>" data-content="<%= @project_content.id %>"
  44 + data-repository-id="<%= @repository.id %>"></div>
  45 +<div id="module-result"></div>
... ...