Commit 9fc6888aac0ae8bee2354e76bb098cc27680d57e
Exists in
master
and in
29 other branches
Merge branch 'mezuro-dev' into mezuro
Showing
114 changed files
with
2790 additions
and
803 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 114 files displayed.
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
0 → 100644
@@ -0,0 +1,189 @@ | @@ -0,0 +1,189 @@ | ||
1 | +class MezuroPluginMyprofileController < ProfileController | ||
2 | + | ||
3 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | ||
4 | + | ||
5 | + | ||
6 | + def choose_base_tool | ||
7 | + @configuration_name = params[:configuration_name] | ||
8 | + @tool_names = Kalibro::Client::BaseToolClient.new | ||
9 | + end | ||
10 | + | ||
11 | + def choose_metric | ||
12 | + @configuration_name = params[:configuration_name] | ||
13 | + @collector_name = params[:collector_name] | ||
14 | + @collector = Kalibro::Client::BaseToolClient.new.base_tool(@collector_name) | ||
15 | + end | ||
16 | + | ||
17 | + def new_metric_configuration | ||
18 | + metric_name = params[:metric_name] | ||
19 | + collector_name = params[:collector_name] | ||
20 | + collector = Kalibro::Client::BaseToolClient.new.base_tool(collector_name) | ||
21 | + @metric = collector.supported_metrics.find {|metric| metric.name == metric_name} | ||
22 | + @configuration_name = params[:configuration_name] | ||
23 | + end | ||
24 | + | ||
25 | + def new_compound_metric_configuration | ||
26 | + @configuration_name = params[:configuration_name] | ||
27 | + @metric_configurations = Kalibro::Client::ConfigurationClient.new.configuration(@configuration_name).metric_configurations | ||
28 | + end | ||
29 | + | ||
30 | + def edit_metric_configuration | ||
31 | + metric_name = params[:metric_name] | ||
32 | + @configuration_name = params[:configuration_name] | ||
33 | + @metric_configuration = Kalibro::Client::MetricConfigurationClient.new.metric_configuration(@configuration_name, metric_name) | ||
34 | + @metric = @metric_configuration.metric | ||
35 | + end | ||
36 | + | ||
37 | + def edit_compound_metric_configuration | ||
38 | + metric_name = params[:metric_name] | ||
39 | + @configuration_name = params[:configuration_name] | ||
40 | + @metric_configuration = Kalibro::Client::MetricConfigurationClient.new.metric_configuration(@configuration_name, metric_name) | ||
41 | + @metric = @metric_configuration.metric | ||
42 | + end | ||
43 | + | ||
44 | + def create_metric_configuration | ||
45 | + @configuration_name = params[:configuration_name] | ||
46 | + metric_configuration = new_metric_configuration_instance | ||
47 | + Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) | ||
48 | + redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" | ||
49 | + end | ||
50 | + | ||
51 | + def create_compound_metric_configuration | ||
52 | + @configuration_name = params[:configuration_name] | ||
53 | + compound_metric_configuration = new_compound_metric_configuration_instance | ||
54 | + Kalibro::Client::MetricConfigurationClient.new.save(compound_metric_configuration, @configuration_name) | ||
55 | + redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" | ||
56 | + end | ||
57 | + | ||
58 | + def update_metric_configuration | ||
59 | + @configuration_name = params[:configuration_name] | ||
60 | + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
61 | + metric_name = params[:metric][:name] | ||
62 | + metric_configuration = metric_configuration_client.metric_configuration(@configuration_name, metric_name) | ||
63 | + metric_configuration = assign_metric_configuration_instance(metric_configuration) | ||
64 | + metric_configuration_client.save(metric_configuration, @configuration_name) | ||
65 | + redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" | ||
66 | + end | ||
67 | + | ||
68 | + def update_compound_metric_configuration | ||
69 | + @configuration_name = params[:configuration_name] | ||
70 | + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
71 | + metric_name = params[:metric_configuration][:metric][:name] | ||
72 | + compound_metric_configuration = metric_configuration_client.metric_configuration(@configuration_name, metric_name) | ||
73 | + compound_metric_configuration = assign_compound_metric_configuration_instance(compound_metric_configuration) | ||
74 | + metric_configuration_client.save(compound_metric_configuration, @configuration_name) | ||
75 | + redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" | ||
76 | + end | ||
77 | + | ||
78 | + def new_range | ||
79 | + @metric_name = params[:metric_name] | ||
80 | + @configuration_name = params[:configuration_name] | ||
81 | + end | ||
82 | + | ||
83 | + def edit_range | ||
84 | + @metric_name = params[:metric_name] | ||
85 | + @configuration_name = params[:configuration_name] | ||
86 | + @beginning_id = params[:beginning_id] | ||
87 | + | ||
88 | + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
89 | + metric_configuration = metric_configuration_client.metric_configuration(@configuration_name, @metric_name) | ||
90 | + @range = metric_configuration.ranges.find{ |range| range.beginning == @beginning_id.to_f } | ||
91 | + end | ||
92 | + | ||
93 | + def create_range | ||
94 | + @range = new_range_instance | ||
95 | + configuration_name = params[:configuration_name] | ||
96 | + metric_name = params[:metric_name] | ||
97 | + beginning_id = params[:beginning_id] | ||
98 | + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
99 | + metric_configuration = metric_configuration_client.metric_configuration(configuration_name, metric_name) | ||
100 | + metric_configuration.add_range(@range) | ||
101 | + metric_configuration_client.save(metric_configuration, configuration_name) | ||
102 | + end | ||
103 | + | ||
104 | + def update_range | ||
105 | + metric_name = params[:metric_name] | ||
106 | + configuration_name = params[:configuration_name] | ||
107 | + beginning_id = params[:beginning_id] | ||
108 | + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
109 | + metric_configuration = metric_configuration_client.metric_configuration(configuration_name, metric_name) | ||
110 | + index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f } | ||
111 | + metric_configuration.ranges[index] = new_range_instance | ||
112 | + Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, configuration_name) | ||
113 | + end | ||
114 | + | ||
115 | + def remove_range | ||
116 | + configuration_name = params[:configuration_name] | ||
117 | + metric_name = params[:metric_name] | ||
118 | + beginning_id = params[:range_beginning] | ||
119 | + metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
120 | + metric_configuration = metric_configuration_client.metric_configuration(configuration_name, metric_name) | ||
121 | + metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f }.inspect | ||
122 | + Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, configuration_name) | ||
123 | + formatted_configuration_name = configuration_name.gsub(/\s/, '+') | ||
124 | + formatted_metric_name = metric_name.gsub(/\s/, '+') | ||
125 | + if metric_configuration.metric.class == Kalibro::Entities::CompoundMetric | ||
126 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?configuration_name=#{formatted_configuration_name}&metric_name=#{formatted_metric_name}" | ||
127 | + else | ||
128 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?configuration_name=#{formatted_configuration_name}&metric_name=#{formatted_metric_name}" | ||
129 | + end | ||
130 | + end | ||
131 | + | ||
132 | + def remove_metric_configuration | ||
133 | + configuration_name = params[:configuration_name] | ||
134 | + metric_name = params[:metric_name] | ||
135 | + Kalibro::Client::MetricConfigurationClient.new.remove(configuration_name, metric_name) | ||
136 | + redirect_to "/#{profile.identifier}/#{configuration_name.downcase.gsub(/\s/, '-')}" | ||
137 | + end | ||
138 | + | ||
139 | + | ||
140 | + | ||
141 | + private | ||
142 | + | ||
143 | + def new_metric_configuration_instance | ||
144 | + metric_configuration = Kalibro::Entities::MetricConfiguration.new | ||
145 | + metric_configuration.metric = Kalibro::Entities::NativeMetric.new | ||
146 | + assign_metric_configuration_instance (metric_configuration) | ||
147 | + end | ||
148 | + | ||
149 | + def new_compound_metric_configuration_instance | ||
150 | + metric_configuration = Kalibro::Entities::MetricConfiguration.new | ||
151 | + metric_configuration.metric = Kalibro::Entities::CompoundMetric.new | ||
152 | + assign_compound_metric_configuration_instance (metric_configuration) | ||
153 | + end | ||
154 | + | ||
155 | + def assign_metric_configuration_instance (metric_configuration) | ||
156 | + metric_configuration.metric.name = params[:metric][:name] | ||
157 | + metric_configuration.metric.description = params[:description] | ||
158 | + metric_configuration.metric.origin = params[:metric][:origin] | ||
159 | + metric_configuration.metric.scope = params[:scope] | ||
160 | + metric_configuration.metric.language = params[:language] | ||
161 | + metric_configuration.code = params[:metric_configuration][:code] | ||
162 | + metric_configuration.weight = params[:metric_configuration][:weight] | ||
163 | + metric_configuration.aggregation_form = params[:metric_configuration][:aggregation_form] | ||
164 | + metric_configuration | ||
165 | + end | ||
166 | + | ||
167 | + def assign_compound_metric_configuration_instance (metric_configuration) | ||
168 | + metric_configuration.metric.name = params[:metric_configuration][:metric][:name] | ||
169 | + metric_configuration.metric.description = params[:metric_configuration][:metric][:description] | ||
170 | + metric_configuration.metric.scope = params[:metric_configuration][:metric][:scope] | ||
171 | + metric_configuration.metric.script = params[:metric_configuration][:metric][:script] | ||
172 | + metric_configuration.code = params[:metric_configuration][:code] | ||
173 | + metric_configuration.weight = params[:metric_configuration][:weight] | ||
174 | + metric_configuration.aggregation_form = params[:metric_configuration][:aggregation_form] | ||
175 | + metric_configuration | ||
176 | + end | ||
177 | + | ||
178 | + def new_range_instance | ||
179 | + range = Kalibro::Entities::Range.new | ||
180 | + range.beginning = params[:range][:beginning] | ||
181 | + range.end = params[:range][:end] | ||
182 | + range.label = params[:range][:label] | ||
183 | + range.grade = params[:range][:grade] | ||
184 | + range.color = params[:range][:color] | ||
185 | + range.comments = params[:range][:comments] | ||
186 | + range | ||
187 | + end | ||
188 | + | ||
189 | +end |
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
1 | class MezuroPluginProfileController < ProfileController | 1 | class MezuroPluginProfileController < ProfileController |
2 | 2 | ||
3 | - def metrics | ||
4 | - project_content = profile.articles.find(params[:id]) | ||
5 | - module_name = params[:module_name] | ||
6 | - render :partial => 'content_viewer/module_result', :locals => { :module_result => project_content.module_result(module_name) } | 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 | + state = project.error.nil? ? project.state : "ERROR" | ||
9 | + render :text => state | ||
10 | + end | ||
11 | + | ||
12 | + def project_error | ||
13 | + content = profile.articles.find(params[:id]) | ||
14 | + project = content.project | ||
15 | + render :partial => 'content_viewer/project_error', :locals => { :project => project } | ||
16 | + end | ||
17 | + | ||
18 | + def project_result | ||
19 | + content = profile.articles.find(params[:id]) | ||
20 | + date = params[:date] | ||
21 | + project_result = date.nil? ? content.project_result : content.get_date_result(date) | ||
22 | + project = content.project | ||
23 | + render :partial => 'content_viewer/project_result', :locals => { :project_result => project_result} | ||
24 | + end | ||
25 | + | ||
26 | + def module_result | ||
27 | + content = profile.articles.find(params[:id]) | ||
28 | + date = params[:date] | ||
29 | + date.nil? ? content.project_result : content.get_date_result(date) | ||
30 | + module_result = content.module_result(params[:module_name]) | ||
31 | + render :partial => 'content_viewer/module_result', :locals => { :module_result => module_result} | ||
7 | end | 32 | end |
8 | 33 | ||
34 | + def project_tree | ||
35 | + content = profile.articles.find(params[:id]) | ||
36 | + date = params[:date] | ||
37 | + project_result = date.nil? ? content.project_result : content.get_date_result(date) | ||
38 | + source_tree = project_result.node_of(params[:module_name]) | ||
39 | + render :partial =>'content_viewer/source_tree', :locals => { :source_tree => source_tree, :project_name => content.project.name} | ||
40 | + end | ||
41 | + | ||
42 | + def module_metrics_history | ||
43 | + metric_name = params[:metric_name] | ||
44 | + content = profile.articles.find(params[:id]) | ||
45 | + module_history = content.result_history(params[:module_name]) | ||
46 | + score_history = (module_history.collect { |module_result| (module_result.metric_results.select { |metric_result| metric_result.metric.name.delete("() ") == metric_name })[0] }).collect { |metric_result| metric_result.value } | ||
47 | + render :partial => 'content_viewer/score_history', :locals => {:score_history => score_history} | ||
48 | + end | ||
49 | + | ||
50 | + def module_grade_history | ||
51 | + content = profile.articles.find(params[:id]) | ||
52 | + modules_results = content.result_history(params[:module_name]) | ||
53 | + score_history = modules_results.collect { |module_result| module_result.grade } | ||
54 | + render :partial => 'content_viewer/score_history', :locals => {:score_history => score_history} | ||
55 | + end | ||
9 | end | 56 | end |
plugins/mezuro/features/mezuro.feature
@@ -1,69 +0,0 @@ | @@ -1,69 +0,0 @@ | ||
1 | -Feature: mezuro content | ||
2 | - As a noosfero user | ||
3 | - I want to create a Kalibro 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 Kalibro project as an option to new content | ||
17 | - Given I am on My Community's cms | ||
18 | - When I follow "New content" | ||
19 | - Then I should see "Kalibro project" | ||
20 | - | ||
21 | - Scenario: I see Kalibro project's input form | ||
22 | - Given I am on My Community's cms | ||
23 | - When I follow "New content" | ||
24 | - And I follow "Kalibro project" | ||
25 | - Then I should see "Title" | ||
26 | - And I should see "License" | ||
27 | - And I should see "Repository type" | ||
28 | - And I should see "GIT" | ||
29 | - And I should see "REMOTE_ZIP" | ||
30 | - And I should see "REMOTE_TARBALL" | ||
31 | - And I should see "SUBVERSION" | ||
32 | - And I should see "Repository url" | ||
33 | - And I should see "Configuration" | ||
34 | - And I should see "Kalibro for Java" | ||
35 | - | ||
36 | - Scenario: I create a sample mezuro content | ||
37 | - Given I am on My Community's cms | ||
38 | - When I create a content of type "Kalibro project" with the following data | ||
39 | - | Title | Sample project | | ||
40 | - | License | BSD | | ||
41 | - | Repository type | GIT | | ||
42 | - | Repository url | git://example | | ||
43 | - Then I should see "Sample project" | ||
44 | - And I should see "Viewed one time" | ||
45 | - And I should see "BSD" | ||
46 | - | ||
47 | - Scenario: I create a real mezuro content | ||
48 | - Given I am on My Community's cms | ||
49 | - When I create a content of type "Kalibro project" with the following data | ||
50 | - | Title | Qt-Calculator | | ||
51 | - | License | GPL 2.0 | | ||
52 | - | Repository type | SUBVERSION | | ||
53 | - | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator | | ||
54 | - Then I should see "Qt-Calculator" | ||
55 | - | ||
56 | - Scenario: I see results from a real Kalibro project | ||
57 | - Given I am on My Community's cms | ||
58 | - When I create a content of type "Kalibro project" with the following data | ||
59 | - | Title | Qt-Calculator | | ||
60 | - | License | GPL | | ||
61 | - | Repository type | SUBVERSION | | ||
62 | - | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator | | ||
63 | - | Configuration | Kalibro for Java | | ||
64 | - Then I should see "Qt-Calculator" | ||
65 | - And I should see "GPL" | ||
66 | - And I should see "SUBVERSION" | ||
67 | - And I should see "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator" | ||
68 | - And I should see "Kalibro for Java" | ||
69 | - And I should see "Kalibro Service is loading the source code" |
plugins/mezuro/lib/kalibro/client/base_tool_client.rb
@@ -13,4 +13,4 @@ class Kalibro::Client::BaseToolClient | @@ -13,4 +13,4 @@ class Kalibro::Client::BaseToolClient | ||
13 | Kalibro::Entities::BaseTool.from_hash(hash) | 13 | Kalibro::Entities::BaseTool.from_hash(hash) |
14 | end | 14 | end |
15 | 15 | ||
16 | -end | ||
17 | \ No newline at end of file | 16 | \ No newline at end of file |
17 | +end |
plugins/mezuro/lib/kalibro/client/configuration_client.rb
1 | class Kalibro::Client::ConfigurationClient | 1 | class Kalibro::Client::ConfigurationClient |
2 | 2 | ||
3 | + def self.save(configuration_content) | ||
4 | + configuration = Kalibro::Entities::Configuration.new | ||
5 | + configuration.name = configuration_content.name | ||
6 | + configuration.description = configuration_content.description | ||
7 | + new.save(configuration) | ||
8 | + end | ||
9 | + | ||
10 | + def self.remove(configuration_name) | ||
11 | + client = new | ||
12 | + client.remove(configuration_name) if client.configuration_names.include? configuration_name | ||
13 | + end | ||
14 | + | ||
3 | def initialize | 15 | def initialize |
4 | @port = Kalibro::Client::Port.new('Configuration') | 16 | @port = Kalibro::Client::Port.new('Configuration') |
5 | end | 17 | end |
@@ -8,10 +20,6 @@ class Kalibro::Client::ConfigurationClient | @@ -8,10 +20,6 @@ class Kalibro::Client::ConfigurationClient | ||
8 | @port.request(:save_configuration, {:configuration => configuration.to_hash}) | 20 | @port.request(:save_configuration, {:configuration => configuration.to_hash}) |
9 | end | 21 | end |
10 | 22 | ||
11 | - def self.save(configuration) | ||
12 | - new.save(configuration) | ||
13 | - end | ||
14 | - | ||
15 | def configuration_names | 23 | def configuration_names |
16 | @port.request(:get_configuration_names)[:configuration_name].to_a | 24 | @port.request(:get_configuration_names)[:configuration_name].to_a |
17 | end | 25 | end |
@@ -25,7 +33,4 @@ class Kalibro::Client::ConfigurationClient | @@ -25,7 +33,4 @@ class Kalibro::Client::ConfigurationClient | ||
25 | @port.request(:remove_configuration, {:configuration_name => configuration_name}) | 33 | @port.request(:remove_configuration, {:configuration_name => configuration_name}) |
26 | end | 34 | end |
27 | 35 | ||
28 | - def self.remove(configuration_name) | ||
29 | - new.remove(configuration_name) | ||
30 | - end | ||
31 | end | 36 | end |
plugins/mezuro/lib/kalibro/client/kalibro_client.rb
1 | class Kalibro::Client::KalibroClient | 1 | class Kalibro::Client::KalibroClient |
2 | + | ||
3 | + def self.process_project(project_name) | ||
4 | + new.process_project(project_name) | ||
5 | + end | ||
2 | 6 | ||
3 | def initialize | 7 | def initialize |
4 | @port = Kalibro::Client::Port.new('Kalibro') | 8 | @port = Kalibro::Client::Port.new('Kalibro') |
@@ -12,8 +16,24 @@ class Kalibro::Client::KalibroClient | @@ -12,8 +16,24 @@ class Kalibro::Client::KalibroClient | ||
12 | @port.request(:process_project, {:project_name => project_name}) | 16 | @port.request(:process_project, {:project_name => project_name}) |
13 | end | 17 | end |
14 | 18 | ||
15 | - def self.process_project(project_name) | ||
16 | - new.process_project(project_name) | 19 | + def self.process_project(project_name, days) |
20 | + if days.to_i.zero? | ||
21 | + new.process_project(project_name) | ||
22 | + else | ||
23 | + new.process_periodically(project_name, days) | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + def process_periodically(project_name, period_in_days) | ||
28 | + @port.request(:process_periodically, {:project_name => project_name, :period_in_days => period_in_days}) | ||
29 | + end | ||
30 | + | ||
31 | + def process_period(project_name) | ||
32 | + @port.request(:get_process_period, {:project_name => project_name})[:period] | ||
33 | + end | ||
34 | + | ||
35 | + def cancel_periodic_process(project_name) | ||
36 | + @port.request(:cancel_periodic_process, {:project_name => project_name}) | ||
17 | end | 37 | end |
18 | 38 | ||
19 | end | 39 | end |
plugins/mezuro/lib/kalibro/client/metric_configuration_client.rb
0 → 100644
@@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
1 | +class Kalibro::Client::MetricConfigurationClient | ||
2 | + | ||
3 | + def initialize | ||
4 | + @port = Kalibro::Client::Port.new('MetricConfiguration') | ||
5 | + end | ||
6 | + | ||
7 | + def save(metric_configuration, configuration_name) | ||
8 | + @port.request(:save_metric_configuration, { | ||
9 | + :metric_configuration => metric_configuration.to_hash, | ||
10 | + :configuration_name => configuration_name}) | ||
11 | + end | ||
12 | + | ||
13 | + def metric_configuration(configuration_name, metric_name) | ||
14 | + hash = @port.request(:get_metric_configuration, { | ||
15 | + :configuration_name => configuration_name, | ||
16 | + :metric_name => metric_name | ||
17 | + })[:metric_configuration] | ||
18 | + Kalibro::Entities::MetricConfiguration.from_hash(hash) | ||
19 | + end | ||
20 | + | ||
21 | + def remove (configuration_name, metric_name) | ||
22 | + @port.request(:remove_metric_configuration, { | ||
23 | + :configuration_name => configuration_name, | ||
24 | + :metric_name=> metric_name | ||
25 | + }) | ||
26 | + end | ||
27 | + | ||
28 | +end | ||
0 | \ No newline at end of file | 29 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/client/module_result_client.rb
1 | class Kalibro::Client::ModuleResultClient | 1 | class Kalibro::Client::ModuleResultClient |
2 | - | 2 | + |
3 | def initialize | 3 | def initialize |
4 | @port = Kalibro::Client::Port.new('ModuleResult') | 4 | @port = Kalibro::Client::Port.new('ModuleResult') |
5 | end | 5 | end |
@@ -7,7 +7,7 @@ class Kalibro::Client::ModuleResultClient | @@ -7,7 +7,7 @@ class Kalibro::Client::ModuleResultClient | ||
7 | def module_result(project_name, module_name, date) | 7 | def module_result(project_name, module_name, date) |
8 | hash = @port.request(:get_module_result, | 8 | hash = @port.request(:get_module_result, |
9 | {:project_name => project_name, :module_name => module_name, | 9 | {:project_name => project_name, :module_name => module_name, |
10 | - :date => date_with_milliseconds(date)})[:module_result] | 10 | + :date => Kalibro::Entities::Entity.date_with_milliseconds(date)})[:module_result] |
11 | Kalibro::Entities::ModuleResult.from_hash(hash) | 11 | Kalibro::Entities::ModuleResult.from_hash(hash) |
12 | end | 12 | end |
13 | 13 | ||
@@ -16,12 +16,4 @@ class Kalibro::Client::ModuleResultClient | @@ -16,12 +16,4 @@ class Kalibro::Client::ModuleResultClient | ||
16 | {:project_name => project_name, :module_name => module_name})[:module_result] | 16 | {:project_name => project_name, :module_name => module_name})[:module_result] |
17 | Kalibro::Entities::Entity.new.to_entity_array(value, Kalibro::Entities::ModuleResult) | 17 | Kalibro::Entities::Entity.new.to_entity_array(value, Kalibro::Entities::ModuleResult) |
18 | end | 18 | end |
19 | - | ||
20 | - private | ||
21 | - | ||
22 | - def date_with_milliseconds(date) | ||
23 | - milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | ||
24 | - date.to_s[0..18] + milliseconds + date.to_s[19..-1] | ||
25 | - end | ||
26 | - | ||
27 | -end | ||
28 | \ No newline at end of file | 19 | \ No newline at end of file |
20 | +end |
plugins/mezuro/lib/kalibro/client/port.rb
@@ -7,7 +7,8 @@ end | @@ -7,7 +7,8 @@ end | ||
7 | class Kalibro::Client::Port | 7 | class Kalibro::Client::Port |
8 | 8 | ||
9 | def initialize(endpoint) | 9 | def initialize(endpoint) |
10 | - @client = Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | 10 | + @endpoint = endpoint |
11 | + initialize_client | ||
11 | end | 12 | end |
12 | 13 | ||
13 | def service_address | 14 | def service_address |
@@ -18,9 +19,20 @@ class Kalibro::Client::Port | @@ -18,9 +19,20 @@ class Kalibro::Client::Port | ||
18 | @service_address | 19 | @service_address |
19 | end | 20 | end |
20 | 21 | ||
22 | + def service_address=(address) | ||
23 | + @service_address = address | ||
24 | + initialize_client | ||
25 | + end | ||
26 | + | ||
21 | def request(action, request_body = nil) | 27 | def request(action, request_body = nil) |
22 | response = @client.request(:kalibro, action) { soap.body = request_body } | 28 | response = @client.request(:kalibro, action) { soap.body = request_body } |
23 | response.to_hash["#{action}_response".to_sym] | 29 | response.to_hash["#{action}_response".to_sym] |
24 | end | 30 | end |
25 | 31 | ||
32 | + private | ||
33 | + | ||
34 | + def initialize_client | ||
35 | + @client = Savon::Client.new("#{service_address}#{@endpoint}Endpoint/?wsdl") | ||
36 | + end | ||
37 | + | ||
26 | end | 38 | end |
plugins/mezuro/lib/kalibro/client/project_client.rb
1 | class Kalibro::Client::ProjectClient | 1 | class Kalibro::Client::ProjectClient |
2 | 2 | ||
3 | + def self.project(project_name) | ||
4 | + new.project(project_name) | ||
5 | + end | ||
6 | + | ||
7 | + def self.save(project_content) | ||
8 | + project = create_project(project_content) | ||
9 | + new.save(project) | ||
10 | + end | ||
11 | + | ||
12 | + def self.remove(project_name) | ||
13 | + instance = new | ||
14 | + if (instance.project_names.include?(project_name)) | ||
15 | + instance.remove(project_name) | ||
16 | + end | ||
17 | + end | ||
18 | + | ||
19 | + def self.create_project (project_content) | ||
20 | + project = Kalibro::Entities::Project.new | ||
21 | + project.name = project_content.name | ||
22 | + project.license = project_content.license | ||
23 | + project.description = project_content.description | ||
24 | + project.repository = create_repository(project_content) | ||
25 | + project.configuration_name = project_content.configuration_name | ||
26 | + project | ||
27 | + end | ||
28 | + | ||
29 | + def self.create_repository(project_content) | ||
30 | + repository = Kalibro::Entities::Repository.new | ||
31 | + repository.type = project_content.repository_type | ||
32 | + repository.address = project_content.repository_url | ||
33 | + repository | ||
34 | + end | ||
35 | + | ||
3 | def initialize | 36 | def initialize |
4 | @port = Kalibro::Client::Port.new('Project') | 37 | @port = Kalibro::Client::Port.new('Project') |
5 | end | 38 | end |
@@ -8,16 +41,20 @@ class Kalibro::Client::ProjectClient | @@ -8,16 +41,20 @@ class Kalibro::Client::ProjectClient | ||
8 | @port.request(:save_project, {:project => project.to_hash}) | 41 | @port.request(:save_project, {:project => project.to_hash}) |
9 | end | 42 | end |
10 | 43 | ||
11 | - def self.save(project) | ||
12 | - new.save(project) | ||
13 | - end | ||
14 | - | ||
15 | def project_names | 44 | def project_names |
16 | @port.request(:get_project_names)[:project_name].to_a | 45 | @port.request(:get_project_names)[:project_name].to_a |
17 | end | 46 | end |
18 | 47 | ||
19 | - def project(name) | ||
20 | - hash = @port.request(:get_project, {:project_name => name})[:project] | 48 | + def project(project_name) |
49 | + begin | ||
50 | + hash = @port.request(:get_project, {:project_name => project_name})[:project] | ||
51 | + rescue Exception => error | ||
52 | + unless (error.message =~ /There is no project named/).nil? | ||
53 | + return nil | ||
54 | + else | ||
55 | + raise error | ||
56 | + end | ||
57 | + end | ||
21 | Kalibro::Entities::Project.from_hash(hash) | 58 | Kalibro::Entities::Project.from_hash(hash) |
22 | end | 59 | end |
23 | 60 | ||
@@ -25,7 +62,4 @@ class Kalibro::Client::ProjectClient | @@ -25,7 +62,4 @@ class Kalibro::Client::ProjectClient | ||
25 | @port.request(:remove_project, {:project_name => project_name}) | 62 | @port.request(:remove_project, {:project_name => project_name}) |
26 | end | 63 | end |
27 | 64 | ||
28 | - def self.remove(project_name) | ||
29 | - new.remove(project_name) | ||
30 | - end | ||
31 | end | 65 | end |
plugins/mezuro/lib/kalibro/client/project_result_client.rb
1 | class Kalibro::Client::ProjectResultClient | 1 | class Kalibro::Client::ProjectResultClient |
2 | 2 | ||
3 | + # TODO test this | ||
4 | + def self.last_result(project_name) | ||
5 | + new.last_result(project_name) | ||
6 | + end | ||
7 | + | ||
3 | def initialize | 8 | def initialize |
4 | @port = Kalibro::Client::Port.new('ProjectResult') | 9 | @port = Kalibro::Client::Port.new('ProjectResult') |
5 | end | 10 | end |
plugins/mezuro/lib/kalibro/entities/configuration.rb
@@ -7,7 +7,11 @@ class Kalibro::Entities::Configuration < Kalibro::Entities::Entity | @@ -7,7 +7,11 @@ class Kalibro::Entities::Configuration < Kalibro::Entities::Entity | ||
7 | end | 7 | end |
8 | 8 | ||
9 | def metric_configurations | 9 | def metric_configurations |
10 | - @metric_configuration | 10 | + if @metric_configuration != nil |
11 | + @metric_configuration | ||
12 | + else | ||
13 | + [] | ||
14 | + end | ||
11 | end | 15 | end |
12 | 16 | ||
13 | def metric_configurations=(metric_configurations) | 17 | def metric_configurations=(metric_configurations) |
plugins/mezuro/lib/kalibro/entities/entity.rb
@@ -2,12 +2,21 @@ class Kalibro::Entities::Entity | @@ -2,12 +2,21 @@ class Kalibro::Entities::Entity | ||
2 | 2 | ||
3 | def self.from_hash(hash) | 3 | def self.from_hash(hash) |
4 | entity = self.new | 4 | entity = self.new |
5 | - hash.each { |field, value| entity.set(field, value) } | 5 | + hash.each { |field, value| entity.set(field, value) if is_valid?(field) } |
6 | entity | 6 | entity |
7 | end | 7 | end |
8 | 8 | ||
9 | + def self.is_valid?(field) | ||
10 | + field.to_s[0] != '@' and field != :attributes! | ||
11 | + end | ||
12 | + | ||
13 | + def self.date_with_milliseconds(date) | ||
14 | + milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | ||
15 | + date.to_s[0..18] + milliseconds + date.to_s[19..-1] | ||
16 | + end | ||
17 | + | ||
9 | def set(field, value) | 18 | def set(field, value) |
10 | - send("#{field}=", value) | 19 | + send("#{field}=", value) if not field.to_s.start_with? '@' |
11 | end | 20 | end |
12 | 21 | ||
13 | def to_entity_array(value, entity_class = nil) | 22 | def to_entity_array(value, entity_class = nil) |
@@ -24,16 +33,16 @@ class Kalibro::Entities::Entity | @@ -24,16 +33,16 @@ class Kalibro::Entities::Entity | ||
24 | fields.each do |field| | 33 | fields.each do |field| |
25 | field_value = self.get(field) | 34 | field_value = self.get(field) |
26 | hash[field] = convert_to_hash(field_value) if ! field_value.nil? | 35 | hash[field] = convert_to_hash(field_value) if ! field_value.nil? |
36 | + if need_xml_type?(field_value) | ||
37 | + hash = {:attributes! => {}}.merge(hash) | ||
38 | + hash[:attributes!][field.to_sym] = { | ||
39 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
40 | + 'xsi:type' => 'kalibro:' + xml_class_name(field_value) } | ||
41 | + end | ||
27 | end | 42 | end |
28 | hash | 43 | hash |
29 | end | 44 | end |
30 | 45 | ||
31 | - def convert_to_hash(value) | ||
32 | - return value.collect { |element| convert_to_hash(element) } if value.kind_of?(Array) | ||
33 | - return value.to_hash if value.kind_of?(Kalibro::Entities::Entity) | ||
34 | - value | ||
35 | - end | ||
36 | - | ||
37 | def ==(other) | 46 | def ==(other) |
38 | begin | 47 | begin |
39 | fields.each.inject(true) { |equal, field| equal && (self.get(field) == other.get(field)) } | 48 | fields.each.inject(true) { |equal, field| equal && (self.get(field) == other.get(field)) } |
@@ -42,6 +51,8 @@ class Kalibro::Entities::Entity | @@ -42,6 +51,8 @@ class Kalibro::Entities::Entity | ||
42 | end | 51 | end |
43 | end | 52 | end |
44 | 53 | ||
54 | + protected | ||
55 | + | ||
45 | def fields | 56 | def fields |
46 | instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } | 57 | instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } |
47 | end | 58 | end |
@@ -50,4 +61,24 @@ class Kalibro::Entities::Entity | @@ -50,4 +61,24 @@ class Kalibro::Entities::Entity | ||
50 | send("#{field}") | 61 | send("#{field}") |
51 | end | 62 | end |
52 | 63 | ||
53 | -end | ||
54 | \ No newline at end of file | 64 | \ No newline at end of file |
65 | + def convert_to_hash(value) | ||
66 | + return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) | ||
67 | + return value.to_hash if value.is_a?(Kalibro::Entities::Entity) | ||
68 | + return self.class.date_with_milliseconds(value) if value.is_a?(DateTime) | ||
69 | + return 'INF' if value.is_a?(Float) and value.infinite? == 1 | ||
70 | + return '-INF' if value.is_a?(Float) and value.infinite? == -1 | ||
71 | + value | ||
72 | + end | ||
73 | + | ||
74 | + def need_xml_type?(value) | ||
75 | + value.is_a?(Kalibro::Entities::Entity) and value.class.superclass != Kalibro::Entities::Entity | ||
76 | + end | ||
77 | + | ||
78 | + def xml_class_name(entity) | ||
79 | + xml_name = entity.class.name | ||
80 | + xml_name["Kalibro::Entities::"] = "" | ||
81 | + xml_name[0..0] = xml_name[0..0].downcase | ||
82 | + xml_name + "Xml" | ||
83 | + end | ||
84 | + | ||
85 | +end |
plugins/mezuro/lib/kalibro/entities/error.rb
1 | class Kalibro::Entities::Error < Kalibro::Entities::Entity | 1 | class Kalibro::Entities::Error < Kalibro::Entities::Entity |
2 | 2 | ||
3 | - attr_accessor :message, :stack_trace_element | 3 | + attr_accessor :error_class, :message, :stack_trace_element |
4 | 4 | ||
5 | def stack_trace_element=(value) | 5 | def stack_trace_element=(value) |
6 | @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement) | 6 | @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement) |
plugins/mezuro/lib/kalibro/entities/metric.rb
@@ -2,4 +2,4 @@ class Kalibro::Entities::Metric < Kalibro::Entities::Entity | @@ -2,4 +2,4 @@ class Kalibro::Entities::Metric < Kalibro::Entities::Entity | ||
2 | 2 | ||
3 | attr_accessor :name, :scope, :description | 3 | attr_accessor :name, :scope, :description |
4 | 4 | ||
5 | -end | ||
6 | \ No newline at end of file | 5 | \ No newline at end of file |
6 | +end |
plugins/mezuro/lib/kalibro/entities/metric_configuration.rb
@@ -11,10 +11,19 @@ class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity | @@ -11,10 +11,19 @@ class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity | ||
11 | end | 11 | end |
12 | end | 12 | end |
13 | 13 | ||
14 | + def weight=(value) | ||
15 | + @weight = value.to_f | ||
16 | + end | ||
17 | + | ||
14 | def range=(value) | 18 | def range=(value) |
15 | @range = to_entity_array(value, Kalibro::Entities::Range) | 19 | @range = to_entity_array(value, Kalibro::Entities::Range) |
16 | end | 20 | end |
17 | 21 | ||
22 | + def add_range(new_range) | ||
23 | + @range = [] if @range.nil? | ||
24 | + @range << new_range | ||
25 | + end | ||
26 | + | ||
18 | def ranges | 27 | def ranges |
19 | @range | 28 | @range |
20 | end | 29 | end |
@@ -23,4 +32,4 @@ class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity | @@ -23,4 +32,4 @@ class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity | ||
23 | @range = ranges | 32 | @range = ranges |
24 | end | 33 | end |
25 | 34 | ||
26 | -end | ||
27 | \ No newline at end of file | 35 | \ No newline at end of file |
36 | +end |
plugins/mezuro/lib/kalibro/entities/metric_result.rb
@@ -14,12 +14,17 @@ class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity | @@ -14,12 +14,17 @@ class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity | ||
14 | end | 14 | end |
15 | end | 15 | end |
16 | 16 | ||
17 | + def value=(value) | ||
18 | + @value = value.to_f | ||
19 | + end | ||
20 | + | ||
17 | def range=(value) | 21 | def range=(value) |
18 | @range = to_entity(value, Kalibro::Entities::Range) | 22 | @range = to_entity(value, Kalibro::Entities::Range) |
19 | end | 23 | end |
20 | 24 | ||
21 | def descendent_result=(value) | 25 | def descendent_result=(value) |
22 | - @descendent_result = to_entity_array(value) | 26 | + array = value.kind_of?(Array) ? value : [value] |
27 | + @descendent_result = array.collect {|element| element.to_f} | ||
23 | end | 28 | end |
24 | 29 | ||
25 | def descendent_results | 30 | def descendent_results |
plugins/mezuro/lib/kalibro/entities/module.rb
@@ -2,4 +2,17 @@ class Kalibro::Entities::Module < Kalibro::Entities::Entity | @@ -2,4 +2,17 @@ class Kalibro::Entities::Module < Kalibro::Entities::Entity | ||
2 | 2 | ||
3 | attr_accessor :name, :granularity | 3 | attr_accessor :name, :granularity |
4 | 4 | ||
5 | -end | ||
6 | \ No newline at end of file | 5 | \ No newline at end of file |
6 | + def self.parent_names(name) | ||
7 | + path = [] | ||
8 | + ancestors = [] | ||
9 | + name.split(".").each do |token| | ||
10 | + path << token | ||
11 | + ancestors << path.join(".") | ||
12 | + end | ||
13 | + ancestors | ||
14 | + end | ||
15 | + | ||
16 | + def ancestor_names | ||
17 | + Kalibro::Entities::Module.parent_names(@name) | ||
18 | + end | ||
19 | +end |
plugins/mezuro/lib/kalibro/entities/module_node.rb
@@ -6,14 +6,6 @@ class Kalibro::Entities::ModuleNode < Kalibro::Entities::Entity | @@ -6,14 +6,6 @@ class Kalibro::Entities::ModuleNode < Kalibro::Entities::Entity | ||
6 | @module = to_entity(value, Kalibro::Entities::Module) | 6 | @module = to_entity(value, Kalibro::Entities::Module) |
7 | end | 7 | end |
8 | 8 | ||
9 | - def module_name | ||
10 | - @module.name | ||
11 | - end | ||
12 | - | ||
13 | - def granularity | ||
14 | - @module.granularity | ||
15 | - end | ||
16 | - | ||
17 | def child=(value) | 9 | def child=(value) |
18 | @child = to_entity_array(value, Kalibro::Entities::ModuleNode) | 10 | @child = to_entity_array(value, Kalibro::Entities::ModuleNode) |
19 | end | 11 | end |
plugins/mezuro/lib/kalibro/entities/module_result.rb
@@ -6,6 +6,15 @@ class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity | @@ -6,6 +6,15 @@ class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity | ||
6 | @module = to_entity(value, Kalibro::Entities::Module) | 6 | @module = to_entity(value, Kalibro::Entities::Module) |
7 | end | 7 | end |
8 | 8 | ||
9 | + def date=(value) | ||
10 | + @date = value | ||
11 | + @date = DateTime.parse(value) if value.is_a?(String) | ||
12 | + end | ||
13 | + | ||
14 | + def grade=(value) | ||
15 | + @grade = value.to_f | ||
16 | + end | ||
17 | + | ||
9 | def metric_result=(value) | 18 | def metric_result=(value) |
10 | @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult) | 19 | @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult) |
11 | end | 20 | end |
plugins/mezuro/lib/kalibro/entities/native_metric.rb
@@ -2,4 +2,16 @@ class Kalibro::Entities::NativeMetric < Kalibro::Entities::Metric | @@ -2,4 +2,16 @@ class Kalibro::Entities::NativeMetric < Kalibro::Entities::Metric | ||
2 | 2 | ||
3 | attr_accessor :origin, :language | 3 | attr_accessor :origin, :language |
4 | 4 | ||
5 | -end | ||
6 | \ No newline at end of file | 5 | \ No newline at end of file |
6 | + def languages | ||
7 | + @language | ||
8 | + end | ||
9 | + | ||
10 | + def languages=(languages) | ||
11 | + @language = languages | ||
12 | + end | ||
13 | + | ||
14 | + def language=(value) | ||
15 | + @language = to_entity_array(value) | ||
16 | + end | ||
17 | + | ||
18 | +end |
plugins/mezuro/lib/kalibro/entities/project.rb
@@ -9,5 +9,4 @@ class Kalibro::Entities::Project < Kalibro::Entities::Entity | @@ -9,5 +9,4 @@ class Kalibro::Entities::Project < Kalibro::Entities::Entity | ||
9 | def error=(value) | 9 | def error=(value) |
10 | @error = to_entity(value, Kalibro::Entities::Error) | 10 | @error = to_entity(value, Kalibro::Entities::Error) |
11 | end | 11 | end |
12 | - | ||
13 | -end | ||
14 | \ No newline at end of file | 12 | \ No newline at end of file |
13 | +end |
plugins/mezuro/lib/kalibro/entities/project_result.rb
1 | class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity | 1 | class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity |
2 | - | ||
3 | - attr_accessor :project, :date, :load_time, :analysis_time, :source_tree | 2 | + |
3 | + attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time | ||
4 | 4 | ||
5 | def project=(value) | 5 | def project=(value) |
6 | @project = to_entity(value, Kalibro::Entities::Project) | 6 | @project = to_entity(value, Kalibro::Entities::Project) |
7 | end | 7 | end |
8 | 8 | ||
9 | + def date=(value) | ||
10 | + @date = value | ||
11 | + @date = DateTime.parse(value) if value.is_a?(String) | ||
12 | + end | ||
13 | + | ||
14 | + def load_time=(value) | ||
15 | + @load_time = value.to_i | ||
16 | + end | ||
17 | + | ||
18 | + def collect_time=(value) | ||
19 | + @collect_time = value.to_i | ||
20 | + end | ||
21 | + | ||
22 | + def analysis_time=(value) | ||
23 | + @analysis_time = value.to_i | ||
24 | + end | ||
25 | + | ||
9 | def source_tree=(value) | 26 | def source_tree=(value) |
10 | @source_tree = to_entity(value, Kalibro::Entities::ModuleNode) | 27 | @source_tree = to_entity(value, Kalibro::Entities::ModuleNode) |
11 | end | 28 | end |
@@ -31,4 +48,29 @@ class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity | @@ -31,4 +48,29 @@ class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity | ||
31 | ('%2d' % amount).sub(/\s/, '0') | 48 | ('%2d' % amount).sub(/\s/, '0') |
32 | end | 49 | end |
33 | 50 | ||
34 | -end | ||
35 | \ No newline at end of file | 51 | \ No newline at end of file |
52 | + def node_of(module_name) | ||
53 | + if module_name.nil? or module_name == project.name | ||
54 | + node = source_tree | ||
55 | + else | ||
56 | + node = get_node(module_name) | ||
57 | + end | ||
58 | + end | ||
59 | + | ||
60 | + def get_node(module_name) | ||
61 | + path = Kalibro::Entities::Module.parent_names(module_name) | ||
62 | + parent = @source_tree | ||
63 | + path.each do |node_name| | ||
64 | + parent = get_leaf_from(parent, node_name) | ||
65 | + end | ||
66 | + return parent | ||
67 | + end | ||
68 | + | ||
69 | + private | ||
70 | + def get_leaf_from(node, module_name) | ||
71 | + node.children.each do |child_node| | ||
72 | + return child_node if child_node.module.name == module_name | ||
73 | + end | ||
74 | + nil | ||
75 | + end | ||
76 | + | ||
77 | +end |
plugins/mezuro/lib/kalibro/entities/range.rb
@@ -2,4 +2,18 @@ class Kalibro::Entities::Range < Kalibro::Entities::Entity | @@ -2,4 +2,18 @@ class Kalibro::Entities::Range < Kalibro::Entities::Entity | ||
2 | 2 | ||
3 | attr_accessor :beginning, :end, :label, :grade, :color, :comments | 3 | attr_accessor :beginning, :end, :label, :grade, :color, :comments |
4 | 4 | ||
5 | + def beginning=(value) | ||
6 | + @beginning = value.to_f | ||
7 | + @beginning = -1.0/0.0 if value == "-INF" | ||
8 | + end | ||
9 | + | ||
10 | + def end=(value) | ||
11 | + @end = value.to_f | ||
12 | + @end = 1.0/0.0 if value == "INF" | ||
13 | + end | ||
14 | + | ||
15 | + def grade=(value) | ||
16 | + @grade = value.to_f | ||
17 | + end | ||
18 | + | ||
5 | end | 19 | end |
6 | \ No newline at end of file | 20 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb
@@ -2,4 +2,8 @@ class Kalibro::Entities::StackTraceElement < Kalibro::Entities::Entity | @@ -2,4 +2,8 @@ class Kalibro::Entities::StackTraceElement < Kalibro::Entities::Entity | ||
2 | 2 | ||
3 | attr_accessor :declaring_class, :method_name, :file_name, :line_number | 3 | attr_accessor :declaring_class, :method_name, :file_name, :line_number |
4 | 4 | ||
5 | + def line_number=(value) | ||
6 | + @line_number = value.to_i | ||
7 | + end | ||
8 | + | ||
5 | end | 9 | end |
6 | \ No newline at end of file | 10 | \ No newline at end of file |
plugins/mezuro/lib/mezuro_plugin.rb
@@ -9,16 +9,11 @@ class MezuroPlugin < Noosfero::Plugin | @@ -9,16 +9,11 @@ class MezuroPlugin < Noosfero::Plugin | ||
9 | end | 9 | end |
10 | 10 | ||
11 | def content_types | 11 | def content_types |
12 | - [MezuroPlugin::ProjectContent, | ||
13 | - MezuroPlugin::ConfigurationContent] | 12 | + [MezuroPlugin::ConfigurationContent, MezuroPlugin::ProjectContent] |
14 | end | 13 | end |
15 | 14 | ||
16 | def stylesheet? | 15 | def stylesheet? |
17 | true | 16 | true |
18 | end | 17 | end |
19 | 18 | ||
20 | - def js_files | ||
21 | - ['javascripts/results.js', 'javascripts/toogle.js'] | ||
22 | - end | ||
23 | - | ||
24 | end | 19 | end |
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
@@ -5,10 +5,10 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -5,10 +5,10 @@ class MezuroPlugin::ConfigurationContent < Article | ||
5 | end | 5 | end |
6 | 6 | ||
7 | def self.description | 7 | def self.description |
8 | - 'Kalibro configuration for some project' | 8 | + 'Sets of thresholds to interpret metrics' |
9 | end | 9 | end |
10 | 10 | ||
11 | - settings_items :description | 11 | + settings_items :description, :metrics |
12 | 12 | ||
13 | include ActionView::Helpers::TagHelper | 13 | include ActionView::Helpers::TagHelper |
14 | def to_html(options = {}) | 14 | def to_html(options = {}) |
@@ -17,8 +17,8 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -17,8 +17,8 @@ class MezuroPlugin::ConfigurationContent < Article | ||
17 | end | 17 | end |
18 | end | 18 | end |
19 | 19 | ||
20 | - def configuration | ||
21 | - Kalibro::Client::ConfigurationClient.new.configuration(title) | 20 | + def configuration #FIXME invalid method name |
21 | + Kalibro::Client::ConfigurationClient.configuration(name) | ||
22 | end | 22 | end |
23 | 23 | ||
24 | after_save :send_configuration_to_service | 24 | after_save :send_configuration_to_service |
@@ -27,18 +27,11 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -27,18 +27,11 @@ class MezuroPlugin::ConfigurationContent < Article | ||
27 | private | 27 | private |
28 | 28 | ||
29 | def send_configuration_to_service | 29 | def send_configuration_to_service |
30 | - Kalibro::Client::ConfigurationClient.save(create_configuration) | 30 | + Kalibro::Client::ConfigurationClient.save(self) |
31 | end | 31 | end |
32 | 32 | ||
33 | def remove_configuration_from_service | 33 | def remove_configuration_from_service |
34 | - Kalibro::Client::ConfigurationClient.remove(title) | ||
35 | - end | ||
36 | - | ||
37 | - def create_configuration | ||
38 | - configuration = Kalibro::Entities::Configuration.new | ||
39 | - configuration.name = title | ||
40 | - configuration.description = description | ||
41 | - configuration | 34 | + Kalibro::Client::ConfigurationClient.remove(name) |
42 | end | 35 | end |
43 | 36 | ||
44 | end | 37 | end |
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
0 → 100644
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +require 'googlecharts' | ||
2 | + | ||
3 | +class MezuroPlugin::Helpers::ContentViewerHelper | ||
4 | + def self.format_grade(grade) | ||
5 | + sprintf("%.2f", grade.to_f) | ||
6 | + end | ||
7 | + | ||
8 | + def self.create_periodicity_options | ||
9 | + [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] | ||
10 | + end | ||
11 | + | ||
12 | + def self.generate_chart(values) | ||
13 | + Gchart.line( | ||
14 | + :title_color => 'FF0000', | ||
15 | + :size => '600x180', | ||
16 | + :bg => {:color => 'efefef', :type => 'stripes'}, | ||
17 | + :line_colors => 'c4a000', | ||
18 | + :data => values, | ||
19 | + :axis_with_labels => 'y') | ||
20 | + end | ||
21 | + | ||
22 | + def self.get_periodicity_option(index) | ||
23 | + options = [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] | ||
24 | + selected_option = options.find { |option| option.last == index.to_i } | ||
25 | + selected_option.first | ||
26 | + end | ||
27 | +end |
plugins/mezuro/lib/mezuro_plugin/metric_configuration_content.rb
0 → 100644
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +class MezuroPlugin::MetricConfigurationContent < Article | ||
2 | + | ||
3 | + def self.short_description | ||
4 | + 'Kalibro Configurated Metric' | ||
5 | + end | ||
6 | + | ||
7 | + def self.description | ||
8 | + 'Sets of thresholds to interpret a metric' | ||
9 | + end | ||
10 | + | ||
11 | + settings_items :description, :code, :weight, :scope, :aggregation_form, :range | ||
12 | + | ||
13 | + include ActionView::Helpers::TagHelper | ||
14 | + def to_html(options = {}) | ||
15 | + lambda do | ||
16 | + render :file => 'content_viewer/show_configuration.rhtml' | ||
17 | + end | ||
18 | + end | ||
19 | + | ||
20 | + def metric_configuration #FIXME invalid method name | ||
21 | + Kalibro::Client::MetricConfigurationClient.metric_configuration(name) | ||
22 | + end | ||
23 | + | ||
24 | + after_save :send_metric_configuration_to_service | ||
25 | + after_destroy :remove_metric_configuration_from_service | ||
26 | + | ||
27 | + private | ||
28 | + | ||
29 | + def send_metric_configuration_to_service | ||
30 | + Kalibro::Client::MetricConfigurationClient.save(self) | ||
31 | + end | ||
32 | + | ||
33 | + def remove_metric_configuration_from_service | ||
34 | + Kalibro::Client::MetricConfigurationClient.remove(name) | ||
35 | + end | ||
36 | + | ||
37 | +end |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
1 | class MezuroPlugin::ProjectContent < Article | 1 | class MezuroPlugin::ProjectContent < Article |
2 | + validate :validate_kalibro_project_name | ||
2 | 3 | ||
3 | def self.short_description | 4 | def self.short_description |
4 | 'Kalibro project' | 5 | 'Kalibro project' |
@@ -8,7 +9,7 @@ class MezuroPlugin::ProjectContent < Article | @@ -8,7 +9,7 @@ class MezuroPlugin::ProjectContent < Article | ||
8 | 'Software project tracked by Kalibro' | 9 | 'Software project tracked by Kalibro' |
9 | end | 10 | end |
10 | 11 | ||
11 | - settings_items :license, :description, :repository_type, :repository_url, :configuration_name | 12 | + settings_items :license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days |
12 | 13 | ||
13 | include ActionView::Helpers::TagHelper | 14 | include ActionView::Helpers::TagHelper |
14 | def to_html(options = {}) | 15 | def to_html(options = {}) |
@@ -16,19 +17,33 @@ class MezuroPlugin::ProjectContent < Article | @@ -16,19 +17,33 @@ class MezuroPlugin::ProjectContent < Article | ||
16 | render :file => 'content_viewer/show_project.rhtml' | 17 | render :file => 'content_viewer/show_project.rhtml' |
17 | end | 18 | end |
18 | end | 19 | end |
20 | + | ||
19 | 21 | ||
20 | - # FIXME is this really needed? | ||
21 | def project | 22 | def project |
22 | - Kalibro::Client::ProjectClient.new.project(title) | 23 | + @project ||= Kalibro::Client::ProjectClient.project(name) |
23 | end | 24 | end |
24 | 25 | ||
25 | def project_result | 26 | def project_result |
26 | - @project_result ||= Kalibro::Client::ProjectResultClient.new.last_result(title) | 27 | + @project_result ||= Kalibro::Client::ProjectResultClient.last_result(name) |
28 | + end | ||
29 | + | ||
30 | + def get_date_result(date) | ||
31 | + client = Kalibro::Client::ProjectResultClient.new | ||
32 | + @project_result ||= client.has_results_before(name, date) ? client.last_result_before(name, date) : | ||
33 | +client.first_result_after(name, date) | ||
27 | end | 34 | end |
28 | 35 | ||
29 | def module_result(module_name) | 36 | def module_result(module_name) |
30 | - @module_client ||= Kalibro::Client::ModuleResultClient.new | ||
31 | - @module_client.module_result(title, module_name, project_result.date) | 37 | + module_name = project.name if module_name.nil? |
38 | + @module_client ||= module_result_client.module_result(project.name, module_name, project_result.date) | ||
39 | + end | ||
40 | + | ||
41 | + def result_history(module_name) | ||
42 | + @result_history ||= module_result_client.result_history(project.name, module_name) | ||
43 | + end | ||
44 | + | ||
45 | + def module_result_client | ||
46 | + @module_result_client ||= Kalibro::Client::ModuleResultClient.new | ||
32 | end | 47 | end |
33 | 48 | ||
34 | after_save :send_project_to_service | 49 | after_save :send_project_to_service |
@@ -36,31 +51,20 @@ class MezuroPlugin::ProjectContent < Article | @@ -36,31 +51,20 @@ class MezuroPlugin::ProjectContent < Article | ||
36 | 51 | ||
37 | private | 52 | private |
38 | 53 | ||
39 | - def send_project_to_service | ||
40 | - Kalibro::Client::ProjectClient.save(create_project) | ||
41 | - Kalibro::Client::KalibroClient.process_project(title) | ||
42 | - end | ||
43 | - | ||
44 | - def remove_project_from_service | ||
45 | - Kalibro::Client::ProjectClient.remove(title) | 54 | + def validate_kalibro_project_name |
55 | + existing = Kalibro::Client::ProjectClient.new.project_names | ||
56 | + | ||
57 | + if existing.include?(name) | ||
58 | + errors.add_to_base("Project name already exists in Kalibro") | ||
59 | + end | ||
46 | end | 60 | end |
47 | 61 | ||
48 | - def create_project | ||
49 | - project = Kalibro::Entities::Project.new | ||
50 | - project.name = title | ||
51 | - project.license = license | ||
52 | - project.description = description | ||
53 | - project.repository = create_repository | ||
54 | - project.configuration_name = configuration_name | ||
55 | - project | 62 | + def send_project_to_service |
63 | + Kalibro::Client::ProjectClient.save(self) | ||
64 | + Kalibro::Client::KalibroClient.process_project(name, periodicity_in_days) | ||
56 | end | 65 | end |
57 | 66 | ||
58 | - def create_repository | ||
59 | - repository = Kalibro::Entities::Repository.new | ||
60 | - repository.type = repository_type | ||
61 | - repository.address = repository_url | ||
62 | - repository | 67 | + def remove_project_from_service |
68 | + Kalibro::Client::ProjectClient.remove(name) | ||
63 | end | 69 | end |
64 | - | ||
65 | end | 70 | end |
66 | - |
534 Bytes
3.31 KB
plugins/mezuro/public/images/mezuro.gif
2 KB
plugins/mezuro/public/images/mezuro.png
3.65 KB
@@ -0,0 +1,140 @@ | @@ -0,0 +1,140 @@ | ||
1 | +var processingTree = false; | ||
2 | +var metricName; | ||
3 | +jQuery(function (){ | ||
4 | + jQuery('.source-tree-link').live("click", reloadModule); | ||
5 | + jQuery('[data-show]').live("click", toggle_mezuro); | ||
6 | + jQuery('[show-metric-history]').live("click", display_metric_history); | ||
7 | + jQuery('[show-grade-history]').live("click", display_grade_history); | ||
8 | + showLoadingProcess(true); | ||
9 | + showProjectContent(); | ||
10 | +}); | ||
11 | + | ||
12 | +function showProjectContent() { | ||
13 | + callAction('project_state', {}, showProjectContentFor); | ||
14 | +} | ||
15 | + | ||
16 | +function display_metric_history() { | ||
17 | + var module_name = jQuery(this).attr('data-module-name'); | ||
18 | + var metric_name = jQuery(this).attr('data-metric-name'); | ||
19 | + metricName = metric_name; | ||
20 | + callAction('module_metrics_history', {module_name: module_name, metric_name: metric_name}, show_metrics); | ||
21 | + return false; | ||
22 | +} | ||
23 | + | ||
24 | +function display_grade_history() { | ||
25 | + var module_name = jQuery(this).attr('data-module-name'); | ||
26 | + callAction('module_grade_history', {module_name: module_name}, show_grades); | ||
27 | + return false; | ||
28 | +} | ||
29 | + | ||
30 | +function show_metrics(content) { | ||
31 | + jQuery('#historical-' + metricName).html(content); | ||
32 | +} | ||
33 | + | ||
34 | +function show_grades(content) { | ||
35 | + jQuery('#historical-grade').html(content); | ||
36 | +} | ||
37 | + | ||
38 | +function toggle_mezuro(){ | ||
39 | + var element = jQuery(this).attr('data-show'); | ||
40 | + jQuery(element).toggle(); | ||
41 | + return false; | ||
42 | +} | ||
43 | + | ||
44 | +function reloadModule(){ | ||
45 | + var module_name = jQuery(this).attr('data-module-name'); | ||
46 | + showLoadingProcess(false); | ||
47 | + processingTree = true; | ||
48 | + callAction('project_tree', {module_name: module_name }, showProjectTree); | ||
49 | + callAction('module_result', {module_name: module_name}, showModuleResult); | ||
50 | + return false; | ||
51 | +} | ||
52 | + | ||
53 | +function reloadProjectWithDate(){ | ||
54 | + var day = jQuery("#project_date_day").val(); | ||
55 | + var month = jQuery("#project_date_month").val(); | ||
56 | + var year = jQuery("#project_date_year").val(); | ||
57 | + | ||
58 | + var date = year + "-" + month + "-" + day + "T00:00:00+00:00"; | ||
59 | + | ||
60 | + reloadProject(date); | ||
61 | + return false; | ||
62 | +} | ||
63 | + | ||
64 | +function reloadProject(date){ | ||
65 | + showLoadingProcess(true); | ||
66 | + | ||
67 | + callAction('project_result', {date: date}, showProjectResult); | ||
68 | + callAction('project_tree', {date: date}, showProjectTree); | ||
69 | + callAction('module_result', {date: date}, showModuleResult); | ||
70 | +} | ||
71 | + | ||
72 | +function showProjectContentFor(state){ | ||
73 | + if (state == 'ERROR') { | ||
74 | + jQuery('#project-state').html('ERROR'); | ||
75 | + callAction('project_error', {}, showProjectResult); | ||
76 | + } | ||
77 | + else if (state == 'READY') { | ||
78 | + jQuery('#msg-time').html(''); | ||
79 | + jQuery('#project-state').html('READY'); | ||
80 | + callAction('project_result', {}, showProjectResult); | ||
81 | + callAction('project_tree', {}, showProjectTree); | ||
82 | + var project_name = jQuery("#project-result").attr('data-project-name'); | ||
83 | + callAction('module_result', {module_name: project_name}, showModuleResult); | ||
84 | + } | ||
85 | + else if (state.endsWith("ING")) { | ||
86 | + jQuery('#project-state').html(state); | ||
87 | + jQuery('#msg-time').html("The project analysis may take long. <br/> You'll receive an e-mail when it's ready!"); | ||
88 | + showProjectContentAfter(20); | ||
89 | + } | ||
90 | +} | ||
91 | + | ||
92 | +function showProjectContentAfter(seconds){ | ||
93 | + if (seconds > 0){ | ||
94 | + setTimeout(function() { showProjectContentAfter(seconds - 10);}, 10000); | ||
95 | + } else { | ||
96 | + showProjectContent(); | ||
97 | + } | ||
98 | +} | ||
99 | + | ||
100 | +function showProjectResult(content) { | ||
101 | + jQuery('#project-result').html(content); | ||
102 | +} | ||
103 | + | ||
104 | +function showProjectTree(content){ | ||
105 | + processingTree = false; | ||
106 | + jQuery('#project-tree').html(content); | ||
107 | + return false; | ||
108 | +} | ||
109 | + | ||
110 | +function showModuleResult(content){ | ||
111 | + if (processingTree != true){ | ||
112 | + jQuery('#module-result').html(content); | ||
113 | + } | ||
114 | + return false; | ||
115 | +} | ||
116 | + | ||
117 | +function callAction(action, params, callback){ | ||
118 | + var profile = projectContentData('profile'); | ||
119 | + var content = projectContentData('content'); | ||
120 | + var endpoint = '/profile/' + profile + '/plugins/mezuro/' + action + '/' + content; | ||
121 | + jQuery.get(endpoint, params, callback); | ||
122 | +} | ||
123 | + | ||
124 | +function projectContentData(data){ | ||
125 | + return jQuery('#project-result').attr('data-' + data); | ||
126 | +} | ||
127 | + | ||
128 | +function showLoadingProcess(firstLoad){ | ||
129 | + if(firstLoad) | ||
130 | + showProjectResult("<img src='/images/loading-small.gif'/>"); | ||
131 | + | ||
132 | + showProjectTree("<img src='/images/loading-small.gif'/>"); | ||
133 | + showModuleResult("<img src='/images/loading-small.gif'/>"); | ||
134 | +} | ||
135 | + | ||
136 | +function sourceNodeToggle(id){ | ||
137 | + var suffixes = ['_hidden', '_plus', '_minus']; | ||
138 | + for (var i in suffixes) | ||
139 | + jQuery('#' + id + suffixes[i]).toggle(); | ||
140 | +} |
plugins/mezuro/public/javascripts/results.js
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -function results($) { | ||
2 | - $('.module-result-link').click(show_module_result); | ||
3 | -} | ||
4 | - | ||
5 | -function show_module_result(){ | ||
6 | - var profile = jQuery('#module-result').attr('data-profile'); | ||
7 | - var project = jQuery('#module-result').attr('data-project-id'); | ||
8 | - var module_name = jQuery(this).attr('data-module-name'); | ||
9 | - var endpoint = '/profile/' + profile + '/plugins/mezuro/metrics/' + project; | ||
10 | - show_loading_message(module_name); | ||
11 | - jQuery.get(endpoint, {module_name: module_name}, show_result_table); | ||
12 | - return false; | ||
13 | -} | ||
14 | - | ||
15 | -function show_loading_message(module_name) { | ||
16 | - jQuery('#module-result').html("Loading results for " + module_name + "..."); | ||
17 | -} | ||
18 | - | ||
19 | -function show_result_table(content){ | ||
20 | - jQuery('#module-result').html(content); | ||
21 | -} | ||
22 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/public/javascripts/toogle.js
@@ -0,0 +1,68 @@ | @@ -0,0 +1,68 @@ | ||
1 | +jQuery(function (){ | ||
2 | + jQuery('#range_submit').live("click", validate_new_range_configuration); | ||
3 | + jQuery('#metric_configuration_submit').live("click", validate_metric_configuration); | ||
4 | +}); | ||
5 | + | ||
6 | + | ||
7 | + | ||
8 | +function validate_metric_configuration(){ | ||
9 | + var code = jQuery('#metric_configuration_code').val(); | ||
10 | + if (is_null(code)) | ||
11 | + { | ||
12 | + alert("Code must be filled out"); | ||
13 | + return false; | ||
14 | + } | ||
15 | + return true; | ||
16 | +} | ||
17 | + | ||
18 | +function is_null(value){ | ||
19 | + if(value == "" || value == null){ | ||
20 | + return true; | ||
21 | + } | ||
22 | + return false; | ||
23 | +} | ||
24 | + | ||
25 | +function IsNotNumeric(value){ | ||
26 | + if(value.match(/[0-9]*\.?[0-9]+/)) | ||
27 | + { | ||
28 | + return false; | ||
29 | + } | ||
30 | + return true; | ||
31 | +} | ||
32 | + | ||
33 | +function IsNotHexadecimal(value){ | ||
34 | + if(value.match(/[0-9a-fA-F]{1,8}/)) | ||
35 | + { | ||
36 | + return false; | ||
37 | + } | ||
38 | + return true; | ||
39 | +} | ||
40 | + | ||
41 | +function validate_new_range_configuration(event){ | ||
42 | + var label = jQuery("#range_label").val(); | ||
43 | + var beginning = jQuery("#range_beginning").val(); | ||
44 | + var end = jQuery("#range_end").val(); | ||
45 | + var color = jQuery("#range_color").val(); | ||
46 | + var grade = jQuery("#range_grade").val(); | ||
47 | + | ||
48 | + if (is_null(label) || is_null(beginning) || is_null(end) || is_null(color) || is_null(grade)) | ||
49 | + { | ||
50 | + alert("Please fill all fields marked with (*)"); | ||
51 | + return false; | ||
52 | + } | ||
53 | + if (IsNotNumeric(beginning) || IsNotNumeric(end) || IsNotNumeric(grade)) | ||
54 | + { | ||
55 | + alert("Beginning, End and Grade must be numeric values"); | ||
56 | + return false; | ||
57 | + } | ||
58 | + if (parseInt(beginning) > parseInt(end)) | ||
59 | + { | ||
60 | + alert("End must be greater than Beginning"); | ||
61 | + return false; | ||
62 | + } | ||
63 | + if (IsNotHexadecimal(color)){ | ||
64 | + alert("Color must be an hexadecimal value"); | ||
65 | + return false; | ||
66 | + } | ||
67 | + return true; | ||
68 | +} |
plugins/mezuro/public/style.css
1 | .link { | 1 | .link { |
2 | cursor: pointer; | 2 | cursor: pointer; |
3 | } | 3 | } |
4 | + | ||
5 | +.source-tree{ | ||
6 | + background: #e7e7e7; | ||
7 | + border: groove 1px #666; | ||
8 | +} | ||
9 | + | ||
10 | +.icon { | ||
11 | + width: 20px; | ||
12 | +} | ||
13 | + | ||
14 | +.source-tree-text{ | ||
15 | + font-family: Arial, Impact; | ||
16 | + font-size: 12px; | ||
17 | + border-left: solid 1px #666; | ||
18 | +} | ||
19 | + | ||
20 | +a:link,active,visited .ancestor{ | ||
21 | + font-family: Arial, Impact; | ||
22 | + color: #5E5400; | ||
23 | +} | ||
24 | + | ||
25 | +.path{ | ||
26 | + font-family: Arial, Impact; | ||
27 | + font-size: 14px; | ||
28 | + font-style: underline; | ||
29 | + display: inline; | ||
30 | +} |
@@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
1 | +Feature: mezuro content | ||
2 | + As a noosfero user | ||
3 | + I want to create a Kalibro 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 Kalibro project as an option to new content | ||
17 | + Given I am on My Community's cms | ||
18 | + When I follow "New content" | ||
19 | + Then I should see "Kalibro project" | ||
20 | + | ||
21 | + Scenario: I see Kalibro project's input form | ||
22 | + Given I am on My Community's cms | ||
23 | + When I follow "New content" | ||
24 | + And I follow "Kalibro project" | ||
25 | + Then I should see "Title" | ||
26 | + And I should see "License" | ||
27 | + And I should see "Repository type" | ||
28 | + And I should see "GIT" | ||
29 | + And I should see "REMOTE_ZIP" | ||
30 | + And I should see "REMOTE_TARBALL" | ||
31 | + And I should see "SUBVERSION" | ||
32 | + And I should see "Repository url" | ||
33 | + And I should see "Configuration" | ||
34 | + And I should see "Kalibro for Java" | ||
35 | + | ||
36 | + Scenario: I create a sample mezuro content | ||
37 | + Given I am on My Community's cms | ||
38 | + When I create a content of type "Kalibro project" with the following data | ||
39 | + | Title | Sample project | | ||
40 | + | License | BSD | | ||
41 | + | Repository type | GIT | | ||
42 | + | Repository url | git://example | | ||
43 | + Then I should see "Sample project" | ||
44 | + And I should see "Viewed one time" | ||
45 | + And I should see "BSD" | ||
46 | + | ||
47 | + Scenario: I create a real mezuro content | ||
48 | + Given I am on My Community's cms | ||
49 | + When I create a content of type "Kalibro project" with the following data | ||
50 | + | Title | Qt-Calculator | | ||
51 | + | License | GPL 2.0 | | ||
52 | + | Repository type | SUBVERSION | | ||
53 | + | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator | | ||
54 | + Then I should see "Qt-Calculator" | ||
55 | + | ||
56 | + Scenario: I see results from a real Kalibro project | ||
57 | + Given I am on My Community's cms | ||
58 | + When I create a content of type "Kalibro project" with the following data | ||
59 | + | Title | Qt-Calculator | | ||
60 | + | License | GPL | | ||
61 | + | Repository type | SUBVERSION | | ||
62 | + | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator | | ||
63 | + | Configuration | Kalibro for Java | | ||
64 | + Then I should see "Qt-Calculator" | ||
65 | + And I should see "GPL" | ||
66 | + And I should see "SUBVERSION" | ||
67 | + And I should see "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator" | ||
68 | + And I should see "Kalibro for Java" | ||
69 | + And I should see "Kalibro Service is loading the source code" |
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +require File.dirname(__FILE__) + '/native_metric_fixtures' | ||
2 | + | ||
3 | +class BaseToolFixtures | ||
4 | + | ||
5 | + def self.analizo | ||
6 | + base_tool = Kalibro::Entities::BaseTool.new | ||
7 | + base_tool.name = 'Analizo' | ||
8 | + base_tool.supported_metrics = [ | ||
9 | + NativeMetricFixtures.total_cof, | ||
10 | + NativeMetricFixtures.amloc] | ||
11 | + base_tool | ||
12 | + end | ||
13 | + | ||
14 | + def self.analizo_hash | ||
15 | + {:name => 'Analizo', :supported_metric => [ | ||
16 | + NativeMetricFixtures.total_cof_hash, | ||
17 | + NativeMetricFixtures.amloc_hash]} | ||
18 | + end | ||
19 | + | ||
20 | +end |
plugins/mezuro/test/fixtures/compound_metric_fixtures.rb
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +class CompoundMetricFixtures | ||
2 | + | ||
3 | + def self.sc | ||
4 | + sc = Kalibro::Entities::CompoundMetric.new | ||
5 | + sc.description = 'Calculate the Structural Complexity of the Code' | ||
6 | + sc.name = 'Structural Complexity' | ||
7 | + sc.scope = 'CLASS' | ||
8 | + sc.script = 'return 42;' | ||
9 | + sc | ||
10 | + end | ||
11 | + | ||
12 | + def self.sc_hash | ||
13 | + {:name => 'Structural Complexity', :scope => 'CLASS', :script => 'return 42;', :description => 'Calculate the Structural Complexity of the Code'} | ||
14 | + end | ||
15 | + | ||
16 | +end |
plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures.rb
0 → 100644
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +require File.dirname(__FILE__) + '/error_fixtures' | ||
2 | + | ||
3 | +class CompoundMetricWithErrorFixtures | ||
4 | + | ||
5 | + def self.create | ||
6 | + fixture = Kalibro::Entities::CompoundMetricWithError.new | ||
7 | + fixture.metric = CompoundMetricFixtures.sc | ||
8 | + fixture.error = ErrorFixtures.create | ||
9 | + fixture | ||
10 | + end | ||
11 | + | ||
12 | + def self.create_hash | ||
13 | + {:metric => CompoundMetricFixtures.sc_hash, :error => ErrorFixtures.create_hash, | ||
14 | + :attributes! => {:metric => { | ||
15 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
16 | + 'xsi:type' => 'kalibro:compoundMetricXml' }}} | ||
17 | + end | ||
18 | + | ||
19 | +end |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +require File.dirname(__FILE__) + '/metric_configuration_fixtures' | ||
2 | + | ||
3 | +class ConfigurationFixtures | ||
4 | + | ||
5 | + def self.kalibro_configuration | ||
6 | + configuration = Kalibro::Entities::Configuration.new | ||
7 | + configuration.name = 'Kalibro for Java' | ||
8 | + configuration.description = 'Kalibro configuration for Java projects.' | ||
9 | + configuration.metric_configurations = [ | ||
10 | + MetricConfigurationFixtures.amloc_configuration, | ||
11 | + MetricConfigurationFixtures.sc_configuration] | ||
12 | + configuration | ||
13 | + end | ||
14 | + | ||
15 | + def self.kalibro_configuration_hash | ||
16 | + {:name => 'Kalibro for Java', :description => 'Kalibro configuration for Java projects.', | ||
17 | + :metric_configuration => [ | ||
18 | + MetricConfigurationFixtures.amloc_configuration_hash, | ||
19 | + MetricConfigurationFixtures.sc_configuration_hash]} | ||
20 | + end | ||
21 | + | ||
22 | +end |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +require File.dirname(__FILE__) + '/stack_trace_element_fixtures' | ||
2 | + | ||
3 | +class ErrorFixtures | ||
4 | + | ||
5 | + def self.create | ||
6 | + error = Kalibro::Entities::Error.new | ||
7 | + error.error_class = 'java.lang.Exception' | ||
8 | + error.message = 'Error message from ErrorTest' | ||
9 | + error.stack_trace = [ | ||
10 | + StackTraceElementFixtures.create('my method 1', 42), | ||
11 | + StackTraceElementFixtures.create('my method 2', 84)] | ||
12 | + error | ||
13 | + end | ||
14 | + | ||
15 | + def self.create_hash | ||
16 | + {:error_class => 'java.lang.Exception', :message => 'Error message from ErrorTest', | ||
17 | + :stack_trace_element => [ | ||
18 | + StackTraceElementFixtures.create_hash('my method 1', 42), | ||
19 | + StackTraceElementFixtures.create_hash('my method 2', 84)]} | ||
20 | + end | ||
21 | + | ||
22 | +end |
plugins/mezuro/test/fixtures/metric_configuration_fixtures.rb
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +require File.dirname(__FILE__) + '/compound_metric_fixtures' | ||
2 | +require File.dirname(__FILE__) + '/native_metric_fixtures' | ||
3 | +require File.dirname(__FILE__) + '/range_fixtures' | ||
4 | + | ||
5 | +class MetricConfigurationFixtures | ||
6 | + | ||
7 | + def self.amloc_configuration | ||
8 | + amloc = Kalibro::Entities::MetricConfiguration.new | ||
9 | + amloc.metric = NativeMetricFixtures.amloc | ||
10 | + amloc.code = 'amloc' | ||
11 | + amloc.weight = 1.0 | ||
12 | + amloc.aggregation_form = 'AVERAGE' | ||
13 | + amloc.ranges = [RangeFixtures.amloc_excellent, RangeFixtures.amloc_bad] | ||
14 | + amloc | ||
15 | + end | ||
16 | + | ||
17 | + def self.metric_configuration_without_ranges | ||
18 | + amloc = Kalibro::Entities::MetricConfiguration.new | ||
19 | + amloc.metric = NativeMetricFixtures.amloc | ||
20 | + amloc.code = 'amloc' | ||
21 | + amloc.weight = 1.0 | ||
22 | + amloc.aggregation_form = 'AVERAGE' | ||
23 | + amloc | ||
24 | + end | ||
25 | + | ||
26 | + def self.sc_configuration | ||
27 | + sc = Kalibro::Entities::MetricConfiguration.new | ||
28 | + sc.metric = CompoundMetricFixtures.sc | ||
29 | + sc.code = 'sc' | ||
30 | + sc.weight = 1.0 | ||
31 | + sc.aggregation_form = 'AVERAGE' | ||
32 | + sc | ||
33 | + end | ||
34 | + | ||
35 | + def self.amloc_configuration_hash | ||
36 | + {:metric => NativeMetricFixtures.amloc_hash, :code => 'amloc', :weight => 1.0, | ||
37 | + :aggregation_form => 'AVERAGE', | ||
38 | + :range => [RangeFixtures.amloc_excellent_hash, RangeFixtures.amloc_bad_hash], | ||
39 | + :attributes! => {:metric => { | ||
40 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
41 | + 'xsi:type' => 'kalibro:nativeMetricXml' }}} | ||
42 | + end | ||
43 | + | ||
44 | + def self.sc_configuration_hash | ||
45 | + {:metric => CompoundMetricFixtures.sc_hash, :code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE', | ||
46 | + :attributes! => {:metric => { | ||
47 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
48 | + 'xsi:type' => 'kalibro:compoundMetricXml' }}} | ||
49 | + end | ||
50 | + | ||
51 | +end |
@@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
1 | +require File.dirname(__FILE__) + '/compound_metric_fixtures' | ||
2 | +require File.dirname(__FILE__) + '/native_metric_fixtures' | ||
3 | +require File.dirname(__FILE__) + '/range_fixtures' | ||
4 | + | ||
5 | +class MetricResultFixtures | ||
6 | + | ||
7 | + def self.amloc_result | ||
8 | + result = Kalibro::Entities::MetricResult.new | ||
9 | + result.metric = NativeMetricFixtures.amloc | ||
10 | + result.value = 0.0 | ||
11 | + result.descendent_results = [40.0, 42.0] | ||
12 | + result.range = RangeFixtures.amloc_excellent | ||
13 | + result | ||
14 | + end | ||
15 | + | ||
16 | + def self.sc_result | ||
17 | + result = Kalibro::Entities::MetricResult.new | ||
18 | + result.metric = CompoundMetricFixtures.sc | ||
19 | + result.value = 1.0 | ||
20 | + result.descendent_results = [2.0, 42.0] | ||
21 | + result | ||
22 | + end | ||
23 | + | ||
24 | + def self.amloc_result_hash | ||
25 | + {:metric => NativeMetricFixtures.amloc_hash, :value => 0.0, :descendent_result => [40.0, 42.0], | ||
26 | + :range => RangeFixtures.amloc_excellent_hash, | ||
27 | + :attributes! => {:metric => { | ||
28 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
29 | + 'xsi:type' => 'kalibro:nativeMetricXml' }}} | ||
30 | + end | ||
31 | + | ||
32 | + def self.sc_result_hash | ||
33 | + {:metric => CompoundMetricFixtures.sc_hash, :value => 1.0, :descendent_result => [2.0, 42.0], | ||
34 | + :attributes! => {:metric => { | ||
35 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
36 | + 'xsi:type' => 'kalibro:compoundMetricXml' }}} | ||
37 | + end | ||
38 | + | ||
39 | +end |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +class ModuleFixtures | ||
2 | + | ||
3 | + def self.qt_calculator | ||
4 | + entity = Kalibro::Entities::Module.new | ||
5 | + entity.name = 'Qt-Calculator' | ||
6 | + entity.granularity = 'APPLICATION' | ||
7 | + entity | ||
8 | + end | ||
9 | + | ||
10 | + def self.qt_calculator_hash | ||
11 | + {:name => 'Qt-Calculator', :granularity => 'APPLICATION'} | ||
12 | + end | ||
13 | + | ||
14 | +end |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +class ModuleNodeFixtures | ||
2 | + | ||
3 | + def self.qt_calculator_tree | ||
4 | + node = Kalibro::Entities::ModuleNode.new | ||
5 | + node.module = ModuleFixtures.qt_calculator | ||
6 | + org_node = new_node('org', 'PACKAGE') | ||
7 | + org_node.children = [new_node('org.Window', 'CLASS')] | ||
8 | + node.children = [org_node, new_node('Dialog', 'CLASS'), new_node('main', 'CLASS')] | ||
9 | + node | ||
10 | + end | ||
11 | + | ||
12 | + def self.qt_calculator_tree_hash | ||
13 | + {:module => ModuleFixtures.qt_calculator_hash, | ||
14 | + :child => [ | ||
15 | + {:module => {:name => 'org', :granularity => 'PACKAGE'}, | ||
16 | + :child => [{:module => {:name => 'org.Window', :granularity => 'CLASS'}}]}, | ||
17 | + {:module => {:name => 'Dialog', :granularity => 'CLASS'}}, | ||
18 | + {:module => {:name => 'main', :granularity => 'CLASS'}} | ||
19 | + ] | ||
20 | + } | ||
21 | + end | ||
22 | + | ||
23 | + private | ||
24 | + | ||
25 | + def self.new_node(name, granularity) | ||
26 | + the_module = Kalibro::Entities::Module.new | ||
27 | + the_module.name = name | ||
28 | + the_module.granularity = granularity | ||
29 | + node = Kalibro::Entities::ModuleNode.new | ||
30 | + node.module = the_module | ||
31 | + node | ||
32 | + end | ||
33 | + | ||
34 | +end |
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
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 | + | ||
5 | +class ModuleResultFixtures | ||
6 | + | ||
7 | + def self.create | ||
8 | + fixture = Kalibro::Entities::ModuleResult.new | ||
9 | + fixture.module = ModuleFixtures.qt_calculator | ||
10 | + fixture.date = DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000') | ||
11 | + fixture.grade = 10.0 | ||
12 | + fixture.metric_results = [ | ||
13 | + MetricResultFixtures.amloc_result, | ||
14 | + MetricResultFixtures.sc_result] | ||
15 | + fixture.compound_metrics_with_error = [CompoundMetricWithErrorFixtures.create] | ||
16 | + fixture | ||
17 | + end | ||
18 | + | ||
19 | + def self.create_hash | ||
20 | + {:module => ModuleFixtures.qt_calculator_hash, | ||
21 | + :date => '2011-10-20T18:26:43.151+00:00', :grade => 10.0, :metric_result => [ | ||
22 | + MetricResultFixtures.amloc_result_hash, | ||
23 | + MetricResultFixtures.sc_result_hash], | ||
24 | + :compound_metric_with_error => [CompoundMetricWithErrorFixtures.create_hash]} | ||
25 | + end | ||
26 | + | ||
27 | +end |
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +class NativeMetricFixtures | ||
2 | + | ||
3 | + def self.total_cof | ||
4 | + total_cof = Kalibro::Entities::NativeMetric.new | ||
5 | + total_cof.name = 'Total Coupling Factor' | ||
6 | + total_cof.scope = 'APPLICATION' | ||
7 | + total_cof.origin = 'Analizo' | ||
8 | + total_cof.languages = ['JAVA'] | ||
9 | + total_cof | ||
10 | + end | ||
11 | + | ||
12 | + def self.total_cof_hash | ||
13 | + {:name => 'Total Coupling Factor', :scope => 'APPLICATION', :origin => 'Analizo', :language => ['JAVA']} | ||
14 | + end | ||
15 | + | ||
16 | + def self.amloc | ||
17 | + total_cof = Kalibro::Entities::NativeMetric.new | ||
18 | + total_cof.name = 'Average Method LOC' | ||
19 | + total_cof.scope = 'CLASS' | ||
20 | + total_cof.origin = 'Analizo' | ||
21 | + total_cof.languages = ['JAVA'] | ||
22 | + total_cof | ||
23 | + end | ||
24 | + | ||
25 | + def self.amloc_hash | ||
26 | + {:name => 'Average Method LOC', :scope => 'CLASS', :origin => 'Analizo', :language => ['JAVA']} | ||
27 | + end | ||
28 | + | ||
29 | +end |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +require File.dirname(__FILE__) + '/repository_fixtures' | ||
2 | + | ||
3 | +class ProjectFixtures | ||
4 | + | ||
5 | + def self.qt_calculator | ||
6 | + project = Kalibro::Entities::Project.new | ||
7 | + project.name = 'Qt-Calculator' | ||
8 | + project.license = 'GPL' | ||
9 | + project.description = 'Calculator for Qt' | ||
10 | + project.repository = RepositoryFixtures.qt_calculator | ||
11 | + project.configuration_name = 'Kalibro for Java' | ||
12 | + project.state = 'READY' | ||
13 | + project | ||
14 | + end | ||
15 | + | ||
16 | + def self.qt_calculator_hash | ||
17 | + {:name => 'Qt-Calculator', :license => 'GPL', :description => 'Calculator for Qt', | ||
18 | + :repository => RepositoryFixtures.qt_calculator_hash, | ||
19 | + :configuration_name => 'Kalibro for Java', :state => 'READY'} | ||
20 | + end | ||
21 | + | ||
22 | +end |
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
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.qt_calculator | ||
8 | + result = Kalibro::Entities::ProjectResult.new | ||
9 | + result.project = ProjectFixtures.qt_calculator | ||
10 | + result.date = ModuleResultFixtures.create.date | ||
11 | + result.load_time = 14878 | ||
12 | + result.analysis_time = 1022 | ||
13 | + result.source_tree = ModuleNodeFixtures.qt_calculator_tree | ||
14 | + result.collect_time = 14878 | ||
15 | + result | ||
16 | + end | ||
17 | + | ||
18 | + def self.qt_calculator_hash | ||
19 | + {:project => ProjectFixtures.qt_calculator_hash, :date => ModuleResultFixtures.create_hash[:date], | ||
20 | + :load_time => 14878, :analysis_time => 1022, :source_tree => ModuleNodeFixtures.qt_calculator_tree_hash, | ||
21 | + :collect_time => 14878} | ||
22 | + end | ||
23 | + | ||
24 | +end |
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +class RangeFixtures | ||
2 | + | ||
3 | + Infinity = 1.0/0.0 | ||
4 | + | ||
5 | + def self.amloc_excellent | ||
6 | + range = Kalibro::Entities::Range.new | ||
7 | + range.beginning = 0.0 | ||
8 | + range.end = 7.0 | ||
9 | + range.label = 'Excellent' | ||
10 | + range.grade = 10.0 | ||
11 | + range.color = 'ff00ff00' | ||
12 | + range | ||
13 | + end | ||
14 | + | ||
15 | + def self.amloc_bad | ||
16 | + range = Kalibro::Entities::Range.new | ||
17 | + range.beginning = 19.5 | ||
18 | + range.end = Infinity | ||
19 | + range.label = 'Bad' | ||
20 | + range.grade = 0.0 | ||
21 | + range.color = 'ffff0000' | ||
22 | + range | ||
23 | + end | ||
24 | + | ||
25 | + def self.amloc_excellent_hash | ||
26 | + {:beginning => 0.0, :end => 7.0, :label => 'Excellent', :grade => 10.0, :color => 'ff00ff00'} | ||
27 | + end | ||
28 | + | ||
29 | + def self.amloc_bad_hash | ||
30 | + {:beginning => 19.5, :end => "INF", :label => 'Bad',:grade => 0.0, :color => 'ffff0000'} | ||
31 | + end | ||
32 | + | ||
33 | +end |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +class RepositoryFixtures | ||
2 | + | ||
3 | + def self.qt_calculator | ||
4 | + repository = Kalibro::Entities::Repository.new | ||
5 | + repository.type = 'SUBVERSION' | ||
6 | + repository.address = 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator' | ||
7 | + repository | ||
8 | + end | ||
9 | + | ||
10 | + def self.qt_calculator_hash | ||
11 | + {:type => 'SUBVERSION', :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} | ||
12 | + end | ||
13 | + | ||
14 | +end |
plugins/mezuro/test/fixtures/stack_trace_element_fixtures.rb
0 → 100644
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +class StackTraceElementFixtures | ||
2 | + | ||
3 | + def self.create(method_name = 'my method name', line_number = 42) | ||
4 | + element = Kalibro::Entities::StackTraceElement.new | ||
5 | + element.declaring_class = 'my.declaring.Class' | ||
6 | + element.method_name = method_name | ||
7 | + element.file_name = 'MyFile.java' | ||
8 | + element.line_number = line_number | ||
9 | + element | ||
10 | + end | ||
11 | + | ||
12 | + def self.create_hash(method_name = 'my method name', line_number = 42) | ||
13 | + {:declaring_class => 'my.declaring.Class', :method_name => method_name, :file_name => 'MyFile.java', | ||
14 | + :line_number => line_number} | ||
15 | + end | ||
16 | + | ||
17 | +end |
@@ -0,0 +1,88 @@ | @@ -0,0 +1,88 @@ | ||
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 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" | ||
6 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | ||
7 | + | ||
8 | +class EchoPortTest < ActiveSupport::TestCase | ||
9 | + | ||
10 | + def setup | ||
11 | + @port = Kalibro::Client::Port.new('Echo') | ||
12 | + @port.service_address=('http://valinhos.ime.usp.br:50688/KalibroFake/'); | ||
13 | + end | ||
14 | + | ||
15 | + should 'echo base tool' do | ||
16 | + test BaseToolFixtures.analizo, 'BaseTool' do |base_tool| | ||
17 | + base_tool.name = "echo " + base_tool.name | ||
18 | + end | ||
19 | + end | ||
20 | + | ||
21 | + should 'echo configuration' do | ||
22 | + test ConfigurationFixtures.kalibro_configuration, 'Configuration' do |configuration| | ||
23 | + configuration.name = "echo " + configuration.name | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + should 'echo metric configuration' do | ||
28 | + test_metric_configuration(MetricConfigurationFixtures.amloc_configuration) | ||
29 | + test_metric_configuration(MetricConfigurationFixtures.sc_configuration) | ||
30 | + end | ||
31 | + | ||
32 | + should 'echo module result' do | ||
33 | + test ModuleResultFixtures.create, 'ModuleResult' do |module_result| | ||
34 | + module_result.module.name = "echo." + module_result.module.name | ||
35 | + end | ||
36 | + end | ||
37 | + | ||
38 | + should 'echo project' do | ||
39 | + test(ProjectFixtures.qt_calculator, 'Project') do |project| | ||
40 | + project.name = "echo " + project.name | ||
41 | + end | ||
42 | + end | ||
43 | + | ||
44 | + should 'echo project result' do | ||
45 | + test(ProjectResultFixtures.qt_calculator, 'ProjectResult') do |project_result| | ||
46 | + project_result.project.name = "echo " + project_result.project.name | ||
47 | + end | ||
48 | + end | ||
49 | + | ||
50 | + should 'echo raw project' do | ||
51 | + project = ProjectFixtures.qt_calculator | ||
52 | + echoed = @port.request(:echo_raw_project, {:project => project.to_hash})[:project] | ||
53 | + project.name = "echo " + project.name | ||
54 | + project.state = nil | ||
55 | + project.error = nil | ||
56 | + assert_equal project, Kalibro::Entities::Project.from_hash(echoed) | ||
57 | + end | ||
58 | + | ||
59 | + should 'work with enums' do | ||
60 | + test_granularity("METHOD", "CLASS") | ||
61 | + test_granularity("CLASS", "PACKAGE") | ||
62 | + test_granularity("PACKAGE", "PACKAGE") | ||
63 | + test_granularity("APPLICATION", "APPLICATION") | ||
64 | + end | ||
65 | + | ||
66 | + private | ||
67 | + | ||
68 | + def test_metric_configuration(fixture) | ||
69 | + test fixture, 'MetricConfiguration' do |metric_configuration| | ||
70 | + metric_configuration.code = "echo_" + metric_configuration.code | ||
71 | + end | ||
72 | + end | ||
73 | + | ||
74 | + def test(fixture, entity_name) | ||
75 | + entity_symbol = entity_name.underscore.to_sym | ||
76 | + request_body = {entity_symbol => fixture.to_hash} | ||
77 | + echoed = @port.request("echo_#{entity_symbol}".to_sym, request_body)[entity_symbol] | ||
78 | + yield fixture | ||
79 | + entity_class = "Kalibro::Entities::#{entity_name}".constantize | ||
80 | + assert_equal fixture, entity_class.from_hash(echoed) | ||
81 | + end | ||
82 | + | ||
83 | + def test_granularity(granularity, parent) | ||
84 | + body = {:granularity => granularity} | ||
85 | + assert_equal parent, @port.request(:infer_parent_granularity, body)[:parent_granularity] | ||
86 | + end | ||
87 | + | ||
88 | +end |
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
0 → 100644
@@ -0,0 +1,156 @@ | @@ -0,0 +1,156 @@ | ||
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 | + @collector = BaseToolFixtures.analizo | ||
18 | + @base_tool_client = Kalibro::Client::BaseToolClient.new | ||
19 | + @metric = NativeMetricFixtures.amloc | ||
20 | + @metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new | ||
21 | + @metric_configuration = MetricConfigurationFixtures.amloc_configuration | ||
22 | + @compound_metric_configuration = MetricConfigurationFixtures.sc_configuration | ||
23 | + @configuration = ConfigurationFixtures.kalibro_configuration | ||
24 | + end | ||
25 | + | ||
26 | + should 'assign configuration name in choose_base_tool' do | ||
27 | + get :choose_base_tool, :profile => @profile.identifier, :configuration_name => "test name" | ||
28 | + assert_equal assigns(:configuration_name), "test name" | ||
29 | + end | ||
30 | + | ||
31 | + should 'create base tool client' do | ||
32 | + get :choose_base_tool, :profile => @profile.identifier, :configuration_name => "test name" | ||
33 | + assert assigns(:tool_names).instance_of?(Kalibro::Client::BaseToolClient) | ||
34 | + end | ||
35 | + | ||
36 | + should 'assign configuration and collector name in choose_metric' do | ||
37 | + Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | ||
38 | + @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector) | ||
39 | + get :choose_metric, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo" | ||
40 | + assert_equal assigns(:configuration_name), "test name" | ||
41 | + assert_equal assigns(:collector_name), "Analizo" | ||
42 | + end | ||
43 | + | ||
44 | + should 'get collector by name' do | ||
45 | + Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | ||
46 | + @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector) | ||
47 | + get :choose_metric, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo" | ||
48 | + assert_equal assigns(:collector), @collector | ||
49 | + end | ||
50 | + | ||
51 | + should 'get chosen native metric and configuration name' do | ||
52 | + Kalibro::Client::BaseToolClient.expects(:new).returns(@base_tool_client) | ||
53 | + @base_tool_client.expects(:base_tool).with(@collector.name).returns(@collector) | ||
54 | + get :new_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :collector_name => "Analizo", :metric_name => @metric.name | ||
55 | + assert_equal assigns(:configuration_name), "test name" | ||
56 | + assert_equal assigns(:metric), @metric | ||
57 | + end | ||
58 | + | ||
59 | + should 'call configuration client in new_compound_metric_configuration method' do | ||
60 | + configuration_client = mock | ||
61 | + Kalibro::Client::ConfigurationClient.expects(:new).returns(configuration_client) | ||
62 | + configuration_client.expects(:configuration).with(@configuration.name).returns(@configuration) | ||
63 | + get :new_compound_metric_configuration, :profile => @profile.identifier, :configuration_name => @configuration.name | ||
64 | + assert_response 200 | ||
65 | + end | ||
66 | + | ||
67 | + should 'assign configuration name and get metric_configuration' do | ||
68 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
69 | + @metric_configuration_client.expects(:metric_configuration).with("test name", @metric.name).returns(@metric_configuration) | ||
70 | + get :edit_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name | ||
71 | + assert_equal assigns(:configuration_name), "test name" | ||
72 | + assert_equal assigns(:metric_configuration), @metric_configuration | ||
73 | + assert_equal assigns(:metric), @metric_configuration.metric | ||
74 | + end | ||
75 | + | ||
76 | + should 'test metric creation' do | ||
77 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
78 | + @metric_configuration_client.expects(:save) | ||
79 | + get :create_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :description => @metric.description, | ||
80 | + :scope => @metric.scope, :language => @metric.language, :metric => { :name => @metric.name, :origin => @metric.origin}, | ||
81 | + :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.code, :aggregation => @metric_configuration.aggregation_form } | ||
82 | + assert_equal assigns(:configuration_name), "test name" | ||
83 | + assert_response 302 | ||
84 | + end | ||
85 | + | ||
86 | + should 'test compound metric creation' do | ||
87 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
88 | + @metric_configuration_client.expects(:save) | ||
89 | + get :create_compound_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", | ||
90 | + :metric_configuration => { :code => @compound_metric_configuration.code, :weight => @compound_metric_configuration.weight, | ||
91 | + :aggregation_form => @compound_metric_configuration.aggregation_form, :metric => { :name => @compound_metric_configuration.metric.name , | ||
92 | + :description => @compound_metric_configuration.metric.description, :scope => @compound_metric_configuration.metric.scope, | ||
93 | + :script => @compound_metric_configuration.metric.script}} | ||
94 | + assert_response 302 | ||
95 | + end | ||
96 | + | ||
97 | + should 'test metric edition' do | ||
98 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
99 | + @metric_configuration_client.expects(:metric_configuration).with("test name","test metric name").returns(@metric_configuration) | ||
100 | + get :edit_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => "test metric name" | ||
101 | + assert_response 200 | ||
102 | + end | ||
103 | + | ||
104 | + should 'test compound metric edition' do | ||
105 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
106 | + @metric_configuration_client.expects(:metric_configuration).with("test name","test metric name").returns(@compound_metric_configuration) | ||
107 | + get :edit_compound_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => "test metric name" | ||
108 | + assert_response 200 | ||
109 | + end | ||
110 | + | ||
111 | + should 'update metric configuration' do | ||
112 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
113 | + @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @metric_configuration.metric.name).returns(@metric_configuration) | ||
114 | + @metric_configuration_client.expects(:save) | ||
115 | + get :update_metric_configuration, :profile => @profile.identifier, :configuration_name => @configuration.name, :description => @metric.description, | ||
116 | + :scope => @metric.scope, :language => @metric.language, :metric => { :name => @metric.name, :origin => @metric.origin}, | ||
117 | + :metric_configuration => { :code => @metric_configuration.code, :weight => @metric_configuration.code, :aggregation => @metric_configuration.aggregation_form } | ||
118 | + assert_response 302 | ||
119 | + end | ||
120 | + | ||
121 | + should 'update compound metric configuration' do | ||
122 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
123 | + @metric_configuration_client.expects(:metric_configuration).with(@configuration.name, @compound_metric_configuration.metric.name).returns(@compound_metric_configuration) | ||
124 | + @metric_configuration_client.expects(:save) | ||
125 | + get :update_compound_metric_configuration, :profile => @profile.identifier, :configuration_name => @configuration.name, | ||
126 | + :metric_configuration => { :code => @compound_metric_configuration.code, :weight => @compound_metric_configuration.weight, | ||
127 | + :aggregation_form => @compound_metric_configuration.aggregation_form, :metric => { :name => @compound_metric_configuration.metric.name , | ||
128 | + :description => @compound_metric_configuration.metric.description, :scope => @compound_metric_configuration.metric.scope, | ||
129 | + :script => @compound_metric_configuration.metric.script}} | ||
130 | + assert_response 302 | ||
131 | + end | ||
132 | + | ||
133 | + should 'assign configuration name and metric name to new range' do | ||
134 | + get :new_range, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name | ||
135 | + assert_equal assigns(:configuration_name), "test name" | ||
136 | + assert_equal assigns(:metric_name), @metric.name | ||
137 | + end | ||
138 | + | ||
139 | + should 'create instance range' do | ||
140 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
141 | + @metric_configuration_client.expects(:metric_configuration).with("test name", @metric.name).returns(@metric_configuration) | ||
142 | + @metric_configuration_client.expects(:save) | ||
143 | + range = @metric_configuration.ranges[0] | ||
144 | + get :create_range, :profile => @profile.identifier, :range => { :beginning => range.beginning, :end => range.end, :label => range.label, | ||
145 | + :grade => range.grade, :color => range.color, :comments => range.comments }, :configuration_name => "test name", :metric_name => @metric.name | ||
146 | + assert assigns(:range).instance_of?(Kalibro::Entities::Range) | ||
147 | + end | ||
148 | + | ||
149 | + should 'redirect from remove metric configuration' do | ||
150 | + Kalibro::Client::MetricConfigurationClient.expects(:new).returns(@metric_configuration_client) | ||
151 | + @metric_configuration_client.expects(:remove) | ||
152 | + get :remove_metric_configuration, :profile => @profile.identifier, :configuration_name => "test name", :metric_name => @metric.name | ||
153 | + assert_response 302 | ||
154 | + end | ||
155 | + | ||
156 | +end |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
1 | require 'test_helper' | 1 | require 'test_helper' |
2 | 2 | ||
3 | -class MezuroPluginProfileControllerTest < ActiveSupport::TestCase | 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/base_tool_fixtures" | ||
7 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures" | ||
8 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" | ||
9 | + | ||
10 | +class MezuroPluginProfileControllerTest < ActionController::TestCase | ||
4 | 11 | ||
5 | def setup | 12 | def setup |
6 | @controller = MezuroPluginProfileController.new | 13 | @controller = MezuroPluginProfileController.new |
7 | @request = ActionController::TestRequest.new | 14 | @request = ActionController::TestRequest.new |
8 | - @response = ActionController::TestResponse.new | 15 | + @response = ActionController::TestResponse.new |
9 | @profile = fast_create(Community) | 16 | @profile = fast_create(Community) |
10 | - @profile_id = @profile.identifier | 17 | + |
18 | + @project_result = ProjectResultFixtures.qt_calculator | ||
19 | + @module_result = ModuleResultFixtures.create | ||
20 | + @project = @project_result.project | ||
21 | + @name = @project.name | ||
22 | + | ||
23 | + @date = "2012-04-13T20:39:41+04:00" | ||
24 | + | ||
11 | end | 25 | end |
12 | 26 | ||
13 | -# def test_metrics_for_unknown_module | ||
14 | -# get :metrics, :profile => @profile_id, :id => 0 | ||
15 | -# assert_response 404 | ||
16 | -# end | 27 | + should 'not find project state for inexistent project content' do |
28 | + get :project_state, :profile => '', :id => -1 | ||
29 | + assert_response 404 | ||
30 | + end | ||
31 | + | ||
32 | + should 'get project state' do | ||
33 | + create_project_content | ||
34 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
35 | + get :project_state, :profile => @profile.identifier, :id => @content.id | ||
36 | + assert_response 200 | ||
37 | + end | ||
17 | 38 | ||
18 | -# def test_metric_unknown_module | ||
19 | -# get :metrics, :profile => @profile_id, :id => @project_content.id, :module_name => 'veryunlikelyname' | ||
20 | -# assert_response 404 | ||
21 | -# end | 39 | + should 'get error state if project has error' do |
40 | + create_project_content | ||
41 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
42 | + @project.expects(:error).returns(ErrorFixtures.create) | ||
43 | + get :project_state, :profile => @profile.identifier, :id => @content.id | ||
44 | + assert_response 200 | ||
45 | + end | ||
22 | 46 | ||
47 | + should 'not find content in project error for inexistent project content' do | ||
48 | + get :project_error, :profile => '', :id => -1 | ||
49 | + assert_response 404 | ||
50 | + end | ||
51 | + | ||
52 | + should 'get project error' do | ||
53 | + create_project_content | ||
54 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
55 | + @project.expects(:error).returns(ErrorFixtures.create) | ||
56 | + get :project_error, :profile => @profile.identifier, :id => @content.id | ||
57 | + assert_response 200 | ||
58 | + assert_select('h3', 'ERROR') | ||
59 | + end | ||
23 | 60 | ||
24 | -# def test_metrics_for_known_module | ||
25 | -# @project_content = create_project_content(@profile) | ||
26 | -# get :metrics, :profile => @profile_id, :id => @project_content.id, :module_name => @project_content.name | ||
27 | -# assert_response 200 | ||
28 | -# # assert_tag # TODO | ||
29 | -# end | 61 | + should 'not find project result for inexistent project content' do |
62 | + get :project_result, :profile => '', :id => -1 | ||
63 | + assert_response 404 | ||
64 | + end | ||
65 | + | ||
66 | + should 'get project results without date' do | ||
67 | + create_project_content | ||
68 | + Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) | ||
69 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
70 | + get :project_result, :profile => @profile.identifier, :id => @content.id | ||
71 | + assert_response 200 | ||
72 | + assert_select('h4', 'Last Result') | ||
73 | + end | ||
74 | + | ||
75 | + should 'get project results from a specific date' do | ||
76 | + create_project_content | ||
77 | + mock_project_result | ||
78 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
79 | + get :project_result, :profile => @profile.identifier, :id => @content.id, :date => @project_result.date | ||
80 | + assert_response 200 | ||
81 | + end | ||
30 | 82 | ||
31 | - protected | 83 | + should 'not find module result for inexistent project content' do |
84 | + get :module_result, :profile => '', :id => -1, :module_name => '' | ||
85 | + assert_response 404 | ||
86 | + end | ||
32 | 87 | ||
33 | - # returns a new ProjectContent for the given profile | ||
34 | - def create_project_content(profile) | ||
35 | - project_content = MezuroPlugin::ProjectContent.create!(:profile => profile, :name => 'foo') | 88 | + should 'get module result without date' do |
89 | + create_project_content | ||
90 | + mock_module_result | ||
91 | + Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) | ||
92 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
36 | 93 | ||
37 | - project = create_project(project_content.name) | ||
38 | - project_content.license = project.license | ||
39 | - project_content.description = project.description | ||
40 | - project_content.repository_type = project.repository.type | ||
41 | - project_content.repository_url = project.repository.address | ||
42 | - project_content.configuration_name = project.configuration_name | 94 | + get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name |
95 | + assert_response 200 | ||
96 | + assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') | ||
97 | + end | ||
43 | 98 | ||
44 | - MezuroPlugin::ProjectContent.any_instance.stubs(:project_content).returns(project_content) | ||
45 | - project_content | 99 | + should 'get module result from a specific date' do |
100 | + create_project_content | ||
101 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
102 | + mock_module_result | ||
103 | + mock_project_result | ||
104 | + get :module_result, :profile => @profile.identifier, :id => @content.id, :date => @project_result.date, :module_name => @name | ||
105 | + assert_response 200 | ||
106 | + assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') | ||
107 | + end | ||
108 | + | ||
109 | + should 'not find project tree for inexistent project content' do | ||
110 | + get :project_tree, :profile => '', :id => -1, :module_name => '' | ||
111 | + assert_response 404 | ||
112 | + end | ||
113 | + | ||
114 | + should 'get project tree without date' do | ||
115 | + create_project_content | ||
116 | + Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) | ||
117 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
118 | + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @name | ||
119 | + assert_response 200 | ||
120 | + assert_select('h2', /Qt-Calculator/) | ||
121 | + end | ||
122 | + | ||
123 | + should 'get project tree from a specific date' do | ||
124 | + create_project_content | ||
125 | + mock_project_result | ||
126 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
127 | + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @name, :date => "2012-04-13T20:39:41+04:00" | ||
128 | + assert_response 200 | ||
129 | + end | ||
130 | + | ||
131 | + should 'get grade history' do | ||
132 | + create_project_content | ||
133 | + mock_module_result_history | ||
134 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
135 | + get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @name | ||
136 | + assert_response 200 | ||
137 | + end | ||
138 | + | ||
139 | + should 'not find metrics history for inexistent project content' do | ||
140 | + get :module_metrics_history, :profile => '', :id => -1, :module_name => '' | ||
141 | + assert_response 404 | ||
142 | + end | ||
143 | + #copied from 'get grade history' test | ||
144 | + should 'get metrics history' do | ||
145 | + create_project_content | ||
146 | + mock_module_result_history | ||
147 | + Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) | ||
148 | + get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @name, | ||
149 | + :metric_name => @module_result.metric_result.first.metric.name.delete("() ") | ||
150 | + assert_response 200 | ||
151 | + end | ||
152 | + | ||
153 | + private | ||
154 | + | ||
155 | + def create_project_content | ||
156 | + client = mock | ||
157 | + @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @name) | ||
158 | + @content.expects(:send_project_to_service).returns(nil) | ||
159 | + Kalibro::Client::ProjectClient.expects(:new).returns(client) | ||
160 | + client.expects(:project_names).returns([]) | ||
161 | + @content.save | ||
162 | + end | ||
163 | + | ||
164 | + def mock_project_result | ||
165 | + project_result_client = mock | ||
166 | + Kalibro::Client::ProjectResultClient.expects(:new).returns(project_result_client) | ||
167 | + project_result_client.expects(:has_results_before).returns(true) | ||
168 | + project_result_client.expects(:last_result_before).returns(@project_result) | ||
46 | end | 169 | end |
47 | 170 | ||
48 | - def create_project(name) | ||
49 | - project = Kalibro::Entities::Project.new | ||
50 | - project.name = name | ||
51 | - project.license = 'GPL' | ||
52 | - project.description = 'testing' | ||
53 | - project.repository = crieate_repository | ||
54 | - project.configuration_name = 'Kalibro Default' | ||
55 | - project | ||
56 | - end | ||
57 | - | ||
58 | - def create_repository | ||
59 | - repository = Kalibro::Entities::Repository.new | ||
60 | - repository.type = 'git' | ||
61 | - repository.address = 'http://git.git' | ||
62 | - repository | ||
63 | - end | ||
64 | - | ||
65 | - #TODO Adicionar module result manualmente | ||
66 | - #TODO Ver testes do project content, refatorar o project content em cima dos testes | ||
67 | - #TODO Repensar design OO: nao amarrar o project_content ao webservice. Criar um modelo abstrato do webservice | 171 | + def mock_module_result |
172 | + module_result_client = mock | ||
173 | + Kalibro::Client::ModuleResultClient.expects(:new).returns(module_result_client) | ||
174 | + module_result_client.expects(:module_result).with(@name, @name, @project_result.date).returns(@module_result) | ||
175 | + end | ||
176 | + | ||
177 | + def mock_module_result_history | ||
178 | + module_result_client = mock | ||
179 | + module_result_client.expects(:result_history).with(@name, @name).returns([@module_result]) | ||
180 | + Kalibro::Client::ModuleResultClient.expects(:new).returns(module_result_client) | ||
181 | + end | ||
68 | end | 182 | end |
plugins/mezuro/test/mezuro_test.rb
@@ -1,11 +0,0 @@ | @@ -1,11 +0,0 @@ | ||
1 | -require "test_helper" | ||
2 | -require File.dirname(__FILE__) + '/../controllers/mezuro_plugin_myprofile_controller' | ||
3 | - | ||
4 | -class MezuroTest < ActiveSupport::TestCase | ||
5 | - | ||
6 | - should 'create a mezuro project' do | ||
7 | - controller = MezuroPluginMyprofileController.new | ||
8 | - controller.create | ||
9 | - end | ||
10 | - | ||
11 | -end |
plugins/mezuro/test/unit/kalibro/client/base_tool_client_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" | ||
4 | + | ||
2 | class BaseToolClientTest < ActiveSupport::TestCase | 5 | class BaseToolClientTest < ActiveSupport::TestCase |
3 | 6 | ||
4 | def setup | 7 | def setup |
@@ -25,7 +28,7 @@ class BaseToolClientTest < ActiveSupport::TestCase | @@ -25,7 +28,7 @@ class BaseToolClientTest < ActiveSupport::TestCase | ||
25 | end | 28 | end |
26 | 29 | ||
27 | should 'get base tool by name' do | 30 | should 'get base tool by name' do |
28 | - analizo = BaseToolTest.analizo | 31 | + analizo = BaseToolFixtures.analizo |
29 | request_body = {:base_tool_name => 'Analizo'} | 32 | request_body = {:base_tool_name => 'Analizo'} |
30 | @port.expects(:request).with(:get_base_tool, request_body).returns({:base_tool => analizo.to_hash}) | 33 | @port.expects(:request).with(:get_base_tool, request_body).returns({:base_tool => analizo.to_hash}) |
31 | assert_equal analizo, @client.base_tool('Analizo') | 34 | assert_equal analizo, @client.base_tool('Analizo') |
plugins/mezuro/test/unit/kalibro/client/configuration_client_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | ||
4 | + | ||
2 | class ConfigurationClientTest < ActiveSupport::TestCase | 5 | class ConfigurationClientTest < ActiveSupport::TestCase |
3 | 6 | ||
4 | def setup | 7 | def setup |
@@ -8,7 +11,7 @@ class ConfigurationClientTest < ActiveSupport::TestCase | @@ -8,7 +11,7 @@ class ConfigurationClientTest < ActiveSupport::TestCase | ||
8 | end | 11 | end |
9 | 12 | ||
10 | should 'save configuration' do | 13 | should 'save configuration' do |
11 | - configuration = ConfigurationTest.kalibro_configuration | 14 | + configuration = ConfigurationFixtures.kalibro_configuration |
12 | @port.expects(:request).with(:save_configuration, {:configuration => configuration.to_hash}) | 15 | @port.expects(:request).with(:save_configuration, {:configuration => configuration.to_hash}) |
13 | @client.save(configuration) | 16 | @client.save(configuration) |
14 | end | 17 | end |
@@ -31,7 +34,7 @@ class ConfigurationClientTest < ActiveSupport::TestCase | @@ -31,7 +34,7 @@ class ConfigurationClientTest < ActiveSupport::TestCase | ||
31 | end | 34 | end |
32 | 35 | ||
33 | should 'get configuration by name' do | 36 | should 'get configuration by name' do |
34 | - configuration = ConfigurationTest.kalibro_configuration | 37 | + configuration = ConfigurationFixtures.kalibro_configuration |
35 | request_body = {:configuration_name => configuration.name} | 38 | request_body = {:configuration_name => configuration.name} |
36 | response_hash = {:configuration => configuration.to_hash} | 39 | response_hash = {:configuration => configuration.to_hash} |
37 | @port.expects(:request).with(:get_configuration, request_body).returns(response_hash) | 40 | @port.expects(:request).with(:get_configuration, request_body).returns(response_hash) |
plugins/mezuro/test/unit/kalibro/client/kalibro_client_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | + | ||
2 | class KalibroClientTest < ActiveSupport::TestCase | 3 | class KalibroClientTest < ActiveSupport::TestCase |
3 | 4 | ||
4 | def setup | 5 | def setup |
@@ -23,7 +24,20 @@ class KalibroClientTest < ActiveSupport::TestCase | @@ -23,7 +24,20 @@ class KalibroClientTest < ActiveSupport::TestCase | ||
23 | instance = mock | 24 | instance = mock |
24 | Kalibro::Client::KalibroClient.expects(:new).returns(instance) | 25 | Kalibro::Client::KalibroClient.expects(:new).returns(instance) |
25 | instance.expects(:process_project).with('myproject') | 26 | instance.expects(:process_project).with('myproject') |
26 | - Kalibro::Client::KalibroClient.process_project('myproject') | 27 | + Kalibro::Client::KalibroClient.process_project('myproject', 0) |
28 | + end | ||
29 | + | ||
30 | + should 'process project with periodicity' do | ||
31 | + name = 'KalibroClientTest' | ||
32 | + @port.expects(:request).with(:process_periodically, {:project_name => name, :period_in_days => 30}) | ||
33 | + @client.process_periodically(name, 30) | ||
34 | + end | ||
35 | + | ||
36 | + should 'instantiate for processing project periodically' do | ||
37 | + instance = mock | ||
38 | + Kalibro::Client::KalibroClient.expects(:new).returns(instance) | ||
39 | + instance.expects(:process_periodically).with('myproject', 30) | ||
40 | + Kalibro::Client::KalibroClient.process_project('myproject', 30) | ||
27 | end | 41 | end |
28 | 42 | ||
29 | end | 43 | end |
plugins/mezuro/test/unit/kalibro/client/metric_configuration_client_test.rb
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" | ||
4 | + | ||
5 | +class MetricConfigurationClientTest < ActiveSupport::TestCase | ||
6 | + | ||
7 | + def setup | ||
8 | + @port = mock | ||
9 | + Kalibro::Client::Port.expects(:new).with('MetricConfiguration').returns(@port) | ||
10 | + @client = Kalibro::Client::MetricConfigurationClient.new | ||
11 | + end | ||
12 | + | ||
13 | + should 'save metric configuration' do | ||
14 | + configuration = MetricConfigurationFixtures.amloc_configuration | ||
15 | + @port.expects(:request).with(:save_metric_configuration, { | ||
16 | + :metric_configuration => configuration.to_hash, | ||
17 | + :configuration_name => 'x' | ||
18 | + }) | ||
19 | + @client.save(configuration, 'x') | ||
20 | + end | ||
21 | + | ||
22 | + should 'get metric configuration by name' do | ||
23 | + configuration = MetricConfigurationFixtures.amloc_configuration | ||
24 | + request_body = { | ||
25 | + :configuration_name => 'configuration.name', | ||
26 | + :metric_name => configuration.metric.name | ||
27 | + } | ||
28 | + response_hash = {:metric_configuration => configuration.to_hash} | ||
29 | + @port.expects(:request).with(:get_metric_configuration, request_body).returns(response_hash) | ||
30 | + assert_equal configuration, @client.metric_configuration('configuration.name', configuration.metric.name) | ||
31 | + end | ||
32 | + | ||
33 | + should 'remove metric configuration by name' do | ||
34 | + metric_name = 'MetricConfigurationClientTest' | ||
35 | + configuration_name = 'xxxx' | ||
36 | + request_body = { | ||
37 | + :configuration_name => configuration_name, | ||
38 | + :metric_name => metric_name | ||
39 | + } | ||
40 | + @port.expects(:request).with(:remove_metric_configuration, request_body) | ||
41 | + @client.remove(configuration_name, metric_name) | ||
42 | + end | ||
43 | + | ||
44 | +end | ||
0 | \ No newline at end of file | 45 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/client/module_result_client_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" | ||
4 | + | ||
2 | class ModuleResultClientTest < ActiveSupport::TestCase | 5 | class ModuleResultClientTest < ActiveSupport::TestCase |
3 | 6 | ||
4 | def setup | 7 | def setup |
5 | @port = mock | 8 | @port = mock |
6 | Kalibro::Client::Port.expects(:new).with('ModuleResult').returns(@port) | 9 | Kalibro::Client::Port.expects(:new).with('ModuleResult').returns(@port) |
7 | @client = Kalibro::Client::ModuleResultClient.new | 10 | @client = Kalibro::Client::ModuleResultClient.new |
8 | - @result = ModuleResultTest.fixture | 11 | + @result = ModuleResultFixtures.create |
9 | end | 12 | end |
10 | 13 | ||
11 | should 'get module result' do | 14 | should 'get module result' do |
@@ -23,5 +26,4 @@ class ModuleResultClientTest < ActiveSupport::TestCase | @@ -23,5 +26,4 @@ class ModuleResultClientTest < ActiveSupport::TestCase | ||
23 | @port.expects(:request).with(:get_result_history, request_body).returns(response) | 26 | @port.expects(:request).with(:get_result_history, request_body).returns(response) |
24 | assert_equal [@result], @client.result_history('Qt-Calculator', 'main') | 27 | assert_equal [@result], @client.result_history('Qt-Calculator', 'main') |
25 | end | 28 | end |
26 | - | ||
27 | -end | ||
28 | \ No newline at end of file | 29 | \ No newline at end of file |
30 | +end |
plugins/mezuro/test/unit/kalibro/client/port_test.rb
plugins/mezuro/test/unit/kalibro/client/project_client_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | ||
4 | + | ||
2 | class ProjectClientTest < ActiveSupport::TestCase | 5 | class ProjectClientTest < ActiveSupport::TestCase |
3 | 6 | ||
4 | def setup | 7 | def setup |
5 | @port = mock | 8 | @port = mock |
6 | Kalibro::Client::Port.expects(:new).with('Project').returns(@port) | 9 | Kalibro::Client::Port.expects(:new).with('Project').returns(@port) |
7 | - @client = Kalibro::Client::ProjectClient.new | 10 | + @project = ProjectFixtures.qt_calculator |
8 | end | 11 | end |
9 | 12 | ||
10 | - should 'save project' do | ||
11 | - project = ProjectTest.qt_calculator | ||
12 | - @port.expects(:request).with(:save_project, {:project => project.to_hash}) | ||
13 | - @client.save(project) | 13 | + should 'get project by name' do |
14 | + request_body = {:project_name => @project.name} | ||
15 | + response_hash = {:project => @project.to_hash} | ||
16 | + @port.expects(:request).with(:get_project, request_body).returns(response_hash) | ||
17 | + assert_equal @project, Kalibro::Client::ProjectClient.project(@project.name) | ||
14 | end | 18 | end |
15 | - | ||
16 | - should 'get project names (zero)' do | ||
17 | - @port.expects(:request).with(:get_project_names).returns({}) | ||
18 | - assert_equal [], @client.project_names | 19 | + |
20 | + should 'raise error when project doesnt exist' do | ||
21 | + request_body = {:project_name => @project.name} | ||
22 | + @port.expects(:request).with(:get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) | ||
23 | + assert_nil Kalibro::Client::ProjectClient.project(@project.name) | ||
19 | end | 24 | end |
20 | 25 | ||
21 | - should 'get project names (one)' do | ||
22 | - name = 'Qt-Calculator' | ||
23 | - @port.expects(:request).with(:get_project_names).returns({:project_name => name}) | ||
24 | - assert_equal [name], @client.project_names | 26 | + should 'save project' do |
27 | + create_project_content_mock | ||
28 | + @project.state = nil | ||
29 | + @port.expects(:request).with(:save_project, {:project => @project.to_hash}) | ||
30 | + Kalibro::Client::ProjectClient.save(@project_content) | ||
25 | end | 31 | end |
26 | 32 | ||
27 | - should 'get project names' do | ||
28 | - names = ['Hello World', 'Qt-Calculator'] | ||
29 | - @port.expects(:request).with(:get_project_names).returns({:project_name => names}) | ||
30 | - assert_equal names, @client.project_names | 33 | + should 'remove existent project from service' do |
34 | + @port.expects(:request).with(:get_project_names).returns({:project_name => @project.name}) | ||
35 | + @port.expects(:request).with(:remove_project, {:project_name => @project.name}) | ||
36 | + Kalibro::Client::ProjectClient.remove(@project.name) | ||
31 | end | 37 | end |
32 | 38 | ||
33 | - should 'get project by name' do | ||
34 | - project = ProjectTest.qt_calculator | ||
35 | - request_body = {:project_name => project.name} | ||
36 | - response_hash = {:project => project.to_hash} | ||
37 | - @port.expects(:request).with(:get_project, request_body).returns(response_hash) | ||
38 | - assert_equal project, @client.project(project.name) | 39 | + should 'not try to remove inexistent project from service' do |
40 | + @port.expects(:request).with(:get_project_names).returns({:project_name => 'Different project'}) | ||
41 | + @port.expects(:request).with(:remove_project, {:project_name => @project.name}).never | ||
42 | + Kalibro::Client::ProjectClient.remove(@project.name) | ||
39 | end | 43 | end |
40 | 44 | ||
41 | - should 'remove project by name' do | ||
42 | - name = 'ProjectClientTest' | ||
43 | - @port.expects(:request).with(:remove_project, {:project_name => name}) | ||
44 | - @client.remove(name) | ||
45 | - end | 45 | + private |
46 | 46 | ||
47 | - should 'instantiate for saving a project' do | ||
48 | - project = mock | ||
49 | - instance = mock | ||
50 | - Kalibro::Client::ProjectClient.expects(:new).returns(instance) | ||
51 | - instance.expects(:save).with(project) | ||
52 | - Kalibro::Client::ProjectClient.save(project) | 47 | + def create_project_content_mock |
48 | + @project_content = mock | ||
49 | + @project_content.expects(:name).returns(@project.name) | ||
50 | + @project_content.expects(:license).returns(@project.license) | ||
51 | + @project_content.expects(:description).returns(@project.description) | ||
52 | + @project_content.expects(:repository_type).returns(@project.repository.type) | ||
53 | + @project_content.expects(:repository_url).returns(@project.repository.address) | ||
54 | + @project_content.expects(:configuration_name).returns(@project.configuration_name) | ||
53 | end | 55 | end |
54 | 56 | ||
55 | end | 57 | end |
plugins/mezuro/test/unit/kalibro/client/project_result_client_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | ||
4 | + | ||
2 | class ProjectResultClientTest < ActiveSupport::TestCase | 5 | class ProjectResultClientTest < ActiveSupport::TestCase |
3 | 6 | ||
4 | def setup | 7 | def setup |
@@ -6,63 +9,50 @@ class ProjectResultClientTest < ActiveSupport::TestCase | @@ -6,63 +9,50 @@ class ProjectResultClientTest < ActiveSupport::TestCase | ||
6 | Kalibro::Client::Port.expects(:new).with('ProjectResult').returns(@port) | 9 | Kalibro::Client::Port.expects(:new).with('ProjectResult').returns(@port) |
7 | @client = Kalibro::Client::ProjectResultClient.new | 10 | @client = Kalibro::Client::ProjectResultClient.new |
8 | 11 | ||
9 | - @result = ProjectResultTest.qt_calculator | 12 | + @result = ProjectResultFixtures.qt_calculator |
10 | @project_name = @result.project.name | 13 | @project_name = @result.project.name |
11 | @date = @result.date | 14 | @date = @result.date |
12 | @flag = DateTime.now.sec % 2 == 0 | 15 | @flag = DateTime.now.sec % 2 == 0 |
16 | + | ||
17 | + @request = {:project_name => @project_name} | ||
18 | + @request_with_date = {:project_name => @project_name, :date => @date} | ||
19 | + @flag_response = {:has_results => @flag} | ||
20 | + @result_response = {:project_result => @result.to_hash} | ||
13 | end | 21 | end |
14 | 22 | ||
15 | should 'retrieve if project has results' do | 23 | should 'retrieve if project has results' do |
16 | - @port.expects(:request).with(:has_results_for, request).returns(flag_response) | 24 | + @port.expects(:request).with(:has_results_for, @request).returns(@flag_response) |
17 | assert_equal @flag, @client.has_results_for(@project_name) | 25 | assert_equal @flag, @client.has_results_for(@project_name) |
18 | end | 26 | end |
19 | 27 | ||
20 | should 'retrieve if project has results before date' do | 28 | should 'retrieve if project has results before date' do |
21 | - @port.expects(:request).with(:has_results_before, request_with_date).returns(flag_response) | 29 | + @port.expects(:request).with(:has_results_before, @request_with_date).returns(@flag_response) |
22 | assert_equal @flag, @client.has_results_before(@project_name, @date) | 30 | assert_equal @flag, @client.has_results_before(@project_name, @date) |
23 | end | 31 | end |
24 | 32 | ||
25 | should 'retrieve if project has results after date' do | 33 | should 'retrieve if project has results after date' do |
26 | - @port.expects(:request).with(:has_results_after, request_with_date).returns(flag_response) | 34 | + @port.expects(:request).with(:has_results_after, @request_with_date).returns(@flag_response) |
27 | assert_equal @flag, @client.has_results_after(@project_name, @date) | 35 | assert_equal @flag, @client.has_results_after(@project_name, @date) |
28 | end | 36 | end |
29 | 37 | ||
30 | should 'get first result of project' do | 38 | should 'get first result of project' do |
31 | - @port.expects(:request).with(:get_first_result_of, request).returns(result_response) | 39 | + @port.expects(:request).with(:get_first_result_of, @request).returns(@result_response) |
32 | assert_equal @result, @client.first_result(@project_name) | 40 | assert_equal @result, @client.first_result(@project_name) |
33 | end | 41 | end |
34 | 42 | ||
35 | should 'get last result of project' do | 43 | should 'get last result of project' do |
36 | - @port.expects(:request).with(:get_last_result_of, request).returns(result_response) | 44 | + @port.expects(:request).with(:get_last_result_of, @request).returns(@result_response) |
37 | assert_equal @result, @client.last_result(@project_name) | 45 | assert_equal @result, @client.last_result(@project_name) |
38 | end | 46 | end |
39 | 47 | ||
40 | should 'get first result of project after date' do | 48 | should 'get first result of project after date' do |
41 | - @port.expects(:request).with(:get_first_result_after, request_with_date).returns(result_response) | 49 | + @port.expects(:request).with(:get_first_result_after, @request_with_date).returns(@result_response) |
42 | assert_equal @result, @client.first_result_after(@project_name, @date) | 50 | assert_equal @result, @client.first_result_after(@project_name, @date) |
43 | end | 51 | end |
44 | 52 | ||
45 | should 'get last result of project before date' do | 53 | should 'get last result of project before date' do |
46 | - @port.expects(:request).with(:get_last_result_before, request_with_date).returns(result_response) | 54 | + @port.expects(:request).with(:get_last_result_before, @request_with_date).returns(@result_response) |
47 | assert_equal @result, @client.last_result_before(@project_name, @date) | 55 | assert_equal @result, @client.last_result_before(@project_name, @date) |
48 | end | 56 | end |
49 | 57 | ||
50 | - private | ||
51 | - | ||
52 | - def request | ||
53 | - {:project_name => @project_name} | ||
54 | - end | ||
55 | - | ||
56 | - def request_with_date | ||
57 | - {:project_name => @project_name, :date => @date} | ||
58 | - end | ||
59 | - | ||
60 | - def flag_response | ||
61 | - {:has_results => @flag} | ||
62 | - end | ||
63 | - | ||
64 | - def result_response | ||
65 | - {:project_result => @result.to_hash} | ||
66 | - end | ||
67 | - | ||
68 | end | 58 | end |
69 | \ No newline at end of file | 59 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/base_tool_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class BaseToolTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.analizo | ||
5 | - total_cof = NativeMetricTest.total_cof | ||
6 | - amloc = NativeMetricTest.amloc | ||
7 | - base_tool = Kalibro::Entities::BaseTool.new | ||
8 | - base_tool.name = 'Analizo' | ||
9 | - base_tool.supported_metrics = [total_cof, amloc] | ||
10 | - base_tool | ||
11 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" |
12 | 4 | ||
13 | - def self.analizo_hash | ||
14 | - total_cof_hash = NativeMetricTest.total_cof_hash | ||
15 | - amloc_hash = NativeMetricTest.amloc_hash | ||
16 | - {:name => 'Analizo', | ||
17 | - :supported_metric => [total_cof_hash, amloc_hash]} | ||
18 | - end | 5 | +class BaseToolTest < ActiveSupport::TestCase |
19 | 6 | ||
20 | def setup | 7 | def setup |
21 | - @hash = self.class.analizo_hash | ||
22 | - @base_tool = self.class.analizo | 8 | + @hash = BaseToolFixtures.analizo_hash |
9 | + @base_tool = BaseToolFixtures.analizo | ||
23 | end | 10 | end |
24 | 11 | ||
25 | should 'create base tool from hash' do | 12 | should 'create base tool from hash' do |
plugins/mezuro/test/unit/kalibro/entities/compound_metric_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class CompoundMetricTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.sc | ||
5 | - sc = Kalibro::Entities::CompoundMetric.new | ||
6 | - sc.name = 'Structural Complexity' | ||
7 | - sc.scope = 'CLASS' | ||
8 | - sc.script = 'return cbo * lcom4;' | ||
9 | - sc | ||
10 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_fixtures" |
4 | + | ||
5 | +class CompoundMetricTest < ActiveSupport::TestCase | ||
11 | 6 | ||
12 | - def self.sc_hash | ||
13 | - {:name => 'Structural Complexity', :scope => 'CLASS', | ||
14 | - :script => 'return cbo * lcom4;'} | ||
15 | - end | ||
16 | - | ||
17 | def setup | 7 | def setup |
18 | - @hash = self.class.sc_hash | ||
19 | - @metric = self.class.sc | 8 | + @hash = CompoundMetricFixtures.sc_hash |
9 | + @metric = CompoundMetricFixtures.sc | ||
20 | end | 10 | end |
21 | 11 | ||
22 | should 'create compound metric from hash' do | 12 | should 'create compound metric from hash' do |
plugins/mezuro/test/unit/kalibro/entities/compound_metric_with_error_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class CompoundMetricWithErrorTest < ActiveSupport::TestCase | ||
3 | - | ||
4 | - def self.fixture | ||
5 | - fixture = Kalibro::Entities::CompoundMetricWithError.new | ||
6 | - fixture.metric = CompoundMetricTest.sc | ||
7 | - fixture.error = ErrorTest.fixture | ||
8 | - fixture | ||
9 | - end | ||
10 | 2 | ||
11 | - def self.fixture_hash | ||
12 | - {:metric => CompoundMetricTest.sc_hash, | ||
13 | - :error => ErrorTest.fixture_hash} | ||
14 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures" |
15 | 4 | ||
5 | +class CompoundMetricWithErrorTest < ActiveSupport::TestCase | ||
6 | + | ||
16 | def setup | 7 | def setup |
17 | - @hash = self.class.fixture_hash | ||
18 | - @entity = self.class.fixture | 8 | + @hash = CompoundMetricWithErrorFixtures.create_hash |
9 | + @entity = CompoundMetricWithErrorFixtures.create | ||
19 | end | 10 | end |
20 | 11 | ||
21 | should 'create error from hash' do | 12 | should 'create error from hash' do |
plugins/mezuro/test/unit/kalibro/entities/configuration_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class ConfigurationTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.kalibro_configuration | ||
5 | - amloc_configuration = MetricConfigurationTest.amloc_configuration | ||
6 | - sc_configuration = MetricConfigurationTest.sc_configuration | ||
7 | - configuration = Kalibro::Entities::Configuration.new | ||
8 | - configuration.name = 'Kalibro for Java' | ||
9 | - configuration.description = 'Kalibro configuration for Java projects.' | ||
10 | - configuration.metric_configurations = [amloc_configuration, sc_configuration] | ||
11 | - configuration | ||
12 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" |
13 | 4 | ||
14 | - def self.kalibro_configuration_hash | ||
15 | - amloc_hash = MetricConfigurationTest.amloc_configuration_hash | ||
16 | - sc_hash = MetricConfigurationTest.sc_configuration_hash | ||
17 | - {:name => 'Kalibro for Java', | ||
18 | - :description => 'Kalibro configuration for Java projects.', | ||
19 | - :metric_configuration => [amloc_hash, sc_hash]} | ||
20 | - end | 5 | +class ConfigurationTest < ActiveSupport::TestCase |
21 | 6 | ||
22 | def setup | 7 | def setup |
23 | - @hash = self.class.kalibro_configuration_hash | ||
24 | - @configuration = self.class.kalibro_configuration | 8 | + @hash = ConfigurationFixtures.kalibro_configuration_hash |
9 | + @configuration = ConfigurationFixtures.kalibro_configuration | ||
25 | end | 10 | end |
26 | 11 | ||
27 | should 'create configuration from hash' do | 12 | should 'create configuration from hash' do |
@@ -32,4 +17,4 @@ class ConfigurationTest < ActiveSupport::TestCase | @@ -32,4 +17,4 @@ class ConfigurationTest < ActiveSupport::TestCase | ||
32 | assert_equal @hash, @configuration.to_hash | 17 | assert_equal @hash, @configuration.to_hash |
33 | end | 18 | end |
34 | 19 | ||
35 | -end | ||
36 | \ No newline at end of file | 20 | \ No newline at end of file |
21 | +end |
plugins/mezuro/test/unit/kalibro/entities/entity_test.rb
plugins/mezuro/test/unit/kalibro/entities/error_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class ErrorTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.fixture | ||
5 | - error = Kalibro::Entities::Error.new | ||
6 | - error.message = 'Error message from ErrorTest' | ||
7 | - element1 = StackTraceElementTest.fixture | ||
8 | - element2 = StackTraceElementTest.fixture('errorTestMethod', 84) | ||
9 | - error.stack_trace = [element1, element2] | ||
10 | - error | ||
11 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures" |
12 | 4 | ||
13 | - def self.fixture_hash | ||
14 | - element1 = StackTraceElementTest.fixture_hash | ||
15 | - element2 = StackTraceElementTest.fixture_hash('errorTestMethod', 84) | ||
16 | - {:message => 'Error message from ErrorTest', | ||
17 | - :stack_trace_element => [element1, element2]} | ||
18 | - end | 5 | +class ErrorTest < ActiveSupport::TestCase |
19 | 6 | ||
20 | def setup | 7 | def setup |
21 | - @hash = self.class.fixture_hash | ||
22 | - @error = self.class.fixture | 8 | + @hash = ErrorFixtures.create_hash |
9 | + @error = ErrorFixtures.create | ||
23 | end | 10 | end |
24 | 11 | ||
25 | should 'create error from hash' do | 12 | should 'create error from hash' do |
plugins/mezuro/test/unit/kalibro/entities/metric_configuration_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class MetricConfigurationTest < ActiveSupport::TestCase | ||
3 | - | ||
4 | - def self.amloc_configuration | ||
5 | - range1 = RangeTest.amloc_excellent | ||
6 | - range2 = RangeTest.amloc_bad | ||
7 | - amloc = Kalibro::Entities::MetricConfiguration.new | ||
8 | - amloc.metric = NativeMetricTest.amloc | ||
9 | - amloc.code = 'amloc' | ||
10 | - amloc.weight = 1.0 | ||
11 | - amloc.aggregation_form = 'AVERAGE' | ||
12 | - amloc.ranges = [range1, range2] | ||
13 | - amloc | ||
14 | - end | ||
15 | 2 | ||
16 | - def self.sc_configuration | ||
17 | - sc = Kalibro::Entities::MetricConfiguration.new | ||
18 | - sc.metric = CompoundMetricTest.sc | ||
19 | - sc.code = 'sc' | ||
20 | - sc.weight = 1.0 | ||
21 | - sc.aggregation_form = 'AVERAGE' | ||
22 | - sc | ||
23 | - end | ||
24 | - | ||
25 | - def self.amloc_configuration_hash | ||
26 | - range1 = RangeTest.amloc_excellent_hash | ||
27 | - range2 = RangeTest.amloc_bad_hash | ||
28 | - {:metric => NativeMetricTest.amloc_hash, | ||
29 | - :code => 'amloc', :weight => 1.0, :aggregation_form => 'AVERAGE', | ||
30 | - :range => [range1, range2]} | ||
31 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" |
4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | ||
32 | 5 | ||
33 | - def self.sc_configuration_hash | ||
34 | - {:metric => CompoundMetricTest.sc_hash, | ||
35 | - :code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE'} | ||
36 | - end | 6 | +class MetricConfigurationTest < ActiveSupport::TestCase |
37 | 7 | ||
38 | def setup | 8 | def setup |
39 | - @hash = self.class.amloc_configuration_hash | ||
40 | - @range = self.class.amloc_configuration | 9 | + @hash = MetricConfigurationFixtures.amloc_configuration_hash |
10 | + @metric_configuration = MetricConfigurationFixtures.amloc_configuration | ||
11 | + @metric_configuration_without_ranges = MetricConfigurationFixtures.metric_configuration_without_ranges | ||
12 | + @range1 = RangeFixtures.amloc_excellent | ||
13 | + @range2 = RangeFixtures.amloc_bad | ||
41 | end | 14 | end |
42 | 15 | ||
43 | should 'create metric configuration from hash' do | 16 | should 'create metric configuration from hash' do |
44 | - assert_equal @range, Kalibro::Entities::MetricConfiguration.from_hash(@hash) | 17 | + assert_equal @metric_configuration, Kalibro::Entities::MetricConfiguration.from_hash(@hash) |
45 | end | 18 | end |
46 | 19 | ||
47 | should 'convert metric configuration to hash' do | 20 | should 'convert metric configuration to hash' do |
48 | - assert_equal @hash, @range.to_hash | 21 | + assert_equal @hash, @metric_configuration.to_hash |
49 | end | 22 | end |
50 | 23 | ||
51 | should 'create appropriate metric type' do | 24 | should 'create appropriate metric type' do |
52 | - assert self.class.amloc_configuration.metric.instance_of?(Kalibro::Entities::NativeMetric) | ||
53 | - assert self.class.sc_configuration.metric.instance_of?(Kalibro::Entities::CompoundMetric) | 25 | + amloc = MetricConfigurationFixtures.amloc_configuration |
26 | + sc = MetricConfigurationFixtures.sc_configuration | ||
27 | + assert amloc.metric.instance_of?(Kalibro::Entities::NativeMetric) | ||
28 | + assert sc.metric.instance_of?(Kalibro::Entities::CompoundMetric) | ||
29 | + end | ||
30 | + | ||
31 | + should 'add a range to an empty range list' do | ||
32 | + @metric_configuration_without_ranges.add_range @range1 | ||
33 | + assert_equal @metric_configuration_without_ranges.ranges, [@range1] | ||
34 | + end | ||
35 | + | ||
36 | + should 'add a range to an non-empty range list' do | ||
37 | + @metric_configuration_without_ranges.ranges = [@range1] | ||
38 | + @metric_configuration_without_ranges.add_range @range2 | ||
39 | + assert_equal @metric_configuration_without_ranges.ranges, [@range1, @range2] | ||
54 | end | 40 | end |
55 | 41 | ||
42 | + | ||
56 | end | 43 | end |
plugins/mezuro/test/unit/kalibro/entities/metric_result_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class MetricResultTest < ActiveSupport::TestCase | ||
3 | - | ||
4 | - def self.amloc_result | ||
5 | - result = Kalibro::Entities::MetricResult.new | ||
6 | - result.metric = NativeMetricTest.amloc | ||
7 | - result.value = 0.0 | ||
8 | - result.descendent_results = [40.0, 42.0] | ||
9 | - result.range = RangeTest.amloc_excellent | ||
10 | - result | ||
11 | - end | ||
12 | - | ||
13 | - def self.sc_result | ||
14 | - result = Kalibro::Entities::MetricResult.new | ||
15 | - result.metric = CompoundMetricTest.sc | ||
16 | - result.value = 1.0 | ||
17 | - result.descendent_results = [2.0, 42.0] | ||
18 | - result | ||
19 | - end | ||
20 | 2 | ||
21 | - def self.amloc_result_hash | ||
22 | - {:metric => NativeMetricTest.amloc_hash, | ||
23 | - :value => 0.0, :descendent_result => [40.0, 42.0], | ||
24 | - :range => RangeTest.amloc_excellent_hash} | ||
25 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures" |
26 | 4 | ||
27 | - def self.sc_result_hash | ||
28 | - {:metric => CompoundMetricTest.sc_hash, | ||
29 | - :value => 1.0, :descendent_result => [2.0, 42.0]} | ||
30 | - end | 5 | +class MetricResultTest < ActiveSupport::TestCase |
31 | 6 | ||
32 | def setup | 7 | def setup |
33 | - @hash = self.class.amloc_result_hash | ||
34 | - @result = self.class.amloc_result | 8 | + @hash = MetricResultFixtures.amloc_result_hash |
9 | + @result = MetricResultFixtures.amloc_result | ||
35 | end | 10 | end |
36 | 11 | ||
37 | should 'create metric result from hash' do | 12 | should 'create metric result from hash' do |
@@ -43,8 +18,8 @@ class MetricResultTest < ActiveSupport::TestCase | @@ -43,8 +18,8 @@ class MetricResultTest < ActiveSupport::TestCase | ||
43 | end | 18 | end |
44 | 19 | ||
45 | should 'create appropriate metric type' do | 20 | should 'create appropriate metric type' do |
46 | - assert self.class.amloc_result.metric.instance_of?(Kalibro::Entities::NativeMetric) | ||
47 | - assert self.class.sc_result.metric.instance_of?(Kalibro::Entities::CompoundMetric) | 21 | + assert MetricResultFixtures.amloc_result.metric.instance_of?(Kalibro::Entities::NativeMetric) |
22 | + assert MetricResultFixtures.sc_result.metric.instance_of?(Kalibro::Entities::CompoundMetric) | ||
48 | end | 23 | end |
49 | 24 | ||
50 | should 'convert single descendent result to array' do | 25 | should 'convert single descendent result to array' do |
plugins/mezuro/test/unit/kalibro/entities/metric_test.rb
plugins/mezuro/test/unit/kalibro/entities/module_node_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | 2 | ||
3 | -class ModuleNodeTest < ActiveSupport::TestCase | ||
4 | - | ||
5 | - def self.qt_calculator_tree | ||
6 | - node = Kalibro::Entities::ModuleNode.new | ||
7 | - node.module = ModuleTest.qt_calculator | ||
8 | - node.children = [new_node('Dialog', 'CLASS'), new_node('main', 'CLASS')] | ||
9 | - node | ||
10 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_node_fixtures" |
11 | 4 | ||
12 | - def self.new_node(name, granularity) | ||
13 | - the_module = Kalibro::Entities::Module.new | ||
14 | - the_module.name = name | ||
15 | - the_module.granularity = granularity | ||
16 | - node = Kalibro::Entities::ModuleNode.new | ||
17 | - node.module = the_module | ||
18 | - node | ||
19 | - end | ||
20 | - | ||
21 | - def self.qt_calculator_tree_hash | ||
22 | - {:module => ModuleTest.qt_calculator_hash, | ||
23 | - :child => [ | ||
24 | - {:module => {:name => 'Dialog', :granularity => 'CLASS'}}, | ||
25 | - {:module => {:name => 'main', :granularity => 'CLASS'}} | ||
26 | - ] | ||
27 | - } | ||
28 | - end | 5 | +class ModuleNodeTest < ActiveSupport::TestCase |
29 | 6 | ||
30 | def setup | 7 | def setup |
31 | - @hash = self.class.qt_calculator_tree_hash | ||
32 | - @node = self.class.qt_calculator_tree | 8 | + @hash = ModuleNodeFixtures.qt_calculator_tree_hash |
9 | + @node = ModuleNodeFixtures.qt_calculator_tree | ||
33 | end | 10 | end |
34 | 11 | ||
35 | should 'create module node from hash' do | 12 | should 'create module node from hash' do |
plugins/mezuro/test/unit/kalibro/entities/module_result_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | 2 | ||
3 | -class ModuleResultTest < ActiveSupport::TestCase | ||
4 | - | ||
5 | - def self.fixture | ||
6 | - amloc_result = MetricResultTest.amloc_result | ||
7 | - sc_result = MetricResultTest.sc_result | ||
8 | - fixture = Kalibro::Entities::ModuleResult.new | ||
9 | - fixture.module = ModuleTest.qt_calculator | ||
10 | - fixture.date = DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000') | ||
11 | - fixture.grade = 10.0 | ||
12 | - fixture.metric_results = [amloc_result, sc_result] | ||
13 | - fixture.compound_metrics_with_error = [CompoundMetricWithErrorTest.fixture] | ||
14 | - fixture | ||
15 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" |
16 | 4 | ||
17 | - def self.fixture_hash | ||
18 | - amloc_result = MetricResultTest.amloc_result_hash | ||
19 | - sc_result = MetricResultTest.sc_result_hash | ||
20 | - {:module => ModuleTest.qt_calculator_hash, | ||
21 | - :date => DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000'), | ||
22 | - :grade => 10.0, :metric_result => [amloc_result, sc_result], | ||
23 | - :compound_metric_with_error => [CompoundMetricWithErrorTest.fixture_hash]} | ||
24 | - end | 5 | +class ModuleResultTest < ActiveSupport::TestCase |
25 | 6 | ||
26 | def setup | 7 | def setup |
27 | - @hash = self.class.fixture_hash | ||
28 | - @result = self.class.fixture | 8 | + @hash = ModuleResultFixtures.create_hash |
9 | + @result = ModuleResultFixtures.create | ||
29 | end | 10 | end |
30 | 11 | ||
31 | should 'create module result from hash' do | 12 | should 'create module result from hash' do |
plugins/mezuro/test/unit/kalibro/entities/module_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class ModuleTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.qt_calculator | ||
5 | - entity = Kalibro::Entities::Module.new | ||
6 | - entity.name = ProjectTest.qt_calculator.name | ||
7 | - entity.granularity = 'APPLICATION' | ||
8 | - entity | ||
9 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures" |
10 | 4 | ||
11 | - def self.qt_calculator_hash | ||
12 | - name = ProjectTest.qt_calculator.name | ||
13 | - {:name => name, :granularity => 'APPLICATION'} | ||
14 | - end | 5 | +class ModuleTest < ActiveSupport::TestCase |
15 | 6 | ||
16 | def setup | 7 | def setup |
17 | - @hash = self.class.qt_calculator_hash | ||
18 | - @module = self.class.qt_calculator | 8 | + @hash = ModuleFixtures.qt_calculator_hash |
9 | + @module = ModuleFixtures.qt_calculator | ||
19 | end | 10 | end |
20 | 11 | ||
21 | should 'create module from hash' do | 12 | should 'create module from hash' do |
@@ -26,4 +17,14 @@ class ModuleTest < ActiveSupport::TestCase | @@ -26,4 +17,14 @@ class ModuleTest < ActiveSupport::TestCase | ||
26 | assert_equal @hash, @module.to_hash | 17 | assert_equal @hash, @module.to_hash |
27 | end | 18 | end |
28 | 19 | ||
29 | -end | ||
30 | \ No newline at end of file | 20 | \ No newline at end of file |
21 | + should 'list ancestor names' do | ||
22 | + @module.name = "org.kalibro.core" | ||
23 | + assert_equal ["org", "org.kalibro", "org.kalibro.core"], @module.ancestor_names | ||
24 | + end | ||
25 | + | ||
26 | + should 'list ancestor with one name' do | ||
27 | + @module.name = "org" | ||
28 | + assert_equal ["org"], @module.ancestor_names | ||
29 | + end | ||
30 | + | ||
31 | +end |
plugins/mezuro/test/unit/kalibro/entities/native_metric_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class NativeMetricTest < ActiveSupport::TestCase | ||
3 | - | ||
4 | - def self.total_cof | ||
5 | - total_cof = Kalibro::Entities::NativeMetric.new | ||
6 | - total_cof.name = 'Total Coupling Factor' | ||
7 | - total_cof.scope = 'APPLICATION' | ||
8 | - total_cof.origin = 'Analizo' | ||
9 | - total_cof.language = 'JAVA' | ||
10 | - total_cof | ||
11 | - end | ||
12 | 2 | ||
13 | - def self.amloc | ||
14 | - total_cof = Kalibro::Entities::NativeMetric.new | ||
15 | - total_cof.name = 'Average Method LOC' | ||
16 | - total_cof.scope = 'CLASS' | ||
17 | - total_cof.origin = 'Analizo' | ||
18 | - total_cof.language = 'JAVA' | ||
19 | - total_cof | ||
20 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures" |
21 | 4 | ||
22 | - def self.total_cof_hash | ||
23 | - {:name => 'Total Coupling Factor', :scope => 'APPLICATION', | ||
24 | - :origin => 'Analizo', :language => 'JAVA'} | ||
25 | - end | 5 | +class NativeMetricTest < ActiveSupport::TestCase |
26 | 6 | ||
27 | - def self.amloc_hash | ||
28 | - {:name => 'Average Method LOC', :scope => 'CLASS', | ||
29 | - :origin => 'Analizo', :language => 'JAVA'} | ||
30 | - end | ||
31 | - | ||
32 | def setup | 7 | def setup |
33 | - @hash = self.class.amloc_hash | ||
34 | - @metric = self.class.amloc | 8 | + @hash = NativeMetricFixtures.amloc_hash |
9 | + @metric = NativeMetricFixtures.amloc | ||
35 | end | 10 | end |
36 | 11 | ||
37 | should 'create native metric from hash' do | 12 | should 'create native metric from hash' do |
plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class ProjectResultTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.qt_calculator | ||
5 | - result = Kalibro::Entities::ProjectResult.new | ||
6 | - result.project = ProjectTest.qt_calculator | ||
7 | - result.date = DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000') | ||
8 | - result.load_time = 14878 | ||
9 | - result.analysis_time = 1022 | ||
10 | - result.source_tree = ModuleNodeTest.qt_calculator_tree | ||
11 | - result | ||
12 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" |
13 | 4 | ||
14 | - def self.qt_calculator_hash | ||
15 | - {:project => ProjectTest.qt_calculator_hash, | ||
16 | - :date => DateTime.parse('Thu, 20 Oct 2011 18:26:43.151 +0000'), | ||
17 | - :load_time => 14878, | ||
18 | - :analysis_time => 1022, | ||
19 | - :source_tree => ModuleNodeTest.qt_calculator_tree_hash} | ||
20 | - end | 5 | +class ProjectResultTest < ActiveSupport::TestCase |
21 | 6 | ||
22 | def setup | 7 | def setup |
23 | - @hash = self.class.qt_calculator_hash | ||
24 | - @result = self.class.qt_calculator | 8 | + @hash = ProjectResultFixtures.qt_calculator_hash |
9 | + @result = ProjectResultFixtures.qt_calculator | ||
25 | end | 10 | end |
26 | 11 | ||
27 | should 'create project result from hash' do | 12 | should 'create project result from hash' do |
@@ -39,5 +24,26 @@ class ProjectResultTest < ActiveSupport::TestCase | @@ -39,5 +24,26 @@ class ProjectResultTest < ActiveSupport::TestCase | ||
39 | should 'retrieve formatted analysis time' do | 24 | should 'retrieve formatted analysis time' do |
40 | assert_equal '00:00:01', @result.formatted_analysis_time | 25 | assert_equal '00:00:01', @result.formatted_analysis_time |
41 | end | 26 | end |
27 | + | ||
28 | + should 'retrieve module node' do | ||
29 | + node = @result.get_node("main") | ||
30 | + assert_equal @hash[:source_tree][:child][2], node.to_hash | ||
31 | + end | ||
32 | + | ||
33 | + should 'retrive complex module' do | ||
34 | + node = @result.get_node("org.Window") | ||
35 | + assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash | ||
36 | + end | ||
37 | + | ||
38 | + should 'return source tree node when nil is given' do | ||
39 | + assert_equal @hash[:source_tree], @result.node_of(nil).to_hash | ||
40 | + end | ||
42 | 41 | ||
43 | -end | ||
44 | \ No newline at end of file | 42 | \ No newline at end of file |
43 | + should 'return source tree node when project name is given' do | ||
44 | + assert_equal @hash[:source_tree], @result.node_of(@result.project.name).to_hash | ||
45 | + end | ||
46 | + | ||
47 | + should 'return correct node when module name is given' do | ||
48 | + assert_equal @hash[:source_tree][:child][2], @result.node_of("main").to_hash | ||
49 | + end | ||
50 | +end |
plugins/mezuro/test/unit/kalibro/entities/project_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class ProjectTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.qt_calculator | ||
5 | - project = Kalibro::Entities::Project.new | ||
6 | - project.name = 'Qt-Calculator' | ||
7 | - project.license = 'GPL' | ||
8 | - project.description = 'Calculator for Qt' | ||
9 | - project.repository = RepositoryTest.qt_calculator | ||
10 | - project.configuration_name = 'Kalibro for Java' | ||
11 | - project.state = 'READY' | ||
12 | - project | ||
13 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" |
14 | 4 | ||
15 | - def self.qt_calculator_hash | ||
16 | - {:name => 'Qt-Calculator', :license => 'GPL', | ||
17 | - :description => 'Calculator for Qt', | ||
18 | - :repository => RepositoryTest.qt_calculator_hash, | ||
19 | - :configuration_name => 'Kalibro for Java', | ||
20 | - :state => 'READY'} | ||
21 | - end | 5 | +class ProjectTest < ActiveSupport::TestCase |
22 | 6 | ||
23 | def setup | 7 | def setup |
24 | - @hash = self.class.qt_calculator_hash | ||
25 | - @project = self.class.qt_calculator | 8 | + @hash = ProjectFixtures.qt_calculator_hash |
9 | + @project = ProjectFixtures.qt_calculator | ||
26 | end | 10 | end |
27 | 11 | ||
28 | should 'create project from hash' do | 12 | should 'create project from hash' do |
plugins/mezuro/test/unit/kalibro/entities/range_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class RangeTest < ActiveSupport::TestCase | ||
3 | - | ||
4 | - Infinity = 1.0/0.0 | ||
5 | 2 | ||
6 | - def self.amloc_excellent | ||
7 | - range = Kalibro::Entities::Range.new | ||
8 | - range.beginning = 0.0 | ||
9 | - range.end = 7.0 | ||
10 | - range.label = 'Excellent' | ||
11 | - range.grade = 10.0 | ||
12 | - range.color = 'ff00ff00' | ||
13 | - range | ||
14 | - end | ||
15 | - | ||
16 | - def self.amloc_bad | ||
17 | - range = Kalibro::Entities::Range.new | ||
18 | - range.beginning = 19.5 | ||
19 | - range.end = Infinity | ||
20 | - range.label = 'Bad' | ||
21 | - range.grade = 0.0 | ||
22 | - range.color = 'ffff0000' | ||
23 | - range | ||
24 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" |
25 | 4 | ||
26 | - def self.amloc_excellent_hash | ||
27 | - {:beginning => 0.0, :end => 7.0, :label => 'Excellent', | ||
28 | - :grade => 10.0, :color => 'ff00ff00'} | ||
29 | - end | ||
30 | - | ||
31 | - def self.amloc_bad_hash | ||
32 | - {:beginning => 19.5, :end => Infinity, :label => 'Bad', | ||
33 | - :grade => 0.0, :color => 'ffff0000'} | ||
34 | - end | 5 | +class RangeTest < ActiveSupport::TestCase |
35 | 6 | ||
36 | def setup | 7 | def setup |
37 | - @hash = self.class.amloc_bad_hash | ||
38 | - @range = self.class.amloc_bad | 8 | + @hash = RangeFixtures.amloc_bad_hash |
9 | + @range = RangeFixtures.amloc_bad | ||
39 | end | 10 | end |
40 | 11 | ||
41 | should 'create range from hash' do | 12 | should 'create range from hash' do |
plugins/mezuro/test/unit/kalibro/entities/repository_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class RepositoryTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.qt_calculator | ||
5 | - repository = Kalibro::Entities::Repository.new | ||
6 | - repository.type = 'SUBVERSION' | ||
7 | - repository.address = 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator' | ||
8 | - repository | ||
9 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" |
10 | 4 | ||
11 | - def self.qt_calculator_hash | ||
12 | - {:type => 'SUBVERSION', | ||
13 | - :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} | ||
14 | - end | 5 | +class RepositoryTest < ActiveSupport::TestCase |
15 | 6 | ||
16 | def setup | 7 | def setup |
17 | - @hash = self.class.qt_calculator_hash | ||
18 | - @repository = self.class.qt_calculator | 8 | + @hash = RepositoryFixtures.qt_calculator_hash |
9 | + @repository = RepositoryFixtures.qt_calculator | ||
19 | end | 10 | end |
20 | 11 | ||
21 | should 'create repository from hash' do | 12 | should 'create repository from hash' do |
plugins/mezuro/test/unit/kalibro/entities/stack_trace_element_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | -class StackTraceElementTest < ActiveSupport::TestCase | ||
3 | 2 | ||
4 | - def self.fixture(method_name = 'stackTraceElementTestMethod', line_number = 42) | ||
5 | - stack_trace_element = Kalibro::Entities::StackTraceElement.new | ||
6 | - stack_trace_element.declaring_class = 'org.declaring.Class' | ||
7 | - stack_trace_element.method_name = method_name | ||
8 | - stack_trace_element.file_name = 'Class.java' | ||
9 | - stack_trace_element.line_number = line_number | ||
10 | - stack_trace_element | ||
11 | - end | 3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/stack_trace_element_fixtures" |
12 | 4 | ||
13 | - def self.fixture_hash(method_name = 'stackTraceElementTestMethod', line_number = 42) | ||
14 | - {:declaring_class => 'org.declaring.Class', | ||
15 | - :method_name => method_name, | ||
16 | - :file_name => 'Class.java', | ||
17 | - :line_number => line_number} | ||
18 | - end | 5 | +class StackTraceElementTest < ActiveSupport::TestCase |
19 | 6 | ||
20 | def setup | 7 | def setup |
21 | - @hash = self.class.fixture_hash | ||
22 | - @stack_trace_element = self.class.fixture | 8 | + @hash = StackTraceElementFixtures.create_hash |
9 | + @stack_trace_element = StackTraceElementFixtures.create | ||
23 | end | 10 | end |
24 | 11 | ||
25 | should 'create stack trace element from hash' do | 12 | should 'create stack trace element from hash' do |
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb
0 → 100644
@@ -0,0 +1,50 @@ | @@ -0,0 +1,50 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | ||
4 | + | ||
5 | +class ConfigurationContentTest < ActiveSupport::TestCase | ||
6 | + | ||
7 | + def setup | ||
8 | + @configuration = ConfigurationFixtures.kalibro_configuration | ||
9 | + @content = MezuroPlugin::ConfigurationContent.new | ||
10 | + @content.name = @configuration.name | ||
11 | + @content.description = @configuration.description | ||
12 | + end | ||
13 | + | ||
14 | + should 'be an article' do | ||
15 | + assert_kind_of Article, @content | ||
16 | + end | ||
17 | + | ||
18 | + should 'provide proper short description' do | ||
19 | + assert_equal 'Kalibro configuration', MezuroPlugin::ConfigurationContent.short_description | ||
20 | + end | ||
21 | + | ||
22 | + should 'provide proper description' do | ||
23 | + assert_equal 'Sets of thresholds to interpret metrics', MezuroPlugin::ConfigurationContent.description | ||
24 | + end | ||
25 | + | ||
26 | + should 'have an html view' do | ||
27 | + assert_not_nil @content.to_html | ||
28 | + end | ||
29 | + | ||
30 | + should 'get configuration from service' do | ||
31 | + Kalibro::Client::ConfigurationClient.expects(:configuration).with(@content.name).returns(@configuration) | ||
32 | + assert_equal @configuration, @content.configuration | ||
33 | + end | ||
34 | + | ||
35 | + should 'send configuration to service after saving' do | ||
36 | + @content.expects :send_configuration_to_service | ||
37 | + @content.run_callbacks :after_save | ||
38 | + end | ||
39 | + | ||
40 | + should 'send correct configuration to service' do | ||
41 | + Kalibro::Client::ConfigurationClient.expects(:save).with(@content) | ||
42 | + @content.send :send_configuration_to_service | ||
43 | + end | ||
44 | + | ||
45 | + should 'remove configuration from service' do | ||
46 | + Kalibro::Client::ConfigurationClient.expects(:remove).with(@content.name) | ||
47 | + @content.send :remove_configuration_from_service | ||
48 | + end | ||
49 | + | ||
50 | +end |
plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +class ContentViewerHelperTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + should 'get the number rounded by two decimal points' do | ||
6 | + assert_equal '4.22', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.22344') | ||
7 | + assert_equal '4.10', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.1') | ||
8 | + assert_equal '4.00', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4') | ||
9 | + end | ||
10 | + | ||
11 | + should 'create the periodicity options array' do | ||
12 | + assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]], MezuroPlugin::Helpers::ContentViewerHelper.create_periodicity_options | ||
13 | + end | ||
14 | +end |
plugins/mezuro/test/unit/mezuro_plugin/metric_configuration_content_test.rb
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +class MetricConfigurationContentTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @metric_configuration = MezuroPlugin::MetricConfigurationContent.new | ||
7 | + end | ||
8 | + | ||
9 | + should 'be a metric configuration' do | ||
10 | + assert_kind_of Article, @metric_configuration | ||
11 | + end | ||
12 | + | ||
13 | + should 'have short description' do | ||
14 | + assert_equal 'Kalibro Configurated Metric', MezuroPlugin::MetricConfigurationContent.short_description | ||
15 | + end | ||
16 | + | ||
17 | + should 'have description' do | ||
18 | + assert_equal 'Sets of thresholds to interpret a metric', MezuroPlugin::MetricConfigurationContent.description | ||
19 | + end | ||
20 | + | ||
21 | + should 'have an html view' do | ||
22 | + assert_not_nil @metric_configuration.to_html | ||
23 | + end | ||
24 | + | ||
25 | + #should 'return metric configuration' do | ||
26 | + # pending "Need refactoring" | ||
27 | + #end | ||
28 | + | ||
29 | + should 'send metric configuration to service after saving' do | ||
30 | + @metric_configuration.expects :send_metric_configuration_to_service | ||
31 | + @metric_configuration.run_callbacks :after_save | ||
32 | + end | ||
33 | + | ||
34 | + should 'send correct metric configuration to service' do | ||
35 | + Kalibro::Client::MetricConfigurationClient.expects(:save).with(@metric_configuration) | ||
36 | + @metric_configuration.send :send_metric_configuration_to_service | ||
37 | + end | ||
38 | + | ||
39 | + should 'remove metric configuration from service' do | ||
40 | + Kalibro::Client::MetricConfigurationClient.expects(:remove).with(@metric_configuration.name) | ||
41 | + @metric_configuration.send :remove_metric_configuration_from_service | ||
42 | + end | ||
43 | + | ||
44 | +end |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | ||
4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | ||
5 | + | ||
2 | class ProjectContentTest < ActiveSupport::TestCase | 6 | class ProjectContentTest < ActiveSupport::TestCase |
3 | 7 | ||
4 | def setup | 8 | def setup |
5 | - @project = ProjectTest.qt_calculator | 9 | + @project = ProjectFixtures.qt_calculator |
6 | @content = MezuroPlugin::ProjectContent.new | 10 | @content = MezuroPlugin::ProjectContent.new |
7 | @content.name = @project.name | 11 | @content.name = @project.name |
8 | @content.license = @project.license | 12 | @content.license = @project.license |
@@ -10,6 +14,7 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -10,6 +14,7 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
10 | @content.repository_type = @project.repository.type | 14 | @content.repository_type = @project.repository.type |
11 | @content.repository_url = @project.repository.address | 15 | @content.repository_url = @project.repository.address |
12 | @content.configuration_name = @project.configuration_name | 16 | @content.configuration_name = @project.configuration_name |
17 | + @content.periodicity_in_days = 1 | ||
13 | end | 18 | end |
14 | 19 | ||
15 | should 'be an article' do | 20 | should 'be an article' do |
@@ -28,19 +33,105 @@ class ProjectContentTest < ActiveSupport::TestCase | @@ -28,19 +33,105 @@ class ProjectContentTest < ActiveSupport::TestCase | ||
28 | assert_not_nil @content.to_html | 33 | assert_not_nil @content.to_html |
29 | end | 34 | end |
30 | 35 | ||
31 | - should 'run send project to service on after_save callback' do | 36 | + should 'get project from service' do |
37 | + Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project) | ||
38 | + assert_equal @project, @content.project | ||
39 | + end | ||
40 | + | ||
41 | + should 'get project result from service' do | ||
42 | + project_result = mock | ||
43 | + Kalibro::Client::ProjectResultClient.expects(:last_result).with(@content.name).returns(project_result) | ||
44 | + assert_equal project_result, @content.project_result | ||
45 | + end | ||
46 | + | ||
47 | + should 'get date result from service when has_result_before is true' do | ||
48 | + client = mock | ||
49 | + project_result = mock | ||
50 | + Kalibro::Client::ProjectResultClient.expects(:new).returns(client) | ||
51 | + client.expects(:has_results_before).with(@project.name, "2012-05-22T22:00:33+04:00").returns(true) | ||
52 | + client.expects(:last_result_before).with(@project.name, "2012-05-22T22:00:33+04:00").returns(project_result) | ||
53 | + assert_equal project_result, @content.get_date_result("2012-05-22T22:00:33+04:00") | ||
54 | + end | ||
55 | + | ||
56 | + should 'get date result from service when has_result_before is false' do | ||
57 | + client = mock | ||
58 | + project_result = mock | ||
59 | + Kalibro::Client::ProjectResultClient.expects(:new).returns(client) | ||
60 | + client.expects(:has_results_before).with(@project.name, "2012-05-22T22:00:33+04:00").returns(false) | ||
61 | + client.expects(:first_result_after).with(@project.name, "2012-05-22T22:00:33+04:00").returns(project_result) | ||
62 | + assert_equal project_result, @content.get_date_result("2012-05-22T22:00:33+04:00") | ||
63 | + end | ||
64 | + | ||
65 | + should 'get module result from service' do | ||
66 | + mock_project_client | ||
67 | + project_result = mock_project_result_client | ||
68 | + module_name = 'My module name' | ||
69 | + module_result_client = mock | ||
70 | + module_result = Kalibro::Entities::ModuleResult.new | ||
71 | + @content.expects(:module_result_client).returns(module_result_client) | ||
72 | + module_result_client.expects(:module_result).with(@project.name, module_name, project_result.date). | ||
73 | +returns(module_result) | ||
74 | + assert_equal module_result, @content.module_result(module_name) | ||
75 | + end | ||
76 | + | ||
77 | + should 'get module result root when nil is given' do | ||
78 | + mock_project_client | ||
79 | + project_result = mock_project_result_client | ||
80 | + module_result_client = mock | ||
81 | + module_result = Kalibro::Entities::ModuleResult.new | ||
82 | + @content.expects(:module_result_client).returns(module_result_client) | ||
83 | + module_result_client.expects(:module_result).with(@project.name, @project.name, project_result.date). | ||
84 | +returns(module_result) | ||
85 | + assert_equal module_result, @content.module_result(nil) | ||
86 | + end | ||
87 | + | ||
88 | + should 'get result history' do | ||
89 | + mock_project_client | ||
90 | + module_name = 'Fake Name' | ||
91 | + module_result_client = mock | ||
92 | + module_result_client.expects(:result_history).with(@project.name, module_name) | ||
93 | + @content.expects(:module_result_client).returns(module_result_client) | ||
94 | + @content.result_history(module_name) | ||
95 | + end | ||
96 | + | ||
97 | + should 'send project to service after saving' do | ||
32 | @content.expects :send_project_to_service | 98 | @content.expects :send_project_to_service |
33 | @content.run_callbacks :after_save | 99 | @content.run_callbacks :after_save |
34 | end | 100 | end |
35 | 101 | ||
36 | should 'send correct project to service' do | 102 | should 'send correct project to service' do |
37 | - Kalibro::Client::ProjectClient.expects(:save).with(@project) | ||
38 | - Kalibro::Client::KalibroClient.expects(:process_project).with(@project.name) | 103 | + Kalibro::Client::ProjectClient.expects(:save).with(@content) |
104 | + Kalibro::Client::KalibroClient.expects(:process_project).with(@content.name, @content.periodicity_in_days) | ||
39 | @content.send :send_project_to_service | 105 | @content.send :send_project_to_service |
40 | end | 106 | end |
41 | 107 | ||
42 | should 'remove project from service' do | 108 | should 'remove project from service' do |
43 | - Kalibro::Client::ProjectClient.expects(:remove).with(@project.name) | 109 | + Kalibro::Client::ProjectClient.expects(:remove).with(@content.name) |
44 | @content.send :remove_project_from_service | 110 | @content.send :remove_project_from_service |
45 | end | 111 | end |
112 | + | ||
113 | + should 'not save a project with an existing project name in kalibro' do | ||
114 | + client = mock | ||
115 | + Kalibro::Client::ProjectClient.expects(:new).returns(client) | ||
116 | + client.expects(:project_names).returns([@content.name]) | ||
117 | + @content.send :validate_kalibro_project_name | ||
118 | + assert_equal "Project name already exists in Kalibro", @content.errors.on_base | ||
119 | + end | ||
120 | + | ||
121 | + private | ||
122 | + | ||
123 | + def mock_project_client | ||
124 | + Kalibro::Client::ProjectClient.expects(:project).with(@content.name).returns(@project) | ||
125 | + end | ||
126 | + | ||
127 | + def mock_project_result_client | ||
128 | + project_result = ProjectResultFixtures.qt_calculator | ||
129 | + Kalibro::Client::ProjectResultClient.expects(:last_result).with(@content.name).returns(project_result) | ||
130 | + project_result | ||
131 | + end | ||
132 | + | ||
133 | + def create_project_error | ||
134 | + raise "Error on Kalibro" | ||
135 | + end | ||
136 | + | ||
46 | end | 137 | end |
plugins/mezuro/test/unit/mezuro_plugin_test.rb
1 | require "test_helper" | 1 | require "test_helper" |
2 | + | ||
2 | class MezuroPluginTest < ActiveSupport::TestCase | 3 | class MezuroPluginTest < ActiveSupport::TestCase |
3 | 4 | ||
4 | def setup | 5 | def setup |
@@ -29,8 +30,4 @@ class MezuroPluginTest < ActiveSupport::TestCase | @@ -29,8 +30,4 @@ class MezuroPluginTest < ActiveSupport::TestCase | ||
29 | assert @plugin.stylesheet? | 30 | assert @plugin.stylesheet? |
30 | end | 31 | end |
31 | 32 | ||
32 | - should 'list javascript files' do | ||
33 | - assert_equal ['javascripts/results.js', 'javascripts/toogle.js'], @plugin.js_files | ||
34 | - end | ||
35 | - | ||
36 | end | 33 | end |
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
1 | <h1> <%= _(MezuroPlugin::ConfigurationContent.short_description) %> </h1> | 1 | <h1> <%= _(MezuroPlugin::ConfigurationContent.short_description) %> </h1> |
2 | 2 | ||
3 | <% | 3 | <% |
4 | - begin | ||
5 | - @configuration = @article.title.nil? ? nil : Kalibro::Client::ConfigurationClient.new.configuration(@article.title) | ||
6 | - rescue | ||
7 | - @configuration = nil | ||
8 | - end | 4 | +begin |
5 | + @configuration = @article.title.nil? ? nil : Kalibro::Client::ConfigurationClient.new.configuration(@article.title) | ||
6 | +rescue | ||
7 | + @configuration = nil | ||
8 | +end | ||
9 | %> | 9 | %> |
10 | 10 | ||
11 | <%= error_messages_for 'kalibro_configuration' %> | 11 | <%= error_messages_for 'kalibro_configuration' %> |
plugins/mezuro/views/cms/mezuro_plugin/_project_content.html.erb
@@ -2,7 +2,8 @@ | @@ -2,7 +2,8 @@ | ||
2 | 2 | ||
3 | <% | 3 | <% |
4 | begin | 4 | begin |
5 | - @project = @article.title.nil? ? nil : Kalibro::Client::ProjectClient.new.project(@article.title) | 5 | + @project = @article.title.nil? ? nil : Kalibro::Client::ProjectClient.project(@article.title) |
6 | + @kalibro_client = Kalibro::Client::KalibroClient.new | ||
6 | rescue | 7 | rescue |
7 | @project = nil | 8 | @project = nil |
8 | end | 9 | end |
@@ -21,7 +22,7 @@ | @@ -21,7 +22,7 @@ | ||
21 | 22 | ||
22 | <%= f.text_field :description %><br/> | 23 | <%= f.text_field :description %><br/> |
23 | 24 | ||
24 | -<% @repository_types = Kalibro::Client::KalibroClient.new.supported_repository_types.sort %> | 25 | +<% @repository_types = @kalibro_client.supported_repository_types.sort %> |
25 | <% @selected = (@project.nil? ? @repository_types : @project.repository.type) %> | 26 | <% @selected = (@project.nil? ? @repository_types : @project.repository.type) %> |
26 | <%= required labelled_form_field _('Repository type'), | 27 | <%= required labelled_form_field _('Repository type'), |
27 | f.select(:repository_type, @repository_types, {:selected => @selected}) %><br/> | 28 | f.select(:repository_type, @repository_types, {:selected => @selected}) %><br/> |
@@ -31,4 +32,9 @@ | @@ -31,4 +32,9 @@ | ||
31 | <% @configuration_names = Kalibro::Client::ConfigurationClient.new.configuration_names.sort %> | 32 | <% @configuration_names = Kalibro::Client::ConfigurationClient.new.configuration_names.sort %> |
32 | <% @selected = (@project.nil? ? @configuration_names[0] : @project.configuration_name) %> | 33 | <% @selected = (@project.nil? ? @configuration_names[0] : @project.configuration_name) %> |
33 | <%= required labelled_form_field _('Configuration'), | 34 | <%= required labelled_form_field _('Configuration'), |
34 | - f.select(:configuration_name, @configuration_names.sort, {:selected => @selected}) %><br/> | ||
35 | \ No newline at end of file | 35 | \ No newline at end of file |
36 | + f.select(:configuration_name, @configuration_names, {:selected => @selected}) %><br/> | ||
37 | + | ||
38 | + | ||
39 | +<% selected = (@project.nil? ? 0 : @kalibro_client.process_period(@article.title).to_i) %> | ||
40 | +<%= required labelled_form_field _('Periodic Avaliation'), | ||
41 | + f.select(:periodicity_in_days, MezuroPlugin::Helpers::ContentViewerHelper.create_periodicity_options ,{:selected => selected}) %><br/> |
plugins/mezuro/views/content_viewer/_module_result.rhtml
1 | -<h5><%= _('Metric Result') %> </h5> | ||
2 | -<strong> | ||
3 | - <%= _('Module:') %> | ||
4 | - <%= module_result.module.name %> | ||
5 | -</strong> | ||
6 | -<br/> | 1 | +<% the_module = module_result.module %> |
2 | +<% module_label = "#{the_module.name} (#{the_module.granularity})" %> | ||
3 | + | ||
4 | +<h5><%= _('Metric results for: ') + module_label %> </h5> | ||
5 | + | ||
7 | <hr/> | 6 | <hr/> |
8 | -<table id="project_metric_result"> | 7 | +<div class="zoomable-image"> |
8 | +<table> | ||
9 | <thead> | 9 | <thead> |
10 | <tr> | 10 | <tr> |
11 | <th>Metric</th> | 11 | <th>Metric</th> |
@@ -17,23 +17,40 @@ | @@ -17,23 +17,40 @@ | ||
17 | <tbody> | 17 | <tbody> |
18 | <% module_result.metric_results.each do |metric_result| %> | 18 | <% module_result.metric_results.each do |metric_result| %> |
19 | <% range = metric_result.range %> | 19 | <% range = metric_result.range %> |
20 | - <tr title=" <%= range.comments %>"> | ||
21 | - <td><%= metric_result.metric.name %></td> | ||
22 | - <td><%= metric_result.value %></td> | ||
23 | - <td><%= metric_result.weight %></td> | ||
24 | - <td style="background-color: #<%= range.color[2..-1] %>"><%= range.label %></td> | ||
25 | - </tr> | 20 | + <% if !range.nil? %> |
21 | + <tr> | ||
22 | + <td><a href="#" data-show=".<%= metric_result.metric.name.delete("() ")%>"><%= metric_result.metric.name %></a></td> | ||
23 | + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td> | ||
24 | + <td><%= metric_result.weight %></td> | ||
25 | + <td style="background-color: #<%= range.color[2..-1] %>"><%= range.label %></td> | ||
26 | + </tr> | ||
27 | + <tr class="<%= metric_result.metric.name.delete("() ")%>" style="display: none;"> | ||
28 | + <td colspan="3"> | ||
29 | + <div id='historical-<%= metric_result.metric.name.delete("() ") %>'> | ||
30 | + <a href="#" show-metric-history="<%= metric_result.metric.name.delete("() ") %>" data-module-name="<%= the_module.name %>" data-metric-name="<%= metric_result.metric.name.delete("() ") %>"> <p style="text-indent: 3em;"> Get Historical Values </p> </a> | ||
31 | + </div> | ||
32 | + </td> | ||
33 | + <td align="right"> | ||
34 | + <%= range.comments.nil? ? '' : range.comments %> | ||
35 | + </td> | ||
36 | + </tr> | ||
37 | + <% end %> | ||
26 | <% end %> | 38 | <% end %> |
27 | </tbody> | 39 | </tbody> |
28 | <tfoot> | 40 | <tfoot> |
29 | <tr> | 41 | <tr> |
30 | - <td colspan = "4" align = "right"> | ||
31 | - <strong> | ||
32 | - <%= _('Grade:') %> | ||
33 | - <%= module_result.grade %> | ||
34 | - </strong> | 42 | + <td colspan = "3"> |
43 | + <div id='historical-grade'></div> | ||
44 | + </td> | ||
45 | + <td align = "right"> | ||
46 | + <a href="#" show-grade-history="<%= module_result.module.name %>" data-module-name="<%= the_module.name%>" > | ||
47 | + <strong> | ||
48 | + <%= _('Grade:') %> | ||
49 | + <%= "%.02f" % module_result.grade %> | ||
50 | + </strong> | ||
51 | + </a> | ||
35 | </td> | 52 | </td> |
36 | </tr> | 53 | </tr> |
37 | </tfoot> | 54 | </tfoot> |
38 | </table> | 55 | </table> |
39 | - | 56 | +</div> |
plugins/mezuro/views/content_viewer/_project_error.rhtml
0 → 100644
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +<h3><%= _('ERROR') %></h3> | ||
2 | +<p> | ||
3 | + <%= "State when error ocurred: #{project.state}" %> | ||
4 | + <br/> | ||
5 | + <% error = project.error %> | ||
6 | + <%= error.message %> | ||
7 | +<ul> | ||
8 | + <% error.stack_trace.each do |trace| %> | ||
9 | + <li><%= "#{trace.declaring_class}.#{trace.method_name}(#{trace.file_name}:#{trace.line_number})" %></li> | ||
10 | + <% end %> | ||
11 | +</ul> | ||
12 | +</p> |
plugins/mezuro/views/content_viewer/_project_result.rhtml
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | + | ||
2 | +<% form_for :project_date, :html=>{:id=>"project_history_date"} do |f| %> | ||
3 | + <%= f.label :day, "Choose project date:" %> | ||
4 | + | ||
5 | +<table> | ||
6 | + <tr> | ||
7 | + <td> | ||
8 | + Day | ||
9 | + </td> | ||
10 | + <td> | ||
11 | + Month | ||
12 | + </td> | ||
13 | + <td> | ||
14 | + Year | ||
15 | + </td> | ||
16 | + </tr> | ||
17 | + <tr> | ||
18 | + <td> | ||
19 | + <%= f.text_field :day, :size => 1, :maxlength => 2, :placeholder =>"dd" %> | ||
20 | + </td> | ||
21 | + <td> | ||
22 | + <%= f.text_field :month, :size => 1, :maxlength => 2, :placeholder =>"mm" %> | ||
23 | + </td> | ||
24 | + <td> | ||
25 | + <%= f.text_field :year, :size => 1, :maxlength => 4, :placeholder =>"yyyy" %> | ||
26 | + </td> | ||
27 | + </tr> | ||
28 | +</table> | ||
29 | + <%= f.submit "Refresh" %> | ||
30 | +<% end %> | ||
31 | + | ||
32 | + | ||
33 | +<h4><%= _('Last Result') %></h4> | ||
34 | + | ||
35 | +<table> | ||
36 | + <tr> | ||
37 | + <td><%= _('Date') %></td> | ||
38 | + <td><%= project_result.date %></td> | ||
39 | + </tr> | ||
40 | + <tr> | ||
41 | + <td><%= _('Load time') %></td> | ||
42 | + <td><%= project_result.formatted_load_time %></td> | ||
43 | + </tr> | ||
44 | + <tr> | ||
45 | + <td><%= _('Analysis time') %></td> | ||
46 | + <td><%= project_result.formatted_analysis_time %></td> | ||
47 | + </tr> | ||
48 | +</table> |
plugins/mezuro/views/content_viewer/_score_history.rhtml
0 → 100644
plugins/mezuro/views/content_viewer/_source_tree.rhtml
1 | -<% module_name = source_tree.module_name %> | ||
2 | -<% module_label = "#{module_name} (#{source_tree.granularity})" %> | 1 | +<h4><%= _('Source tree') %></h4> |
2 | +<% module_name = source_tree.module.name %> | ||
3 | +<% module_label = "#{module_name} (#{source_tree.module.granularity})" %> | ||
4 | + | ||
5 | +<p><h2 class="path"> | ||
6 | + <% if module_name != project_name %> | ||
7 | + <a href="#" class="source-tree-link" data-module-name="<%= project_name %>"> | ||
8 | + <%= project_name %> | ||
9 | + </a> | ||
10 | + <% end %> | ||
11 | + | ||
12 | + | ||
13 | + <% split_link = source_tree.module.ancestor_names %> | ||
14 | + <% split_link.each do |link| %> | ||
15 | + /<a href="#" class="source-tree-link" data-module-name="<%= link %>"> | ||
16 | + <%= link.split(".").last %> | ||
17 | + </a> | ||
18 | + <% end %> | ||
19 | +</h2></p> | ||
20 | + | ||
3 | <% if source_tree.children %> | 21 | <% if source_tree.children %> |
4 | - <table> | ||
5 | - <tr> | ||
6 | - <td width="10%"> | ||
7 | - <img alt="+" src="/plugins/mezuro/images/plus.png" class="link" | ||
8 | - id="<%= module_name %>_plus" onclick="toogle('<%= module_name %>')"/> | ||
9 | - <img alt="-" src="/plugins/mezuro/images/minus.png" class="link" | ||
10 | - id="<%= module_name %>_minus" onclick="toogle('<%= module_name %>')" style="display: none"/> | ||
11 | - </td> | ||
12 | - <td> | ||
13 | - <a href="#" class="module-result-link" data-module-name="<%= module_name %>"> | ||
14 | - <%= module_label %> | ||
15 | - </a> | ||
16 | - </td> | ||
17 | - </tr> | ||
18 | - <tr id="<%= module_name %>_hidden" style="display: none"> | ||
19 | - <td></td> | ||
20 | - <td style="text-align: left"> | ||
21 | - <% source_tree.children.each do |child| %> | ||
22 | - <%= render :partial => 'source_tree', :locals => { :source_tree => child } %> | ||
23 | - <% end %> | ||
24 | - </td> | ||
25 | - </tr> | ||
26 | - </table> | ||
27 | -<% else %> | ||
28 | - <table> | ||
29 | - <tr> | ||
30 | - <td width="1"></td> | ||
31 | - <td> | ||
32 | - <a href="#" class="module-result-link" data-module-name="<%= module_name %>"> | ||
33 | - <%= module_label %> | ||
34 | - </a> | ||
35 | - </td> | ||
36 | - </tr> | 22 | + <table border="0" class="source-tree"> |
23 | + <% source_tree.children.each do |child| %> | ||
24 | + <% if child.module.granularity=='PACKAGE' %> | ||
25 | + <tr> | ||
26 | + <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td> | ||
27 | + <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"><%= child.module.name %></a></td> | ||
28 | + </tr> | ||
29 | + <% else %> | ||
30 | + <tr> | ||
31 | + <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td> | ||
32 | + <td class="source-tree-text"> | ||
33 | + <a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"> | ||
34 | + <%= child.module.name %> | ||
35 | + </a> | ||
36 | + </td> | ||
37 | + </tr> | ||
38 | + <% end %> | ||
39 | + <% end %> | ||
37 | </table> | 40 | </table> |
38 | <% end %> | 41 | <% end %> |
plugins/mezuro/views/content_viewer/show_configuration.rhtml
1 | -<% @configuration = @page.configuration %> | 1 | +<% @configuration_content = @page |
2 | +@configuration = Kalibro::Client::ConfigurationClient.new.configuration(@configuration_content.name) %> | ||
2 | 3 | ||
3 | <table id="project_info"> | 4 | <table id="project_info"> |
4 | <tr> | 5 | <tr> |
@@ -10,3 +11,39 @@ | @@ -10,3 +11,39 @@ | ||
10 | <td><%= @configuration.description %></td> | 11 | <td><%= @configuration.description %></td> |
11 | </tr> | 12 | </tr> |
12 | </table> | 13 | </table> |
14 | + | ||
15 | +<br/> | ||
16 | + | ||
17 | +<%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_myprofile", | ||
18 | +:action => "choose_base_tool", :params => {:configuration_name => @configuration.name} %><br/> | ||
19 | + | ||
20 | +<table> | ||
21 | + <tr class="titles"> | ||
22 | + <td><h5>Metric Name</h5></td> | ||
23 | + <td><h5>Collector Name</h5></td> | ||
24 | + <td><h5>Metric Code</h5></td> | ||
25 | + </tr> | ||
26 | + <% @configuration.metric_configurations.each do |metric_configuration| %> | ||
27 | + <tr class="metric"> | ||
28 | + <td><%= metric_configuration.metric.name %></td> | ||
29 | + <% if metric_configuration.metric.instance_of? Kalibro::Entities::NativeMetric %> | ||
30 | + <td> | ||
31 | + <%= metric_configuration.metric.origin %> | ||
32 | + </td> | ||
33 | + <td><%= metric_configuration.code %></td> | ||
34 | + <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_metric_configuration", :params => | ||
35 | + {:configuration_name => @configuration.name, :metric_name => metric_configuration.metric.name} %></td> | ||
36 | + <% else %> | ||
37 | + <td> | ||
38 | + Compound Metric | ||
39 | + </td> | ||
40 | + <td><%= metric_configuration.code %></td> | ||
41 | + <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_compound_metric_configuration", :params => | ||
42 | + {:configuration_name => @configuration.name, :metric_name => metric_configuration.metric.name} %></td> | ||
43 | + <% end %> | ||
44 | + | ||
45 | + <td><%= link_to "Remove", :controller => "mezuro_plugin_myprofile", :action => "remove_metric_configuration", :params => | ||
46 | + {:configuration_name => @configuration.name, :metric_name => metric_configuration.metric.name} %></td> | ||
47 | + </tr> | ||
48 | + <% end %> | ||
49 | +</table> |
plugins/mezuro/views/content_viewer/show_project.rhtml
1 | +<script src="/plugins/mezuro/javascripts/project_content.js" type="text/javascript"></script> | ||
2 | + | ||
1 | <% @project = @page.project %> | 3 | <% @project = @page.project %> |
4 | +<% if (@project==nil) %> | ||
5 | + <h3>Warning:</h3> | ||
6 | + <p>This project doesn't exist on the Web Service. Do you want to <a href="/myprofile/<%= @page.profile.name %>/cms/destroy/<%= @page.id%>">delete</a> or <a href="/myprofile/<%= @page.profile.name %>/cms/edit/<%= @page.id%>">save it again</a>?</p> | ||
7 | +<% else %> | ||
8 | + | ||
2 | 9 | ||
3 | -<table id="project_info"> | 10 | +<table> |
4 | <tr> | 11 | <tr> |
5 | <td><%= _('Name') %></td> | 12 | <td><%= _('Name') %></td> |
6 | <td><%= @project.name %></td> | 13 | <td><%= @project.name %></td> |
@@ -25,55 +32,26 @@ | @@ -25,55 +32,26 @@ | ||
25 | <td><%= _('Configuration') %></td> | 32 | <td><%= _('Configuration') %></td> |
26 | <td><%= @project.configuration_name %></td> | 33 | <td><%= @project.configuration_name %></td> |
27 | </tr> | 34 | </tr> |
35 | + <tr> | ||
36 | + <td><%= _('Periodicity') %></td> | ||
37 | + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td> | ||
38 | + </tr> | ||
39 | + <tr> | ||
40 | + <td><%= _('Status')%></td> | ||
41 | + <td> | ||
42 | + <div id="project-state"><%= @project.state %></div> | ||
43 | + <div id="msg-time"></div> | ||
44 | + </td> | ||
45 | + </tr> | ||
28 | </table> | 46 | </table> |
29 | 47 | ||
30 | <br /> | 48 | <br /> |
31 | 49 | ||
32 | -<% if ! @project.error.nil? %> | ||
33 | - <h3><%= _('ERROR') %></h3> | ||
34 | - <p> | ||
35 | - <%= "State when error ocurred: #{@project.state}" %> | ||
36 | - <br/> | ||
37 | - <% error = @project.error %> | ||
38 | - <%= error.message %> | ||
39 | - <ul><% error.stack_trace.each do |trace| %> | ||
40 | - <li><%= "#{trace.declaring_class}.#{trace.method_name}(#{trace.file_name}:#{trace.line_number})" %></li> | ||
41 | - <% end %></ul> | ||
42 | - </p> | ||
43 | -<% elsif @project.state.end_with? 'ING' %> | ||
44 | - <p> | ||
45 | - <%= _("Kalibro Service is #{@project.state.downcase} the source code.") %> | ||
46 | - <br/> | ||
47 | - <%= _('Reload the page manually in a few moments.') %> | ||
48 | - </p> | ||
49 | -<% elsif @project.state == 'READY' %> | ||
50 | - <h3><%= _('LAST RESULT') %></h3> | ||
51 | - <% @project_result = @page.project_result %> | ||
52 | - | ||
53 | - <table id="project_result_info"> | ||
54 | - <tr> | ||
55 | - <td><%= _('Date') %></td> | ||
56 | - <td><%= @project_result.date %></td> | ||
57 | - </tr> | ||
58 | - <tr> | ||
59 | - <td><%= _('Load time') %></td> | ||
60 | - <td><%= @project_result.formatted_load_time %></td> | ||
61 | - </tr> | ||
62 | - <tr> | ||
63 | - <td><%= _('Analysis time') %></td> | ||
64 | - <td><%= @project_result.formatted_analysis_time %></td> | ||
65 | - </tr> | ||
66 | - </table> | ||
67 | - | ||
68 | - <h5><%= _('Source tree') %></h5> | ||
69 | - | ||
70 | - <%= render :partial => 'source_tree', :locals => { :source_tree => @project_result.source_tree } %> | ||
71 | - | ||
72 | - <div id='module-result' data-profile="<%= @page.profile.identifier %>" data-project-id='<%= @page.id %>'> | ||
73 | - <%= render :partial => 'module_result', :locals => { :module_result => @page.module_result(@project.name) } %> | ||
74 | - </div> | 50 | +<div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>" |
51 | + data-project-name="<%= @project.name %>"> | ||
52 | +</div> | ||
53 | +<div id="project-tree"></div> | ||
54 | +<div id="module-result"> | ||
55 | +</div> | ||
56 | +<% end %> | ||
75 | 57 | ||
76 | - <script type="text/javascript"> | ||
77 | - jQuery(results); | ||
78 | - </script> | ||
79 | -<% end %> | ||
80 | \ No newline at end of file | 58 | \ No newline at end of file |