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
Too many changes.
To preserve performance only 100 of 160 files displayed.
... | ... | @@ -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 | ... | ... |