Commit 10f091ec2df1ae6e581715a5581741c76c09f92d
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/199' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/199
Showing
160 changed files
with
4111 additions
and
1926 deletions
Show diff stats
... | ... | @@ -0,0 +1,14 @@ |
1 | +Then /^I directly delete content with name "([^\"]*)" for testing purposes$/ do |content_name| | |
2 | + Article.find_by_name(content_name).destroy | |
3 | +end | |
4 | + | |
5 | +Then /^I should be at the url "([^\"]*)"$/ do |url| | |
6 | + if response.class.to_s == 'Webrat::SeleniumResponse' | |
7 | + URI.parse(response.selenium.get_location).path.should == url | |
8 | + else | |
9 | + URI.parse(current_url).path.should == url | |
10 | + end | |
11 | +end | |
12 | + | |
13 | +Then /^I don't fill anything$/ do | |
14 | +end | ... | ... |
plugins/mezuro/AUTHORS
1 | -KALIBRO PLUGIN AUTHORS | |
2 | -===================== | |
1 | +Mezuro Authors | |
2 | +============== | |
3 | 3 | |
4 | -Copyright 2010-2011 | |
5 | - Almir Alves Pereira (almir.sne at gmail.com) | |
6 | - Andre Casimiro (ah.casimiro at gmail.com) | |
7 | - Carlos Morais (carlos88morais at gmail.com) | |
8 | - Everton Santos (everton2x4 at gmail.com) | |
9 | - Paulo Meirelles (paulo at softwarelivre.org) | |
10 | - Rafael Messias (rmmartins at gmail.com) | |
4 | +Copyright 2010-2012 | |
5 | +------------------- | |
11 | 6 | |
12 | -Collaborators: | |
13 | -- Ana Paula Oliveira dos Santos (ana at ime.usp.br) | |
14 | -- Lucianna Almeida (lucianna.th at gmail.com) | |
15 | -- Joao Machini (joao.machini at gmail.com) | |
16 | -- Rodrigo Souto (rodrigo@colivre.coop.br) | |
17 | -- Thiago Colucci (ticolucci at gmail.com) | |
18 | -- Vinicius Daros (vinicius.k.daros at gmail.com) | |
19 | -- Viviane Almeida Santos (viviane.almeida at gmail.com) | |
7 | + Almir Alves Pereira (almir.sne at gmail.com) | |
8 | + Alessandro Palmeira (alessandro.palmeira at gmail.com) | |
9 | + Andre Casimiro (ah.casimiro at gmail.com) | |
10 | + Antonio Terceiro (terceiro at colivre.coop.br) | |
11 | + Caio Salgado (caio.csalgado at gmail.com) | |
12 | + Carlos Morais (carlos88morais at gmail.com) | |
13 | + Diego Araújo (diegoamc90 at gmail.com) | |
14 | + Everton Santos (everton2x4 at gmail.com) | |
15 | + Jefferson Fernandes (jeffs.fernandes at gmail.com) | |
16 | + Joao Machini (joao.machini at gmail.com) | |
17 | + João da Silva (jaodsilv@linux.ime.usp.br) | |
18 | + Paulo Meirelles (paulo at softwarelivre.org) | |
19 | + Rafael Manso (rr.manzo at gmail.com) | |
20 | + Rafael Messias (rmmartins at gmail.com) | |
21 | + Renan Teruo (renanteruoc at gmail.com) | |
22 | + Rodrigo Souto (rodrigo at colivre.coop.br) | |
23 | + | |
24 | +Collaborators (from USP Lab XP course 2010 on another code) | |
25 | +----------------------------------------------------------- | |
26 | + | |
27 | + Ana Paula Oliveira dos Santos (anapaulao.santos at gmail.com) | |
28 | + Lucianna Almeida (lucianna.th at gmail.com) | |
29 | + Thiago Colucci (ticolucci at gmail.com) | |
30 | + Vinicius Daros (vinicius.k.daros at gmail.com) | |
31 | + Viviane Almeida Santos (viviane.almeida at gmail.com) | |
32 | + | |
33 | +Advisors | |
34 | +-------- | |
35 | + | |
36 | + Fabio Kon (fabio.kon at ime.usp.br) | |
37 | + Alfredo Goldman (gold at ime.usp.br) | |
20 | 38 | ... | ... |
plugins/mezuro/README
1 | -README - Mezuro (Kalibro Plugin) | |
1 | +README - Mezuro (Mezuro Plugin) | |
2 | 2 | ================================ |
3 | 3 | |
4 | -Mezuro is source code tracking network based on Noosfero Platform with Kalibro Plugin to access Kalibro Web Service. | |
4 | +Mezuro is a source code tracking platform based on Noosfero social networking | |
5 | +platform with Mezuro Plugin actived to access Kalibro Web Service. | |
6 | + | |
5 | 7 | |
6 | 8 | INSTALL |
7 | 9 | ======= |
8 | 10 | |
9 | -See the Noosfero install file and include Ruby gem Savon: | |
11 | +Dependences | |
12 | +----------- | |
13 | + | |
14 | +See the Noosfero install file. After install Noosfero, install Mezuro dependences: | |
10 | 15 | |
11 | -gem install savon | |
16 | +$ gem install nokogiri -v 1.5.0 | |
17 | +$ gem install savon -v 0.9.7 | |
18 | +$ gem install googlecharts | |
12 | 19 | |
13 | -Also, you need to enable Mezuro Plugin in the Noosfero: | |
20 | +Enable Plugin | |
21 | +------------- | |
22 | + | |
23 | +Also, you need to enable Mezuro Plugin at you Noosfero: | |
14 | 24 | |
15 | 25 | cd <your_noosfero_dir> |
16 | 26 | ./script/noosfero-plugins enable mezuro |
17 | 27 | |
18 | -To run Mezuro (kalibro Plugin) and its acceptance tests, you need to install the Kalibro Service. | |
28 | + | |
29 | +Install Service | |
30 | +--------------- | |
31 | + | |
32 | +To run Mezuro (Noosfero with Mezuro Plugin), you need to install the Kalibro | |
33 | +Service. | |
34 | + | |
19 | 35 | For that, access https://gitorious.org/kalibro/kalibro/blobs/master/INSTALL |
20 | 36 | |
21 | 37 | |
22 | -SOURCE CODE | |
38 | +Configure Service Address | |
39 | +------------------------- | |
40 | + | |
41 | +Finally, copy service.yaml.example to service.yaml and define your Kalibro | |
42 | +Service address: | |
43 | + | |
44 | +$ cd <your_noosfero_dir>/plugin/mezuro | |
45 | +$ cp service.yaml.example service.yaml | |
46 | + | |
47 | +If you install Kalibro Service at localhost, just keep the default | |
48 | +adress: | |
49 | + | |
50 | +http://localhost:8080/KalibroService/ | |
51 | + | |
52 | +Applying Mezuro Theme | |
53 | +--------------------- | |
54 | + | |
55 | +$ cd public/designs/themes && rm -f default | |
56 | +$ git clone git://gitorious.org/mezuro/mezuro-theme.git | |
57 | +$ ln -s mezuro-theme/ default && cd ../../../ | |
58 | + | |
59 | +Active Plugin | |
60 | +------------- | |
61 | + | |
62 | +As a Noosfero administrator user, go to administrator panel: | |
63 | + | |
64 | +- Click on "Enable/disable plugins" option | |
65 | +- Click on "Mezuro Plugin" check-box | |
66 | + | |
67 | + | |
68 | +DEVELOPMENT | |
23 | 69 | =========== |
24 | 70 | |
25 | -To get the Mezuro (Noosfero with Kalibro Plugin) development repository: | |
71 | +Get the Mezuro (Noosfero with Mezuro Plugin) development repository: | |
26 | 72 | |
27 | -git clone https://gitorious.org/+mezuro/noosfero/mezuro-noosfero-plugin | |
28 | -cd mezuro-noosfero-plugin | |
29 | -git checkout mezuro | |
73 | +$ git clone https://gitorious.org/+mezuro/noosfero/mezuro | |
74 | +$ cd mezuro | |
75 | +$ git checkout mezuro | |
30 | 76 | |
31 | -AUTHORS | |
32 | -======= | |
77 | +Running Mezuro tests | |
78 | +-------------------- | |
33 | 79 | |
34 | -Please see the file AUTHORS. | |
80 | +$ rake test:noosfero_plugins:mezuro | |
35 | 81 | |
36 | -BUGS | |
37 | -==== | |
38 | 82 | |
39 | -If you found any bug, please report at mezuro@listas.softwarelivre.org | |
40 | -(http://listas.softwarelivre.org/cgi-bin/mailman/listinfo/mezuro) | |
83 | +Get Involved | |
84 | +============ | |
85 | + | |
86 | +If you found any bug and/or want to collaborate, please send an e-mail to | |
87 | +paulo@softwarelivre.org | |
88 | + | |
41 | 89 | |
42 | 90 | LICENSE |
43 | 91 | ======= |
44 | -Copyright (c) The Authors developers. | |
92 | + | |
93 | +Copyright (c) The Author developers. | |
45 | 94 | |
46 | 95 | See Noosfero license. |
47 | 96 | |
48 | 97 | |
98 | +AUTHORS | |
99 | +======= | |
100 | + | |
101 | +Please, see the Mezuro AUTHORS file. | |
102 | + | |
103 | + | |
49 | 104 | ACKNOWLEDGMENTS |
50 | 105 | =============== |
51 | 106 | |
52 | 107 | The authors have been supported by organizations: |
53 | 108 | |
109 | +University of São Paulo (USP) | |
110 | +FLOSS Competence Center | |
111 | +http://ccsl.ime.usp.br | |
112 | + | |
54 | 113 | Brazilian National Research Council (CNPQ) |
55 | 114 | http://www.cnpq.br/ |
56 | - | |
57 | -USP FLOSS Competence Center | |
58 | -http://ccsl.ime.usp.br/ | ... | ... |
... | ... | @@ -0,0 +1,73 @@ |
1 | +README/TODO do branch cucumber_tests | |
2 | + | |
3 | +Tarefas: | |
4 | +- Escrever uma história (procurar uma já escrita) para isso | |
5 | +- Descobrir o porquê dos erros nos testes do mezuro (repository_url) | |
6 | +- Dar rebase com o mezuro-dev (os tais testes passam no mezuro-dev) | |
7 | +- Fazer mais testes | |
8 | +- Ver como/quando o selenium pode ser integrado ao projeto (conversar com noosfero/ talvez até tentar implementar alguma coisa??) | |
9 | + | |
10 | + | |
11 | +Testes de aceitação a serem feitos: (* já feito) | |
12 | + | |
13 | +Projetos: | |
14 | + Criar | |
15 | + * correto | |
16 | + * errado | |
17 | + duplicado | |
18 | + Editar | |
19 | + correto | |
20 | + errado | |
21 | + Deletar(não precisa fazer - problema do noosfero) | |
22 | + | |
23 | +Configurações: | |
24 | + criar | |
25 | + *correta | |
26 | + *errado (sem titulo) | |
27 | + *duplicada | |
28 | + editar - verificar se mantem as metricas | |
29 | + correto | |
30 | + não é possível mudar o titulo | |
31 | + deletar (não precisa fazer - problema do noosfero) | |
32 | + metricas: | |
33 | + criar | |
34 | + nativa: | |
35 | + *correta | |
36 | + *errada | |
37 | + duplicada (é pra funcionar?) | |
38 | + composta: | |
39 | + *correta | |
40 | + errada | |
41 | + duplicada | |
42 | + editar | |
43 | + para metrica correta | |
44 | + para metrica errada | |
45 | + *deletar | |
46 | + ranges: | |
47 | + criar | |
48 | + *range correto | |
49 | + range errado | |
50 | + todos os casos | |
51 | + editar | |
52 | + para range correto | |
53 | + para range errado | |
54 | + deletar | |
55 | + | |
56 | +Testes falhando: | |
57 | + | |
58 | +Arquivo adding_metric_configuration.feature: | |
59 | + Scenario: adding a native metric configuration without code | |
60 | + Precisa do selenium para ver em qual página está. | |
61 | + Scenario: adding a compound metric configuration | |
62 | + Scenario: adding a compound metric configuration with invalid script | |
63 | + As métricas compostas não estão salvando direito. | |
64 | + | |
65 | + | |
66 | +Arquivo creating_project.feature: | |
67 | + Scenario: I create a Kalibro project with valid attributes | |
68 | + ás vezes falha por erro de já existir na Kalibro. Esse erro teóricamente já havia sido resolvido. | |
69 | + | |
70 | + | |
71 | +Arquivo adding_ranges.feature: | |
72 | + Scenario: adding a range to a metric configuration | |
73 | + Precisa do selenium para esperar a página carregar. | ... | ... |
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,126 @@ |
1 | +class MezuroPluginMyprofileController < ProfileController | |
2 | + | |
3 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
4 | + | |
5 | + | |
6 | + def choose_base_tool | |
7 | + @configuration_content = profile.articles.find(params[:id]) | |
8 | + @base_tools = Kalibro::BaseTool.all_names | |
9 | + end | |
10 | + | |
11 | + def choose_metric | |
12 | + @configuration_content = profile.articles.find(params[:id]) | |
13 | + @base_tool = params[:base_tool] | |
14 | + @supported_metrics = Kalibro::BaseTool.find_by_name(@base_tool).supported_metrics | |
15 | + end | |
16 | + | |
17 | + def new_metric_configuration | |
18 | + @configuration_content = profile.articles.find(params[:id]) | |
19 | + @metric = Kalibro::BaseTool.find_by_name(params[:base_tool]).metric params[:metric_name] | |
20 | + end | |
21 | + | |
22 | + def new_compound_metric_configuration | |
23 | + @configuration_content = profile.articles.find(params[:id]) | |
24 | + @metric_configurations = @configuration_content.metric_configurations | |
25 | + end | |
26 | + | |
27 | + def edit_metric_configuration | |
28 | + @configuration_content = profile.articles.find(params[:id]) | |
29 | + @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name]) | |
30 | + @metric = @metric_configuration.metric | |
31 | + end | |
32 | + | |
33 | + def edit_compound_metric_configuration | |
34 | + @configuration_content = profile.articles.find(params[:id]) | |
35 | + @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name]) | |
36 | + @metric_configurations = @configuration_content.metric_configurations | |
37 | + @metric = @metric_configuration.metric | |
38 | + end | |
39 | + | |
40 | + def create_metric_configuration | |
41 | + id = params[:id] | |
42 | + metric_name = params[:metric_configuration][:metric][:name] | |
43 | + (Kalibro::MetricConfiguration.new(params[:metric_configuration])).save | |
44 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | |
45 | + end | |
46 | + | |
47 | + def create_compound_metric_configuration | |
48 | + id = params[:id] | |
49 | + metric_name = params[:metric_configuration][:metric][:name] | |
50 | + Kalibro::MetricConfiguration.new(params[:metric_configuration]).save | |
51 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | |
52 | + end | |
53 | + | |
54 | + def update_metric_configuration | |
55 | + @configuration_content = profile.articles.find(params[:id]) | |
56 | + metric_name = params[:metric_configuration][:metric][:name] | |
57 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) | |
58 | + metric_configuration.update_attributes params[:metric_configuration] | |
59 | + redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | |
60 | + end | |
61 | + | |
62 | + def update_compound_metric_configuration | |
63 | + @configuration_content = profile.articles.find(params[:id]) | |
64 | + metric_name = params[:metric_configuration][:metric][:name] | |
65 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) | |
66 | + metric_configuration.update_attributes params[:metric_configuration] | |
67 | + redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | |
68 | + end | |
69 | + | |
70 | + def remove_metric_configuration | |
71 | + configuration_content = profile.articles.find(params[:id]) | |
72 | + metric_name = params[:metric_name] | |
73 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | |
74 | + metric_configuration.destroy | |
75 | + redirect_to "/#{profile.identifier}/#{configuration_content.slug}" | |
76 | + end | |
77 | + | |
78 | + def new_range | |
79 | + @configuration_content = profile.articles.find(params[:id]) | |
80 | + @metric_name = params[:metric_name] | |
81 | + @range = Kalibro::Range.new | |
82 | + end | |
83 | + | |
84 | + def edit_range | |
85 | + @configuration_content = profile.articles.find(params[:id]) | |
86 | + @metric_name = params[:metric_name] | |
87 | + @beginning_id = params[:beginning_id] | |
88 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) | |
89 | + @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" } | |
90 | + end | |
91 | + | |
92 | + def create_range | |
93 | + @configuration_content = profile.articles.find(params[:id]) | |
94 | + @range = Kalibro::Range.new params[:range] | |
95 | + metric_name = params[:metric_name] | |
96 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) | |
97 | + metric_configuration.add_range(@range) | |
98 | + metric_configuration.save | |
99 | + end | |
100 | + | |
101 | + def update_range | |
102 | + configuration_content = profile.articles.find(params[:id]) | |
103 | + metric_name = params[:metric_name] | |
104 | + beginning_id = params[:beginning_id] | |
105 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | |
106 | + index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } | |
107 | + metric_configuration.ranges[index] = Kalibro::Range.new params[:range] | |
108 | + metric_configuration.save | |
109 | + end | |
110 | + | |
111 | + def remove_range | |
112 | + configuration_content = profile.articles.find(params[:id]) | |
113 | + metric_name = params[:metric_name] | |
114 | + beginning_id = params[:beginning_id] | |
115 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | |
116 | + metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } | |
117 | + metric_configuration.save | |
118 | + formatted_metric_name = metric_name.gsub(/\s/, '+') | |
119 | + if metric_configuration.metric.class == Kalibro::CompoundMetric | |
120 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | |
121 | + else | |
122 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | |
123 | + end | |
124 | + end | |
125 | + | |
126 | +end | ... | ... |
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
1 | 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 | |
7 | 10 | end |
8 | 11 | |
12 | + def project_error | |
13 | + @content = profile.articles.find(params[:id]) | |
14 | + @project = @content.project | |
15 | + render :partial => 'content_viewer/project_error' | |
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.project_result_with_date(date) | |
22 | + render :partial => 'content_viewer/project_result' | |
23 | + end | |
24 | + | |
25 | + def module_result | |
26 | + @content = profile.articles.find(params[:id]) | |
27 | + @module_result = @content.module_result(params) | |
28 | + render :partial => 'content_viewer/module_result' | |
29 | + end | |
30 | + | |
31 | + def project_tree | |
32 | + @content = profile.articles.find(params[:id]) | |
33 | + date = params[:date] | |
34 | + project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) | |
35 | + @project_name = @content.project.name | |
36 | + @source_tree = project_result.node_of(params[:module_name]) | |
37 | + render :partial =>'content_viewer/source_tree' | |
38 | + end | |
39 | + | |
40 | + def module_metrics_history | |
41 | + metric_name = params[:metric_name] | |
42 | + @content = profile.articles.find(params[:id]) | |
43 | + module_history = @content.result_history(params[:module_name]) | |
44 | + @score_history = filtering_metric_history(metric_name, module_history) | |
45 | + render :partial => 'content_viewer/score_history' | |
46 | + end | |
47 | + | |
48 | + def module_grade_history | |
49 | + @content = profile.articles.find(params[:id]) | |
50 | + modules_results = @content.result_history(params[:module_name]) | |
51 | + @score_history = modules_results.collect { |module_result| module_result.grade } | |
52 | + render :partial => 'content_viewer/score_history' | |
53 | + end | |
54 | + | |
55 | + private | |
56 | + | |
57 | + def filtering_metric_history(metric_name, module_history) | |
58 | + metrics_history = module_history.map do |module_result| | |
59 | + module_result.metric_results | |
60 | + end | |
61 | + metric_history = metrics_history.map do |array_of_metric_result| | |
62 | + (array_of_metric_result.select do |metric_result| | |
63 | + metric_result.metric.name.delete("() ") == metric_name | |
64 | + end).first | |
65 | + end | |
66 | + metric_history.map do |metric_result| | |
67 | + metric_result.value | |
68 | + end | |
69 | + end | |
9 | 70 | end | ... | ... |
plugins/mezuro/features/mezuro.feature
... | ... | @@ -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" |
... | ... | @@ -0,0 +1,29 @@ |
1 | +class Kalibro::BaseTool < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :name, :description, :supported_metric | |
4 | + | |
5 | + def self.all_names | |
6 | + request("BaseTool", :get_base_tool_names)[:base_tool_name].to_a | |
7 | + end | |
8 | + | |
9 | + def self.find_by_name(base_tool_name) | |
10 | + new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] | |
11 | + end | |
12 | + | |
13 | + def supported_metric=(value) | |
14 | + @supported_metric = Kalibro::NativeMetric.to_objects_array value | |
15 | + end | |
16 | + | |
17 | + def supported_metrics | |
18 | + @supported_metric | |
19 | + end | |
20 | + | |
21 | + def supported_metrics=(supported_metrics) | |
22 | + @supported_metric = supported_metrics | |
23 | + end | |
24 | + | |
25 | + def metric(name) | |
26 | + supported_metrics.find {|metric| metric.name == name} | |
27 | + end | |
28 | + | |
29 | +end | ... | ... |
plugins/mezuro/lib/kalibro/client/base_tool_client.rb
... | ... | @@ -1,16 +0,0 @@ |
1 | -class Kalibro::Client::BaseToolClient | |
2 | - | |
3 | - def initialize | |
4 | - @port = Kalibro::Client::Port.new('BaseTool') | |
5 | - end | |
6 | - | |
7 | - def base_tool_names | |
8 | - @port.request(:get_base_tool_names)[:base_tool_name].to_a | |
9 | - end | |
10 | - | |
11 | - def base_tool(name) | |
12 | - hash = @port.request(:get_base_tool, {:base_tool_name => name})[:base_tool] | |
13 | - Kalibro::Entities::BaseTool.from_hash(hash) | |
14 | - end | |
15 | - | |
16 | -end | |
17 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/client/configuration_client.rb
... | ... | @@ -1,31 +0,0 @@ |
1 | -class Kalibro::Client::ConfigurationClient | |
2 | - | |
3 | - def initialize | |
4 | - @port = Kalibro::Client::Port.new('Configuration') | |
5 | - end | |
6 | - | |
7 | - def save(configuration) | |
8 | - @port.request(:save_configuration, {:configuration => configuration.to_hash}) | |
9 | - end | |
10 | - | |
11 | - def self.save(configuration) | |
12 | - new.save(configuration) | |
13 | - end | |
14 | - | |
15 | - def configuration_names | |
16 | - @port.request(:get_configuration_names)[:configuration_name].to_a | |
17 | - end | |
18 | - | |
19 | - def configuration(name) | |
20 | - hash = @port.request(:get_configuration, {:configuration_name => name})[:configuration] | |
21 | - Kalibro::Entities::Configuration.from_hash(hash) | |
22 | - end | |
23 | - | |
24 | - def remove(configuration_name) | |
25 | - @port.request(:remove_configuration, {:configuration_name => configuration_name}) | |
26 | - end | |
27 | - | |
28 | - def self.remove(configuration_name) | |
29 | - new.remove(configuration_name) | |
30 | - end | |
31 | -end |
plugins/mezuro/lib/kalibro/client/kalibro_client.rb
... | ... | @@ -1,19 +0,0 @@ |
1 | -class Kalibro::Client::KalibroClient | |
2 | - | |
3 | - def initialize | |
4 | - @port = Kalibro::Client::Port.new('Kalibro') | |
5 | - end | |
6 | - | |
7 | - def supported_repository_types | |
8 | - @port.request(:get_supported_repository_types)[:repository_type].to_a | |
9 | - end | |
10 | - | |
11 | - def process_project(project_name) | |
12 | - @port.request(:process_project, {:project_name => project_name}) | |
13 | - end | |
14 | - | |
15 | - def self.process_project(project_name) | |
16 | - new.process_project(project_name) | |
17 | - end | |
18 | - | |
19 | -end |
plugins/mezuro/lib/kalibro/client/module_result_client.rb
... | ... | @@ -1,27 +0,0 @@ |
1 | -class Kalibro::Client::ModuleResultClient | |
2 | - | |
3 | - def initialize | |
4 | - @port = Kalibro::Client::Port.new('ModuleResult') | |
5 | - end | |
6 | - | |
7 | - def module_result(project_name, module_name, date) | |
8 | - hash = @port.request(:get_module_result, | |
9 | - {:project_name => project_name, :module_name => module_name, | |
10 | - :date => date_with_milliseconds(date)})[:module_result] | |
11 | - Kalibro::Entities::ModuleResult.from_hash(hash) | |
12 | - end | |
13 | - | |
14 | - def result_history(project_name, module_name) | |
15 | - value = @port.request(:get_result_history, | |
16 | - {:project_name => project_name, :module_name => module_name})[:module_result] | |
17 | - Kalibro::Entities::Entity.new.to_entity_array(value, Kalibro::Entities::ModuleResult) | |
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 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/client/port.rb
... | ... | @@ -1,26 +0,0 @@ |
1 | -require 'savon' | |
2 | - | |
3 | -Savon.configure do |config| | |
4 | - config.log = HTTPI.log = (RAILS_ENV == 'development') | |
5 | -end | |
6 | - | |
7 | -class Kalibro::Client::Port | |
8 | - | |
9 | - def initialize(endpoint) | |
10 | - @client = Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | |
11 | - end | |
12 | - | |
13 | - def service_address | |
14 | - if @service_address.nil? | |
15 | - service_file = "#{RAILS_ROOT}/plugins/mezuro/SERVICE" | |
16 | - File.open(service_file).each_line{ | line | @service_address = line } | |
17 | - end | |
18 | - @service_address | |
19 | - end | |
20 | - | |
21 | - def request(action, request_body = nil) | |
22 | - response = @client.request(:kalibro, action) { soap.body = request_body } | |
23 | - response.to_hash["#{action}_response".to_sym] | |
24 | - end | |
25 | - | |
26 | -end |
plugins/mezuro/lib/kalibro/client/project_client.rb
... | ... | @@ -1,31 +0,0 @@ |
1 | -class Kalibro::Client::ProjectClient | |
2 | - | |
3 | - def initialize | |
4 | - @port = Kalibro::Client::Port.new('Project') | |
5 | - end | |
6 | - | |
7 | - def save(project) | |
8 | - @port.request(:save_project, {:project => project.to_hash}) | |
9 | - end | |
10 | - | |
11 | - def self.save(project) | |
12 | - new.save(project) | |
13 | - end | |
14 | - | |
15 | - def project_names | |
16 | - @port.request(:get_project_names)[:project_name].to_a | |
17 | - end | |
18 | - | |
19 | - def project(name) | |
20 | - hash = @port.request(:get_project, {:project_name => name})[:project] | |
21 | - Kalibro::Entities::Project.from_hash(hash) | |
22 | - end | |
23 | - | |
24 | - def remove(project_name) | |
25 | - @port.request(:remove_project, {:project_name => project_name}) | |
26 | - end | |
27 | - | |
28 | - def self.remove(project_name) | |
29 | - new.remove(project_name) | |
30 | - end | |
31 | -end |
plugins/mezuro/lib/kalibro/client/project_result_client.rb
... | ... | @@ -1,41 +0,0 @@ |
1 | -class Kalibro::Client::ProjectResultClient | |
2 | - | |
3 | - def initialize | |
4 | - @port = Kalibro::Client::Port.new('ProjectResult') | |
5 | - end | |
6 | - | |
7 | - def has_results_for(project_name) | |
8 | - @port.request(:has_results_for, {:project_name => project_name})[:has_results] | |
9 | - end | |
10 | - | |
11 | - def has_results_before(project_name, date) | |
12 | - @port.request(:has_results_before, {:project_name => project_name, :date => date})[:has_results] | |
13 | - end | |
14 | - | |
15 | - def has_results_after(project_name, date) | |
16 | - @port.request(:has_results_after, {:project_name => project_name, :date => date})[:has_results] | |
17 | - end | |
18 | - | |
19 | - def first_result(project_name) | |
20 | - hash = @port.request(:get_first_result_of, {:project_name => project_name})[:project_result] | |
21 | - Kalibro::Entities::ProjectResult.from_hash(hash) | |
22 | - end | |
23 | - | |
24 | - def last_result(project_name) | |
25 | - hash = @port.request(:get_last_result_of, {:project_name => project_name})[:project_result] | |
26 | - Kalibro::Entities::ProjectResult.from_hash(hash) | |
27 | - end | |
28 | - | |
29 | - def first_result_after(project_name, date) | |
30 | - request_body = {:project_name => project_name, :date => date} | |
31 | - hash = @port.request(:get_first_result_after, request_body)[:project_result] | |
32 | - Kalibro::Entities::ProjectResult.from_hash(hash) | |
33 | - end | |
34 | - | |
35 | - def last_result_before(project_name, date) | |
36 | - request_body = {:project_name => project_name, :date => date} | |
37 | - hash = @port.request(:get_last_result_before, request_body)[:project_result] | |
38 | - Kalibro::Entities::ProjectResult.from_hash(hash) | |
39 | - end | |
40 | - | |
41 | -end | |
42 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/compound_metric_with_error.rb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +class Kalibro::CompoundMetricWithError < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :metric, :error | |
4 | + | |
5 | + def metric=(value) | |
6 | + @metric = Kalibro::CompoundMetric.to_object value | |
7 | + end | |
8 | + | |
9 | + def error=(value) | |
10 | + @error = Kalibro::Error.to_object value | |
11 | + end | |
12 | + | |
13 | +end | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
1 | +class Kalibro::Configuration < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :name, :description, :metric_configuration | |
4 | + | |
5 | + def metric_configuration=(value) | |
6 | + @metric_configuration = Kalibro::MetricConfiguration.to_objects_array value | |
7 | + end | |
8 | + | |
9 | + def metric_configurations | |
10 | + if @metric_configuration != nil | |
11 | + @metric_configuration | |
12 | + else | |
13 | + [] | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + def metric_configurations=(metric_configurations) | |
18 | + @metric_configuration = metric_configurations | |
19 | + end | |
20 | + | |
21 | + def self.find_by_name(configuration_name) | |
22 | + begin | |
23 | + new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration] | |
24 | + rescue Exception => error | |
25 | + nil | |
26 | + end | |
27 | + end | |
28 | + | |
29 | + def self.all_names | |
30 | + begin | |
31 | + request("Configuration", :get_configuration_names)[:configuration_name] | |
32 | + rescue Exception | |
33 | + [] | |
34 | + end | |
35 | + end | |
36 | + | |
37 | + def update_attributes(attributes={}) | |
38 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | |
39 | + save | |
40 | + end | |
41 | + | |
42 | + def metric_configurations_hash | |
43 | + self.to_hash[:metric_configuration] | |
44 | + end | |
45 | +end | ... | ... |
plugins/mezuro/lib/kalibro/entities/base_tool.rb
... | ... | @@ -1,17 +0,0 @@ |
1 | -class Kalibro::Entities::BaseTool < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :name, :description, :supported_metric | |
4 | - | |
5 | - def supported_metric=(value) | |
6 | - @supported_metric = to_entity_array(value, Kalibro::Entities::NativeMetric) | |
7 | - end | |
8 | - | |
9 | - def supported_metrics | |
10 | - @supported_metric | |
11 | - end | |
12 | - | |
13 | - def supported_metrics=(supported_metrics) | |
14 | - @supported_metric = supported_metrics | |
15 | - end | |
16 | - | |
17 | -end | |
18 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/compound_metric.rb
plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb
... | ... | @@ -1,13 +0,0 @@ |
1 | -class Kalibro::Entities::CompoundMetricWithError < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :metric, :error | |
4 | - | |
5 | - def metric=(value) | |
6 | - @metric = to_entity(value, Kalibro::Entities::CompoundMetric) | |
7 | - end | |
8 | - | |
9 | - def error=(value) | |
10 | - @error = to_entity(value, Kalibro::Entities::Error) | |
11 | - end | |
12 | - | |
13 | -end | |
14 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/configuration.rb
... | ... | @@ -1,17 +0,0 @@ |
1 | -class Kalibro::Entities::Configuration < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :name, :description, :metric_configuration | |
4 | - | |
5 | - def metric_configuration=(value) | |
6 | - @metric_configuration = to_entity_array(value, Kalibro::Entities::MetricConfiguration) | |
7 | - end | |
8 | - | |
9 | - def metric_configurations | |
10 | - @metric_configuration | |
11 | - end | |
12 | - | |
13 | - def metric_configurations=(metric_configurations) | |
14 | - @metric_configuration = metric_configurations | |
15 | - end | |
16 | - | |
17 | -end |
plugins/mezuro/lib/kalibro/entities/entity.rb
... | ... | @@ -1,53 +0,0 @@ |
1 | -class Kalibro::Entities::Entity | |
2 | - | |
3 | - def self.from_hash(hash) | |
4 | - entity = self.new | |
5 | - hash.each { |field, value| entity.set(field, value) } | |
6 | - entity | |
7 | - end | |
8 | - | |
9 | - def set(field, value) | |
10 | - send("#{field}=", value) | |
11 | - end | |
12 | - | |
13 | - def to_entity_array(value, entity_class = nil) | |
14 | - array = value.kind_of?(Array) ? value : [value] | |
15 | - array.each.collect { |element| to_entity(element, entity_class) } | |
16 | - end | |
17 | - | |
18 | - def to_entity(value, entity_class) | |
19 | - value.kind_of?(Hash) ? entity_class.from_hash(value) : value | |
20 | - end | |
21 | - | |
22 | - def to_hash | |
23 | - hash = Hash.new | |
24 | - fields.each do |field| | |
25 | - field_value = self.get(field) | |
26 | - hash[field] = convert_to_hash(field_value) if ! field_value.nil? | |
27 | - end | |
28 | - hash | |
29 | - end | |
30 | - | |
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) | |
38 | - begin | |
39 | - fields.each.inject(true) { |equal, field| equal && (self.get(field) == other.get(field)) } | |
40 | - rescue NoMethodError | |
41 | - false | |
42 | - end | |
43 | - end | |
44 | - | |
45 | - def fields | |
46 | - instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } | |
47 | - end | |
48 | - | |
49 | - def get(field) | |
50 | - send("#{field}") | |
51 | - end | |
52 | - | |
53 | -end | |
54 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/error.rb
... | ... | @@ -1,17 +0,0 @@ |
1 | -class Kalibro::Entities::Error < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :message, :stack_trace_element | |
4 | - | |
5 | - def stack_trace_element=(value) | |
6 | - @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement) | |
7 | - end | |
8 | - | |
9 | - def stack_trace | |
10 | - @stack_trace_element | |
11 | - end | |
12 | - | |
13 | - def stack_trace=(stack_trace) | |
14 | - @stack_trace_element = stack_trace | |
15 | - end | |
16 | - | |
17 | -end | |
18 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/metric.rb
plugins/mezuro/lib/kalibro/entities/metric_configuration.rb
... | ... | @@ -1,26 +0,0 @@ |
1 | -class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :metric, :code, :weight, :aggregation_form, :range | |
4 | - | |
5 | - def metric=(value) | |
6 | - if value.kind_of?(Hash) | |
7 | - @metric = to_entity(value, Kalibro::Entities::CompoundMetric) if value.has_key?(:script) | |
8 | - @metric = to_entity(value, Kalibro::Entities::NativeMetric) if value.has_key?(:origin) | |
9 | - else | |
10 | - @metric = value | |
11 | - end | |
12 | - end | |
13 | - | |
14 | - def range=(value) | |
15 | - @range = to_entity_array(value, Kalibro::Entities::Range) | |
16 | - end | |
17 | - | |
18 | - def ranges | |
19 | - @range | |
20 | - end | |
21 | - | |
22 | - def ranges=(ranges) | |
23 | - @range = ranges | |
24 | - end | |
25 | - | |
26 | -end | |
27 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/metric_result.rb
... | ... | @@ -1,33 +0,0 @@ |
1 | -class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :metric, :value, :range, :descendent_result, :weight | |
4 | - | |
5 | - def metric=(value) | |
6 | - if value.kind_of?(Hash) | |
7 | - if value.has_key?(:script) | |
8 | - @metric = to_entity(value, Kalibro::Entities::CompoundMetric) | |
9 | - else | |
10 | - @metric = to_entity(value, Kalibro::Entities::NativeMetric) | |
11 | - end | |
12 | - else | |
13 | - @metric = value | |
14 | - end | |
15 | - end | |
16 | - | |
17 | - def range=(value) | |
18 | - @range = to_entity(value, Kalibro::Entities::Range) | |
19 | - end | |
20 | - | |
21 | - def descendent_result=(value) | |
22 | - @descendent_result = to_entity_array(value) | |
23 | - end | |
24 | - | |
25 | - def descendent_results | |
26 | - @descendent_result | |
27 | - end | |
28 | - | |
29 | - def descendent_results=(descendent_results) | |
30 | - @descendent_result = descendent_results | |
31 | - end | |
32 | - | |
33 | -end |
plugins/mezuro/lib/kalibro/entities/module.rb
plugins/mezuro/lib/kalibro/entities/module_node.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -class Kalibro::Entities::ModuleNode < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :module, :child | |
4 | - | |
5 | - def module=(value) | |
6 | - @module = to_entity(value, Kalibro::Entities::Module) | |
7 | - end | |
8 | - | |
9 | - def module_name | |
10 | - @module.name | |
11 | - end | |
12 | - | |
13 | - def granularity | |
14 | - @module.granularity | |
15 | - end | |
16 | - | |
17 | - def child=(value) | |
18 | - @child = to_entity_array(value, Kalibro::Entities::ModuleNode) | |
19 | - end | |
20 | - | |
21 | - def children | |
22 | - @child | |
23 | - end | |
24 | - | |
25 | - def children=(children) | |
26 | - @child = children | |
27 | - end | |
28 | - | |
29 | -end |
plugins/mezuro/lib/kalibro/entities/module_result.rb
... | ... | @@ -1,33 +0,0 @@ |
1 | -class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error | |
4 | - | |
5 | - def module=(value) | |
6 | - @module = to_entity(value, Kalibro::Entities::Module) | |
7 | - end | |
8 | - | |
9 | - def metric_result=(value) | |
10 | - @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult) | |
11 | - end | |
12 | - | |
13 | - def metric_results | |
14 | - @metric_result | |
15 | - end | |
16 | - | |
17 | - def metric_results=(metric_results) | |
18 | - @metric_result = metric_results | |
19 | - end | |
20 | - | |
21 | - def compound_metric_with_error=(value) | |
22 | - @compound_metric_with_error = to_entity_array(value, Kalibro::Entities::CompoundMetricWithError) | |
23 | - end | |
24 | - | |
25 | - def compound_metrics_with_error | |
26 | - @compound_metric_with_error | |
27 | - end | |
28 | - | |
29 | - def compound_metrics_with_error=(compound_metrics_with_error) | |
30 | - @compound_metric_with_error = compound_metrics_with_error | |
31 | - end | |
32 | - | |
33 | -end | |
34 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/native_metric.rb
plugins/mezuro/lib/kalibro/entities/project.rb
... | ... | @@ -1,13 +0,0 @@ |
1 | -class Kalibro::Entities::Project < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :error | |
4 | - | |
5 | - def repository=(value) | |
6 | - @repository = to_entity(value, Kalibro::Entities::Repository) | |
7 | - end | |
8 | - | |
9 | - def error=(value) | |
10 | - @error = to_entity(value, Kalibro::Entities::Error) | |
11 | - end | |
12 | - | |
13 | -end | |
14 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/project_result.rb
... | ... | @@ -1,34 +0,0 @@ |
1 | -class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity | |
2 | - | |
3 | - attr_accessor :project, :date, :load_time, :analysis_time, :source_tree | |
4 | - | |
5 | - def project=(value) | |
6 | - @project = to_entity(value, Kalibro::Entities::Project) | |
7 | - end | |
8 | - | |
9 | - def source_tree=(value) | |
10 | - @source_tree = to_entity(value, Kalibro::Entities::ModuleNode) | |
11 | - end | |
12 | - | |
13 | - def formatted_load_time | |
14 | - format_milliseconds(@load_time) | |
15 | - end | |
16 | - | |
17 | - def formatted_analysis_time | |
18 | - format_milliseconds(@analysis_time) | |
19 | - end | |
20 | - | |
21 | - def format_milliseconds(value) | |
22 | - seconds = value.to_i/1000 | |
23 | - hours = seconds/3600 | |
24 | - seconds -= hours * 3600 | |
25 | - minutes = seconds/60 | |
26 | - seconds -= minutes * 60 | |
27 | - "#{format(hours)}:#{format(minutes)}:#{format(seconds)}" | |
28 | - end | |
29 | - | |
30 | - def format(amount) | |
31 | - ('%2d' % amount).sub(/\s/, '0') | |
32 | - end | |
33 | - | |
34 | -end | |
35 | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/range.rb
plugins/mezuro/lib/kalibro/entities/repository.rb
plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb
... | ... | @@ -0,0 +1,21 @@ |
1 | +class Kalibro::Error < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :error_class, :message, :stack_trace_element, :cause | |
4 | + | |
5 | + def stack_trace_element=(value) | |
6 | + @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value | |
7 | + end | |
8 | + | |
9 | + def stack_trace | |
10 | + @stack_trace_element | |
11 | + end | |
12 | + | |
13 | + def stack_trace=(stack_trace) | |
14 | + @stack_trace_element = stack_trace | |
15 | + end | |
16 | + | |
17 | + def cause=(cause_value) | |
18 | + @cause = Kalibro::Error.to_object cause_value | |
19 | + end | |
20 | + | |
21 | +end | ... | ... |
... | ... | @@ -0,0 +1,72 @@ |
1 | +class Kalibro::MetricConfiguration < Kalibro::Model | |
2 | + | |
3 | + NATIVE_TYPE='native' | |
4 | + COMPOUND_TYPE='compound' | |
5 | + | |
6 | + attr_accessor :metric, :code, :weight, :aggregation_form, :range, :configuration_name | |
7 | + | |
8 | + def metric=(value) | |
9 | + if value.kind_of?(Hash) | |
10 | + @metric = native?(value) ? Kalibro::NativeMetric.to_object(value) : Kalibro::CompoundMetric.to_object(value) | |
11 | + else | |
12 | + @metric = value | |
13 | + end | |
14 | + end | |
15 | + | |
16 | + def weight=(value) | |
17 | + @weight = value.to_f | |
18 | + end | |
19 | + | |
20 | + def range=(value) | |
21 | + @range = Kalibro::Range.to_objects_array value | |
22 | + end | |
23 | + | |
24 | + def add_range(new_range) | |
25 | + @range = [] if @range.nil? | |
26 | + @range << new_range | |
27 | + end | |
28 | + | |
29 | + def ranges | |
30 | + @range | |
31 | + end | |
32 | + | |
33 | + def ranges=(ranges) | |
34 | + @range = ranges | |
35 | + end | |
36 | + | |
37 | + def update_attributes(attributes={}) | |
38 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | |
39 | + save | |
40 | + end | |
41 | + | |
42 | + def self.find_by_configuration_name_and_metric_name(configuration_name, metric_name) | |
43 | + metric_configuration = new request("MetricConfiguration", :get_metric_configuration, { | |
44 | + :configuration_name => configuration_name, | |
45 | + :metric_name => metric_name | |
46 | + })[:metric_configuration] | |
47 | + metric_configuration.configuration_name = configuration_name | |
48 | + metric_configuration | |
49 | + end | |
50 | + | |
51 | + def destroy | |
52 | + self.class.request("MetricConfiguration", :remove_metric_configuration, { | |
53 | + :configuration_name => configuration_name, | |
54 | + :metric_name=> metric.name | |
55 | + }) | |
56 | + end | |
57 | + | |
58 | + def to_hash | |
59 | + super :except => [:configuration_name] | |
60 | + end | |
61 | + | |
62 | + private | |
63 | + | |
64 | + def native?(value) | |
65 | + value.has_key?(:origin) ? true : false | |
66 | + end | |
67 | + | |
68 | + def save_params | |
69 | + {:metric_configuration => to_hash, :configuration_name => configuration_name} | |
70 | + end | |
71 | + | |
72 | +end | ... | ... |
... | ... | @@ -0,0 +1,40 @@ |
1 | +class Kalibro::MetricResult < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :metric, :value, :range, :descendent_result, :weight | |
4 | + | |
5 | + def metric=(value) | |
6 | + if value.kind_of?(Hash) | |
7 | + @metric = native?(value) ? Kalibro::NativeMetric.to_object(value) : Kalibro::CompoundMetric.to_object(value) | |
8 | + else | |
9 | + @metric = value | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + def value=(value) | |
14 | + @value = value.to_f | |
15 | + end | |
16 | + | |
17 | + def range=(value) | |
18 | + @range = Kalibro::Range.to_object value | |
19 | + end | |
20 | + | |
21 | + def descendent_result=(value) | |
22 | + array = value.kind_of?(Array) ? value : [value] | |
23 | + @descendent_result = array.collect {|element| element.to_f} | |
24 | + end | |
25 | + | |
26 | + def descendent_results | |
27 | + @descendent_result | |
28 | + end | |
29 | + | |
30 | + def descendent_results=(descendent_results) | |
31 | + @descendent_result = descendent_results | |
32 | + end | |
33 | + | |
34 | + private | |
35 | + | |
36 | + def native?(value) | |
37 | + value.has_key?(:origin) ? true : false | |
38 | + end | |
39 | + | |
40 | +end | ... | ... |
... | ... | @@ -0,0 +1,126 @@ |
1 | +class Kalibro::Model | |
2 | + | |
3 | + def initialize(attributes={}) | |
4 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | |
5 | + end | |
6 | + | |
7 | + def to_hash(options={}) | |
8 | + hash = Hash.new | |
9 | + excepts = !options[:except].nil? ? options[:except] : [] | |
10 | + fields.each do |field| | |
11 | + if(!excepts.include?(field)) | |
12 | + field_value = send(field) | |
13 | + hash[field] = convert_to_hash(field_value) if ! field_value.nil? | |
14 | + if field_value.is_a?(Kalibro::Model) | |
15 | + hash = {:attributes! => {}}.merge(hash) | |
16 | + hash[:attributes!][field.to_sym] = { | |
17 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
18 | + 'xsi:type' => 'kalibro:' + xml_class_name(field_value) } | |
19 | + end | |
20 | + end | |
21 | + end | |
22 | + hash | |
23 | + end | |
24 | + | |
25 | + def self.request(endpoint, action, request_body = nil) | |
26 | + response = client(endpoint).request(:kalibro, action) { soap.body = request_body } | |
27 | + response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method | |
28 | + end | |
29 | + | |
30 | + def self.to_objects_array value | |
31 | + array = value.kind_of?(Array) ? value : [value] | |
32 | + array.each.collect { |element| to_object(element) } | |
33 | + end | |
34 | + | |
35 | + def self.to_object value | |
36 | + value.kind_of?(Hash) ? new(value) : value | |
37 | + end | |
38 | + | |
39 | + def self.create(attributes={}) | |
40 | + new_model = new attributes | |
41 | + new_model.save | |
42 | + new_model | |
43 | + end | |
44 | + | |
45 | + def save | |
46 | + begin | |
47 | + self.class.request(save_endpoint, save_action, save_params) | |
48 | + true | |
49 | + rescue Exception => error | |
50 | + false | |
51 | + end | |
52 | + end | |
53 | + | |
54 | + def destroy | |
55 | + begin | |
56 | + self.class.request(destroy_endpoint, destroy_action, destroy_params) | |
57 | + rescue Exception | |
58 | + end | |
59 | + end | |
60 | + | |
61 | + protected | |
62 | + | |
63 | + def fields | |
64 | + instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } | |
65 | + end | |
66 | + | |
67 | + def convert_to_hash(value) | |
68 | + return value if value.nil? | |
69 | + return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) | |
70 | + return value.to_hash if value.is_a?(Kalibro::Model) | |
71 | + return self.class.date_with_milliseconds(value) if value.is_a?(DateTime) | |
72 | + return 'INF' if value.is_a?(Float) and value.infinite? == 1 | |
73 | + return '-INF' if value.is_a?(Float) and value.infinite? == -1 | |
74 | + value | |
75 | + end | |
76 | + | |
77 | + def xml_class_name(object) | |
78 | + xml_name = object.class.name | |
79 | + xml_name["Kalibro::"] = "" | |
80 | + xml_name[0..0] = xml_name[0..0].downcase | |
81 | + xml_name + "Xml" | |
82 | + end | |
83 | + | |
84 | + def self.client(endpoint) | |
85 | + service_address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml") | |
86 | + Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | |
87 | + end | |
88 | + | |
89 | + def self.is_valid?(field) | |
90 | + field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil? | |
91 | + end | |
92 | + | |
93 | + def self.date_with_milliseconds(date) | |
94 | + milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | |
95 | + date.to_s[0..18] + milliseconds + date.to_s[19..-1] | |
96 | + end | |
97 | + | |
98 | + def class_name | |
99 | + self.class.name.gsub(/Kalibro::/,"") | |
100 | + end | |
101 | + | |
102 | + def save_endpoint | |
103 | + class_name | |
104 | + end | |
105 | + | |
106 | + def save_action | |
107 | + "save_#{class_name.underscore}".to_sym | |
108 | + end | |
109 | + | |
110 | + def save_params | |
111 | + {class_name.underscore.to_sym => self.to_hash} | |
112 | + end | |
113 | + | |
114 | + def destroy_endpoint | |
115 | + class_name | |
116 | + end | |
117 | + | |
118 | + def destroy_action | |
119 | + "remove_#{class_name.underscore}".to_sym | |
120 | + end | |
121 | + | |
122 | + def destroy_params | |
123 | + {"#{class_name.underscore}_name".to_sym => self.name} | |
124 | + end | |
125 | + | |
126 | +end | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +class Kalibro::Module < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :name, :granularity | |
4 | + | |
5 | + def self.parent_names(name) | |
6 | + path = [] | |
7 | + ancestors = [] | |
8 | + name.split(".").each do |token| | |
9 | + path << token | |
10 | + ancestors << path.join(".") | |
11 | + end | |
12 | + ancestors | |
13 | + end | |
14 | + | |
15 | + def ancestor_names | |
16 | + self.class.parent_names(@name) | |
17 | + end | |
18 | +end | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +class Kalibro::ModuleNode < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :module, :child | |
4 | + | |
5 | + def module=(value) | |
6 | + @module = Kalibro::Module.to_object value | |
7 | + end | |
8 | + | |
9 | + def child=(value) | |
10 | + @child = Kalibro::ModuleNode.to_objects_array value | |
11 | + end | |
12 | + | |
13 | + def children | |
14 | + @child | |
15 | + end | |
16 | + | |
17 | + def children=(children) | |
18 | + @child = children | |
19 | + end | |
20 | + | |
21 | +end | ... | ... |
... | ... | @@ -0,0 +1,63 @@ |
1 | +class Kalibro::ModuleResult < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error | |
4 | + | |
5 | + def self.find_by_project_name_and_module_name_and_date(project_name, module_name, date) | |
6 | + new request( | |
7 | + 'ModuleResult', | |
8 | + :get_module_result, | |
9 | + { | |
10 | + :project_name => project_name, | |
11 | + :module_name => module_name, | |
12 | + :date => date_with_milliseconds(date) | |
13 | + })[:module_result] | |
14 | + end | |
15 | + | |
16 | + def self.all_by_project_name_and_module_name(project_name, module_name) | |
17 | + response = request( | |
18 | + 'ModuleResult', | |
19 | + :get_result_history, | |
20 | + { | |
21 | + :project_name => project_name, | |
22 | + :module_name => module_name | |
23 | + })[:module_result] | |
24 | + Kalibro::ModuleResult.to_objects_array(response) | |
25 | + end | |
26 | + | |
27 | + def module=(value) | |
28 | + @module = Kalibro::Module.to_object value | |
29 | + end | |
30 | + | |
31 | + def date=(value) | |
32 | + @date = value.is_a?(String) ? DateTime.parse(value) : value | |
33 | + end | |
34 | + | |
35 | + def grade=(value) | |
36 | + @grade = value.to_f | |
37 | + end | |
38 | + | |
39 | + def metric_result=(value) | |
40 | + @metric_result = Kalibro::MetricResult.to_objects_array value | |
41 | + end | |
42 | + | |
43 | + def metric_results | |
44 | + @metric_result | |
45 | + end | |
46 | + | |
47 | + def metric_results=(metric_results) | |
48 | + @metric_result = metric_results | |
49 | + end | |
50 | + | |
51 | + def compound_metric_with_error=(value) | |
52 | + @compound_metric_with_error = Kalibro::CompoundMetricWithError.to_objects_array value | |
53 | + end | |
54 | + | |
55 | + def compound_metrics_with_error | |
56 | + @compound_metric_with_error | |
57 | + end | |
58 | + | |
59 | + def compound_metrics_with_error=(compound_metrics_with_error) | |
60 | + @compound_metric_with_error = compound_metrics_with_error | |
61 | + end | |
62 | + | |
63 | +end | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +class Kalibro::NativeMetric < Kalibro::Metric | |
2 | + | |
3 | + attr_accessor :origin, :language | |
4 | + | |
5 | + def languages | |
6 | + @language | |
7 | + end | |
8 | + | |
9 | + def languages=(languages) | |
10 | + @language = languages | |
11 | + end | |
12 | + | |
13 | + def language=(value) | |
14 | + @language = Kalibro::Model.to_objects_array value | |
15 | + end | |
16 | + | |
17 | +end | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +class Kalibro::Project < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :error | |
4 | + | |
5 | + def self.all_names | |
6 | + request("Project", :get_project_names)[:project_name] | |
7 | + end | |
8 | + | |
9 | + def self.find_by_name(project_name) | |
10 | + new request("Project", :get_project, :project_name => project_name)[:project] | |
11 | + end | |
12 | + | |
13 | + def repository=(value) | |
14 | + @repository = Kalibro::Repository.to_object value | |
15 | + end | |
16 | + | |
17 | + def error=(value) | |
18 | + @error = Kalibro::Error.to_object value | |
19 | + end | |
20 | + | |
21 | + def process_project(days = '0') | |
22 | + if days.to_i.zero? | |
23 | + self.class.request("Kalibro", :process_project, {:project_name => name}) | |
24 | + else | |
25 | + self.class.request("Kalibro", :process_periodically, {:project_name => name, :period_in_days => days}) | |
26 | + end | |
27 | + end | |
28 | + | |
29 | + def process_period | |
30 | + self.class.request("Kalibro", :get_process_period, {:project_name => name})[:period] | |
31 | + end | |
32 | + | |
33 | + def cancel_periodic_process | |
34 | + self.class.request("Kalibro", :cancel_periodic_process, {:project_name => name}) | |
35 | + end | |
36 | + | |
37 | +end | ... | ... |
... | ... | @@ -0,0 +1,104 @@ |
1 | +class Kalibro::ProjectResult < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :project, :date, :load_time, :analysis_time, :source_tree, :collect_time | |
4 | + | |
5 | + def self.last_result(project_name) | |
6 | + new request('ProjectResult', :get_last_result_of, {:project_name => project_name})[:project_result] | |
7 | + end | |
8 | + | |
9 | + def self.first_result(project_name) | |
10 | + new request('ProjectResult', :get_first_result_of, {:project_name => project_name})[:project_result] | |
11 | + end | |
12 | + | |
13 | + def self.first_result_after(project_name, date) | |
14 | + new request('ProjectResult', :get_first_result_after, {:project_name => project_name, :date => date})[:project_result] | |
15 | + end | |
16 | + | |
17 | + def self.last_result_before(project_name, date) | |
18 | + new request('ProjectResult', :get_last_result_before, {:project_name => project_name, :date => date})[:project_result] | |
19 | + end | |
20 | + | |
21 | + def self.has_results?(project_name) | |
22 | + request('ProjectResult', :has_results_for, {:project_name => project_name})[:has_results] | |
23 | + end | |
24 | + | |
25 | + def self.has_results_before?(project_name, date) | |
26 | + request('ProjectResult', :has_results_before, {:project_name => project_name, :date => date})[:has_results] | |
27 | + end | |
28 | + | |
29 | + def self.has_results_after?(project_name, date) | |
30 | + request('ProjectResult', :has_results_after, {:project_name => project_name, :date => date})[:has_results] | |
31 | + end | |
32 | + | |
33 | + def project=(value) | |
34 | + @project = (value.kind_of?(Hash)) ? Kalibro::Project.new(value) : value | |
35 | + end | |
36 | + | |
37 | + def date=(value) | |
38 | + @date = value.is_a?(String) ? DateTime.parse(value) : value | |
39 | + end | |
40 | + | |
41 | + def load_time=(value) | |
42 | + @load_time = value.to_i | |
43 | + end | |
44 | + | |
45 | + def collect_time=(value) | |
46 | + @collect_time = value.to_i | |
47 | + end | |
48 | + | |
49 | + def analysis_time=(value) | |
50 | + @analysis_time = value.to_i | |
51 | + end | |
52 | + | |
53 | + def source_tree=(value) | |
54 | + @source_tree = value.kind_of?(Hash) ? Kalibro::ModuleNode.new(value) : value | |
55 | + end | |
56 | + | |
57 | + def formatted_load_time | |
58 | + format_milliseconds(@load_time) | |
59 | + end | |
60 | + | |
61 | + def formatted_analysis_time | |
62 | + format_milliseconds(@analysis_time) | |
63 | + end | |
64 | + | |
65 | + def format_milliseconds(value) | |
66 | + seconds = value.to_i/1000 | |
67 | + hours = seconds/3600 | |
68 | + seconds -= hours * 3600 | |
69 | + minutes = seconds/60 | |
70 | + seconds -= minutes * 60 | |
71 | + "#{format(hours)}:#{format(minutes)}:#{format(seconds)}" | |
72 | + end | |
73 | + | |
74 | + def format(amount) | |
75 | + ('%2d' % amount).sub(/\s/, '0') | |
76 | + end | |
77 | + | |
78 | + def node_of(module_name) | |
79 | + if module_name.nil? or module_name == project.name | |
80 | + node = source_tree | |
81 | + else | |
82 | + node = get_node(module_name) | |
83 | + end | |
84 | + end | |
85 | + | |
86 | + def get_node(module_name) | |
87 | + path = Kalibro::Module.parent_names(module_name) | |
88 | + parent = @source_tree | |
89 | + path.each do |node_name| | |
90 | + parent = get_leaf_from(parent, node_name) | |
91 | + end | |
92 | + return parent | |
93 | + end | |
94 | + | |
95 | + private | |
96 | + | |
97 | + def get_leaf_from(node, module_name) | |
98 | + node.children.each do |child_node| | |
99 | + return child_node if child_node.module.name == module_name | |
100 | + end | |
101 | + nil | |
102 | + end | |
103 | + | |
104 | +end | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +class Kalibro::Range < Kalibro::Model | |
2 | + | |
3 | + attr_accessor :beginning, :end, :label, :grade, :color, :comments | |
4 | + | |
5 | + def beginning=(value) | |
6 | + @beginning = value.to_f | |
7 | + @beginning = -1.0/0.0 if value == "-INF" | |
8 | + end | |
9 | + | |
10 | + def beginning | |
11 | + if !@beginning.nil? | |
12 | + case @beginning.to_s | |
13 | + when "-Infinity": "-INF" | |
14 | + else @beginning | |
15 | + end | |
16 | + end | |
17 | + end | |
18 | + | |
19 | + def end=(value) | |
20 | + @end = value.to_f | |
21 | + @end = 1.0/0.0 if value == "INF" | |
22 | + end | |
23 | + | |
24 | + def end | |
25 | + if !@end.nil? | |
26 | + case @end.to_s | |
27 | + when "Infinity": "INF" | |
28 | + else @end | |
29 | + end | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + def grade=(value) | |
34 | + @grade = value.to_f | |
35 | + end | |
36 | + | |
37 | +end | ... | ... |
plugins/mezuro/lib/mezuro_plugin.rb
... | ... | @@ -9,16 +9,11 @@ class MezuroPlugin < Noosfero::Plugin |
9 | 9 | end |
10 | 10 | |
11 | 11 | def content_types |
12 | - [MezuroPlugin::ProjectContent, | |
13 | - MezuroPlugin::ConfigurationContent] | |
12 | + [MezuroPlugin::ConfigurationContent, MezuroPlugin::ProjectContent] | |
14 | 13 | end |
15 | 14 | |
16 | 15 | def stylesheet? |
17 | 16 | true |
18 | 17 | end |
19 | 18 | |
20 | - def js_files | |
21 | - ['javascripts/results.js', 'javascripts/toogle.js'] | |
22 | - end | |
23 | - | |
24 | 19 | end | ... | ... |
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
1 | 1 | class MezuroPlugin::ConfigurationContent < Article |
2 | + validate_on_create :validate_kalibro_configuration_name | |
3 | + | |
4 | + settings_items :description, :configuration_to_clone_name | |
5 | + | |
6 | + after_save :send_configuration_to_service | |
7 | + after_destroy :remove_configuration_from_service | |
2 | 8 | |
3 | 9 | def self.short_description |
4 | 10 | 'Kalibro configuration' |
5 | 11 | end |
6 | 12 | |
7 | 13 | def self.description |
8 | - 'Kalibro configuration for some project' | |
14 | + 'Sets of thresholds to interpret metrics' | |
9 | 15 | end |
10 | 16 | |
11 | - settings_items :description | |
12 | - | |
13 | 17 | include ActionView::Helpers::TagHelper |
14 | 18 | def to_html(options = {}) |
15 | 19 | lambda do |
... | ... | @@ -18,27 +22,65 @@ class MezuroPlugin::ConfigurationContent < Article |
18 | 22 | end |
19 | 23 | |
20 | 24 | def configuration |
21 | - Kalibro::Client::ConfigurationClient.new.configuration(title) | |
25 | + @configuration ||= Kalibro::Configuration.find_by_name(self.name) | |
26 | + if @configuration.nil? | |
27 | + errors.add_to_base("Kalibro Configuration not found") | |
28 | + end | |
29 | + @configuration | |
22 | 30 | end |
23 | 31 | |
24 | - after_save :send_configuration_to_service | |
25 | - after_destroy :remove_configuration_from_service | |
32 | + def metric_configurations | |
33 | + configuration.metric_configurations | |
34 | + end | |
35 | + | |
36 | + def configuration_names | |
37 | + ["None"] + Kalibro::Configuration.all_names.sort | |
38 | + end | |
26 | 39 | |
27 | 40 | private |
28 | 41 | |
42 | + def validate_kalibro_configuration_name | |
43 | + existing = configuration_names.map { |a| a.downcase} | |
44 | + | |
45 | + if existing.include?(name.downcase) | |
46 | + errors.add_to_base("Configuration name already exists in Kalibro") | |
47 | + end | |
48 | + end | |
49 | + | |
29 | 50 | def send_configuration_to_service |
30 | - Kalibro::Client::ConfigurationClient.save(create_configuration) | |
51 | + if editing_configuration? | |
52 | + configuration.update_attributes({:description => description}) | |
53 | + else | |
54 | + create_kalibro_configuration | |
55 | + end | |
31 | 56 | end |
32 | 57 | |
33 | 58 | def remove_configuration_from_service |
34 | - Kalibro::Client::ConfigurationClient.remove(title) | |
59 | + configuration.destroy | |
35 | 60 | end |
36 | 61 | |
37 | - def create_configuration | |
38 | - configuration = Kalibro::Entities::Configuration.new | |
39 | - configuration.name = title | |
40 | - configuration.description = description | |
41 | - configuration | |
62 | + def create_kalibro_configuration | |
63 | + attributes = {:name => name, :description => description} | |
64 | + if cloning_configuration? | |
65 | + attributes[:metric_configuration] = configuration_to_clone.metric_configurations_hash | |
66 | + end | |
67 | + Kalibro::Configuration.create attributes | |
68 | + end | |
69 | + | |
70 | + def editing_configuration? | |
71 | + configuration.present? | |
72 | + end | |
73 | + | |
74 | + def configuration_to_clone | |
75 | + @configuration_to_clone ||= find_configuration_to_clone | |
76 | + end | |
77 | + | |
78 | + def find_configuration_to_clone | |
79 | + configuration_to_clone_name.nil? ? nil : Kalibro::Configuration.find_by_name(configuration_to_clone_name) | |
80 | + end | |
81 | + | |
82 | + def cloning_configuration? | |
83 | + configuration_to_clone.present? | |
42 | 84 | end |
43 | 85 | |
44 | 86 | end | ... | ... |
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,34 @@ |
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 | + :max_value => values.max, | |
21 | + :min_value => values.min | |
22 | + ) | |
23 | + end | |
24 | + | |
25 | + def self.get_periodicity_option(index) | |
26 | + options = [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] | |
27 | + selected_option = options.find { |option| option.last == index.to_i } | |
28 | + selected_option.first | |
29 | + end | |
30 | + | |
31 | + def self.format_name(metric_result) | |
32 | + metric_result.metric.name.delete("() ") | |
33 | + end | |
34 | +end | ... | ... |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
1 | -class MezuroPlugin::ProjectContent < Article | |
1 | +class MezuroPlugin::ProjectContent < Article | |
2 | + include ActionView::Helpers::TagHelper | |
3 | + | |
4 | + settings_items :license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days | |
5 | + | |
6 | + validate_on_create :validate_kalibro_project_name | |
7 | + validate_on_create :validate_repository_url | |
2 | 8 | |
3 | 9 | def self.short_description |
4 | 10 | 'Kalibro project' |
... | ... | @@ -8,59 +14,98 @@ class MezuroPlugin::ProjectContent < Article |
8 | 14 | 'Software project tracked by Kalibro' |
9 | 15 | end |
10 | 16 | |
11 | - settings_items :license, :description, :repository_type, :repository_url, :configuration_name | |
12 | - | |
13 | - include ActionView::Helpers::TagHelper | |
14 | 17 | def to_html(options = {}) |
15 | 18 | lambda do |
16 | 19 | render :file => 'content_viewer/show_project.rhtml' |
17 | 20 | end |
18 | 21 | end |
19 | 22 | |
20 | - # FIXME is this really needed? | |
21 | 23 | def project |
22 | - Kalibro::Client::ProjectClient.new.project(title) | |
24 | + begin | |
25 | + @project ||= Kalibro::Project.find_by_name(name) | |
26 | + rescue Exception => error | |
27 | + errors.add_to_base(error.message) | |
28 | + end | |
23 | 29 | end |
24 | 30 | |
25 | 31 | def project_result |
26 | - @project_result ||= Kalibro::Client::ProjectResultClient.new.last_result(title) | |
32 | + begin | |
33 | + @project_result ||= Kalibro::ProjectResult.last_result(name) | |
34 | + rescue Exception => error | |
35 | + errors.add_to_base(error.message) | |
36 | + end | |
37 | + end | |
38 | + | |
39 | + def project_result_with_date(date) | |
40 | + begin | |
41 | + @project_result ||= Kalibro::ProjectResult.has_results_before?(name, date) ? Kalibro::ProjectResult.last_result_before(name, date) : | |
42 | +Kalibro::ProjectResult.first_result_after(name, date) | |
43 | + rescue Exception => error | |
44 | + errors.add_to_base(error.message) | |
45 | + end | |
27 | 46 | end |
28 | 47 | |
29 | - def module_result(module_name) | |
30 | - @module_client ||= Kalibro::Client::ModuleResultClient.new | |
31 | - @module_client.module_result(title, module_name, project_result.date) | |
48 | + def module_result(attributes) | |
49 | + module_name = attributes[:module_name].nil? ? project.name : attributes[:module_name] | |
50 | + date = attributes[:date].nil? ? project_result.date : project_result_with_date(attributes[:date]).date | |
51 | + begin | |
52 | + @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, module_name, date) | |
53 | + rescue Exception => error | |
54 | + errors.add_to_base(error.message) | |
55 | + end | |
56 | + end | |
57 | + | |
58 | + def result_history(module_name) | |
59 | + begin | |
60 | + @result_history ||= Kalibro::ModuleResult.all_by_project_name_and_module_name(name, module_name) | |
61 | + rescue Exception => error | |
62 | + errors.add_to_base(error.message) | |
63 | + end | |
32 | 64 | end |
33 | 65 | |
34 | 66 | after_save :send_project_to_service |
35 | - after_destroy :remove_project_from_service | |
67 | + after_destroy :destroy_project_from_service | |
36 | 68 | |
37 | 69 | private |
38 | 70 | |
39 | - def send_project_to_service | |
40 | - Kalibro::Client::ProjectClient.save(create_project) | |
41 | - Kalibro::Client::KalibroClient.process_project(title) | |
71 | + def validate_kalibro_project_name | |
72 | + begin | |
73 | + existing = Kalibro::Project.all_names | |
74 | + rescue Exception => error | |
75 | + errors.add_to_base(error.message) | |
76 | + end | |
77 | + | |
78 | + if existing.any?{|existing_name| existing_name.casecmp(name)==0} # existing.include?(name) + case insensitive | |
79 | + errors.add_to_base("Project name already exists in Kalibro") | |
80 | + end | |
42 | 81 | end |
43 | - | |
44 | - def remove_project_from_service | |
45 | - Kalibro::Client::ProjectClient.remove(title) | |
82 | + | |
83 | + def validate_repository_url | |
84 | + if(repository_url.nil? || repository_url == "") | |
85 | + errors.add_to_base("Repository URL is mandatory") | |
86 | + end | |
87 | + end | |
88 | + | |
89 | + def send_project_to_service | |
90 | + created_project = create_kalibro_project | |
91 | + created_project.process_project(periodicity_in_days) | |
46 | 92 | end |
47 | 93 | |
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 | |
94 | + def create_kalibro_project | |
95 | + Kalibro::Project.create( | |
96 | + :name => name, | |
97 | + :license => license, | |
98 | + :description => description, | |
99 | + :repository => { | |
100 | + :type => repository_type, | |
101 | + :address => repository_url | |
102 | + }, | |
103 | + :configuration_name => configuration_name | |
104 | + ) | |
56 | 105 | end |
57 | 106 | |
58 | - def create_repository | |
59 | - repository = Kalibro::Entities::Repository.new | |
60 | - repository.type = repository_type | |
61 | - repository.address = repository_url | |
62 | - repository | |
107 | + def destroy_project_from_service | |
108 | + project.destroy | |
63 | 109 | end |
64 | 110 | |
65 | 111 | 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,150 @@ |
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 | + jQuery('#project_date_submit').live("click", reloadProjectWithDate); | |
9 | + showLoadingProcess(true); | |
10 | + showProjectContent(); | |
11 | +}); | |
12 | + | |
13 | +function showProjectContent() { | |
14 | + callAction('project_state', {}, showProjectContentFor); | |
15 | +} | |
16 | + | |
17 | +function display_metric_history() { | |
18 | + var module_name = jQuery(this).attr('data-module-name'); | |
19 | + var metric_name = jQuery(this).attr('data-metric-name'); | |
20 | + metricName = metric_name; | |
21 | + callAction('module_metrics_history', {module_name: module_name, metric_name: metric_name}, show_metrics); | |
22 | + return false; | |
23 | +} | |
24 | + | |
25 | +function display_grade_history() { | |
26 | + var module_name = jQuery(this).attr('data-module-name'); | |
27 | + callAction('module_grade_history', {module_name: module_name}, show_grades); | |
28 | + return false; | |
29 | +} | |
30 | + | |
31 | +function show_metrics(content) { | |
32 | + jQuery('#historical-' + metricName).html(content); | |
33 | +} | |
34 | + | |
35 | +function show_grades(content) { | |
36 | + jQuery('#historical-grade').html(content); | |
37 | +} | |
38 | + | |
39 | +function toggle_mezuro(){ | |
40 | + var element = jQuery(this).attr('data-show'); | |
41 | + jQuery(element).toggle(); | |
42 | + return false; | |
43 | +} | |
44 | + | |
45 | +function reloadModule(){ | |
46 | + var module_name = jQuery(this).attr('data-module-name'); | |
47 | + showLoadingProcess(false); | |
48 | + processingTree = true; | |
49 | + callAction('project_tree', {module_name: module_name }, showProjectTree); | |
50 | + callAction('module_result', {module_name: module_name}, showModuleResult); | |
51 | + return false; | |
52 | +} | |
53 | + | |
54 | +function reloadProjectWithDate(){ | |
55 | + var day = jQuery("#project_date_day").val(); | |
56 | + var month = jQuery("#project_date_month").val(); | |
57 | + var year = jQuery("#project_date_year").val(); | |
58 | + | |
59 | + if(day.length == 1) | |
60 | + day = "0" + day; | |
61 | + if(month.length == 1) | |
62 | + month = "0" + month; | |
63 | + | |
64 | + var date = new Date(year + "-" + month + "-" + day + "T00:00:00+00:00"); | |
65 | + | |
66 | + if(isNaN(date)){ | |
67 | + alert("Invalid date! " + date); | |
68 | + return false; | |
69 | + } | |
70 | + reloadProject(date); | |
71 | + return false; | |
72 | +} | |
73 | + | |
74 | +function reloadProject(date){ | |
75 | + showLoadingProcess(true); | |
76 | + | |
77 | + callAction('project_result', {date: date}, showProjectResult); | |
78 | + callAction('project_tree', {date: date}, showProjectTree); | |
79 | + callAction('module_result', {date: date}, showModuleResult); | |
80 | +} | |
81 | + | |
82 | +function showProjectContentFor(state){ | |
83 | + if (state == 'ERROR') { | |
84 | + jQuery('#project-state').html('ERROR'); | |
85 | + callAction('project_error', {}, showProjectResult); | |
86 | + } | |
87 | + else if (state == 'READY') { | |
88 | + jQuery('#msg-time').html(''); | |
89 | + jQuery('#project-state').html('READY'); | |
90 | + callAction('project_result', {}, showProjectResult); | |
91 | + callAction('project_tree', {}, showProjectTree); | |
92 | + var project_name = jQuery("#project-result").attr('data-project-name'); | |
93 | + callAction('module_result', {module_name: project_name}, showModuleResult); | |
94 | + } | |
95 | + else if (state.endsWith("ING")) { | |
96 | + jQuery('#project-state').html(state); | |
97 | + jQuery('#msg-time').html("The project analysis may take long. <br/> You'll receive an e-mail when it's ready!"); | |
98 | + showProjectContentAfter(20); | |
99 | + } | |
100 | +} | |
101 | + | |
102 | +function showProjectContentAfter(seconds){ | |
103 | + if (seconds > 0){ | |
104 | + setTimeout(function() { showProjectContentAfter(seconds - 10);}, 10000); | |
105 | + } else { | |
106 | + showProjectContent(); | |
107 | + } | |
108 | +} | |
109 | + | |
110 | +function showProjectResult(content) { | |
111 | + jQuery('#project-result').html(content); | |
112 | +} | |
113 | + | |
114 | +function showProjectTree(content){ | |
115 | + processingTree = false; | |
116 | + jQuery('#project-tree').html(content); | |
117 | + return false; | |
118 | +} | |
119 | + | |
120 | +function showModuleResult(content){ | |
121 | + if (processingTree != true){ | |
122 | + jQuery('#module-result').html(content); | |
123 | + } | |
124 | + return false; | |
125 | +} | |
126 | + | |
127 | +function callAction(action, params, callback){ | |
128 | + var profile = projectContentData('profile'); | |
129 | + var content = projectContentData('content'); | |
130 | + var endpoint = '/profile/' + profile + '/plugins/mezuro/' + action + '/' + content; | |
131 | + jQuery.get(endpoint, params, callback); | |
132 | +} | |
133 | + | |
134 | +function projectContentData(data){ | |
135 | + return jQuery('#project-result').attr('data-' + data); | |
136 | +} | |
137 | + | |
138 | +function showLoadingProcess(firstLoad){ | |
139 | + if(firstLoad) | |
140 | + showProjectResult("<img src='/images/loading-small.gif'/>"); | |
141 | + | |
142 | + showProjectTree("<img src='/images/loading-small.gif'/>"); | |
143 | + showModuleResult("<img src='/images/loading-small.gif'/>"); | |
144 | +} | |
145 | + | |
146 | +function sourceNodeToggle(id){ | |
147 | + var suffixes = ['_hidden', '_plus', '_minus']; | |
148 | + for (var i in suffixes) | |
149 | + jQuery('#' + id + suffixes[i]).toggle(); | |
150 | +} | ... | ... |
plugins/mezuro/public/javascripts/results.js
... | ... | @@ -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 | 0 | \ No newline at end of file |
plugins/mezuro/public/javascripts/toogle.js
... | ... | @@ -0,0 +1,77 @@ |
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 IsNotInfinite(value){ | |
34 | + if(value.match(/INF/)){ | |
35 | + return false; | |
36 | + } | |
37 | + return true; | |
38 | +} | |
39 | + | |
40 | +function IsNotHexadecimal(value){ | |
41 | + if(value.match(/^[0-9a-fA-F]{1,8}$/)) | |
42 | + { | |
43 | + return false; | |
44 | + } | |
45 | + return true; | |
46 | +} | |
47 | + | |
48 | +function validate_new_range_configuration(event){ | |
49 | + var label = jQuery("#range_label").val(); | |
50 | + var beginning = jQuery("#range_beginning").val(); | |
51 | + var end = jQuery("#range_end").val(); | |
52 | + var color = jQuery("#range_color").val(); | |
53 | + var grade = jQuery("#range_grade").val(); | |
54 | + | |
55 | + if (is_null(label) || is_null(beginning) || is_null(end) || is_null(color) || is_null(grade)) | |
56 | + { | |
57 | + alert("Please fill all fields marked with (*)"); | |
58 | + return false; | |
59 | + } | |
60 | + if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)) || IsNotNumeric(grade)) | |
61 | + { | |
62 | + alert("Beginning, End and Grade must be numeric values"); | |
63 | + return false; | |
64 | + } | |
65 | + if (parseInt(beginning) > parseInt(end)) | |
66 | + { | |
67 | + if(IsNotInfinite(beginning) && IsNotInfinite(end)){ | |
68 | + alert("End must be greater than Beginning"); | |
69 | + return false; | |
70 | + } | |
71 | + } | |
72 | + if (IsNotHexadecimal(color)){ | |
73 | + alert("Color must be an hexadecimal value"); | |
74 | + return false; | |
75 | + } | |
76 | + return true; | |
77 | +} | ... | ... |
plugins/mezuro/public/style.css
1 | 1 | .link { |
2 | 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 | +} | ... | ... |
plugins/mezuro/test/features/adding_metric_configuration.feature
0 → 100644
... | ... | @@ -0,0 +1,67 @@ |
1 | +Feature: Add metric configuration to a configuration | |
2 | + As a mezuro user | |
3 | + I want to add metric configurations to a Kalibro configuration | |
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 | + And I am on My Community's cms | |
16 | + And I create a content of type "Kalibro configuration" with the following data | |
17 | + | Title | My Configuration | | |
18 | + | Description | A sample description | | |
19 | + | |
20 | + Scenario: adding a native metric configuration | |
21 | + When I follow "Add metric" | |
22 | + And I follow "Analizo" | |
23 | + And I follow "Lines of Code" | |
24 | + And I fill in the following: | |
25 | + | Code: | Sample Code | | |
26 | + | Weight: | 10.0 | | |
27 | + And I select "Average" from "Aggregation Form:" | |
28 | + And I press "Add" | |
29 | + Then I should see "Lines of Code" | |
30 | + And I should see "Analizo" | |
31 | + And I should see "Sample Code" | |
32 | + | |
33 | + Scenario: adding a native metric configuration without code | |
34 | + When I follow "Add metric" | |
35 | + And I follow "Analizo" | |
36 | + And I follow "Number of Children" | |
37 | + And I don't fill anything | |
38 | + And I press "Add" | |
39 | + Then I should be at the url "/myprofile/my-community/plugin/mezuro/new_metric_configuration" | |
40 | + | |
41 | + Scenario: adding a compound metric configuration | |
42 | + When I follow "Add metric" | |
43 | + And I follow "New Compound Metric" | |
44 | + And I fill in the following: | |
45 | + | Name: | Compound sample | | |
46 | + | Description: | 10.0 | | |
47 | + | Script: | return 42; | | |
48 | + | Code: | anyCode | | |
49 | + | Weight: | 10.0 | | |
50 | + And I select "Class" from "Scope:" | |
51 | + And I select "Average" from "Aggregation Form:" | |
52 | + And I press "Add" | |
53 | + Then I should see "Compound sample" | |
54 | + | |
55 | + Scenario: adding a compound metric configuration with invalid script | |
56 | + When I follow "Add metric" | |
57 | + And I follow "New Compound Metric" | |
58 | + And I fill in the following: | |
59 | + | Name: | Compound sample | | |
60 | + | Description: | 10.0 | | |
61 | + | Script: | invalid script | | |
62 | + | Code: | anyCode | | |
63 | + | Weight: | 10.0 | | |
64 | + And I select "Class" from "Scope:" | |
65 | + And I select "Average" from "Aggregation Form:" | |
66 | + And I press "Add" | |
67 | + Then I should see "Compound sample" | ... | ... |
... | ... | @@ -0,0 +1,42 @@ |
1 | +Feature: Add range to a metric configuration | |
2 | + As a mezuro user | |
3 | + I want to add ranges to a Kalibro metric configuration | |
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 | + And I am on My Community's cms | |
16 | + And I create a content of type "Kalibro configuration" with the following data | |
17 | + | Title | My Configuration | | |
18 | + | Description | A sample description | | |
19 | + And I follow "Add metric" | |
20 | + And I follow "Analizo" | |
21 | + And I follow "Lines of Code" | |
22 | + And I fill in the following: | |
23 | + | Code: | Sample Code | | |
24 | + | Weight: | 10.0 | | |
25 | + And I select "Average" from "Aggregation Form:" | |
26 | + And I press "Add" | |
27 | + Then I should see "Lines of Code" | |
28 | + And I should see "Analizo" | |
29 | + And I should see "Sample Code" | |
30 | + | |
31 | + Scenario: adding a range to a metric configuration | |
32 | + When I follow "New Range" and wait | |
33 | + And I fill in the following: | |
34 | + | (*) Label: | label | | |
35 | + | (*) Beginning: | 1 | | |
36 | + | (*) End: | 10 | | |
37 | + | (*) Grade: | 100 | | |
38 | + | (*) Color: | FFFF00FF | | |
39 | + | Comments: | Comentário | | |
40 | + And I press "Save Range" and wait | |
41 | + And I should see "label" within "#ranges" | |
42 | + | ... | ... |
plugins/mezuro/test/features/creating_configuration.feature
0 → 100644
... | ... | @@ -0,0 +1,40 @@ |
1 | +Feature: Create configuration | |
2 | + As a mezuro user | |
3 | + I want to create a Kalibro configuration | |
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: creating with valid attributes | |
17 | + Given I am on My Community's cms | |
18 | + When I create a content of type "Kalibro configuration" with the following data | |
19 | + | Title | Qt_Calculator | | |
20 | + | Description | A sample description | | |
21 | + Then I should see "Name" | |
22 | + And I should see "Qt_Calculator" | |
23 | + And I should see "Description" | |
24 | + And I should see "A sample description" | |
25 | + | |
26 | + Scenario: creating with duplicated name | |
27 | + Given I am on My Community's cms | |
28 | + And I create a content of type "Kalibro configuration" with the following data | |
29 | + | Title | Original Title | | |
30 | + And I am on My Community's cms | |
31 | + When I create a content of type "Kalibro configuration" with the following data | |
32 | + | Title | Original Title | | |
33 | + Then I should see "1 error prohibited this article from being saved" | |
34 | + | |
35 | + Scenario: creating without title | |
36 | + Given I am on My Community's cms | |
37 | + When I create a content of type "Kalibro configuration" with the following data | |
38 | + | Title | | | |
39 | + Then I should see "1 error prohibited this article from being saved" | |
40 | + | ... | ... |
... | ... | @@ -0,0 +1,55 @@ |
1 | +Feature: Create project | |
2 | + As a mezuro 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's input form | |
17 | + Given I am on My Community's cms | |
18 | + When I follow "New content" | |
19 | + And I follow "Kalibro project" | |
20 | + Then I should see "Title" | |
21 | + And I should see "License" | |
22 | + And I should see "Repository type" | |
23 | + And I should see "GIT" | |
24 | + And I should see "REMOTE_ZIP" | |
25 | + And I should see "REMOTE_TARBALL" | |
26 | + And I should see "SUBVERSION" | |
27 | + And I should see "Repository url" | |
28 | + And I should see "Configuration" | |
29 | + And I should see "Kalibro for Java" | |
30 | + | |
31 | + Scenario: I create a Kalibro project with valid attributes | |
32 | + Given I am on My Community's cms | |
33 | + When I create a content of type "Kalibro project" with the following data | |
34 | + | Title | Sample Project | | |
35 | + | License | GPL | | |
36 | + | Repository type | SUBVERSION | | |
37 | + | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator | | |
38 | + | Configuration | Kalibro for Java | | |
39 | + Then I should see "Sample Project" | |
40 | + And I should see "GPL" | |
41 | + And I should see "SUBVERSION" | |
42 | + And I should see "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator" | |
43 | + And I should see "Kalibro for Java" | |
44 | + And I directly delete content with name "Sample Project" for testing purposes | |
45 | + | |
46 | + Scenario: I can't create a Kalibro project with invalid attributes | |
47 | + Given I am on My Community's cms | |
48 | + When I create a content of type "Kalibro project" with the following data | |
49 | + | Title | | | |
50 | + | License | GPL | | |
51 | + | Repository type | SUBVERSION | | |
52 | + | Repository url | | | |
53 | + | Configuration | Kalibro for Java | | |
54 | + Then I should see "Title can't be blank" | |
55 | + And I should see "Missing repository url" | ... | ... |
... | ... | @@ -0,0 +1,90 @@ |
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 | + address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml") | |
13 | + address['KalibroService'] = 'KalibroFake' | |
14 | + @port.service_address=(address); | |
15 | + end | |
16 | + | |
17 | + should 'echo base tool' do | |
18 | + test BaseToolFixtures.analizo, 'BaseTool' do |base_tool| | |
19 | + base_tool.name = "echo " + base_tool.name | |
20 | + end | |
21 | + end | |
22 | + | |
23 | + should 'echo configuration' do | |
24 | + test ConfigurationFixtures.kalibro_configuration, 'Configuration' do |configuration| | |
25 | + configuration.name = "echo " + configuration.name | |
26 | + end | |
27 | + end | |
28 | + | |
29 | + should 'echo metric configuration' do | |
30 | + test_metric_configuration(MetricConfigurationFixtures.amloc_configuration) | |
31 | + test_metric_configuration(MetricConfigurationFixtures.sc_configuration) | |
32 | + end | |
33 | + | |
34 | + should 'echo module result' do | |
35 | + test ModuleResultFixtures.create, 'ModuleResult' do |module_result| | |
36 | + module_result.module.name = "echo." + module_result.module.name | |
37 | + end | |
38 | + end | |
39 | + | |
40 | + should 'echo project' do | |
41 | + test(ProjectFixtures.qt_calculator, 'Project') do |project| | |
42 | + project.name = "echo " + project.name | |
43 | + end | |
44 | + end | |
45 | + | |
46 | + should 'echo project result' do | |
47 | + test(ProjectResultFixtures.qt_calculator, 'ProjectResult') do |project_result| | |
48 | + project_result.project.name = "echo " + project_result.project.name | |
49 | + end | |
50 | + end | |
51 | + | |
52 | + should 'echo raw project' do | |
53 | + project = ProjectFixtures.qt_calculator | |
54 | + echoed = @port.request(:echo_raw_project, {:project => project.to_hash})[:project] | |
55 | + project.name = "echo " + project.name | |
56 | + project.state = nil | |
57 | + project.error = nil | |
58 | + assert_equal project, Kalibro::Entities::Project.from_hash(echoed) | |
59 | + end | |
60 | + | |
61 | + should 'work with enums' do | |
62 | + test_granularity("METHOD", "CLASS") | |
63 | + test_granularity("CLASS", "PACKAGE") | |
64 | + test_granularity("PACKAGE", "PACKAGE") | |
65 | + test_granularity("APPLICATION", "APPLICATION") | |
66 | + end | |
67 | + | |
68 | + private | |
69 | + | |
70 | + def test_metric_configuration(fixture) | |
71 | + test fixture, 'MetricConfiguration' do |metric_configuration| | |
72 | + metric_configuration.code = "echo_" + metric_configuration.code | |
73 | + end | |
74 | + end | |
75 | + | |
76 | + def test(fixture, entity_name) | |
77 | + entity_symbol = entity_name.underscore.to_sym | |
78 | + request_body = {entity_symbol => fixture.to_hash} | |
79 | + echoed = @port.request("echo_#{entity_symbol}".to_sym, request_body)[entity_symbol] | |
80 | + yield fixture | |
81 | + entity_class = "Kalibro::Entities::#{entity_name}".constantize | |
82 | + assert_equal fixture, entity_class.from_hash(echoed) | |
83 | + end | |
84 | + | |
85 | + def test_granularity(granularity, parent) | |
86 | + body = {:granularity => granularity} | |
87 | + assert_equal parent, @port.request(:infer_parent_granularity, body)[:parent_granularity] | |
88 | + end | |
89 | + | |
90 | +end | ... | ... |
plugins/mezuro/test/features/editing_configuration.feature
0 → 100644
... | ... | @@ -0,0 +1,49 @@ |
1 | +Feature: editing a configuration | |
2 | + As a mezuro user | |
3 | + I want to edit a Kalibro configuration | |
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 | + And I am on My Community's cms | |
16 | + And I create a content of type "Kalibro configuration" with the following data | |
17 | + | Title | My Configuration | | |
18 | + | Description | A sample description | | |
19 | + And I follow "Add metric" | |
20 | + And I follow "Analizo" | |
21 | + And I follow "Lines of Code" | |
22 | + And I fill in the following: | |
23 | + | Code: | SampleCode | | |
24 | + | Weight: | 10.0 | | |
25 | + And I select "Average" from "Aggregation Form:" | |
26 | + And I press "Add" | |
27 | + And I press "Save" and wait | |
28 | + | |
29 | + Scenario: Keep metrics after editing configuration | |
30 | + When I follow "Edit" within "article-actions" and wait | |
31 | + And I press "Save" | |
32 | + Then I should see "Lines of Code" | |
33 | + | |
34 | + #FIXME: Create new step for this scenario | |
35 | + Scenario: Check if title is edit-disabled | |
36 | + When I follow "Edit" within "article-actions" and wait | |
37 | + And I fill in the following: | |
38 | + | Title | Some Title | | |
39 | + And I press "Save" and wait | |
40 | + Then I should not see "Some Title" | |
41 | + | |
42 | + | |
43 | + Scenario: Check if description is edit-enabled | |
44 | + When I follow "Edit" within "article-actions" and wait | |
45 | + And I fill in the following: | |
46 | + | Description | Some Description | | |
47 | + And I press "Save" and wait | |
48 | + Then I should see "Some Description" | |
49 | + And I should see "Lines of Code" | ... | ... |
plugins/mezuro/test/features/removing_metric_configuration.feature
0 → 100644
... | ... | @@ -0,0 +1,32 @@ |
1 | +Feature: Remove a metric configuration from a configuration | |
2 | + As a mezuro user | |
3 | + I want to remove metric configurations from a configuration | |
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 | + And I am on My Community's cms | |
16 | + And I create a content of type "Kalibro configuration" with the following data | |
17 | + | Title | My Configuration | | |
18 | + | Description | A sample description | | |
19 | + When I follow "Add metric" | |
20 | + And I follow "Analizo" | |
21 | + And I follow "Lines of Code" | |
22 | + And I fill in the following: | |
23 | + | Code: | Sample Code | | |
24 | + | Weight: | 10.0 | | |
25 | + And I select "Average" from "Aggregation Form:" | |
26 | + And I press "Add" | |
27 | + And I press "Save" | |
28 | + And I should see "Lines of Code" | |
29 | + | |
30 | + Scenario: I remove a metric configuration | |
31 | + When I follow "Remove" | |
32 | + Then I should not see "Lines of Code" | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +require File.dirname(__FILE__) + '/native_metric_fixtures' | |
2 | + | |
3 | +class BaseToolFixtures | |
4 | + | |
5 | + def self.base_tool | |
6 | + Kalibro::BaseTool.new base_tool_hash | |
7 | + end | |
8 | + | |
9 | + def self.base_tool_hash | |
10 | + {:name => 'Analizo', :supported_metric => [ | |
11 | + NativeMetricFixtures.total_cof_hash, | |
12 | + NativeMetricFixtures.amloc_hash]} | |
13 | + end | |
14 | + | |
15 | +end | ... | ... |
plugins/mezuro/test/fixtures/compound_metric_fixtures.rb
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +class CompoundMetricFixtures | |
2 | + | |
3 | + def self.compound_metric | |
4 | + Kalibro::CompoundMetric.new compound_metric_hash | |
5 | + end | |
6 | + | |
7 | + def self.compound_metric_hash | |
8 | + {:name => 'Structural Complexity', :scope => 'CLASS', :script => 'return 42;', :description => 'Calculate the Structural Complexity of the Code'} | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +require File.dirname(__FILE__) + '/error_fixtures' | |
2 | +require File.dirname(__FILE__) + '/compound_metric_fixtures' | |
3 | + | |
4 | +class CompoundMetricWithErrorFixtures | |
5 | + | |
6 | + def self.compound_metric_with_error | |
7 | + Kalibro::CompoundMetricWithError.new compound_metric_with_error_hash | |
8 | + end | |
9 | + | |
10 | + def self.compound_metric_with_error_hash | |
11 | + {:metric => CompoundMetricFixtures.compound_metric_hash, :error => ErrorFixtures.error_hash, | |
12 | + :attributes! => {:metric => { | |
13 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
14 | + 'xsi:type' => 'kalibro:compoundMetricXml' }, | |
15 | + :error => { | |
16 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
17 | + 'xsi:type' => 'kalibro:errorXml' }}} | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +require File.dirname(__FILE__) + '/metric_configuration_fixtures' | |
2 | + | |
3 | +class ConfigurationFixtures | |
4 | + | |
5 | + def self.configuration | |
6 | + Kalibro::Configuration.new configuration_hash | |
7 | + end | |
8 | + | |
9 | + def self.configuration_hash | |
10 | + { | |
11 | + :name => 'Sample Configuration', | |
12 | + :description => 'Kalibro configuration for Java projects.', | |
13 | + :metric_configuration => [ | |
14 | + MetricConfigurationFixtures.amloc_metric_configuration_hash, | |
15 | + MetricConfigurationFixtures.sc_metric_configuration_hash | |
16 | + ] | |
17 | + } | |
18 | + end | |
19 | + | |
20 | + def self.configuration_content(clone_configuration) | |
21 | + MezuroPlugin::ConfigurationContent.new({ | |
22 | + :name => 'Sample Configuration', | |
23 | + :description => 'Kalibro configuration for Java projects.', | |
24 | + :configuration_to_clone_name => clone_configuration | |
25 | + }) | |
26 | + end | |
27 | + | |
28 | +end | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +require File.dirname(__FILE__) + '/stack_trace_element_fixtures' | |
2 | + | |
3 | +class ErrorFixtures | |
4 | + | |
5 | + def self.error | |
6 | + Kalibro::Error.new error_hash | |
7 | + end | |
8 | + | |
9 | + def self.error_hash | |
10 | + { | |
11 | + :error_class => 'java.lang.Exception', | |
12 | + :message => 'Error message from ErrorTest', | |
13 | + :stack_trace_element => [ | |
14 | + StackTraceElementFixtures.stack_trace_element_hash('my method 1', 42), | |
15 | + StackTraceElementFixtures.stack_trace_element_hash('my method 2', 84) | |
16 | + ] | |
17 | + } | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
plugins/mezuro/test/fixtures/metric_configuration_fixtures.rb
0 → 100644
... | ... | @@ -0,0 +1,47 @@ |
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_metric_configuration | |
8 | + amloc = Kalibro::MetricConfiguration.new amloc_metric_configuration_hash | |
9 | + amloc.configuration_name = "Sample Configuration" | |
10 | + amloc | |
11 | + end | |
12 | + | |
13 | + def self.metric_configuration_without_ranges | |
14 | + amloc = Kalibro::MetricConfiguration.new | |
15 | + { | |
16 | + :metric => NativeMetricFixtures.amloc_hash, | |
17 | + :code => 'amloc', | |
18 | + :weight => 1.0, | |
19 | + :aggregation_form => 'AVERAGE' | |
20 | + } | |
21 | + amloc.configuration_name = "Sample Configuration" | |
22 | + amloc | |
23 | + end | |
24 | + | |
25 | + def self.sc_metric_configuration | |
26 | + sc = Kalibro::MetricConfiguration.new sc_metric_configuration_hash | |
27 | + sc.configuration_name = "Sample Configuration" | |
28 | + sc | |
29 | + end | |
30 | + | |
31 | + def self.amloc_metric_configuration_hash | |
32 | + {:metric => NativeMetricFixtures.amloc_hash, :code => 'amloc', :weight => 1.0, | |
33 | + :aggregation_form => 'AVERAGE', | |
34 | + :range => [RangeFixtures.range_excellent_hash, RangeFixtures.range_bad_hash], | |
35 | + :attributes! => {:metric => { | |
36 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
37 | + 'xsi:type' => 'kalibro:nativeMetricXml' }}} | |
38 | + end | |
39 | + | |
40 | + def self.sc_metric_configuration_hash | |
41 | + {:metric => CompoundMetricFixtures.compound_metric_hash, :code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE', | |
42 | + :attributes! => {:metric => { | |
43 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
44 | + 'xsi:type' => 'kalibro:compoundMetricXml' }}} | |
45 | + end | |
46 | + | |
47 | +end | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
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.native_metric_result | |
8 | + Kalibro::MetricResult.new native_metric_result_hash | |
9 | + end | |
10 | + | |
11 | + def self.compound_metric_result | |
12 | + Kalibro::MetricResult.new compound_metric_result_hash | |
13 | + end | |
14 | + | |
15 | + def self.native_metric_result_hash | |
16 | + { | |
17 | + :metric => NativeMetricFixtures.amloc_hash, | |
18 | + :value => 0.0, | |
19 | + :descendent_result => [40.0, 42.0], | |
20 | + :range => RangeFixtures.range_excellent_hash, | |
21 | + :attributes! => { | |
22 | + :metric => { | |
23 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
24 | + 'xsi:type' => 'kalibro:nativeMetricXml' }, | |
25 | + :range => { | |
26 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
27 | + 'xsi:type' => 'kalibro:rangeXml' } | |
28 | + } | |
29 | + } | |
30 | + end | |
31 | + | |
32 | + def self.compound_metric_result_hash | |
33 | + { | |
34 | + :metric => CompoundMetricFixtures.compound_metric_hash, | |
35 | + :value => 1.0, | |
36 | + :descendent_result => [2.0, 42.0], | |
37 | + :attributes! => { | |
38 | + :metric => { | |
39 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
40 | + 'xsi:type' => 'kalibro:compoundMetricXml' } | |
41 | + } | |
42 | + } | |
43 | + end | |
44 | + | |
45 | +end | ... | ... |
... | ... | @@ -0,0 +1,47 @@ |
1 | +require File.dirname(__FILE__) + '/module_fixtures' | |
2 | + | |
3 | +class ModuleNodeFixtures | |
4 | + | |
5 | + def self.module_node | |
6 | + Kalibro::ModuleNode.new module_node_hash | |
7 | + end | |
8 | + | |
9 | + def self.module_node_hash | |
10 | + { | |
11 | + :module => ModuleFixtures.module_hash,:attributes! => {:module => { | |
12 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
13 | + 'xsi:type' => 'kalibro:moduleXml' }}, | |
14 | + :child => [{ | |
15 | + :module => { | |
16 | + :name => 'org', | |
17 | + :granularity => 'PACKAGE' | |
18 | + },:attributes! => {:module => { | |
19 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
20 | + 'xsi:type' => 'kalibro:moduleXml' }}, | |
21 | + :child => [{ | |
22 | + :module => { | |
23 | + :name => 'org.Window', | |
24 | + :granularity => 'CLASS' | |
25 | + },:attributes! => {:module => { | |
26 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
27 | + 'xsi:type' => 'kalibro:moduleXml' }} | |
28 | + }] | |
29 | + },{ | |
30 | + :module => { | |
31 | + :name => 'Dialog', | |
32 | + :granularity => 'CLASS' | |
33 | + },:attributes! => {:module => { | |
34 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
35 | + 'xsi:type' => 'kalibro:moduleXml' }} | |
36 | + },{ | |
37 | + :module => { | |
38 | + :name => 'main', | |
39 | + :granularity => 'CLASS' | |
40 | + },:attributes! => {:module => { | |
41 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
42 | + 'xsi:type' => 'kalibro:moduleXml' }} | |
43 | + }] | |
44 | + } | |
45 | + end | |
46 | + | |
47 | +end | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
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.module_result | |
8 | + Kalibro::ModuleResult.new module_result_hash | |
9 | + end | |
10 | + | |
11 | + def self.module_result_hash | |
12 | + { | |
13 | + :module => ModuleFixtures.module_hash, | |
14 | + :date => '2011-10-20T18:26:43.151+00:00', | |
15 | + :grade => 10.0, | |
16 | + :metric_result => [ | |
17 | + MetricResultFixtures.native_metric_result_hash, | |
18 | + MetricResultFixtures.compound_metric_result_hash], | |
19 | + :compound_metric_with_error => [CompoundMetricWithErrorFixtures.compound_metric_with_error_hash], | |
20 | + :attributes! => { | |
21 | + :module => { | |
22 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | |
23 | + 'xsi:type' => 'kalibro:moduleXml' } | |
24 | + } | |
25 | + } | |
26 | + end | |
27 | + | |
28 | +end | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +class NativeMetricFixtures | |
2 | + | |
3 | + def self.total_cof | |
4 | + Kalibro::NativeMetric.new total_cof_hash | |
5 | + end | |
6 | + | |
7 | + def self.total_cof_hash | |
8 | + {:name => 'Total Coupling Factor', :scope => 'APPLICATION', :origin => 'Analizo', :language => ['JAVA']} | |
9 | + end | |
10 | + | |
11 | + def self.amloc | |
12 | + Kalibro::NativeMetric.new amloc_hash | |
13 | + end | |
14 | + | |
15 | + def self.amloc_hash | |
16 | + {:name => 'Average Method LOC', :scope => 'CLASS', :origin => 'Analizo', :language => ['JAVA']} | |
17 | + end | |
18 | + | |
19 | +end | ... | ... |
... | ... | @@ -0,0 +1,40 @@ |
1 | +require File.dirname(__FILE__) + '/repository_fixtures' | |
2 | + | |
3 | +class ProjectFixtures | |
4 | + | |
5 | + def self.project | |
6 | + Kalibro::Project.new project_hash | |
7 | + end | |
8 | + | |
9 | + def self.project_hash | |
10 | + { | |
11 | + :name => 'Qt-Calculator', | |
12 | + :license => 'GPL', | |
13 | + :description => 'Calculator for Qt', | |
14 | + :repository => RepositoryFixtures.repository_hash, | |
15 | + :configuration_name => 'Kalibro for Java', | |
16 | + :state => 'READY', | |
17 | + :attributes! => | |
18 | + { | |
19 | + :repository=> | |
20 | + { | |
21 | + "xsi:type"=>"kalibro:repositoryXml", | |
22 | + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance" | |
23 | + } | |
24 | + } | |
25 | + } | |
26 | + end | |
27 | + | |
28 | + def self.project_content | |
29 | + content = MezuroPlugin::ProjectContent.new | |
30 | + content.name = 'Qt-Calculator' | |
31 | + content.license = 'GPL' | |
32 | + content.description = 'Calculator for Qt' | |
33 | + content.repository_type = RepositoryFixtures.repository_hash[:type] | |
34 | + content.repository_url = RepositoryFixtures.repository_hash[:address] | |
35 | + content.configuration_name = 'Kalibro for Java' | |
36 | + content.periodicity_in_days = 1 | |
37 | + content | |
38 | + end | |
39 | + | |
40 | +end | ... | ... |
... | ... | @@ -0,0 +1,35 @@ |
1 | +require File.dirname(__FILE__) + '/project_fixtures' | |
2 | +require File.dirname(__FILE__) + '/module_node_fixtures' | |
3 | +require File.dirname(__FILE__) + '/module_result_fixtures' | |
4 | + | |
5 | +class ProjectResultFixtures | |
6 | + | |
7 | + def self.project_result | |
8 | + Kalibro::ProjectResult.new project_result_hash | |
9 | + end | |
10 | + | |
11 | + def self.project_result_hash | |
12 | + { | |
13 | + :project => ProjectFixtures.project_hash, | |
14 | + :date => ModuleResultFixtures.module_result_hash[:date], | |
15 | + :load_time => 14878, | |
16 | + :analysis_time => 1022, | |
17 | + :source_tree => ModuleNodeFixtures.module_node_hash, | |
18 | + :collect_time => 14878, | |
19 | + :attributes! => | |
20 | + { | |
21 | + :source_tree => | |
22 | + { | |
23 | + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", | |
24 | + "xsi:type"=>"kalibro:moduleNodeXml" | |
25 | + }, | |
26 | + :project => | |
27 | + { | |
28 | + "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", | |
29 | + "xsi:type"=>"kalibro:projectXml" | |
30 | + } | |
31 | + } | |
32 | + } | |
33 | + end | |
34 | + | |
35 | +end | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +class RangeFixtures | |
2 | + | |
3 | + Infinity = 1.0/0.0 | |
4 | + | |
5 | + def self.range_excellent | |
6 | + Kalibro::Range.new range_excellent_hash | |
7 | + end | |
8 | + | |
9 | + def self.range_bad | |
10 | + Kalibro::Range.new range_bad_hash | |
11 | + end | |
12 | + | |
13 | + def self.range_excellent_hash | |
14 | + {:beginning => 0.0, :end => 7.0, :label => 'Excellent', :grade => 10.0, :color => 'ff00ff00'} | |
15 | + end | |
16 | + | |
17 | + def self.range_bad_hash | |
18 | + {:beginning => 19.5, :end => "INF", :label => 'Bad',:grade => 0.0, :color => 'ffff0000'} | |
19 | + end | |
20 | + | |
21 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +class RepositoryFixtures | |
2 | + | |
3 | + def self.repository | |
4 | + Kalibro::Repository.new repository_hash | |
5 | + end | |
6 | + | |
7 | + def self.repository_hash | |
8 | + {:type => 'SUBVERSION', :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
plugins/mezuro/test/fixtures/stack_trace_element_fixtures.rb
0 → 100644
... | ... | @@ -0,0 +1,16 @@ |
1 | +class StackTraceElementFixtures | |
2 | + | |
3 | + def self.stack_trace_element(method_name = 'my method name', line_number = 42) | |
4 | + Kalibro::StackTraceElement.new stack_trace_element_hash(method_name, line_number) | |
5 | + end | |
6 | + | |
7 | + def self.stack_trace_element_hash(method_name = 'my method name', line_number = 42) | |
8 | + { | |
9 | + :declaring_class => 'my.declaring.Class', | |
10 | + :method_name => method_name, | |
11 | + :file_name => 'MyFile.java', | |
12 | + :line_number => line_number | |
13 | + } | |
14 | + end | |
15 | + | |
16 | +end | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
0 → 100644
... | ... | @@ -0,0 +1,228 @@ |
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 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
9 | + | |
10 | +class MezuroPluginMyprofileControllerTest < ActionController::TestCase | |
11 | + | |
12 | + def setup | |
13 | + @controller = MezuroPluginMyprofileController.new | |
14 | + @request = ActionController::TestRequest.new | |
15 | + @response = ActionController::TestResponse.new | |
16 | + @profile = fast_create(Community) | |
17 | + | |
18 | + @base_tool = BaseToolFixtures.base_tool | |
19 | + @base_tool_hash = BaseToolFixtures.base_tool_hash | |
20 | + @metric = NativeMetricFixtures.amloc | |
21 | + @metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration | |
22 | + @metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash | |
23 | + @compound_metric_configuration = MetricConfigurationFixtures.sc_metric_configuration | |
24 | + @compound_metric_configuration_hash = MetricConfigurationFixtures.sc_metric_configuration_hash | |
25 | + @configuration = ConfigurationFixtures.configuration | |
26 | + @configuration_hash = ConfigurationFixtures.configuration_hash | |
27 | + | |
28 | + Kalibro::Configuration.expects(:all_names).returns([]) | |
29 | + @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name) | |
30 | + @content.expects(:send_configuration_to_service).returns(nil) | |
31 | + @content.stubs(:solr_save) | |
32 | + @content.save | |
33 | + | |
34 | + @native_hash = @metric_configuration.to_hash.merge({:configuration_name => @metric_configuration.configuration_name}) | |
35 | + @native_hash.delete :attributes! | |
36 | + @compound_hash = @compound_metric_configuration.to_hash.merge({:configuration_name => @compound_metric_configuration.configuration_name}) | |
37 | + @compound_hash.delete :attributes! | |
38 | + | |
39 | + @range = RangeFixtures.range_excellent | |
40 | + @range_hash = RangeFixtures.range_excellent_hash | |
41 | + end | |
42 | + | |
43 | + should 'test choose base tool' do | |
44 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name}) | |
45 | + get :choose_base_tool, :profile => @profile.identifier, :id => @content.id | |
46 | + assert_equal [@base_tool.name], assigns(:base_tools) | |
47 | + assert_equal @content, assigns(:configuration_content) | |
48 | + assert_response 200 | |
49 | + end | |
50 | + | |
51 | + should 'test choose metric' do | |
52 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash}) | |
53 | + get :choose_metric, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name | |
54 | + assert_equal @content, assigns(:configuration_content) | |
55 | + assert_equal @base_tool.name, assigns(:base_tool) | |
56 | + assert_equal @base_tool.supported_metric[0].name, assigns(:supported_metrics)[0].name | |
57 | + assert_response 200 | |
58 | + end | |
59 | + | |
60 | + should 'test new metric configuration' do | |
61 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash}) | |
62 | + get :new_metric_configuration, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name, :metric_name => @metric.name | |
63 | + assert_equal @content, assigns(:configuration_content) | |
64 | + assert_equal @metric.name, assigns(:metric).name | |
65 | + assert_response 200 | |
66 | + end | |
67 | + | |
68 | + | |
69 | + should 'test new compound metric configuration' do | |
70 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, {:configuration_name => @content.name}).returns({:configuration => @configuration_hash}) | |
71 | + get :new_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id | |
72 | + assert_equal @content, assigns(:configuration_content) | |
73 | + assert_equal @configuration.metric_configuration[0].code, assigns(:metric_configurations)[0].code | |
74 | + assert_response 200 | |
75 | + end | |
76 | + | |
77 | + should 'test edit metric configuration' do | |
78 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
79 | + :configuration_name => @content.name, | |
80 | + :metric_name => @metric_configuration.metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
81 | + get :edit_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
82 | + assert_equal @content, assigns(:configuration_content) | |
83 | + assert_equal @metric_configuration.code, assigns(:metric_configuration).code | |
84 | + assert_equal @metric_configuration.metric.name, assigns(:metric).name | |
85 | + assert_response 200 | |
86 | + end | |
87 | + | |
88 | + should 'test edit compound metric configuration' do | |
89 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
90 | + :configuration_name => @content.name, | |
91 | + :metric_name => @compound_metric_configuration.metric.name}).returns({:metric_configuration => @compound_metric_configuration_hash}) | |
92 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, {:configuration_name => @content.name}).returns({:configuration => @configuration_hash}) | |
93 | + get :edit_compound_metric_configuration, | |
94 | + :profile => @profile.identifier, | |
95 | + :id => @content.id, | |
96 | + :metric_name => @compound_metric_configuration.metric.name | |
97 | + assert_equal @content, assigns(:configuration_content) | |
98 | + assert_equal @compound_metric_configuration.code, assigns(:metric_configuration).code | |
99 | + assert_equal @compound_metric_configuration.metric.name, assigns(:metric).name | |
100 | + assert_equal @configuration.metric_configuration[0].code, assigns(:metric_configurations)[0].code | |
101 | + assert_response 200 | |
102 | + end | |
103 | + | |
104 | + should 'test create native metric configuration' do | |
105 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
106 | + :metric_configuration => @metric_configuration.to_hash, | |
107 | + :configuration_name => @metric_configuration.configuration_name}) | |
108 | + get :create_metric_configuration, | |
109 | + :profile => @profile.identifier, | |
110 | + :id => @content.id, | |
111 | + :metric_configuration => @native_hash | |
112 | + assert_response 302 | |
113 | + end | |
114 | + | |
115 | + should 'test compound metric creation' do | |
116 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
117 | + :metric_configuration => @compound_metric_configuration.to_hash, | |
118 | + :configuration_name => @compound_metric_configuration.configuration_name}) | |
119 | + get :create_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, | |
120 | + :metric_configuration => @compound_hash | |
121 | + assert_response 302 | |
122 | + end | |
123 | + | |
124 | + should 'test update native metric configuration' do | |
125 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
126 | + :configuration_name => @content.name, | |
127 | + :metric_name => @metric_configuration.metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
128 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
129 | + :metric_configuration => @metric_configuration.to_hash, | |
130 | + :configuration_name => @metric_configuration.configuration_name}) | |
131 | + get :update_metric_configuration, :profile => @profile.identifier, :id => @content.id, | |
132 | + :metric_configuration => @native_hash | |
133 | + assert_equal @content, assigns(:configuration_content) | |
134 | + assert_response 302 | |
135 | + end | |
136 | + | |
137 | + should 'test update compound metric configuration' do | |
138 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
139 | + :configuration_name => @content.name, | |
140 | + :metric_name => @compound_metric_configuration.metric.name}).returns({:metric_configuration => @compound_metric_configuration_hash}) | |
141 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
142 | + :metric_configuration => @compound_metric_configuration.to_hash, | |
143 | + :configuration_name => @compound_metric_configuration.configuration_name}) | |
144 | + get :update_compound_metric_configuration, :profile => @profile.identifier, :id => @content.id, | |
145 | + :metric_configuration => @compound_hash | |
146 | + assert_equal @content, assigns(:configuration_content) | |
147 | + assert_response 302 | |
148 | + end | |
149 | + | |
150 | + should 'test remove metric configuration' do | |
151 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
152 | + :configuration_name => @content.name, | |
153 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
154 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :remove_metric_configuration, { | |
155 | + :metric_name => @metric.name, | |
156 | + :configuration_name => @metric_configuration.configuration_name}) | |
157 | + get :remove_metric_configuration, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
158 | + assert_response 302 | |
159 | + end | |
160 | + | |
161 | + should 'test new range' do | |
162 | + get :new_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name | |
163 | + assert_equal @content, assigns(:configuration_content) | |
164 | + assert_equal @metric.name, assigns(:metric_name) | |
165 | + assert_response 200 | |
166 | + end | |
167 | + | |
168 | + should 'test edit range' do | |
169 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
170 | + :configuration_name => @content.name, | |
171 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
172 | + get :edit_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name, :beginning_id => @range.beginning | |
173 | + assert_equal @content, assigns(:configuration_content) | |
174 | + assert_equal @metric.name, assigns(:metric_name) | |
175 | + assert_equal @range.beginning, assigns(:beginning_id) | |
176 | + assert_equal @range.end, assigns(:range).end | |
177 | + assert_response 200 | |
178 | + end | |
179 | + | |
180 | + should 'test create instance range' do | |
181 | + metric_configuration = @metric_configuration | |
182 | + metric_configuration.add_range(@range) | |
183 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
184 | + :configuration_name => @content.name, | |
185 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
186 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
187 | + :metric_configuration => metric_configuration.to_hash, | |
188 | + :configuration_name => metric_configuration.configuration_name}) | |
189 | + get :create_range, :profile => @profile.identifier, :range => @range_hash, :id => @content.id, :metric_name => @metric.name | |
190 | + assert_equal @content, assigns(:configuration_content) | |
191 | + assert_equal @range.end, assigns(:range).end | |
192 | + assert_response 200 | |
193 | + end | |
194 | + | |
195 | + should 'test update range' do | |
196 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
197 | + :configuration_name => @content.name, | |
198 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
199 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
200 | + :metric_configuration => @metric_configuration.to_hash, | |
201 | + :configuration_name => @metric_configuration.configuration_name}) | |
202 | + get :update_range, | |
203 | + :profile => @profile.identifier, | |
204 | + :range => @range_hash, | |
205 | + :id => @content.id, | |
206 | + :metric_name => @metric.name, | |
207 | + :beginning_id => @range.beginning | |
208 | + assert_response 200 | |
209 | + end | |
210 | + | |
211 | + should 'test remove range' do | |
212 | + metric_configuration = @metric_configuration | |
213 | + metric_configuration.ranges.delete_if { |range| range.beginning == @range.beginning.to_f } | |
214 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, { | |
215 | + :configuration_name => @content.name, | |
216 | + :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash}) | |
217 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
218 | + :metric_configuration => metric_configuration.to_hash, | |
219 | + :configuration_name => metric_configuration.configuration_name}) | |
220 | + get :remove_range, | |
221 | + :profile => @profile.identifier, | |
222 | + :id => @content.id, | |
223 | + :metric_name => @metric.name, | |
224 | + :beginning_id => @range.beginning | |
225 | + assert_response 302 | |
226 | + end | |
227 | + | |
228 | +end | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
1 | 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/repository_fixtures" | |
7 | + | |
8 | +class MezuroPluginProfileControllerTest < ActionController::TestCase | |
4 | 9 | |
5 | 10 | def setup |
6 | 11 | @controller = MezuroPluginProfileController.new |
7 | 12 | @request = ActionController::TestRequest.new |
8 | - @response = ActionController::TestResponse.new | |
13 | + @response = ActionController::TestResponse.new | |
9 | 14 | @profile = fast_create(Community) |
10 | - @profile_id = @profile.identifier | |
15 | + | |
16 | + @project_result = ProjectResultFixtures.project_result | |
17 | + @module_result = ModuleResultFixtures.module_result | |
18 | + @repository_url = RepositoryFixtures.repository.address | |
19 | + @project = @project_result.project | |
20 | + @date = "2012-04-13T20:39:41+04:00" | |
21 | + | |
22 | + Kalibro::Project.expects(:all_names).returns([]) | |
23 | + @content = MezuroPlugin::ProjectContent.new(:profile => @profile, :name => @project.name, :repository_url => @repository_url) | |
24 | + @content.expects(:send_project_to_service).returns(nil) | |
25 | + @content.save | |
11 | 26 | end |
12 | 27 | |
13 | -# def test_metrics_for_unknown_module | |
14 | -# get :metrics, :profile => @profile_id, :id => 0 | |
15 | -# assert_response 404 | |
16 | -# end | |
28 | + should 'test project state without error' do | |
29 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | |
30 | + get :project_state, :profile => @profile.identifier, :id => @content.id | |
31 | + assert_response 200 | |
32 | + assert_equal @content, assigns(:content) | |
33 | + end | |
17 | 34 | |
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 | |
35 | + should 'test project state with error' do | |
36 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})}) | |
37 | + get :project_state, :profile => @profile.identifier, :id => @content.id | |
38 | + assert_response 200 | |
39 | + assert_equal "ERROR", @response.body | |
40 | + assert_equal @content, assigns(:content) | |
41 | + end | |
22 | 42 | |
43 | + should 'test project error' do | |
44 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})}) | |
45 | + get :project_error, :profile => @profile.identifier, :id => @content.id | |
46 | + assert_response 200 | |
47 | + assert_select('h3', 'ERROR') | |
48 | + assert_equal @content, assigns(:content) | |
49 | + assert_equal @project.name, assigns(:project).name | |
50 | + end | |
23 | 51 | |
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 | |
52 | + should 'test project result without date' do | |
53 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | |
54 | + get :project_result, :profile => @profile.identifier, :id => @content.id, :date => nil | |
55 | + assert_equal @content, assigns(:content) | |
56 | + assert_equal @project_result.project.name, assigns(:project_result).project.name | |
57 | + assert_response 200 | |
58 | + assert_select('h4', 'Last Result') | |
59 | + end | |
60 | + | |
61 | + should 'test project results from a specific date' do | |
62 | + request_body = {:project_name => @project.name, :date => @date} | |
63 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | |
64 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | |
65 | + get :project_result, :profile => @profile.identifier, :id => @content.id, :date => @date | |
66 | + assert_equal @content, assigns(:content) | |
67 | + assert_equal @project_result.project.name, assigns(:project_result).project.name | |
68 | + assert_response 200 | |
69 | + assert_select('h4', 'Last Result') | |
70 | + end | |
30 | 71 | |
31 | - protected | |
32 | 72 | |
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') | |
73 | + should 'get module result without date' do | |
74 | + date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | |
75 | + Kalibro::ProjectResult.expects(:request). | |
76 | + with("ProjectResult", :get_last_result_of, {:project_name => @project.name}). | |
77 | + returns({:project_result => @project_result.to_hash}) | |
78 | + Kalibro::ModuleResult.expects(:request). | |
79 | + with("ModuleResult", :get_module_result, {:project_name => @project.name, :module_name => @project.name, :date => date_with_milliseconds}). | |
80 | + returns({:module_result => @module_result.to_hash}) | |
81 | + get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil | |
82 | + assert_equal @content, assigns(:content) | |
83 | + assert_equal @module_result.grade, assigns(:module_result).grade | |
84 | + assert_response 200 | |
85 | + assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') | |
86 | + end | |
36 | 87 | |
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 | |
88 | + should 'get module result with a specific date' do | |
89 | + date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | |
90 | + request_body = {:project_name => @project.name, :date => @project_result.date} | |
91 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | |
92 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | |
93 | + Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_module_result, {:project_name => @project.name, :module_name => @project.name, :date => date_with_milliseconds}).returns({:module_result => @module_result.to_hash}) | |
94 | + get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date | |
95 | + assert_equal @content, assigns(:content) | |
96 | + assert_equal @module_result.grade, assigns(:module_result).grade | |
97 | + assert_response 200 | |
98 | + assert_select('h5', 'Metric results for: Qt-Calculator (APPLICATION)') | |
99 | + end | |
43 | 100 | |
44 | - MezuroPlugin::ProjectContent.any_instance.stubs(:project_content).returns(project_content) | |
45 | - project_content | |
101 | + should 'test project tree without date' do | |
102 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | |
103 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | |
104 | + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => nil | |
105 | + assert_equal @content, assigns(:content) | |
106 | + assert_equal @project.name, assigns(:project_name) | |
107 | + assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name | |
108 | + assert_response 200 | |
109 | + assert_select('h2', /Qt-Calculator/) | |
46 | 110 | end |
47 | - | |
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 | |
111 | + | |
112 | + should 'test project tree with a specific date' do | |
113 | + request_body = {:project_name => @project.name, :date => @project_result.date} | |
114 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | |
115 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | |
116 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | |
117 | + get :project_tree, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, :date => @project_result.date | |
118 | + assert_equal @content, assigns(:content) | |
119 | + assert_equal @project.name, assigns(:project_name) | |
120 | + assert_equal @project_result.source_tree.module.name, assigns(:source_tree).module.name | |
121 | + assert_response 200 | |
56 | 122 | end |
57 | 123 | |
58 | - def create_repository | |
59 | - repository = Kalibro::Entities::Repository.new | |
60 | - repository.type = 'git' | |
61 | - repository.address = 'http://git.git' | |
62 | - repository | |
124 | + should 'test module metrics history' do | |
125 | + Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result}) | |
126 | + get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, | |
127 | + :metric_name => @module_result.metric_result.first.metric.name.delete("() ") | |
128 | + assert_equal @content, assigns(:content) | |
129 | + assert_equal [@module_result.metric_result[0].value], assigns(:score_history) | |
130 | + assert_response 200 | |
63 | 131 | 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 | |
132 | + | |
133 | + should 'test grade history' do | |
134 | + Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result}) | |
135 | + get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name | |
136 | + assert_equal @content, assigns(:content) | |
137 | + assert_equal [@module_result.grade], assigns(:score_history) | |
138 | + assert_response 200 | |
139 | + end | |
140 | + | |
68 | 141 | end | ... | ... |
plugins/mezuro/test/mezuro_test.rb
... | ... | @@ -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 |
... | ... | @@ -0,0 +1,36 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/base_tool_fixtures" | |
4 | + | |
5 | +class BaseToolTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = BaseToolFixtures.base_tool_hash | |
9 | + @base_tool = BaseToolFixtures.base_tool | |
10 | + end | |
11 | + | |
12 | + should 'create base tool from hash' do | |
13 | + assert_equal @base_tool.name, Kalibro::BaseTool.new(@hash).name | |
14 | + end | |
15 | + | |
16 | + should 'convert base tool to hash' do | |
17 | + assert_equal @hash, @base_tool.to_hash | |
18 | + end | |
19 | + | |
20 | + should 'get base tool names' do | |
21 | + names = ['Analizo', 'Checkstyle'] | |
22 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => names}) | |
23 | + assert_equal names, Kalibro::BaseTool.all_names | |
24 | + end | |
25 | + | |
26 | + should 'get base tool by name' do | |
27 | + request_body = {:base_tool_name => @base_tool.name} | |
28 | + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, request_body).returns({:base_tool => @hash}) | |
29 | + assert_equal @base_tool.name, Kalibro::BaseTool.find_by_name(@base_tool.name).name | |
30 | + end | |
31 | + | |
32 | + should 'get base tool metrics' do | |
33 | + assert_equal @base_tool.supported_metrics[0].name, @base_tool.metric('Total Coupling Factor').name | |
34 | + end | |
35 | + | |
36 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/client/base_tool_client_test.rb
... | ... | @@ -1,34 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class BaseToolClientTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - @port = mock | |
6 | - Kalibro::Client::Port.expects(:new).with('BaseTool').returns(@port) | |
7 | - @client = Kalibro::Client::BaseToolClient.new | |
8 | - end | |
9 | - | |
10 | - should 'get base tool names (zero)' do | |
11 | - @port.expects(:request).with(:get_base_tool_names).returns({}) | |
12 | - assert_equal [], @client.base_tool_names | |
13 | - end | |
14 | - | |
15 | - should 'get base tool names (one)' do | |
16 | - name = 'Analizo' | |
17 | - @port.expects(:request).with(:get_base_tool_names).returns({:base_tool_name => name}) | |
18 | - assert_equal [name], @client.base_tool_names | |
19 | - end | |
20 | - | |
21 | - should 'get base tool names' do | |
22 | - names = ['Analizo', 'Checkstyle'] | |
23 | - @port.expects(:request).with(:get_base_tool_names).returns({:base_tool_name => names}) | |
24 | - assert_equal names, @client.base_tool_names | |
25 | - end | |
26 | - | |
27 | - should 'get base tool by name' do | |
28 | - analizo = BaseToolTest.analizo | |
29 | - request_body = {:base_tool_name => 'Analizo'} | |
30 | - @port.expects(:request).with(:get_base_tool, request_body).returns({:base_tool => analizo.to_hash}) | |
31 | - assert_equal analizo, @client.base_tool('Analizo') | |
32 | - end | |
33 | - | |
34 | -end | |
35 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/client/configuration_client_test.rb
... | ... | @@ -1,47 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ConfigurationClientTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - @port = mock | |
6 | - Kalibro::Client::Port.expects(:new).with('Configuration').returns(@port) | |
7 | - @client = Kalibro::Client::ConfigurationClient.new | |
8 | - end | |
9 | - | |
10 | - should 'save configuration' do | |
11 | - configuration = ConfigurationTest.kalibro_configuration | |
12 | - @port.expects(:request).with(:save_configuration, {:configuration => configuration.to_hash}) | |
13 | - @client.save(configuration) | |
14 | - end | |
15 | - | |
16 | - should 'get configuration names (zero)' do | |
17 | - @port.expects(:request).with(:get_configuration_names).returns({}) | |
18 | - assert_equal [], @client.configuration_names | |
19 | - end | |
20 | - | |
21 | - should 'get configuration names (one)' do | |
22 | - name = 'Kalibro for Java' | |
23 | - @port.expects(:request).with(:get_configuration_names).returns({:configuration_name => name}) | |
24 | - assert_equal [name], @client.configuration_names | |
25 | - end | |
26 | - | |
27 | - should 'get configuration names' do | |
28 | - names = ['Kalibro for Java', 'ConfigurationClientTest configuration'] | |
29 | - @port.expects(:request).with(:get_configuration_names).returns({:configuration_name => names}) | |
30 | - assert_equal names, @client.configuration_names | |
31 | - end | |
32 | - | |
33 | - should 'get configuration by name' do | |
34 | - configuration = ConfigurationTest.kalibro_configuration | |
35 | - request_body = {:configuration_name => configuration.name} | |
36 | - response_hash = {:configuration => configuration.to_hash} | |
37 | - @port.expects(:request).with(:get_configuration, request_body).returns(response_hash) | |
38 | - assert_equal configuration, @client.configuration(configuration.name) | |
39 | - end | |
40 | - | |
41 | - should 'remove configuration by name' do | |
42 | - name = 'ConfigurationClientTest' | |
43 | - @port.expects(:request).with(:remove_configuration, {:configuration_name => name}) | |
44 | - @client.remove(name) | |
45 | - end | |
46 | - | |
47 | -end | |
48 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/client/kalibro_client_test.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class KalibroClientTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - @port = mock | |
6 | - Kalibro::Client::Port.expects(:new).with('Kalibro').returns(@port) | |
7 | - @client = Kalibro::Client::KalibroClient.new | |
8 | - end | |
9 | - | |
10 | - should 'get supported repository types' do | |
11 | - types = ['BAZAAR', 'GIT', 'SUBVERSION'] | |
12 | - @port.expects(:request).with(:get_supported_repository_types).returns({:repository_type => types}) | |
13 | - assert_equal types, @client.supported_repository_types | |
14 | - end | |
15 | - | |
16 | - should 'process project' do | |
17 | - name = 'KalibroClientTest' | |
18 | - @port.expects(:request).with(:process_project, {:project_name => name}) | |
19 | - @client.process_project(name) | |
20 | - end | |
21 | - | |
22 | - should 'instantiate for processing project' do | |
23 | - instance = mock | |
24 | - Kalibro::Client::KalibroClient.expects(:new).returns(instance) | |
25 | - instance.expects(:process_project).with('myproject') | |
26 | - Kalibro::Client::KalibroClient.process_project('myproject') | |
27 | - end | |
28 | - | |
29 | -end |
plugins/mezuro/test/unit/kalibro/client/module_result_client_test.rb
... | ... | @@ -1,27 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ModuleResultClientTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - @port = mock | |
6 | - Kalibro::Client::Port.expects(:new).with('ModuleResult').returns(@port) | |
7 | - @client = Kalibro::Client::ModuleResultClient.new | |
8 | - @result = ModuleResultTest.fixture | |
9 | - end | |
10 | - | |
11 | - should 'get module result' do | |
12 | - date_string = '2012-01-10T16:07:15.442-02:00' | |
13 | - date = DateTime.parse(date_string) | |
14 | - request_body = {:project_name => 'Qt-Calculator', :module_name => 'main', :date => date_string} | |
15 | - response = {:module_result => @result.to_hash} | |
16 | - @port.expects(:request).with(:get_module_result, request_body).returns(response) | |
17 | - assert_equal @result, @client.module_result('Qt-Calculator', 'main', date) | |
18 | - end | |
19 | - | |
20 | - should 'get result history' do | |
21 | - request_body = {:project_name => 'Qt-Calculator', :module_name => 'main'} | |
22 | - response = {:module_result => @result.to_hash} | |
23 | - @port.expects(:request).with(:get_result_history, request_body).returns(response) | |
24 | - assert_equal [@result], @client.result_history('Qt-Calculator', 'main') | |
25 | - end | |
26 | - | |
27 | -end | |
28 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/client/port_test.rb
... | ... | @@ -1,33 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class PortTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - @client = mock | |
6 | - set_default_address | |
7 | - Savon::Client.expects(:new).with("#{@default_address}PortTestEndpoint/?wsdl").returns(@client) | |
8 | - @port = Kalibro::Client::Port.new('PortTest') | |
9 | - end | |
10 | - | |
11 | - | |
12 | - should 'get default address' do | |
13 | - assert_equal @default_address, @port.service_address | |
14 | - end | |
15 | - | |
16 | - should 'request action and return response' do | |
17 | - response_body = {:port_test_response_key => 'PortTest response value'} | |
18 | - response_hash = {:port_test_action_response => response_body} | |
19 | - response = mock | |
20 | - response.expects(:to_hash).returns(response_hash) | |
21 | - @client.expects(:request).with(:kalibro, :port_test_action).returns(response) | |
22 | - | |
23 | - assert_equal response_body, @port.request(:port_test_action) | |
24 | - end | |
25 | - | |
26 | - private | |
27 | - | |
28 | - def set_default_address | |
29 | - service_file = "#{RAILS_ROOT}/plugins/mezuro/SERVICE" | |
30 | - File.open(service_file).each_line{ | line | @default_address = line } | |
31 | - end | |
32 | - | |
33 | -end | |
34 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/client/project_client_test.rb
... | ... | @@ -1,55 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ProjectClientTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - @port = mock | |
6 | - Kalibro::Client::Port.expects(:new).with('Project').returns(@port) | |
7 | - @client = Kalibro::Client::ProjectClient.new | |
8 | - end | |
9 | - | |
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) | |
14 | - 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 | - end | |
20 | - | |
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 | |
25 | - end | |
26 | - | |
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 | |
31 | - end | |
32 | - | |
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 | - end | |
40 | - | |
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 | |
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) | |
53 | - end | |
54 | - | |
55 | -end |
plugins/mezuro/test/unit/kalibro/client/project_result_client_test.rb
... | ... | @@ -1,68 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ProjectResultClientTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - @port = mock | |
6 | - Kalibro::Client::Port.expects(:new).with('ProjectResult').returns(@port) | |
7 | - @client = Kalibro::Client::ProjectResultClient.new | |
8 | - | |
9 | - @result = ProjectResultTest.qt_calculator | |
10 | - @project_name = @result.project.name | |
11 | - @date = @result.date | |
12 | - @flag = DateTime.now.sec % 2 == 0 | |
13 | - end | |
14 | - | |
15 | - should 'retrieve if project has results' do | |
16 | - @port.expects(:request).with(:has_results_for, request).returns(flag_response) | |
17 | - assert_equal @flag, @client.has_results_for(@project_name) | |
18 | - end | |
19 | - | |
20 | - should 'retrieve if project has results before date' do | |
21 | - @port.expects(:request).with(:has_results_before, request_with_date).returns(flag_response) | |
22 | - assert_equal @flag, @client.has_results_before(@project_name, @date) | |
23 | - end | |
24 | - | |
25 | - should 'retrieve if project has results after date' do | |
26 | - @port.expects(:request).with(:has_results_after, request_with_date).returns(flag_response) | |
27 | - assert_equal @flag, @client.has_results_after(@project_name, @date) | |
28 | - end | |
29 | - | |
30 | - should 'get first result of project' do | |
31 | - @port.expects(:request).with(:get_first_result_of, request).returns(result_response) | |
32 | - assert_equal @result, @client.first_result(@project_name) | |
33 | - end | |
34 | - | |
35 | - should 'get last result of project' do | |
36 | - @port.expects(:request).with(:get_last_result_of, request).returns(result_response) | |
37 | - assert_equal @result, @client.last_result(@project_name) | |
38 | - end | |
39 | - | |
40 | - should 'get first result of project after date' do | |
41 | - @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) | |
43 | - end | |
44 | - | |
45 | - should 'get last result of project before date' do | |
46 | - @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) | |
48 | - end | |
49 | - | |
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 | |
69 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/compound_metric_test.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_fixtures" | |
4 | + | |
5 | +class CompoundMetricTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = CompoundMetricFixtures.compound_metric_hash | |
9 | + @metric = CompoundMetricFixtures.compound_metric | |
10 | + end | |
11 | + | |
12 | + should 'create compound metric from hash' do | |
13 | + assert_equal @hash[:script], Kalibro::CompoundMetric.new(@hash).script | |
14 | + end | |
15 | + | |
16 | + should 'convert compound metric to hash' do | |
17 | + assert_equal @hash, @metric.to_hash | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/compound_metric_with_error_test.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/compound_metric_with_error_fixtures" | |
4 | + | |
5 | +class CompoundMetricWithErrorTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = CompoundMetricWithErrorFixtures.compound_metric_with_error_hash | |
9 | + @compound_metric_with_error = CompoundMetricWithErrorFixtures.compound_metric_with_error | |
10 | + end | |
11 | + | |
12 | + should 'create error from hash' do | |
13 | + assert_equal @hash[:error][:message], Kalibro::CompoundMetricWithError.new(@hash).error.message | |
14 | + end | |
15 | + | |
16 | + should 'convert error to hash' do | |
17 | + assert_equal @hash, @compound_metric_with_error.to_hash | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
... | ... | @@ -0,0 +1,54 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | |
4 | + | |
5 | +class ConfigurationTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = ConfigurationFixtures.configuration_hash | |
9 | + @configuration = ConfigurationFixtures.configuration | |
10 | + @configuration_content = ConfigurationFixtures.configuration_content([]) | |
11 | + end | |
12 | + | |
13 | + should 'initialize configuration' do | |
14 | + assert_equal @hash[:name], Kalibro::Configuration.new(@hash).name | |
15 | + end | |
16 | + | |
17 | + should 'convert configuration to hash' do | |
18 | + assert_equal @hash, @configuration.to_hash | |
19 | + end | |
20 | + | |
21 | + should 'return true when configuration is saved successfully' do | |
22 | + Kalibro::Configuration.expects(:request).with("Configuration", :save_configuration, {:configuration => @configuration.to_hash}) | |
23 | + assert @configuration.save | |
24 | + end | |
25 | + | |
26 | + should 'return false when configuration is not saved successfully' do | |
27 | + Kalibro::Configuration.expects(:request).with("Configuration", :save_configuration, {:configuration => @configuration.to_hash}).raises(Exception.new) | |
28 | + assert !(@configuration.save) | |
29 | + end | |
30 | + | |
31 | + should 'get all configuration names' do | |
32 | + names = ['Kalibro for Java', 'ConfigurationClientTest configuration'] | |
33 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration_names).returns({:configuration_name => names}) | |
34 | + assert_equal names, Kalibro::Configuration.all_names | |
35 | + end | |
36 | + | |
37 | + should 'find configuration by name' do | |
38 | + request_body = {:configuration_name => @configuration.name} | |
39 | + response_hash = {:configuration => @configuration.to_hash} | |
40 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).returns(response_hash) | |
41 | + assert_equal @configuration.name, Kalibro::Configuration.find_by_name(@configuration.name).name | |
42 | + end | |
43 | + | |
44 | + should 'return nil when configuration doesnt exist' do | |
45 | + request_body = {:configuration_name => @configuration.name} | |
46 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).raises(Exception.new) | |
47 | + assert_nil Kalibro::Configuration.find_by_name(@configuration.name) | |
48 | + end | |
49 | + | |
50 | + should 'destroy configuration by name' do | |
51 | + Kalibro::Configuration.expects(:request).with("Configuration", :remove_configuration, {:configuration_name => @configuration.name}) | |
52 | + @configuration.destroy | |
53 | + end | |
54 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/entities/base_tool_test.rb
... | ... | @@ -1,33 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class BaseToolTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
12 | - | |
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 | |
19 | - | |
20 | - def setup | |
21 | - @hash = self.class.analizo_hash | |
22 | - @base_tool = self.class.analizo | |
23 | - end | |
24 | - | |
25 | - should 'create base tool from hash' do | |
26 | - assert_equal @base_tool, Kalibro::Entities::BaseTool.from_hash(@hash) | |
27 | - end | |
28 | - | |
29 | - should 'convert base tool to hash' do | |
30 | - assert_equal @hash, @base_tool.to_hash | |
31 | - end | |
32 | - | |
33 | -end | |
34 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/compound_metric_test.rb
... | ... | @@ -1,30 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class CompoundMetricTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
11 | - | |
12 | - def self.sc_hash | |
13 | - {:name => 'Structural Complexity', :scope => 'CLASS', | |
14 | - :script => 'return cbo * lcom4;'} | |
15 | - end | |
16 | - | |
17 | - def setup | |
18 | - @hash = self.class.sc_hash | |
19 | - @metric = self.class.sc | |
20 | - end | |
21 | - | |
22 | - should 'create compound metric from hash' do | |
23 | - assert_equal @metric, Kalibro::Entities::CompoundMetric.from_hash(@hash) | |
24 | - end | |
25 | - | |
26 | - should 'convert compound metric to hash' do | |
27 | - assert_equal @hash, @metric.to_hash | |
28 | - end | |
29 | - | |
30 | -end | |
31 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/compound_metric_with_error_test.rb
... | ... | @@ -1,29 +0,0 @@ |
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 | - | |
11 | - def self.fixture_hash | |
12 | - {:metric => CompoundMetricTest.sc_hash, | |
13 | - :error => ErrorTest.fixture_hash} | |
14 | - end | |
15 | - | |
16 | - def setup | |
17 | - @hash = self.class.fixture_hash | |
18 | - @entity = self.class.fixture | |
19 | - end | |
20 | - | |
21 | - should 'create error from hash' do | |
22 | - assert_equal @entity, Kalibro::Entities::CompoundMetricWithError.from_hash(@hash) | |
23 | - end | |
24 | - | |
25 | - should 'convert error to hash' do | |
26 | - assert_equal @hash, @entity.to_hash | |
27 | - end | |
28 | - | |
29 | -end |
plugins/mezuro/test/unit/kalibro/entities/configuration_test.rb
... | ... | @@ -1,35 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ConfigurationTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
13 | - | |
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 | |
21 | - | |
22 | - def setup | |
23 | - @hash = self.class.kalibro_configuration_hash | |
24 | - @configuration = self.class.kalibro_configuration | |
25 | - end | |
26 | - | |
27 | - should 'create configuration from hash' do | |
28 | - assert_equal @configuration, Kalibro::Entities::Configuration.from_hash(@hash) | |
29 | - end | |
30 | - | |
31 | - should 'convert configuration to hash' do | |
32 | - assert_equal @hash, @configuration.to_hash | |
33 | - end | |
34 | - | |
35 | -end | |
36 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/entity_test.rb
... | ... | @@ -1,50 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class EntityTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - @hash = {:name => 'Carlos', :age => 25, | |
6 | - :brothers => [{:name => 'Saulo', :age => 22}, {:name => 'Isis', :age => 26}]} | |
7 | - @person = Person.create('Carlos', 25) | |
8 | - @person.brothers = [Person.create('Saulo', 22), Person.create('Isis', 26)] | |
9 | - @clone = @person.clone | |
10 | - end | |
11 | - | |
12 | - should 'be equal to clone' do | |
13 | - assert_equal @person, @clone | |
14 | - end | |
15 | - | |
16 | - should 'be different when field is different' do | |
17 | - @clone.name = 'Other' | |
18 | - assert @person != @clone | |
19 | - end | |
20 | - | |
21 | - should 'not throw exception when comparing with incompatible object' do | |
22 | - assert @person != @hash | |
23 | - end | |
24 | - | |
25 | - should 'create from hash' do | |
26 | - assert_equal @person, Person.from_hash(@hash) | |
27 | - end | |
28 | - | |
29 | - should 'convert to hash' do | |
30 | - assert_equal @hash, @person.to_hash | |
31 | - end | |
32 | - | |
33 | - class Person < Kalibro::Entities::Entity | |
34 | - | |
35 | - attr_accessor :name, :age, :brothers | |
36 | - | |
37 | - def self.create(name, age) | |
38 | - person = Person.new | |
39 | - person.name = name | |
40 | - person.age = age | |
41 | - person | |
42 | - end | |
43 | - | |
44 | - def brothers=(value) | |
45 | - @brothers = to_entity_array(value, Person) | |
46 | - end | |
47 | - | |
48 | - end | |
49 | - | |
50 | -end | |
51 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/error_test.rb
... | ... | @@ -1,33 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ErrorTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
12 | - | |
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 | |
19 | - | |
20 | - def setup | |
21 | - @hash = self.class.fixture_hash | |
22 | - @error = self.class.fixture | |
23 | - end | |
24 | - | |
25 | - should 'create error from hash' do | |
26 | - assert_equal @error, Kalibro::Entities::Error.from_hash(@hash) | |
27 | - end | |
28 | - | |
29 | - should 'convert error to hash' do | |
30 | - assert_equal @hash, @error.to_hash | |
31 | - end | |
32 | - | |
33 | -end | |
34 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/metric_configuration_test.rb
... | ... | @@ -1,56 +0,0 @@ |
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 | - | |
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 | |
32 | - | |
33 | - def self.sc_configuration_hash | |
34 | - {:metric => CompoundMetricTest.sc_hash, | |
35 | - :code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE'} | |
36 | - end | |
37 | - | |
38 | - def setup | |
39 | - @hash = self.class.amloc_configuration_hash | |
40 | - @range = self.class.amloc_configuration | |
41 | - end | |
42 | - | |
43 | - should 'create metric configuration from hash' do | |
44 | - assert_equal @range, Kalibro::Entities::MetricConfiguration.from_hash(@hash) | |
45 | - end | |
46 | - | |
47 | - should 'convert metric configuration to hash' do | |
48 | - assert_equal @hash, @range.to_hash | |
49 | - end | |
50 | - | |
51 | - 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) | |
54 | - end | |
55 | - | |
56 | -end |
plugins/mezuro/test/unit/kalibro/entities/metric_result_test.rb
... | ... | @@ -1,55 +0,0 @@ |
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 | - | |
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 | |
26 | - | |
27 | - def self.sc_result_hash | |
28 | - {:metric => CompoundMetricTest.sc_hash, | |
29 | - :value => 1.0, :descendent_result => [2.0, 42.0]} | |
30 | - end | |
31 | - | |
32 | - def setup | |
33 | - @hash = self.class.amloc_result_hash | |
34 | - @result = self.class.amloc_result | |
35 | - end | |
36 | - | |
37 | - should 'create metric result from hash' do | |
38 | - assert_equal @result, Kalibro::Entities::MetricResult.from_hash(@hash) | |
39 | - end | |
40 | - | |
41 | - should 'convert metric result to hash' do | |
42 | - assert_equal @hash, @result.to_hash | |
43 | - end | |
44 | - | |
45 | - 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) | |
48 | - end | |
49 | - | |
50 | - should 'convert single descendent result to array' do | |
51 | - @result.descendent_result = 1 | |
52 | - assert_equal [1], @result.descendent_results | |
53 | - end | |
54 | - | |
55 | -end | |
56 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/metric_test.rb
... | ... | @@ -1,23 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class MetricTest < ActiveSupport::TestCase | |
3 | - | |
4 | - def setup | |
5 | - name = 'MetricTest metric' | |
6 | - scope = 'METHOD' | |
7 | - description = 'Metric created for testing' | |
8 | - @hash = {:name => name, :scope => scope, :description => description} | |
9 | - @metric = Kalibro::Entities::Metric.new | |
10 | - @metric.name = name | |
11 | - @metric.scope = scope | |
12 | - @metric.description = description | |
13 | - end | |
14 | - | |
15 | - should 'create metric from hash' do | |
16 | - assert_equal @metric, Kalibro::Entities::Metric.from_hash(@hash) | |
17 | - end | |
18 | - | |
19 | - should 'convert metric to hash' do | |
20 | - assert_equal @hash, @metric.to_hash | |
21 | - end | |
22 | - | |
23 | -end | |
24 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/module_node_test.rb
... | ... | @@ -1,43 +0,0 @@ |
1 | -require "test_helper" | |
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 | |
11 | - | |
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 | |
29 | - | |
30 | - def setup | |
31 | - @hash = self.class.qt_calculator_tree_hash | |
32 | - @node = self.class.qt_calculator_tree | |
33 | - end | |
34 | - | |
35 | - should 'create module node from hash' do | |
36 | - assert_equal @node, Kalibro::Entities::ModuleNode.from_hash(@hash) | |
37 | - end | |
38 | - | |
39 | - should 'convert children hash to array of ModuleNode' do | |
40 | - assert_equal @hash, @node.to_hash | |
41 | - end | |
42 | - | |
43 | -end | |
44 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/module_result_test.rb
... | ... | @@ -1,39 +0,0 @@ |
1 | -require "test_helper" | |
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 | |
16 | - | |
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 | |
25 | - | |
26 | - def setup | |
27 | - @hash = self.class.fixture_hash | |
28 | - @result = self.class.fixture | |
29 | - end | |
30 | - | |
31 | - should 'create module result from hash' do | |
32 | - assert_equal @result, Kalibro::Entities::ModuleResult.from_hash(@hash) | |
33 | - end | |
34 | - | |
35 | - should 'convert module result to hash' do | |
36 | - assert_equal @hash, @result.to_hash | |
37 | - end | |
38 | - | |
39 | -end | |
40 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/module_test.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ModuleTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
10 | - | |
11 | - def self.qt_calculator_hash | |
12 | - name = ProjectTest.qt_calculator.name | |
13 | - {:name => name, :granularity => 'APPLICATION'} | |
14 | - end | |
15 | - | |
16 | - def setup | |
17 | - @hash = self.class.qt_calculator_hash | |
18 | - @module = self.class.qt_calculator | |
19 | - end | |
20 | - | |
21 | - should 'create module from hash' do | |
22 | - assert_equal @module, Kalibro::Entities::Module.from_hash(@hash) | |
23 | - end | |
24 | - | |
25 | - should 'convert module to hash' do | |
26 | - assert_equal @hash, @module.to_hash | |
27 | - end | |
28 | - | |
29 | -end | |
30 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/native_metric_test.rb
... | ... | @@ -1,45 +0,0 @@ |
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 | - | |
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 | |
21 | - | |
22 | - def self.total_cof_hash | |
23 | - {:name => 'Total Coupling Factor', :scope => 'APPLICATION', | |
24 | - :origin => 'Analizo', :language => 'JAVA'} | |
25 | - end | |
26 | - | |
27 | - def self.amloc_hash | |
28 | - {:name => 'Average Method LOC', :scope => 'CLASS', | |
29 | - :origin => 'Analizo', :language => 'JAVA'} | |
30 | - end | |
31 | - | |
32 | - def setup | |
33 | - @hash = self.class.amloc_hash | |
34 | - @metric = self.class.amloc | |
35 | - end | |
36 | - | |
37 | - should 'create native metric from hash' do | |
38 | - assert_equal @metric, Kalibro::Entities::NativeMetric.from_hash(@hash) | |
39 | - end | |
40 | - | |
41 | - should 'convert native metric to hash' do | |
42 | - assert_equal @hash, @metric.to_hash | |
43 | - end | |
44 | - | |
45 | -end | |
46 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb
... | ... | @@ -1,43 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ProjectResultTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
13 | - | |
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 | |
21 | - | |
22 | - def setup | |
23 | - @hash = self.class.qt_calculator_hash | |
24 | - @result = self.class.qt_calculator | |
25 | - end | |
26 | - | |
27 | - should 'create project result from hash' do | |
28 | - assert_equal @result, Kalibro::Entities::ProjectResult.from_hash(@hash) | |
29 | - end | |
30 | - | |
31 | - should 'convert project result to hash' do | |
32 | - assert_equal @hash, @result.to_hash | |
33 | - end | |
34 | - | |
35 | - should 'retrieve formatted load time' do | |
36 | - assert_equal '00:00:14', @result.formatted_load_time | |
37 | - end | |
38 | - | |
39 | - should 'retrieve formatted analysis time' do | |
40 | - assert_equal '00:00:01', @result.formatted_analysis_time | |
41 | - end | |
42 | - | |
43 | -end | |
44 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/project_test.rb
... | ... | @@ -1,36 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class ProjectTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
14 | - | |
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 | |
22 | - | |
23 | - def setup | |
24 | - @hash = self.class.qt_calculator_hash | |
25 | - @project = self.class.qt_calculator | |
26 | - end | |
27 | - | |
28 | - should 'create project from hash' do | |
29 | - assert_equal @project, Kalibro::Entities::Project.from_hash(@hash) | |
30 | - end | |
31 | - | |
32 | - should 'convert project to hash' do | |
33 | - assert_equal @hash, @project.to_hash | |
34 | - end | |
35 | - | |
36 | -end | |
37 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/range_test.rb
... | ... | @@ -1,49 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class RangeTest < ActiveSupport::TestCase | |
3 | - | |
4 | - Infinity = 1.0/0.0 | |
5 | - | |
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 | |
25 | - | |
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 | |
35 | - | |
36 | - def setup | |
37 | - @hash = self.class.amloc_bad_hash | |
38 | - @range = self.class.amloc_bad | |
39 | - end | |
40 | - | |
41 | - should 'create range from hash' do | |
42 | - assert_equal @range, Kalibro::Entities::Range.from_hash(@hash) | |
43 | - end | |
44 | - | |
45 | - should 'convert range to hash' do | |
46 | - assert_equal @hash, @range.to_hash | |
47 | - end | |
48 | - | |
49 | -end |
plugins/mezuro/test/unit/kalibro/entities/repository_test.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class RepositoryTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
10 | - | |
11 | - def self.qt_calculator_hash | |
12 | - {:type => 'SUBVERSION', | |
13 | - :address => 'https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator'} | |
14 | - end | |
15 | - | |
16 | - def setup | |
17 | - @hash = self.class.qt_calculator_hash | |
18 | - @repository = self.class.qt_calculator | |
19 | - end | |
20 | - | |
21 | - should 'create repository from hash' do | |
22 | - assert_equal @repository, Kalibro::Entities::Repository.from_hash(@hash) | |
23 | - end | |
24 | - | |
25 | - should 'convert repository to hash' do | |
26 | - assert_equal @hash, @repository.to_hash | |
27 | - end | |
28 | - | |
29 | -end | |
30 | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/entities/stack_trace_element_test.rb
... | ... | @@ -1,33 +0,0 @@ |
1 | -require "test_helper" | |
2 | -class StackTraceElementTest < ActiveSupport::TestCase | |
3 | - | |
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 | |
12 | - | |
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 | |
19 | - | |
20 | - def setup | |
21 | - @hash = self.class.fixture_hash | |
22 | - @stack_trace_element = self.class.fixture | |
23 | - end | |
24 | - | |
25 | - should 'create stack trace element from hash' do | |
26 | - assert_equal @stack_trace_element, Kalibro::Entities::StackTraceElement.from_hash(@hash) | |
27 | - end | |
28 | - | |
29 | - should 'convert stack trace element to hash' do | |
30 | - assert_equal @hash, @stack_trace_element.to_hash | |
31 | - end | |
32 | - | |
33 | -end |
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/error_fixtures" | |
4 | + | |
5 | +class ErrorTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = ErrorFixtures.error_hash | |
9 | + @error = ErrorFixtures.error | |
10 | + end | |
11 | + | |
12 | + should 'create error from hash' do | |
13 | + assert_equal @hash[:message], Kalibro::Error.new(@hash).message | |
14 | + end | |
15 | + | |
16 | + should 'convert error to hash' do | |
17 | + assert_equal @hash, @error.to_hash | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/metric_configuration_test.rb
0 → 100644
... | ... | @@ -0,0 +1,70 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_configuration_fixtures" | |
4 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
5 | + | |
6 | +class MetricConfigurationTest < ActiveSupport::TestCase | |
7 | + | |
8 | + def setup | |
9 | + @native_metric_configuration = MetricConfigurationFixtures.amloc_metric_configuration | |
10 | + @native_metric_configuration_hash = MetricConfigurationFixtures.amloc_metric_configuration_hash | |
11 | + @compound_metric_configuration = MetricConfigurationFixtures.sc_metric_configuration | |
12 | + @metric_configuration_without_ranges = MetricConfigurationFixtures.metric_configuration_without_ranges | |
13 | + @excellent_range = RangeFixtures.range_excellent | |
14 | + @bad_range = RangeFixtures.range_bad | |
15 | + end | |
16 | + | |
17 | + should 'create metric configuration from hash' do | |
18 | + assert_equal @native_metric_configuration_hash[:code], Kalibro::MetricConfiguration.new(@native_metric_configuration_hash).code | |
19 | + end | |
20 | + | |
21 | + should 'convert metric configuration to hash' do | |
22 | + assert_equal @native_metric_configuration_hash, @native_metric_configuration.to_hash() | |
23 | + end | |
24 | + | |
25 | + should 'create appropriate metric type' do | |
26 | + assert @native_metric_configuration.metric.instance_of?(Kalibro::NativeMetric) | |
27 | + assert @compound_metric_configuration.metric.instance_of?(Kalibro::CompoundMetric) | |
28 | + end | |
29 | + | |
30 | + should 'add a range to an empty range list' do | |
31 | + @metric_configuration_without_ranges.add_range @excellent_range | |
32 | + assert_equal @metric_configuration_without_ranges.ranges, [@excellent_range] | |
33 | + end | |
34 | + | |
35 | + should 'add a range to an non-empty range list' do | |
36 | + @metric_configuration_without_ranges.ranges = [@excellent_range] | |
37 | + @metric_configuration_without_ranges.add_range @bad_range | |
38 | + assert_equal @metric_configuration_without_ranges.ranges, [@excellent_range, @bad_range] | |
39 | + end | |
40 | + | |
41 | + should 'save metric configuration' do | |
42 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :save_metric_configuration, { | |
43 | + :metric_configuration => @native_metric_configuration_hash, | |
44 | + :configuration_name => @native_metric_configuration.configuration_name | |
45 | + }) | |
46 | + @native_metric_configuration.save | |
47 | + end | |
48 | + | |
49 | + should 'get metric configuration by name and configuration name' do | |
50 | + request_body = { | |
51 | + :configuration_name => @native_metric_configuration.configuration_name, | |
52 | + :metric_name => @native_metric_configuration.metric.name | |
53 | + } | |
54 | + response_hash = {:metric_configuration => @native_metric_configuration_hash} | |
55 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :get_metric_configuration, request_body).returns(response_hash) | |
56 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@native_metric_configuration.configuration_name, | |
57 | + @native_metric_configuration.metric.name) | |
58 | + assert_equal @native_metric_configuration.code, metric_configuration.code | |
59 | + end | |
60 | + | |
61 | + should 'destroy metric configuration by name' do | |
62 | + request_body = { | |
63 | + :configuration_name => @native_metric_configuration.configuration_name, | |
64 | + :metric_name => @native_metric_configuration.metric.name | |
65 | + } | |
66 | + Kalibro::MetricConfiguration.expects(:request).with("MetricConfiguration", :remove_metric_configuration, request_body) | |
67 | + @native_metric_configuration.destroy | |
68 | + end | |
69 | + | |
70 | +end | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures" | |
4 | + | |
5 | +class MetricResultTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = MetricResultFixtures.native_metric_result_hash | |
9 | + @result = MetricResultFixtures.native_metric_result | |
10 | + end | |
11 | + | |
12 | + should 'create metric result from hash' do | |
13 | + assert_equal @hash[:metric][:name], Kalibro::MetricResult.new(@hash).metric.name | |
14 | + end | |
15 | + | |
16 | + should 'convert metric result to hash' do | |
17 | + assert_equal @hash, @result.to_hash | |
18 | + end | |
19 | + | |
20 | + should 'create appropriate metric type' do | |
21 | + assert MetricResultFixtures.native_metric_result.metric.instance_of?(Kalibro::NativeMetric) | |
22 | + assert MetricResultFixtures.compound_metric_result.metric.instance_of?(Kalibro::CompoundMetric) | |
23 | + end | |
24 | + | |
25 | + should 'convert single descendent result to array' do | |
26 | + @result.descendent_result = 1 | |
27 | + assert_equal [1], @result.descendent_results | |
28 | + end | |
29 | + | |
30 | +end | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +require "test_helper" | |
2 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_node_fixtures" | |
3 | + | |
4 | +class ModuleNodeTest < ActiveSupport::TestCase | |
5 | + | |
6 | + def setup | |
7 | + @hash = ModuleNodeFixtures.module_node_hash | |
8 | + @node = ModuleNodeFixtures.module_node | |
9 | + end | |
10 | + | |
11 | + should 'create module node from hash' do | |
12 | + assert_equal( @node.child[0].module.name, Kalibro::ModuleNode.new(@hash).child[0].module.name) | |
13 | + end | |
14 | + | |
15 | + should 'convert children hash to array of ModuleNode' do | |
16 | + assert_equal @hash, @node.to_hash | |
17 | + end | |
18 | + | |
19 | +end | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" | |
4 | + | |
5 | +class ModuleResultTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = ModuleResultFixtures.module_result_hash | |
9 | + @module_result = ModuleResultFixtures.module_result | |
10 | + end | |
11 | + should 'create module result' do | |
12 | + assert_equal @module_result.date.to_s , Kalibro::ModuleResult.new(@hash).date.to_s | |
13 | + end | |
14 | + | |
15 | + should 'convert module result to hash' do | |
16 | + assert_equal @hash, @module_result.to_hash | |
17 | + end | |
18 | + | |
19 | + should 'find module result' do | |
20 | + date = DateTime.parse(@module_result.date.to_s) | |
21 | + name = @module_result.module.name | |
22 | + request_body = {:project_name => name, :module_name => name, :date => '2011-10-20T18:26:43.0+00:00'} | |
23 | + response = {:module_result => @hash} | |
24 | + Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_module_result, request_body).returns(response) | |
25 | + assert_equal @module_result.grade, Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, name, date).grade | |
26 | + end | |
27 | + | |
28 | + should 'find all module results' do | |
29 | + name = @module_result.module.name | |
30 | + request_body = {:project_name => name, :module_name => name} | |
31 | + response = {:module_result => @hash} | |
32 | + Kalibro::ModuleResult.expects(:request).with('ModuleResult',:get_result_history, request_body).returns(response) | |
33 | + response_array = Kalibro::ModuleResult.all_by_project_name_and_module_name(name, name) | |
34 | + assert_equal [@module_result].class, response_array.class | |
35 | + assert_equal @module_result.grade, response_array[0].grade | |
36 | + end | |
37 | + | |
38 | +end | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures" | |
4 | + | |
5 | +class ModuleTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = ModuleFixtures.module_hash | |
9 | + @module = ModuleFixtures.module | |
10 | + end | |
11 | + | |
12 | + should 'create module from hash' do | |
13 | + assert_equal @hash[:name], Kalibro::Module.new(@hash).name | |
14 | + end | |
15 | + | |
16 | + should 'convert module to hash' do | |
17 | + assert_equal @hash, @module.to_hash | |
18 | + end | |
19 | + | |
20 | + should 'list ancestor names' do | |
21 | + @module.name = "org.kalibro.core" | |
22 | + assert_equal ["org", "org.kalibro", "org.kalibro.core"], @module.ancestor_names | |
23 | + end | |
24 | + | |
25 | + should 'list ancestor with one name' do | |
26 | + @module.name = "org" | |
27 | + assert_equal ["org"], @module.ancestor_names | |
28 | + end | |
29 | + | |
30 | +end | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/native_metric_fixtures" | |
4 | + | |
5 | +class NativeMetricTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = NativeMetricFixtures.amloc_hash | |
9 | + @metric = NativeMetricFixtures.amloc | |
10 | + end | |
11 | + | |
12 | + should 'create native metric from hash' do | |
13 | + assert_equal @hash[:name], Kalibro::NativeMetric.new(@hash).name | |
14 | + end | |
15 | + | |
16 | + should 'convert native metric to hash' do | |
17 | + assert_equal @hash, @metric.to_hash | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
... | ... | @@ -0,0 +1,94 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_result_fixtures" | |
4 | + | |
5 | +class ProjectResultTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = ProjectResultFixtures.project_result_hash | |
9 | + @project_result = ProjectResultFixtures.project_result | |
10 | + | |
11 | + @project_name = @project_result.project.name | |
12 | + @date = @project_result.date | |
13 | + @flag = DateTime.now.sec % 2 == 0 #random choose between true or false | |
14 | + | |
15 | + @request = {:project_name => @project_name} | |
16 | + @request_with_date = {:project_name => @project_name, :date => @date} | |
17 | + @flag_response = {:has_results => @flag} | |
18 | + @result_response = {:project_result => @project_result.to_hash} | |
19 | + end | |
20 | + | |
21 | + should 'create project result from hash' do | |
22 | + assert_equal @project_result.analysis_time, Kalibro::ProjectResult.new(@hash).analysis_time | |
23 | + end | |
24 | + | |
25 | + should 'convert project result to hash' do | |
26 | + assert_equal @hash, @project_result.to_hash | |
27 | + end | |
28 | + | |
29 | + should 'get last result' do | |
30 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_of, @request).returns(@result_response) | |
31 | + assert_equal @project_result.analysis_time , Kalibro::ProjectResult.last_result(@project_name).analysis_time | |
32 | + end | |
33 | + | |
34 | + should 'get first result' do | |
35 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_first_result_of, @request).returns(@result_response) | |
36 | + assert_equal @project_result.analysis_time, Kalibro::ProjectResult.first_result(@project_name).analysis_time | |
37 | + end | |
38 | + | |
39 | + should 'get first result after date' do | |
40 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_first_result_after, @request_with_date).returns(@result_response) | |
41 | + assert_equal @project_result.analysis_time, Kalibro::ProjectResult.first_result_after(@project_name, @date).analysis_time | |
42 | + end | |
43 | + | |
44 | + should 'get last result before date' do | |
45 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:get_last_result_before, @request_with_date).returns(@result_response) | |
46 | + assert_equal @project_result.analysis_time, Kalibro::ProjectResult.last_result_before(@project_name, @date).analysis_time | |
47 | + end | |
48 | + | |
49 | + should 'verify if project has results' do | |
50 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_for, @request).returns(@flag_response) | |
51 | + assert_equal @flag, Kalibro::ProjectResult.has_results?(@project_name) | |
52 | + end | |
53 | + | |
54 | + should 'verify if project has results before date' do | |
55 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_before, @request_with_date).returns(@flag_response) | |
56 | + assert_equal @flag, Kalibro::ProjectResult.has_results_before?(@project_name, @date) | |
57 | + end | |
58 | + | |
59 | + should 'verify if project has results after date' do | |
60 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult',:has_results_after, @request_with_date).returns(@flag_response) | |
61 | + assert_equal @flag, Kalibro::ProjectResult.has_results_after?(@project_name, @date) | |
62 | + end | |
63 | + | |
64 | + should 'retrieve formatted load time' do | |
65 | + assert_equal '00:00:14', @project_result.formatted_load_time | |
66 | + end | |
67 | + | |
68 | + should 'retrieve formatted analysis time' do | |
69 | + assert_equal '00:00:01', @project_result.formatted_analysis_time | |
70 | + end | |
71 | + | |
72 | + should 'retrieve module node' do | |
73 | + node = @project_result.get_node("main") | |
74 | + assert_equal @hash[:source_tree][:child][2], node.to_hash | |
75 | + end | |
76 | + | |
77 | + should 'retrive complex module' do | |
78 | + node = @project_result.get_node("org.Window") | |
79 | + assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash | |
80 | + end | |
81 | + | |
82 | + should 'return source tree node when nil is given' do | |
83 | + assert_equal @hash[:source_tree], @project_result.node_of(nil).to_hash | |
84 | + end | |
85 | + | |
86 | + should 'return source tree node when project name is given' do | |
87 | + assert_equal @hash[:source_tree], @project_result.node_of(@project_result.project.name).to_hash | |
88 | + end | |
89 | + | |
90 | + should 'return correct node when module name is given' do | |
91 | + assert_equal @hash[:source_tree][:child][2], @project_result.node_of("main").to_hash | |
92 | + end | |
93 | + | |
94 | +end | ... | ... |
... | ... | @@ -0,0 +1,82 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/project_fixtures" | |
4 | + | |
5 | +class ProjectTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = ProjectFixtures.project_hash | |
9 | + @project = ProjectFixtures.project | |
10 | + @project_content = ProjectFixtures.project_content | |
11 | + end | |
12 | + | |
13 | + should 'get all project names' do | |
14 | + response_hash = {:project_name => [@project.name]} | |
15 | + Kalibro::Project.expects(:request).with("Project", :get_project_names).returns(response_hash) | |
16 | + assert_equal response_hash[:project_name], Kalibro::Project.all_names | |
17 | + end | |
18 | + | |
19 | + should 'find project by name' do | |
20 | + request_body = {:project_name => @project.name} | |
21 | + response_hash = {:project => @hash} | |
22 | + Kalibro::Project.expects(:new).with(@hash).returns(@project) | |
23 | + Kalibro::Project.expects(:request).with("Project", :get_project, request_body).returns(response_hash) | |
24 | + assert_equal @project, Kalibro::Project.find_by_name(@project.name) | |
25 | + end | |
26 | + | |
27 | + should 'raise error when project doesnt exist' do | |
28 | + request_body = {:project_name => @project.name} | |
29 | + Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) | |
30 | + assert_raise Exception do Kalibro::Project.find_by_name(@project.name) end | |
31 | + end | |
32 | + | |
33 | + should 'return true when project is saved successfully' do | |
34 | + Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}) | |
35 | + assert @project.save | |
36 | + end | |
37 | + | |
38 | + should 'return false when project is not saved successfully' do | |
39 | + Kalibro::Project.expects(:request).with("Project", :save_project, {:project => @project.to_hash}).raises(Exception.new) | |
40 | + assert !(@project.save) | |
41 | + end | |
42 | + | |
43 | + should 'remove existent project from service' do | |
44 | + Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}) | |
45 | + @project.destroy | |
46 | + end | |
47 | + | |
48 | + should 'initialize new project from hash' do | |
49 | + project = Kalibro::Project.new @hash | |
50 | + assert_equal @project.name, project.name | |
51 | + assert_equal @project.repository.type, project.repository.type | |
52 | + end | |
53 | + | |
54 | + should 'convert project to hash' do | |
55 | + hash = @project.to_hash | |
56 | + assert_equal @hash[:name], hash[:name] | |
57 | + assert_equal @hash[:configuration_name], hash[:configuration_name] | |
58 | + assert_equal @hash[:repository], hash[:repository] | |
59 | + assert_equal @hash[:state], hash[:state] | |
60 | + end | |
61 | + | |
62 | + should 'process project without days' do | |
63 | + Kalibro::Project.expects(:request).with('Kalibro', :process_project, {:project_name => @project.name}) | |
64 | + @project.process_project | |
65 | + end | |
66 | + | |
67 | + should 'process project with days' do | |
68 | + Kalibro::Project.expects(:request).with('Kalibro', :process_periodically, {:project_name => @project.name, :period_in_days => "1"}) | |
69 | + @project.process_project "1" | |
70 | + end | |
71 | + | |
72 | + should 'process period' do | |
73 | + Kalibro::Project.expects(:request).with('Kalibro', :get_process_period, {:project_name => @project.name}).returns({:period => "1"}) | |
74 | + assert_equal "1", @project.process_period | |
75 | + end | |
76 | + | |
77 | + should 'cancel periodic process' do | |
78 | + Kalibro::Project.expects(:request).with("Kalibro", :cancel_periodic_process, {:project_name => @project.name}) | |
79 | + @project.cancel_periodic_process | |
80 | + end | |
81 | + | |
82 | +end | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/range_fixtures" | |
4 | + | |
5 | +class RangeTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = RangeFixtures.range_bad_hash | |
9 | + @range = RangeFixtures.range_bad | |
10 | + end | |
11 | + | |
12 | + should 'create range from hash' do | |
13 | + assert_equal @hash[:label], Kalibro::Range.new(@hash).label | |
14 | + end | |
15 | + | |
16 | + should 'convert range to hash' do | |
17 | + assert_equal @hash, @range.to_hash | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/repository_fixtures" | |
4 | + | |
5 | +class RepositoryTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = RepositoryFixtures.repository_hash | |
9 | + @repository = RepositoryFixtures.repository | |
10 | + end | |
11 | + | |
12 | + should 'new repository from hash' do | |
13 | + assert_equal @repository.type, Kalibro::Repository.new(@hash).type | |
14 | + end | |
15 | + | |
16 | + should 'convert repository to hash' do | |
17 | + assert_equal @hash, @repository.to_hash | |
18 | + end | |
19 | + | |
20 | + should 'get supported repository types' do | |
21 | + types = ['BAZAAR', 'GIT', 'SUBVERSION'] | |
22 | + Kalibro::Repository.expects(:request).with('Kalibro', :get_supported_repository_types).returns({:repository_type => types}) | |
23 | + assert_equal types, Kalibro::Repository.repository_types | |
24 | + end | |
25 | + | |
26 | +end | ... | ... |
plugins/mezuro/test/unit/kalibro/stack_trace_element_test.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | + | |
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/stack_trace_element_fixtures" | |
4 | + | |
5 | +class StackTraceElementTest < ActiveSupport::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @hash = StackTraceElementFixtures.stack_trace_element_hash | |
9 | + @stack_trace_element = StackTraceElementFixtures.stack_trace_element | |
10 | + end | |
11 | + | |
12 | + should 'create stack trace element from hash' do | |
13 | + assert_equal @hash[:method_name], Kalibro::StackTraceElement.new(@hash).method_name | |
14 | + end | |
15 | + | |
16 | + should 'convert stack trace element to hash' do | |
17 | + assert_equal @hash, @stack_trace_element.to_hash | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb
0 → 100644
... | ... | @@ -0,0 +1,79 @@ |
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.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 'not save a configuration with an existing cofiguration name in kalibro' do | |
31 | + Kalibro::Configuration.expects(:all_names).returns([@content.name.upcase]) | |
32 | + @content.send :validate_kalibro_configuration_name | |
33 | + assert_equal "Configuration name already exists in Kalibro", @content.errors.on_base | |
34 | + end | |
35 | + | |
36 | + should 'get configuration from service' do | |
37 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | |
38 | + assert_equal @configuration, @content.configuration | |
39 | + end | |
40 | + | |
41 | + should 'send configuration to service after saving' do | |
42 | + @content.expects :send_configuration_to_service | |
43 | + @content.stubs(:solr_save) | |
44 | + @content.run_callbacks :after_save | |
45 | + end | |
46 | + | |
47 | + should 'create new configuration' do | |
48 | + Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description) | |
49 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(nil) | |
50 | + @content.send :send_configuration_to_service | |
51 | + end | |
52 | + | |
53 | + should 'clone configuration' do | |
54 | + @content.configuration_to_clone_name = 'clone name' | |
55 | + Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description, :metric_configuration => @configuration.metric_configurations_hash) | |
56 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(nil) | |
57 | + Kalibro::Configuration.expects(:find_by_name).with('clone name').returns(@configuration) | |
58 | + @content.send :send_configuration_to_service | |
59 | + end | |
60 | + | |
61 | + should 'edit configuration' do | |
62 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | |
63 | + @configuration.expects(:update_attributes).with(:description => @content.description) | |
64 | + @content.send :send_configuration_to_service | |
65 | + end | |
66 | + | |
67 | + should 'send correct configuration to service but comunication fails' do | |
68 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | |
69 | + @configuration.expects(:save).returns(false) | |
70 | + @content.send :send_configuration_to_service | |
71 | + end | |
72 | + | |
73 | + should 'remove configuration from service' do | |
74 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | |
75 | + @configuration.expects(:destroy) | |
76 | + @content.send :remove_configuration_from_service | |
77 | + end | |
78 | + | |
79 | +end | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/helpers/content_viewer_helper_test.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +require "test_helper" | |
2 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/metric_result_fixtures" | |
3 | + | |
4 | +class ContentViewerHelperTest < ActiveSupport::TestCase | |
5 | + | |
6 | + should 'get the number rounded by two decimal points' do | |
7 | + assert_equal '4.22', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.22344') | |
8 | + assert_equal '4.10', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4.1') | |
9 | + assert_equal '4.00', MezuroPlugin::Helpers::ContentViewerHelper.format_grade('4') | |
10 | + end | |
11 | + | |
12 | + should 'create the periodicity options array' do | |
13 | + assert_equal [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]], MezuroPlugin::Helpers::ContentViewerHelper.create_periodicity_options | |
14 | + end | |
15 | + | |
16 | + should 'format metric name for module result' do | |
17 | + metric_result = MetricResultFixtures.native_metric_result | |
18 | + assert_equal 'AverageMethodLOC', MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) | |
19 | + end | |
20 | +end | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
1 | 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 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_fixtures" | |
6 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/module_result_fixtures" | |
7 | + | |
2 | 8 | class ProjectContentTest < ActiveSupport::TestCase |
3 | 9 | |
4 | 10 | def setup |
5 | - @project = ProjectTest.qt_calculator | |
6 | - @content = MezuroPlugin::ProjectContent.new | |
7 | - @content.name = @project.name | |
8 | - @content.license = @project.license | |
9 | - @content.description = @project.description | |
10 | - @content.repository_type = @project.repository.type | |
11 | - @content.repository_url = @project.repository.address | |
12 | - @content.configuration_name = @project.configuration_name | |
13 | - end | |
14 | - | |
15 | - should 'be an article' do | |
16 | - assert_kind_of Article, @content | |
11 | + @project = ProjectFixtures.project | |
12 | + @content = ProjectFixtures.project_content | |
13 | + @project_result = ProjectResultFixtures.project_result | |
14 | + @module = ModuleFixtures.module | |
15 | + @module_result = ModuleResultFixtures.module_result | |
17 | 16 | end |
18 | 17 | |
19 | 18 | should 'provide proper short description' do |
... | ... | @@ -28,19 +27,95 @@ class ProjectContentTest < ActiveSupport::TestCase |
28 | 27 | assert_not_nil @content.to_html |
29 | 28 | end |
30 | 29 | |
31 | - should 'run send project to service on after_save callback' do | |
30 | + should 'get project from service' do | |
31 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | |
32 | + assert_equal @project.name, @content.project.name | |
33 | + end | |
34 | + | |
35 | + should 'get project result from service' do | |
36 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | |
37 | + assert_equal @project_result.load_time, @content.project_result.load_time | |
38 | + end | |
39 | + | |
40 | + should 'get date result from service when has_result_before is true' do | |
41 | + request_body = {:project_name => @project.name, :date => @project_result.date} | |
42 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => true}) | |
43 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_last_result_before, request_body).returns({:project_result => @project_result.to_hash}) | |
44 | + assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time | |
45 | + end | |
46 | + | |
47 | + should 'get date result from service when has_result_before is false' do | |
48 | + request_body = {:project_name => @project.name, :date => @project_result.date} | |
49 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false}) | |
50 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash}) | |
51 | + assert_equal @project_result.load_time, @content.project_result_with_date(@project_result.date).load_time | |
52 | + end | |
53 | + | |
54 | + should 'get module result from service without date' do | |
55 | + date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | |
56 | + Kalibro::ProjectResult.expects(:request).with('ProjectResult', :get_last_result_of, {:project_name => @project.name}).returns({:project_result => @project_result.to_hash}) | |
57 | + Kalibro::ModuleResult.expects(:request).with( | |
58 | + 'ModuleResult', | |
59 | + :get_module_result, | |
60 | + { | |
61 | + :project_name => @project.name, | |
62 | + :module_name => @module.name, | |
63 | + :date => date_with_milliseconds | |
64 | + }).returns({:module_result => @module_result.to_hash}) | |
65 | + assert_equal @module_result.grade, @content.module_result({:module_name => @module.name}).grade | |
66 | + end | |
67 | + | |
68 | + should 'get module result from service with date' do | |
69 | + date_with_milliseconds = Kalibro::ProjectResult.date_with_milliseconds(@project_result.date) | |
70 | + request_body = {:project_name => @project.name, :date => @project_result.date} | |
71 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :has_results_before, request_body).returns({:has_results => false}) | |
72 | + Kalibro::ProjectResult.expects(:request).with("ProjectResult", :get_first_result_after, request_body).returns({:project_result => @project_result.to_hash}) | |
73 | + Kalibro::ModuleResult.expects(:request).with( | |
74 | + 'ModuleResult', | |
75 | + :get_module_result, | |
76 | + { | |
77 | + :project_name => @project.name, | |
78 | + :module_name => @module.name, | |
79 | + :date => date_with_milliseconds | |
80 | + }).returns({:module_result => @module_result.to_hash}) | |
81 | + assert_equal @module_result.grade, @content.module_result({:module_name => @module.name, :date => @project_result.date}).grade | |
82 | + end | |
83 | + | |
84 | + should 'get result history' do | |
85 | + Kalibro::ModuleResult.expects(:request).with( | |
86 | + 'ModuleResult', | |
87 | + :get_result_history, | |
88 | + { | |
89 | + :project_name => @project.name, | |
90 | + :module_name => @module.name | |
91 | + }).returns({:module_result => @module_result.to_hash}) | |
92 | + @content.result_history(@module.name) | |
93 | + end | |
94 | + | |
95 | + should 'send project to service after saving' do | |
32 | 96 | @content.expects :send_project_to_service |
33 | 97 | @content.run_callbacks :after_save |
34 | 98 | end |
35 | 99 | |
36 | 100 | 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) | |
101 | + hash = ProjectFixtures.project_hash | |
102 | + hash.delete(:attributes!) | |
103 | + hash.delete(:state) | |
104 | + Kalibro::Project.expects(:create).with(hash).returns(@project) | |
105 | + @project.expects(:process_project).with(@content.periodicity_in_days) | |
39 | 106 | @content.send :send_project_to_service |
40 | 107 | end |
41 | 108 | |
42 | - should 'remove project from service' do | |
43 | - Kalibro::Client::ProjectClient.expects(:remove).with(@project.name) | |
44 | - @content.send :remove_project_from_service | |
109 | + should 'destroy project from service' do | |
110 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) | |
111 | + Kalibro::Project.expects(:request).with("Project", :remove_project, {:project_name => @project.name}) | |
112 | + @content.send :destroy_project_from_service | |
45 | 113 | end |
114 | + | |
115 | + should 'not save a project with an existing project name in kalibro' do | |
116 | + Kalibro::Project.expects(:all_names).returns([@content.name]) | |
117 | + @content.send :validate_kalibro_project_name | |
118 | + assert_equal "Project name already exists in Kalibro", @content.errors.on_base | |
119 | + end | |
120 | + | |
46 | 121 | end | ... | ... |
plugins/mezuro/test/unit/mezuro_plugin_test.rb
1 | 1 | require "test_helper" |
2 | + | |
2 | 3 | class MezuroPluginTest < ActiveSupport::TestCase |
3 | 4 | |
4 | 5 | def setup |
... | ... | @@ -29,8 +30,4 @@ class MezuroPluginTest < ActiveSupport::TestCase |
29 | 30 | assert @plugin.stylesheet? |
30 | 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 | 33 | end | ... | ... |
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
... | ... | @@ -2,9 +2,9 @@ |
2 | 2 | |
3 | 3 | <% |
4 | 4 | begin |
5 | - @configuration = @article.title.nil? ? nil : Kalibro::Client::ConfigurationClient.new.configuration(@article.title) | |
5 | + configuration = @article.title.nil? ? nil : @article.configuration | |
6 | 6 | rescue |
7 | - @configuration = nil | |
7 | + configuration = nil | |
8 | 8 | end |
9 | 9 | %> |
10 | 10 | |
... | ... | @@ -13,8 +13,20 @@ |
13 | 13 | <%= hidden_field_tag 'kalibro_configuration[profile_id]', profile.id %> |
14 | 14 | <%= hidden_field_tag 'id', @article.id %> |
15 | 15 | |
16 | +<% configuration_names = @article.configuration_names %> | |
17 | + | |
18 | +<% selected = (configuration.nil? ? "None" : @article.configuration_to_clone_name) %> | |
19 | + | |
16 | 20 | <%= required_fields_message %> |
17 | 21 | |
18 | -<%= required f.text_field(:name) %> | |
22 | +<%= required labelled_form_field _('Clone Configuration'), | |
23 | +if !configuration.nil? && !@article.id.nil? | |
24 | + f.select(:configuration_to_clone_name, configuration_names, {:selected => selected}, :disabled => 'true') | |
25 | +else | |
26 | + f.select(:configuration_to_clone_name, configuration_names, {:selected => selected}) | |
27 | +end %> | |
28 | +<br/> | |
29 | + | |
30 | +<%= required f.text_field(:name, :disabled => !(configuration.nil? || @article.id.nil?)) %> | |
19 | 31 | |
20 | 32 | <%= f.text_field :description %><br/> | ... | ... |
plugins/mezuro/views/cms/mezuro_plugin/_project_content.html.erb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | <% |
4 | 4 | begin |
5 | - @project = @article.title.nil? ? nil : Kalibro::Client::ProjectClient.new.project(@article.title) | |
5 | + @project = @article.title.nil? ? nil : Kalibro::Project.find_by_name(@article.title) | |
6 | 6 | rescue |
7 | 7 | @project = nil |
8 | 8 | end |
... | ... | @@ -14,21 +14,34 @@ |
14 | 14 | <%= hidden_field_tag 'id', @article.id %> |
15 | 15 | |
16 | 16 | <%= required_fields_message %> |
17 | - | |
18 | -<%= required f.text_field(:name) %> | |
17 | +<% if !@project.nil? && !@article.id.nil? %> | |
18 | + <%= required f.text_field(:name, :disabled => 'true') %> | |
19 | +<% else %> | |
20 | + <%= required f.text_field(:name) %> | |
21 | +<% end %> | |
19 | 22 | |
20 | 23 | <%= f.text_field :license %><br/> |
21 | 24 | |
22 | 25 | <%= f.text_field :description %><br/> |
23 | 26 | |
24 | -<% @repository_types = Kalibro::Client::KalibroClient.new.supported_repository_types.sort %> | |
27 | +<% @repository_types = Kalibro::Repository.repository_types.sort %> | |
25 | 28 | <% @selected = (@project.nil? ? @repository_types : @project.repository.type) %> |
26 | 29 | <%= required labelled_form_field _('Repository type'), |
27 | 30 | f.select(:repository_type, @repository_types, {:selected => @selected}) %><br/> |
28 | 31 | |
29 | 32 | <%= required f.text_field(:repository_url) %><br/> |
30 | 33 | |
31 | -<% @configuration_names = Kalibro::Client::ConfigurationClient.new.configuration_names.sort %> | |
34 | +<% @configuration_names = Kalibro::Configuration.all_names.sort %> | |
32 | 35 | <% @selected = (@project.nil? ? @configuration_names[0] : @project.configuration_name) %> |
33 | -<%= required labelled_form_field _('Configuration'), | |
34 | - f.select(:configuration_name, @configuration_names.sort, {:selected => @selected}) %><br/> | |
35 | 36 | \ No newline at end of file |
37 | + | |
38 | +<% if !@project.nil? && !@article.id.nil? %> | |
39 | + <%= required labelled_form_field _('Configuration'), | |
40 | + f.select(:configuration_name, @configuration_names, {:selected => @selected}, :disabled => 'true') %> | |
41 | +<% else %> | |
42 | + <%= required labelled_form_field _('Configuration'), | |
43 | + f.select(:configuration_name, @configuration_names, {:selected => @selected}) %><br/> | |
44 | +<% end %> | |
45 | + | |
46 | +<% selected = (@project.nil? ? 0 : @project.process_period.to_i) %> | |
47 | +<%= required labelled_form_field _('Periodic Avaliation'), | |
48 | + 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/> | |
7 | -<hr/> | |
8 | -<table id="project_metric_result"> | |
9 | - <thead> | |
10 | - <tr> | |
11 | - <th>Metric</th> | |
12 | - <th>Value</th> | |
13 | - <th>Weight</th> | |
14 | - <th>Threshold</th> | |
15 | - </tr> | |
16 | - </thead> | |
17 | - <tbody> | |
18 | - <% module_result.metric_results.each do |metric_result| %> | |
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> | |
26 | - <% end %> | |
27 | - </tbody> | |
28 | - <tfoot> | |
29 | - <tr> | |
30 | - <td colspan = "4" align = "right"> | |
31 | - <strong> | |
32 | - <%= _('Grade:') %> | |
33 | - <%= module_result.grade %> | |
34 | - </strong> | |
35 | - </td> | |
36 | - </tr> | |
37 | - </tfoot> | |
38 | -</table> | |
1 | +<% unless @content.errors[:base].nil? %> | |
2 | + <%= @content.errors[:base] %> | |
3 | +<% else %> | |
4 | + <% the_module = @module_result.module %> | |
5 | + <% module_label = "#{the_module.name} (#{the_module.granularity})" %> | |
39 | 6 | |
7 | + <h5><%= _('Metric results for: ') + module_label %> </h5> | |
8 | + | |
9 | + <hr/> | |
10 | + <div class="zoomable-image"> | |
11 | + <table> | |
12 | + <thead> | |
13 | + <tr> | |
14 | + <th>Metric</th> | |
15 | + <th>Value</th> | |
16 | + <th>Weight</th> | |
17 | + <th>Threshold</th> | |
18 | + </tr> | |
19 | + </thead> | |
20 | + <tbody> | |
21 | + <% @module_result.metric_results.each do |metric_result| %> | |
22 | + <% range = metric_result.range %> | |
23 | + <% if !range.nil? %> | |
24 | + <tr> | |
25 | + <td><a href="#" data-show=".<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>"><%= metric_result.metric.name %></a></td> | |
26 | + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td> | |
27 | + <td><%= metric_result.weight %></td> | |
28 | + <td style="background-color: #<%= range.color[2..-1] %>"><%= range.label %></td> | |
29 | + </tr> | |
30 | + <tr class="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" style="display: none;"> | |
31 | + <td colspan="3"> | |
32 | + <div id='historical-<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>'> | |
33 | + <a href="#" show-metric-history="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" data-module-name="<%= the_module.name %>" data-metric-name="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>"> <p style="text-indent: 3em;"> Get Historical Values </p> </a> | |
34 | + </div> | |
35 | + </td> | |
36 | + <td align="right"> | |
37 | + <%= range.comments.nil? ? '' : range.comments %> | |
38 | + </td> | |
39 | + </tr> | |
40 | + <% end %> | |
41 | + <% end %> | |
42 | + </tbody> | |
43 | + <tfoot> | |
44 | + <tr> | |
45 | + <td colspan = "3"> | |
46 | + <div id='historical-grade'></div> | |
47 | + </td> | |
48 | + <td align = "right"> | |
49 | + <a href="#" show-grade-history="<%= @module_result.module.name %>" data-module-name="<%= the_module.name%>" > | |
50 | + <strong> | |
51 | + <%= _('Grade:') %> | |
52 | + <%= "%.02f" % @module_result.grade %> | |
53 | + </strong> | |
54 | + </a> | |
55 | + </td> | |
56 | + </tr> | |
57 | + </tfoot> | |
58 | + </table> | |
59 | + </div> | |
60 | +<% end %> | ... | ... |
plugins/mezuro/views/content_viewer/_project_error.rhtml
0 → 100644
... | ... | @@ -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,51 @@ |
1 | +<% unless @content.errors[:base].nil? %> | |
2 | + <%= @content.errors[:base] %> | |
3 | +<% else %> | |
4 | + <% form_for :project_date, :html=>{:id=>"project_history_date"} do |f| %> | |
5 | + <%= f.label :day, "Choose project date:" %> | |
6 | + | |
7 | + <table> | |
8 | + <tr> | |
9 | + <td> | |
10 | + Day | |
11 | + </td> | |
12 | + <td> | |
13 | + Month | |
14 | + </td> | |
15 | + <td> | |
16 | + Year | |
17 | + </td> | |
18 | + </tr> | |
19 | + <tr> | |
20 | + <td> | |
21 | + <%= f.text_field :day, :size => 1, :maxlength => 2, :placeholder =>"dd" %> | |
22 | + </td> | |
23 | + <td> | |
24 | + <%= f.text_field :month, :size => 1, :maxlength => 2, :placeholder =>"mm" %> | |
25 | + </td> | |
26 | + <td> | |
27 | + <%= f.text_field :year, :size => 1, :maxlength => 4, :placeholder =>"yyyy" %> | |
28 | + </td> | |
29 | + </tr> | |
30 | + </table> | |
31 | + <%= f.submit "Refresh" %> | |
32 | + <% end %> | |
33 | + | |
34 | + | |
35 | + <h4><%= _('Last Result') %></h4> | |
36 | + | |
37 | + <table> | |
38 | + <tr> | |
39 | + <td><%= _('Date') %></td> | |
40 | + <td><%= @project_result.date %></td> | |
41 | + </tr> | |
42 | + <tr> | |
43 | + <td><%= _('Load time') %></td> | |
44 | + <td><%= @project_result.formatted_load_time %></td> | |
45 | + </tr> | |
46 | + <tr> | |
47 | + <td><%= _('Analysis time') %></td> | |
48 | + <td><%= @project_result.formatted_analysis_time %></td> | |
49 | + </tr> | |
50 | + </table> | |
51 | +<% end %> | ... | ... |
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})" %> | |
3 | -<% 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> | |
1 | +<% unless @content.errors[:base].nil? %> | |
2 | + <%= @content.errors[:base] %> | |
27 | 3 | <% 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> | |
37 | - </table> | |
4 | + <h4><%= _('Source tree') %></h4> | |
5 | + <% module_name = @source_tree.module.name %> | |
6 | + <% module_label = "#{module_name} (#{@source_tree.module.granularity})" %> | |
7 | + | |
8 | + <p><h2 class="path"> | |
9 | + <% if module_name != @project_name %> | |
10 | + <a href="#" class="source-tree-link" data-module-name="<%= @project_name %>"> | |
11 | + <%= @project_name %> | |
12 | + </a> | |
13 | + <% end %> | |
14 | + | |
15 | + | |
16 | + <% split_link = @source_tree.module.ancestor_names %> | |
17 | + <% split_link.each do |link| %> | |
18 | + /<a href="#" class="source-tree-link" data-module-name="<%= link %>"> | |
19 | + <%= link.split(".").last %> | |
20 | + </a> | |
21 | + <% end %> | |
22 | + </h2></p> | |
23 | + | |
24 | + <% if @source_tree.children %> | |
25 | + <table border="0" class="source-tree"> | |
26 | + <% @source_tree.children.each do |child| %> | |
27 | + <% if child.module.granularity=='PACKAGE' %> | |
28 | + <tr> | |
29 | + <td class="icon"><%= image_tag('/plugins/mezuro/images/folder.png')%></td> | |
30 | + <td class="source-tree-text"><a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"><%= child.module.name %></a></td> | |
31 | + </tr> | |
32 | + <% else %> | |
33 | + <tr> | |
34 | + <td class="icon"><%= image_tag('/plugins/mezuro/images/file.png') %></td> | |
35 | + <td class="source-tree-text"> | |
36 | + <a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>"> | |
37 | + <%= child.module.name %> | |
38 | + </a> | |
39 | + </td> | |
40 | + </tr> | |
41 | + <% end %> | |
42 | + <% end %> | |
43 | + </table> | |
44 | + <% end %> | |
38 | 45 | <% end %> | ... | ... |
plugins/mezuro/views/content_viewer/show_configuration.rhtml
1 | -<% @configuration = @page.configuration %> | |
1 | +<% @configuration_content = @page | |
2 | +@configuration = @page.configuration %> | |
2 | 3 | |
3 | 4 | <table id="project_info"> |
4 | 5 | <tr> |
... | ... | @@ -10,3 +11,40 @@ |
10 | 11 | <td><%= @configuration.description %></td> |
11 | 12 | </tr> |
12 | 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 => { :id => @configuration_content.id } %><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 | + <td/><td/> | |
26 | + </tr> | |
27 | + <% @configuration.metric_configurations.each do |metric_configuration| %> | |
28 | + <tr class="metric"> | |
29 | + <td><%= metric_configuration.metric.name %></td> | |
30 | + <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %> | |
31 | + <td> | |
32 | + <%= metric_configuration.metric.origin %> | |
33 | + </td> | |
34 | + <td><%= metric_configuration.code %></td> | |
35 | + <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_metric_configuration", :params => | |
36 | + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
37 | + <% else %> | |
38 | + <td> | |
39 | + Compound Metric | |
40 | + </td> | |
41 | + <td><%= metric_configuration.code %></td> | |
42 | + <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_compound_metric_configuration", :params => | |
43 | + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
44 | + <% end %> | |
45 | + | |
46 | + <td><%= link_to "Remove", :controller => "mezuro_plugin_myprofile", :action => "remove_metric_configuration", :params => | |
47 | + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
48 | + </tr> | |
49 | + <% end %> | |
50 | +</table> | ... | ... |
plugins/mezuro/views/content_viewer/show_project.rhtml
1 | -<% @project = @page.project %> | |
2 | - | |
3 | -<table id="project_info"> | |
4 | - <tr> | |
5 | - <td><%= _('Name') %></td> | |
6 | - <td><%= @project.name %></td> | |
7 | - </tr> | |
8 | - <tr> | |
9 | - <td><%= _('License') %></td> | |
10 | - <td><%= @project.license %></td> | |
11 | - </tr> | |
12 | - <tr> | |
13 | - <td><%= _('Description') %></td> | |
14 | - <td><%= @project.description %></td> | |
15 | - </tr> | |
16 | - <tr> | |
17 | - <td><%= _('Repository type') %></td> | |
18 | - <td><%= @project.repository.type %></td> | |
19 | - </tr> | |
20 | - <tr> | |
21 | - <td><%= _('Repository address') %></td> | |
22 | - <td><%= @project.repository.address %></td> | |
23 | - </tr> | |
24 | - <tr> | |
25 | - <td><%= _('Configuration') %></td> | |
26 | - <td><%= @project.configuration_name %></td> | |
27 | - </tr> | |
28 | -</table> | |
29 | - | |
30 | -<br /> | |
31 | - | |
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> | |
1 | +<script src="/plugins/mezuro/javascripts/project_content.js" type="text/javascript"></script> | |
67 | 2 | |
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> | |
75 | - | |
76 | - <script type="text/javascript"> | |
77 | - jQuery(results); | |
78 | - </script> | |
79 | -<% end %> | |
80 | 3 | \ No newline at end of file |
4 | +<% @project = @page.project %> | |
5 | +<% unless @page.errors[:base].nil? %> | |
6 | + <%= @page.errors[:base] %> | |
7 | +<% else %> | |
8 | + | |
9 | + <% if (@project==nil) %> | |
10 | + <h3>Warning:</h3> | |
11 | + <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> | |
12 | + <% else %> | |
13 | + | |
14 | + | |
15 | + <table> | |
16 | + <tr> | |
17 | + <td><%= _('Name') %></td> | |
18 | + <td><%= @project.name %></td> | |
19 | + </tr> | |
20 | + <tr> | |
21 | + <td><%= _('License') %></td> | |
22 | + <td><%= @project.license %></td> | |
23 | + </tr> | |
24 | + <tr> | |
25 | + <td><%= _('Description') %></td> | |
26 | + <td><%= @project.description %></td> | |
27 | + </tr> | |
28 | + <tr> | |
29 | + <td><%= _('Repository type') %></td> | |
30 | + <td><%= @project.repository.type %></td> | |
31 | + </tr> | |
32 | + <tr> | |
33 | + <td><%= _('Repository address') %></td> | |
34 | + <td><%= @project.repository.address %></td> | |
35 | + </tr> | |
36 | + <tr> | |
37 | + <td><%= _('Configuration') %></td> | |
38 | + <td><%= @project.configuration_name %></td> | |
39 | + </tr> | |
40 | + <tr> | |
41 | + <td><%= _('Periodicity') %></td> | |
42 | + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td> | |
43 | + </tr> | |
44 | + <tr> | |
45 | + <td><%= _('Status')%></td> | |
46 | + <td> | |
47 | + <div id="project-state"><%= @project.state %></div> | |
48 | + <div id="msg-time"></div> | |
49 | + </td> | |
50 | + </tr> | |
51 | + </table> | |
52 | + | |
53 | + <br /> | |
54 | + | |
55 | + <div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>" | |
56 | + data-project-name="<%= @project.name %>"> | |
57 | + </div> | |
58 | + <div id="project-tree"></div> | |
59 | + <div id="module-result"> | |
60 | + </div> | |
61 | + <% end %> | |
62 | +<% end %> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/_edit_range.html.erb
0 → 100644
... | ... | @@ -0,0 +1,4 @@ |
1 | +<% remote_form_for :range, :url => {:action =>"update_range", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | |
2 | + <%= hidden_field_tag :beginning_id, beginning_id %> | |
3 | + <%= render :partial => "range_form", :locals => {:f => f, :metric_name => metric_name, :id => id, :beginning_id => beginning_id, :range => range } %> | |
4 | +<% end %> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/_metric_codes.html.erb
0 → 100644
... | ... | @@ -0,0 +1,12 @@ |
1 | +<table> | |
2 | + <tr class="titles"> | |
3 | + <td><h5>Metric Name</h5></td> | |
4 | + <td><h5>Metric Code</h5></td> | |
5 | + </tr> | |
6 | + <% metric_configurations.each do |metric_configuration| %> | |
7 | + <tr class="metric"> | |
8 | + <td><%= metric_configuration.metric.name %></td> | |
9 | + <td><%= metric_configuration.code %></td> | |
10 | + </tr> | |
11 | + <% end %> | |
12 | +</table> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/_new_range.html.erb
0 → 100644
plugins/mezuro/views/mezuro_plugin_myprofile/_range.html.erb
0 → 100644
... | ... | @@ -0,0 +1,17 @@ |
1 | +<tr> | |
2 | + <td> | |
3 | + <%=range.label%> | |
4 | + </td> | |
5 | + <td> | |
6 | + <%=range.beginning%> | |
7 | + </td> | |
8 | + <td> | |
9 | + <%=range.end%> | |
10 | + </td> | |
11 | + <td> | |
12 | + <%=range.grade%> | |
13 | + </td> | |
14 | + <td bgcolor="#<%= range.color[2..-1] %>"></td> | |
15 | + <td><%= link_to_remote "Edit", :url => {:action =>"edit_range", :controller => "mezuro_plugin_myprofile", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning} %></td> | |
16 | + <td><%= link_to "Remove", :action =>"remove_range", :controller => "mezuro_plugin_myprofile", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning %></td> | |
17 | +</tr> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/_range_form.html.erb
0 → 100644
... | ... | @@ -0,0 +1,53 @@ |
1 | +<%= hidden_field_tag :id, id %> | |
2 | +<%= hidden_field_tag :metric_name, metric_name %> | |
3 | +<table> | |
4 | + <tr> | |
5 | + <td> | |
6 | + <%= f.label :label, "(*) Label:" %> | |
7 | + </td> | |
8 | + <td> | |
9 | + <%= f.text_field :label %> | |
10 | + </td> | |
11 | + </tr> | |
12 | + <tr> | |
13 | + <td> | |
14 | + <%= f.label :beginning, "(*) Beginning:" %> | |
15 | + </td> | |
16 | + <td> | |
17 | + <%= f.text_field :beginning, :value => @range.beginning %> | |
18 | + </td> | |
19 | + </tr> | |
20 | + <tr> | |
21 | + <td> | |
22 | + <%= f.label :end, "(*) End:" %> | |
23 | + </td> | |
24 | + <td> | |
25 | + <%= f.text_field :end, :value => @range.end %> | |
26 | + </td> | |
27 | + </tr> | |
28 | + <tr> | |
29 | + <td> | |
30 | + <%= f.label :grade, "(*) Grade:" %> | |
31 | + </td> | |
32 | + <td> | |
33 | + <%= f.text_field :grade %> | |
34 | + </td> | |
35 | + </tr> | |
36 | + <tr> | |
37 | + <td> | |
38 | + <%= f.label :color, "(*) Color:" %> | |
39 | + </td> | |
40 | + <td> | |
41 | + <%= f.text_field :color %> | |
42 | + </td> | |
43 | + </tr> | |
44 | + <tr> | |
45 | + <td> | |
46 | + <%= f.label :comments, "Comments:" %> | |
47 | + </td> | |
48 | + <td> | |
49 | + <%= f.text_field :comments %> | |
50 | + </td> | |
51 | + </tr> | |
52 | +</table> | |
53 | +<%= f.submit "Save Range" %> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/choose_base_tool.html.erb
0 → 100644
... | ... | @@ -0,0 +1,16 @@ |
1 | +<h2><%= @configuration_content.name%> Configuration</h2> | |
2 | + | |
3 | +<%= link_to "New Compound Metric", :controller => "mezuro_plugin_myprofile", :action => "new_compound_metric_configuration", :params => | |
4 | +{ :id => @configuration_content.id } %> | |
5 | + | |
6 | +<h5>Base Tools:</h5> | |
7 | +<table id="project_info"> | |
8 | + <% @base_tools.each do |base_tool| %> | |
9 | + <tr> | |
10 | + <td> | |
11 | + <%= link_to base_tool, :controller => "mezuro_plugin_myprofile", :action => "choose_metric", :params => | |
12 | + { :base_tool => base_tool, :id => @configuration_content.id} %> | |
13 | + </td> | |
14 | + </tr> | |
15 | + <% end %> | |
16 | +</table> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/choose_metric.html.erb
0 → 100644
... | ... | @@ -0,0 +1,18 @@ |
1 | +<h2><%= @configuration_content.name %> Configuration</h2> | |
2 | + | |
3 | +<table id="project_info"> | |
4 | + <tr> | |
5 | + <h5>Metric Collector: <%= @base_tool %></h5> | |
6 | + </tr> | |
7 | + <tr> | |
8 | + <h5>Choose a metric to add:</h5> | |
9 | + </tr> | |
10 | + <% @supported_metrics.each do |metric| %> | |
11 | + <tr class="metric" title="<%= metric.name %>"> | |
12 | + <td> | |
13 | + <%= link_to metric.name, :controller => "mezuro_plugin_myprofile", :action => "new_metric_configuration", :params => {:metric_name => metric.name, | |
14 | + :base_tool => @base_tool, :id => @configuration_content.id } %> | |
15 | + </td> | |
16 | + </tr> | |
17 | + <% end %> | |
18 | +</table> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/create_range.rjs
0 → 100644
plugins/mezuro/views/mezuro_plugin_myprofile/edit_compound_metric_configuration.html.erb
0 → 100644
... | ... | @@ -0,0 +1,77 @@ |
1 | +<h2><%= @configuration_content.name %> Configuration</h2> | |
2 | + | |
3 | +<% form_for :metric_configuration, :url => {:action =>"update_compound_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | |
4 | + <%= hidden_field_tag :id, @configuration_content.id %> | |
5 | + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %> | |
6 | + | |
7 | + <p> | |
8 | + <%= "Metric Name:" + @metric.name %> | |
9 | + </p> | |
10 | + <% f.fields_for :metric do |m| %> | |
11 | + <%= m.hidden_field :name, :value => @metric.name %> | |
12 | + <p> | |
13 | + <%= m.label :description, "Description:" %> | |
14 | + <%= m.text_field "description", :value => @metric.description %> | |
15 | + </p> | |
16 | + <p> | |
17 | + <%= m.label :scope, "Scope:" %> | |
18 | + <%= m.select :scope, [["Class", "CLASS"]], :selected => @metric.scope %> | |
19 | + </p> | |
20 | + <p> | |
21 | + <%= m.label :script, "Script:" %> | |
22 | + <%= m.text_area "script", :value => @metric.script %> | |
23 | + </p> | |
24 | + <% end %> | |
25 | + <p> | |
26 | + <%= f.label :code, "Code:" %> | |
27 | + <%= f.text_field "code" %> | |
28 | + </p> | |
29 | + <p> | |
30 | + <%= f.label :aggregation_form, "Aggregation Form:" %> | |
31 | + <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"], | |
32 | + ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %> | |
33 | + </p> | |
34 | + <p> | |
35 | + <%= f.label :weight, "Weight:" %> | |
36 | + <%= f.text_field :weight %> | |
37 | + </p> | |
38 | + <p> | |
39 | + <%= f.submit "Save" %> | |
40 | + </p> | |
41 | +<% end %> | |
42 | + | |
43 | + | |
44 | +<h5> Ranges </h5><br/> | |
45 | + | |
46 | +<table id="ranges"> | |
47 | + <tr> | |
48 | + <td> | |
49 | + Label | |
50 | + </td> | |
51 | + <td> | |
52 | + Beginning | |
53 | + </td> | |
54 | + <td> | |
55 | + End | |
56 | + </td> | |
57 | + <td> | |
58 | + Grade | |
59 | + </td> | |
60 | + <td> | |
61 | + Color | |
62 | + </td> | |
63 | + </tr> | |
64 | + <% if (@metric_configuration.ranges!=nil) | |
65 | + @metric_configuration.ranges.each do |range| %> | |
66 | + <%= render :partial => "range", :locals => {:range => range, :id => @configuration_content.id, | |
67 | + :metric_name => @metric_configuration.metric.name} %> | |
68 | + <% end | |
69 | + end %> | |
70 | +</table> | |
71 | + | |
72 | +<br/> | |
73 | +<%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_myprofile", :id => @configuration_content.id, :metric_name => @metric.name} %> | |
74 | +<div id="range_form" style="display:none"></div> | |
75 | + | |
76 | +<br/> | |
77 | +<%= render :partial => "metric_codes", :locals => {:metric_configurations => @metric_configurations} %> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/edit_metric_configuration.html.erb
0 → 100644
... | ... | @@ -0,0 +1,86 @@ |
1 | +<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script> | |
2 | + | |
3 | +<h2><%= @configuration_content.name %> Configuration</h2> | |
4 | + | |
5 | +<% form_for :metric_configuration, :url => {:action =>"update_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | |
6 | + <%= hidden_field_tag :id, @configuration_content.id %> | |
7 | + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %> | |
8 | + | |
9 | + <% f.fields_for :metric do |m| %> | |
10 | + | |
11 | + <% @metric.language.each do |language| %> | |
12 | + <%= m.hidden_field :language, :multiple => true, :value => language %> | |
13 | + <% end %> | |
14 | + | |
15 | + <%= m.hidden_field "scope", :value => @metric.scope %> | |
16 | + <p> | |
17 | + <%= m.label :origin, "Collector Name:" %> | |
18 | + <%= @metric.origin %> | |
19 | + <%= m.hidden_field "origin", :value => @metric.origin %> | |
20 | + </p> | |
21 | + <p> | |
22 | + <%= m.label :metric_name, "Metric Name:" %> | |
23 | + <%= @metric.name %> | |
24 | + <%= m.hidden_field "name", :value => @metric.name %> | |
25 | + </p> | |
26 | + <!--<p>--> | |
27 | + <% m.label :description, "Description:" %> | |
28 | + <% @metric.description %> | |
29 | + <% m.hidden_field "description", :value => @metric.description %> | |
30 | + <!--</p>--> | |
31 | + <% end %> | |
32 | + <p> | |
33 | + <%= f.label :code, "Code:" %> | |
34 | + <%= @metric_configuration.code %> | |
35 | + <%= f.hidden_field "code", :value => @metric_configuration.code %> | |
36 | + </p> | |
37 | + <p> | |
38 | + <%= f.label :aggregation_form, "Aggregation Form:" %> | |
39 | + <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"], | |
40 | + ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %> | |
41 | + </p> | |
42 | + <p> | |
43 | + <%= f.label :weight, "Weight:" %> | |
44 | + <%= f.text_field "weight", :value => @metric_configuration.weight %> | |
45 | + </p> | |
46 | + | |
47 | + <p> | |
48 | + <%= f.submit "Save" %> | |
49 | + </p> | |
50 | +<% end %> | |
51 | + | |
52 | + | |
53 | +<h5> Ranges </h5><br/> | |
54 | + | |
55 | +<table id="ranges"> | |
56 | + <tr> | |
57 | + <td> | |
58 | + Label | |
59 | + </td> | |
60 | + <td> | |
61 | + Beginning | |
62 | + </td> | |
63 | + <td> | |
64 | + End | |
65 | + </td> | |
66 | + <td> | |
67 | + Grade | |
68 | + </td> | |
69 | + <td> | |
70 | + Color | |
71 | + </td> | |
72 | + <td></td> | |
73 | + <td></td> | |
74 | + </tr> | |
75 | + <% if (@metric_configuration.ranges!=nil) | |
76 | + @metric_configuration.ranges.each do |range| %> | |
77 | + <%= render :partial => "range", :locals => {:range => range, :id => @configuration_content.id, | |
78 | + :metric_name => @metric.name} %> | |
79 | + <% end | |
80 | + end %> | |
81 | +</table> | |
82 | + | |
83 | +<br/> | |
84 | +<%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_myprofile", :id => @configuration_content.id, :metric_name => @metric.name} %> | |
85 | +<div id="range_form" style="display:none"></div> | |
86 | + | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/edit_range.rjs
0 → 100644
plugins/mezuro/views/mezuro_plugin_myprofile/new_compound_metric_configuration.html.erb
0 → 100644
... | ... | @@ -0,0 +1,44 @@ |
1 | +<h2><%= @configuration_content.name %> Configuration</h2> | |
2 | + | |
3 | +<% form_for :metric_configuration, :url => {:action =>"create_compound_metric_configuration", | |
4 | +:controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | |
5 | + <%= hidden_field_tag :id, @configuration_content.id %> | |
6 | + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %> | |
7 | + | |
8 | + <% f.fields_for :metric do |m| %> | |
9 | + <p> | |
10 | + <%= m.label :name, "Name:" %> | |
11 | + <%= m.text_field "name" %> | |
12 | + </p> | |
13 | + <p> | |
14 | + <%= m.label :description, "Description:" %> | |
15 | + <%= m.text_field "description" %> | |
16 | + </p> | |
17 | + <p> | |
18 | + <%= m.label :scope, "Scope:" %> | |
19 | + <%= m.select :scope, [["Class", "CLASS"]] %> | |
20 | + </p> | |
21 | + <p> | |
22 | + <%= m.label :script, "Script:" %> | |
23 | + <%= m.text_area "script" %> | |
24 | + </p> | |
25 | + <% end %> | |
26 | + <p> | |
27 | + <%= f.label :code, "Code:" %> | |
28 | + <%= f.text_field "code" %> | |
29 | + </p> | |
30 | + <p> | |
31 | + <%= f.label :aggregation_form, "Aggregation Form:" %> | |
32 | + <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"], | |
33 | + ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %> | |
34 | + </p> | |
35 | + <p> | |
36 | + <%= f.label :weight, "Weight:" %> | |
37 | + <%= f.text_field :weight %> | |
38 | + </p> | |
39 | + <p> | |
40 | + <%= f.submit "Add" %> | |
41 | + </p> | |
42 | +<% end %> | |
43 | + | |
44 | +<%= render :partial => "metric_codes", :locals => {:metric_configurations => @metric_configurations} %> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/new_metric_configuration.html.erb
0 → 100644
... | ... | @@ -0,0 +1,51 @@ |
1 | +<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script> | |
2 | + | |
3 | +<h2><%= @configuration_content.name %> Configuration</h2> | |
4 | + | |
5 | +<% form_for :metric_configuration, :url => {:action =>"create_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | |
6 | + <%= hidden_field_tag :id, @configuration_content.id %> | |
7 | + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %> | |
8 | + | |
9 | + <% f.fields_for :metric do |m| %> | |
10 | + | |
11 | + <% @metric.language.each do |language| %> | |
12 | + <%= m.hidden_field :language, :multiple => true, :value => language %> | |
13 | + <% end %> | |
14 | + | |
15 | + <%= m.hidden_field "scope", :value => @metric.scope %> | |
16 | + <p> | |
17 | + <%= m.label :origin, "Collector Name:" %> | |
18 | + <%= @metric.origin %> | |
19 | + <%= m.hidden_field "origin", :value => @metric.origin %> | |
20 | + </p> | |
21 | + <p> | |
22 | + <%= m.label :name, "Metric Name:" %> | |
23 | + <%= @metric.name %> | |
24 | + <%= m.hidden_field "name", :value => @metric.name %> | |
25 | + </p> | |
26 | + <!--<p>--> | |
27 | + <% m.label :description, "Description:" %> | |
28 | + <% @metric.description %> | |
29 | + <% m.hidden_field "description", :value => @metric.description %> | |
30 | + <!--</p>--> | |
31 | + <% end %> | |
32 | + <p> | |
33 | + <%= f.label :code, "Code:" %> | |
34 | + <%= f.text_field :code %> | |
35 | + </p> | |
36 | + <p> | |
37 | + <%= f.label :aggregation_form, "Aggregation Form:" %> | |
38 | + <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"], | |
39 | + ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %> | |
40 | + </p> | |
41 | + <p> | |
42 | + <%= f.label :weight, "Weight:" %> | |
43 | + <%= f.text_field :weight %> | |
44 | + </p> | |
45 | + | |
46 | + <p> | |
47 | + <%= f.submit "Add" %> | |
48 | + </p> | |
49 | + | |
50 | +<% end %> | |
51 | + | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/new_range.rjs
0 → 100644
plugins/mezuro/views/mezuro_plugin_myprofile/update_range.rjs
0 → 100644
... | ... | @@ -0,0 +1 @@ |
1 | +page.reload() | ... | ... |