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

Too many changes.

To preserve performance only 100 of 192 files displayed.

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 +
... ...