Commit c9ee80a9fe648550d4b817f07d078d90c310317d
1 parent
97d0870a
Exists in
master
and in
29 other branches
[Mezuro] Refactored configuration and mezuro_plugin_myprofile_controller
Conflicts: plugins/mezuro/test/unit/kalibro/client/port_test.rb
Showing
22 changed files
with
144 additions
and
331 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
@@ -26,38 +26,44 @@ class MezuroPluginMyprofileController < ProfileController | @@ -26,38 +26,44 @@ class MezuroPluginMyprofileController < ProfileController | ||
26 | 26 | ||
27 | def edit_metric_configuration | 27 | def edit_metric_configuration |
28 | @configuration_content = profile.articles.find(params[:id]) | 28 | @configuration_content = profile.articles.find(params[:id]) |
29 | - @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, params[:metric_name]) | 29 | + @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name]) |
30 | @metric = @metric_configuration.metric | 30 | @metric = @metric_configuration.metric |
31 | end | 31 | end |
32 | 32 | ||
33 | def edit_compound_metric_configuration | 33 | def edit_compound_metric_configuration |
34 | @configuration_content = profile.articles.find(params[:id]) | 34 | @configuration_content = profile.articles.find(params[:id]) |
35 | - @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, params[:metric_name]) | 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 | 36 | @metric_configurations = @configuration_content.metric_configurations |
37 | @metric = @metric_configuration.metric | 37 | @metric = @metric_configuration.metric |
38 | end | 38 | end |
39 | 39 | ||
40 | def create_metric_configuration | 40 | def create_metric_configuration |
41 | - configuration_content = profile.articles.find(params[:id]) | ||
42 | - metric_name = generic_metric_configuration_creation(new_metric_configuration_instance, configuration_content.name) | ||
43 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | 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/, '+')}" | ||
44 | end | 45 | end |
45 | 46 | ||
46 | def create_compound_metric_configuration | 47 | def create_compound_metric_configuration |
47 | - configuration_content = profile.articles.find(params[:id]) | ||
48 | - metric_name = generic_metric_configuration_creation(new_compound_metric_configuration_instance, configuration_content.name) | ||
49 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | 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/, '+')}" | ||
50 | end | 52 | end |
51 | 53 | ||
52 | def update_metric_configuration | 54 | def update_metric_configuration |
53 | @configuration_content = profile.articles.find(params[:id]) | 55 | @configuration_content = profile.articles.find(params[:id]) |
54 | - auxiliar_update_metric_configuration(Kalibro::MetricConfiguration::NATIVE_TYPE) | 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] | ||
55 | redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | 59 | redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" |
56 | end | 60 | end |
57 | 61 | ||
58 | def update_compound_metric_configuration | 62 | def update_compound_metric_configuration |
59 | @configuration_content = profile.articles.find(params[:id]) | 63 | @configuration_content = profile.articles.find(params[:id]) |
60 | - auxiliar_update_metric_configuration(Kalibro::MetricConfiguration::COMPOUND_TYPE) | 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] | ||
61 | redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | 67 | redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" |
62 | end | 68 | end |
63 | 69 | ||
@@ -71,7 +77,7 @@ class MezuroPluginMyprofileController < ProfileController | @@ -71,7 +77,7 @@ class MezuroPluginMyprofileController < ProfileController | ||
71 | @metric_name = params[:metric_name] | 77 | @metric_name = params[:metric_name] |
72 | @beginning_id = params[:beginning_id] | 78 | @beginning_id = params[:beginning_id] |
73 | 79 | ||
74 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, @metric_name) | 80 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) |
75 | @range = metric_configuration.ranges.find{ |range| range.beginning == @beginning_id.to_f } | 81 | @range = metric_configuration.ranges.find{ |range| range.beginning == @beginning_id.to_f } |
76 | end | 82 | end |
77 | 83 | ||
@@ -80,7 +86,7 @@ class MezuroPluginMyprofileController < ProfileController | @@ -80,7 +86,7 @@ class MezuroPluginMyprofileController < ProfileController | ||
80 | @range = Kalibro::Range.new params[:range] | 86 | @range = Kalibro::Range.new params[:range] |
81 | metric_name = params[:metric_name] | 87 | metric_name = params[:metric_name] |
82 | beginning_id = params[:beginning_id] | 88 | beginning_id = params[:beginning_id] |
83 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, metric_name) | 89 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) |
84 | metric_configuration.add_range(@range) | 90 | metric_configuration.add_range(@range) |
85 | metric_configuration.save | 91 | metric_configuration.save |
86 | end | 92 | end |
@@ -89,7 +95,7 @@ class MezuroPluginMyprofileController < ProfileController | @@ -89,7 +95,7 @@ class MezuroPluginMyprofileController < ProfileController | ||
89 | configuration_content = profile.articles.find(params[:id]) | 95 | configuration_content = profile.articles.find(params[:id]) |
90 | metric_name = params[:metric_name] | 96 | metric_name = params[:metric_name] |
91 | beginning_id = params[:beginning_id] | 97 | beginning_id = params[:beginning_id] |
92 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(configuration_content.name, metric_name) | 98 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) |
93 | index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f } | 99 | index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f } |
94 | metric_configuration.ranges[index] = Kalibro::Range.new params[:range] | 100 | metric_configuration.ranges[index] = Kalibro::Range.new params[:range] |
95 | metric_configuration.save | 101 | metric_configuration.save |
@@ -99,7 +105,7 @@ class MezuroPluginMyprofileController < ProfileController | @@ -99,7 +105,7 @@ class MezuroPluginMyprofileController < ProfileController | ||
99 | configuration_content = profile.articles.find(params[:id]) | 105 | configuration_content = profile.articles.find(params[:id]) |
100 | metric_name = params[:metric_name] | 106 | metric_name = params[:metric_name] |
101 | beginning_id = params[:range_beginning] | 107 | beginning_id = params[:range_beginning] |
102 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(configuration_content.name, metric_name) | 108 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) |
103 | metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f }.inspect | 109 | metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f }.inspect |
104 | metric_configuration.save | 110 | metric_configuration.save |
105 | formatted_metric_name = metric_name.gsub(/\s/, '+') | 111 | formatted_metric_name = metric_name.gsub(/\s/, '+') |
@@ -113,52 +119,9 @@ class MezuroPluginMyprofileController < ProfileController | @@ -113,52 +119,9 @@ class MezuroPluginMyprofileController < ProfileController | ||
113 | def remove_metric_configuration | 119 | def remove_metric_configuration |
114 | configuration_content = profile.articles.find(params[:id]) | 120 | configuration_content = profile.articles.find(params[:id]) |
115 | metric_name = params[:metric_name] | 121 | metric_name = params[:metric_name] |
116 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(configuration_content.name, metric_name) | 122 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) |
117 | metric_configuration.destroy | 123 | metric_configuration.destroy |
118 | redirect_to "/#{profile.identifier}/#{configuration_content.slug}" | 124 | redirect_to "/#{profile.identifier}/#{configuration_content.slug}" |
119 | end | 125 | end |
120 | 126 | ||
121 | - private | ||
122 | - | ||
123 | - def new_metric_configuration_instance | ||
124 | - metric_configuration = Kalibro::MetricConfiguration.new | ||
125 | - metric_configuration.metric = Kalibro::NativeMetric.new | ||
126 | - assign_metric_configuration_instance(metric_configuration, Kalibro::MetricConfiguration::NATIVE_TYPE) | ||
127 | - end | ||
128 | - | ||
129 | - def new_compound_metric_configuration_instance | ||
130 | - metric_configuration = Kalibro::MetricConfiguration.new | ||
131 | - metric_configuration.metric = Kalibro::CompoundMetric.new | ||
132 | - assign_metric_configuration_instance(metric_configuration, Kalibro::MetricConfiguration::COMPOUND_TYPE) | ||
133 | - end | ||
134 | - | ||
135 | - def assign_metric_configuration_instance(metric_configuration, type=Kalibro::MetricConfiguration::NATIVE_TYPE) | ||
136 | - metric_configuration.metric.name = params[:metric_configuration][:metric][:name] | ||
137 | - metric_configuration.metric.description = params[:metric_configuration][:metric][:description] | ||
138 | - metric_configuration.metric.scope = params[:metric_configuration][:metric][:scope] | ||
139 | - metric_configuration.code = params[:metric_configuration][:code] | ||
140 | - metric_configuration.weight = params[:metric_configuration][:weight] | ||
141 | - metric_configuration.aggregation_form = params[:metric_configuration][:aggregation_form] | ||
142 | - | ||
143 | - if type == Kalibro::MetricConfiguration::NATIVE_TYPE | ||
144 | - metric_configuration.metric.origin = params[:metric_configuration][:metric][:origin] | ||
145 | - metric_configuration.metric.language = params[:metric_configuration][:metric][:language] | ||
146 | - elsif type == Kalibro::MetricConfiguration::COMPOUND_TYPE | ||
147 | - metric_configuration.metric.script = params[:metric_configuration][:metric][:script] | ||
148 | - end | ||
149 | - metric_configuration | ||
150 | - end | ||
151 | - | ||
152 | - def generic_metric_configuration_creation(metric_configuration, configuration_name) | ||
153 | - metric_configuration.save | ||
154 | - metric_configuration.metric.name | ||
155 | - end | ||
156 | - | ||
157 | - def auxiliar_update_metric_configuration(type) | ||
158 | - metric_name = params[:metric_configuration][:metric][:name] | ||
159 | - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_and_name(@configuration_content.name, metric_name) | ||
160 | - metric_configuration = assign_metric_configuration_instance(metric_configuration, type) | ||
161 | - metric_configuration.save | ||
162 | - end | ||
163 | - | ||
164 | end | 127 | end |
plugins/mezuro/lib/kalibro/client/configuration_client.rb
@@ -1,45 +0,0 @@ | @@ -1,45 +0,0 @@ | ||
1 | -class Kalibro::Client::ConfigurationClient | ||
2 | - | ||
3 | - def self.configuration(configuration_name) | ||
4 | - new.configuration(configuration_name) | ||
5 | - end | ||
6 | - | ||
7 | - def self.save(configuration_content) | ||
8 | - begin | ||
9 | - configuration = new.configuration(configuration_content.name) | ||
10 | - rescue | ||
11 | - configuration = Kalibro::Entities::Configuration.new | ||
12 | - configuration.name = configuration_content.name | ||
13 | - end | ||
14 | - | ||
15 | - configuration.description = configuration_content.description | ||
16 | - new.save(configuration) | ||
17 | - end | ||
18 | - | ||
19 | - def self.remove(configuration_name) | ||
20 | - client = new | ||
21 | - client.remove(configuration_name) if client.configuration_names.include? configuration_name | ||
22 | - end | ||
23 | - | ||
24 | - def initialize | ||
25 | - @port = Kalibro::Client::Port.new('Configuration') | ||
26 | - end | ||
27 | - | ||
28 | - def save(configuration) | ||
29 | - @port.request(:save_configuration, {:configuration => configuration.to_hash}) | ||
30 | - end | ||
31 | - | ||
32 | - def configuration_names | ||
33 | - @port.request(:get_configuration_names)[:configuration_name].to_a | ||
34 | - end | ||
35 | - | ||
36 | - def configuration(name) | ||
37 | - hash = @port.request(:get_configuration, {:configuration_name => name})[:configuration] | ||
38 | - Kalibro::Entities::Configuration.from_hash(hash) | ||
39 | - end | ||
40 | - | ||
41 | - def remove(configuration_name) | ||
42 | - @port.request(:remove_configuration, {:configuration_name => configuration_name}) | ||
43 | - end | ||
44 | - | ||
45 | -end |
plugins/mezuro/lib/kalibro/configuration.rb
@@ -19,11 +19,7 @@ class Kalibro::Configuration < Kalibro::Model | @@ -19,11 +19,7 @@ class Kalibro::Configuration < Kalibro::Model | ||
19 | end | 19 | end |
20 | 20 | ||
21 | def self.find_by_name(configuration_name) | 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 | 22 | + new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration] |
27 | end | 23 | end |
28 | 24 | ||
29 | def self.create(configuration_content) | 25 | def self.create(configuration_content) |
@@ -37,7 +33,7 @@ class Kalibro::Configuration < Kalibro::Model | @@ -37,7 +33,7 @@ class Kalibro::Configuration < Kalibro::Model | ||
37 | begin | 33 | begin |
38 | self.class.request("Configuration", :save_configuration, {:configuration => to_hash}) | 34 | self.class.request("Configuration", :save_configuration, {:configuration => to_hash}) |
39 | true | 35 | true |
40 | - rescue | 36 | + rescue Exception => error |
41 | false | 37 | false |
42 | end | 38 | end |
43 | end | 39 | end |
plugins/mezuro/lib/kalibro/entities/configuration.rb
@@ -1,21 +0,0 @@ | @@ -1,21 +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 | - 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 | -end |
plugins/mezuro/lib/kalibro/metric_configuration.rb
@@ -35,7 +35,12 @@ class Kalibro::MetricConfiguration < Kalibro::Model | @@ -35,7 +35,12 @@ class Kalibro::MetricConfiguration < Kalibro::Model | ||
35 | @range = ranges | 35 | @range = ranges |
36 | end | 36 | end |
37 | 37 | ||
38 | - def self.find_by_configuration_and_metric(configuration_name, metric_name) | 38 | + def update_attributes(attributes={}) |
39 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | ||
40 | + save | ||
41 | + end | ||
42 | + | ||
43 | + def self.find_by_configuration_name_and_metric_name(configuration_name, metric_name) | ||
39 | metric_configuration = new request("MetricConfiguration", :get_metric_configuration, { | 44 | metric_configuration = new request("MetricConfiguration", :get_metric_configuration, { |
40 | :configuration_name => configuration_name, | 45 | :configuration_name => configuration_name, |
41 | :metric_name => metric_name | 46 | :metric_name => metric_name |
@@ -45,14 +50,9 @@ class Kalibro::MetricConfiguration < Kalibro::Model | @@ -45,14 +50,9 @@ class Kalibro::MetricConfiguration < Kalibro::Model | ||
45 | end | 50 | end |
46 | 51 | ||
47 | def save | 52 | def save |
48 | - begin | ||
49 | self.class.request("MetricConfiguration", :save_metric_configuration, { | 53 | self.class.request("MetricConfiguration", :save_metric_configuration, { |
50 | :metric_configuration => to_hash, | 54 | :metric_configuration => to_hash, |
51 | :configuration_name => configuration_name}) | 55 | :configuration_name => configuration_name}) |
52 | - true | ||
53 | - rescue | ||
54 | - false | ||
55 | - end | ||
56 | end | 56 | end |
57 | 57 | ||
58 | def destroy | 58 | def destroy |
plugins/mezuro/lib/kalibro/model.rb
@@ -19,6 +19,10 @@ class Kalibro::Model | @@ -19,6 +19,10 @@ class Kalibro::Model | ||
19 | hash | 19 | hash |
20 | end | 20 | end |
21 | 21 | ||
22 | + def self.request(endpoint, action, request_body = nil) | ||
23 | + response = client(endpoint).request(:kalibro, action) { soap.body = request_body } | ||
24 | + response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method | ||
25 | + end | ||
22 | protected | 26 | protected |
23 | 27 | ||
24 | def fields | 28 | def fields |
@@ -46,13 +50,9 @@ class Kalibro::Model | @@ -46,13 +50,9 @@ class Kalibro::Model | ||
46 | Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | 50 | Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") |
47 | end | 51 | end |
48 | 52 | ||
49 | - def self.request(endpoint, action, request_body = nil) | ||
50 | - response = client(endpoint).request(:kalibro, action) { soap.body = request_body } | ||
51 | - response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method | ||
52 | - end | ||
53 | 53 | ||
54 | def self.is_valid?(field) | 54 | def self.is_valid?(field) |
55 | - field.to_s[0] != '@' and field != :attributes! | 55 | + field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil? |
56 | end | 56 | end |
57 | 57 | ||
58 | def to_objects_array(value, model_class = nil) | 58 | def to_objects_array(value, model_class = nil) |
plugins/mezuro/lib/kalibro/project.rb
@@ -7,11 +7,7 @@ class Kalibro::Project < Kalibro::Model | @@ -7,11 +7,7 @@ class Kalibro::Project < Kalibro::Model | ||
7 | end | 7 | end |
8 | 8 | ||
9 | def self.find_by_name(project_name) | 9 | def self.find_by_name(project_name) |
10 | - begin | ||
11 | - new request("Project", :get_project, :project_name => project_name)[:project] | ||
12 | - rescue Exception => error | ||
13 | - nil | ||
14 | - end | 10 | + new request("Project", :get_project, :project_name => project_name)[:project] |
15 | end | 11 | end |
16 | 12 | ||
17 | def self.create(content) | 13 | def self.create(content) |
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
@@ -19,7 +19,16 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -19,7 +19,16 @@ class MezuroPlugin::ConfigurationContent < Article | ||
19 | end | 19 | end |
20 | 20 | ||
21 | def configuration | 21 | def configuration |
22 | - Kalibro::Client::ConfigurationClient.configuration(name) | 22 | + begin |
23 | + configuration = Kalibro::Configuration.find_by_name(self.name) | ||
24 | + configuration.description = self.description | ||
25 | + configuration | ||
26 | + rescue Exception | ||
27 | + Kalibro::Configuration.new({ | ||
28 | + :name => self.name, | ||
29 | + :description => self.description | ||
30 | + }) | ||
31 | + end | ||
23 | end | 32 | end |
24 | 33 | ||
25 | def metric_configurations | 34 | def metric_configurations |
@@ -33,7 +42,7 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -33,7 +42,7 @@ class MezuroPlugin::ConfigurationContent < Article | ||
33 | private | 42 | private |
34 | 43 | ||
35 | def validate_kalibro_configuration_name | 44 | def validate_kalibro_configuration_name |
36 | - existing = Kalibro::Client::ConfigurationClient.new.configuration_names | 45 | + existing = Kalibro::Configuration.all_names |
37 | existing.each { |a| a.downcase!} | 46 | existing.each { |a| a.downcase!} |
38 | 47 | ||
39 | if existing.include?(name.downcase) | 48 | if existing.include?(name.downcase) |
@@ -42,11 +51,11 @@ class MezuroPlugin::ConfigurationContent < Article | @@ -42,11 +51,11 @@ class MezuroPlugin::ConfigurationContent < Article | ||
42 | end | 51 | end |
43 | 52 | ||
44 | def send_configuration_to_service | 53 | def send_configuration_to_service |
45 | - Kalibro::Client::ConfigurationClient.save(self) | 54 | + configuration.save |
46 | end | 55 | end |
47 | 56 | ||
48 | def remove_configuration_from_service | 57 | def remove_configuration_from_service |
49 | - Kalibro::Client::ConfigurationClient.remove(name) | 58 | + configuration.destroy |
50 | end | 59 | end |
51 | 60 | ||
52 | end | 61 | end |
plugins/mezuro/test/fixtures/configuration_fixtures.rb
@@ -2,21 +2,19 @@ require File.dirname(__FILE__) + '/metric_configuration_fixtures' | @@ -2,21 +2,19 @@ require File.dirname(__FILE__) + '/metric_configuration_fixtures' | ||
2 | 2 | ||
3 | class ConfigurationFixtures | 3 | class ConfigurationFixtures |
4 | 4 | ||
5 | - def self.kalibro_configuration | ||
6 | - configuration = Kalibro::Entities::Configuration.new | ||
7 | - configuration.name = 'Kalibro for Java' | ||
8 | - configuration.description = 'Kalibro configuration for Java projects.' | ||
9 | - configuration.metric_configurations = [ | ||
10 | - MetricConfigurationFixtures.amloc_configuration, | ||
11 | - MetricConfigurationFixtures.sc_configuration] | ||
12 | - configuration | 5 | + def self.configuration |
6 | + Kalibro::Configuration.new configuration_hash | ||
13 | end | 7 | end |
14 | 8 | ||
15 | - def self.kalibro_configuration_hash | ||
16 | - {:name => 'Kalibro for Java', :description => 'Kalibro configuration for Java projects.', | 9 | + def self.configuration_hash |
10 | + { | ||
11 | + :name => 'Kalibro for Java', | ||
12 | + :description => 'Kalibro configuration for Java projects.', | ||
17 | :metric_configuration => [ | 13 | :metric_configuration => [ |
18 | - MetricConfigurationFixtures.amloc_configuration_hash, | ||
19 | - MetricConfigurationFixtures.sc_configuration_hash]} | 14 | + MetricConfigurationFixtures.amloc_metric_configuration_hash, |
15 | + MetricConfigurationFixtures.sc_metric_configuration_hash | ||
16 | + ] | ||
17 | + } | ||
20 | end | 18 | end |
21 | - | 19 | + |
22 | end | 20 | end |
plugins/mezuro/test/unit/kalibro/client/configuration_client_test.rb
@@ -1,50 +0,0 @@ | @@ -1,50 +0,0 @@ | ||
1 | -require "test_helper" | ||
2 | - | ||
3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | ||
4 | - | ||
5 | -class ConfigurationClientTest < ActiveSupport::TestCase | ||
6 | - | ||
7 | - def setup | ||
8 | - @port = mock | ||
9 | - Kalibro::Client::Port.expects(:new).with('Configuration').returns(@port) | ||
10 | - @client = Kalibro::Client::ConfigurationClient.new | ||
11 | - end | ||
12 | - | ||
13 | - should 'save configuration' do | ||
14 | - configuration = ConfigurationFixtures.kalibro_configuration | ||
15 | - @port.expects(:request).with(:save_configuration, {:configuration => configuration.to_hash}) | ||
16 | - @client.save(configuration) | ||
17 | - end | ||
18 | - | ||
19 | - should 'get configuration names (zero)' do | ||
20 | - @port.expects(:request).with(:get_configuration_names).returns({}) | ||
21 | - assert_equal [], @client.configuration_names | ||
22 | - end | ||
23 | - | ||
24 | - should 'get configuration names (one)' do | ||
25 | - name = 'Kalibro for Java' | ||
26 | - @port.expects(:request).with(:get_configuration_names).returns({:configuration_name => name}) | ||
27 | - assert_equal [name], @client.configuration_names | ||
28 | - end | ||
29 | - | ||
30 | - should 'get configuration names' do | ||
31 | - names = ['Kalibro for Java', 'ConfigurationClientTest configuration'] | ||
32 | - @port.expects(:request).with(:get_configuration_names).returns({:configuration_name => names}) | ||
33 | - assert_equal names, @client.configuration_names | ||
34 | - end | ||
35 | - | ||
36 | - should 'get configuration by name' do | ||
37 | - configuration = ConfigurationFixtures.kalibro_configuration | ||
38 | - request_body = {:configuration_name => configuration.name} | ||
39 | - response_hash = {:configuration => configuration.to_hash} | ||
40 | - @port.expects(:request).with(:get_configuration, request_body).returns(response_hash) | ||
41 | - assert_equal configuration, @client.configuration(configuration.name) | ||
42 | - end | ||
43 | - | ||
44 | - should 'remove configuration by name' do | ||
45 | - name = 'ConfigurationClientTest' | ||
46 | - @port.expects(:request).with(:remove_configuration, {:configuration_name => name}) | ||
47 | - @client.remove(name) | ||
48 | - end | ||
49 | - | ||
50 | -end | ||
51 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/client/port_test.rb
@@ -1,34 +0,0 @@ | @@ -1,34 +0,0 @@ | ||
1 | -require "test_helper" | ||
2 | - | ||
3 | -class PortTest < ActiveSupport::TestCase | ||
4 | - | ||
5 | - def setup | ||
6 | - @client = mock | ||
7 | - set_default_address | ||
8 | - Savon::Client.expects(:new).with("#{@default_address}PortTestEndpoint/?wsdl").returns(@client) | ||
9 | - @port = Kalibro::Client::Port.new('PortTest') | ||
10 | - end | ||
11 | - | ||
12 | - | ||
13 | - should 'get default address' do | ||
14 | - assert_equal @default_address, @port.service_address | ||
15 | - end | ||
16 | - | ||
17 | - should 'request action and return response' do | ||
18 | - response_body = {:port_test_response_key => 'PortTest response value'} | ||
19 | - response_hash = {:port_test_action_response => response_body} | ||
20 | - response = mock | ||
21 | - response.expects(:to_hash).returns(response_hash) | ||
22 | - @client.expects(:request).with(:kalibro, :port_test_action).returns(response) | ||
23 | - | ||
24 | - assert_equal response_body, @port.request(:port_test_action) | ||
25 | - end | ||
26 | - | ||
27 | - private | ||
28 | - | ||
29 | - def set_default_address | ||
30 | - service_file = "#{RAILS_ROOT}/plugins/mezuro/SERVICE" | ||
31 | - File.open(service_file).each_line{ | line | @default_address = line } | ||
32 | - end | ||
33 | - | ||
34 | -end | ||
35 | \ No newline at end of file | 0 | \ No newline at end of file |
@@ -0,0 +1,58 @@ | @@ -0,0 +1,58 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | ||
4 | + | ||
5 | +class ConfigurationTest < ActiveSupport::TestCase | ||
6 | + | ||
7 | + def setup | ||
8 | + @hash = ConfigurationFixtures.configuration_hash | ||
9 | + @configuration = ConfigurationFixtures.configuration | ||
10 | + end | ||
11 | + | ||
12 | + should 'initialize configuration' do | ||
13 | + assert_equal @hash[:name], Kalibro::Configuration.new(@hash).name | ||
14 | + end | ||
15 | + | ||
16 | + should 'convert configuration to hash' do | ||
17 | + assert_equal @hash, @configuration.to_hash | ||
18 | + end | ||
19 | + | ||
20 | + should 'return true when configuration is saved successfully' do | ||
21 | + Kalibro::Configuration.expects(:request).with("Configuration", :save_configuration, {:configuration => @configuration.to_hash}) | ||
22 | + assert @configuration.save | ||
23 | + end | ||
24 | + | ||
25 | + should 'return false when configuration is not saved successfully' do | ||
26 | + Kalibro::Configuration.expects(:request).with("Configuration", :save_configuration, {:configuration => @configuration.to_hash}).raises(Exception.new) | ||
27 | + assert !(@configuration.save) | ||
28 | + end | ||
29 | + | ||
30 | + should 'get all configuration names' do | ||
31 | + names = ['Kalibro for Java', 'ConfigurationClientTest configuration'] | ||
32 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration_names).returns({:configuration_name => names}) | ||
33 | + assert_equal names, Kalibro::Configuration.all_names | ||
34 | + end | ||
35 | + | ||
36 | + should 'find configuration by name' do | ||
37 | + request_body = {:configuration_name => @configuration.name} | ||
38 | + response_hash = {:configuration => @configuration.to_hash} | ||
39 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).returns(response_hash) | ||
40 | + assert_equal @configuration.name, Kalibro::Configuration.find_by_name(@configuration.name).name | ||
41 | + end | ||
42 | + | ||
43 | + should 'raise error when configuration doesnt exist' do | ||
44 | + request_body = {:configuration_name => @configuration.name} | ||
45 | + Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).raises(Exception.new) | ||
46 | + assert_raise Exception do Kalibro::Configuration.find_by_name(@configuration.name) end | ||
47 | + end | ||
48 | + | ||
49 | + should 'destroy configuration by name' do | ||
50 | + Kalibro::Configuration.expects(:request).with("Configuration", :remove_configuration, {:configuration_name => @configuration.name}) | ||
51 | + @configuration.destroy | ||
52 | + end | ||
53 | + | ||
54 | + should 'raise error when try to destroy inexistent configuration from service' do | ||
55 | + Kalibro::Configuration.expects(:request).with("Configuration", :remove_configuration, {:configuration_name => @configuration.name}).raises(Exception.new) | ||
56 | + assert_raise Exception do @configuration.destroy end | ||
57 | + end | ||
58 | +end |
plugins/mezuro/test/unit/kalibro/entities/configuration_test.rb
@@ -1,20 +0,0 @@ | @@ -1,20 +0,0 @@ | ||
1 | -require "test_helper" | ||
2 | - | ||
3 | -require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | ||
4 | - | ||
5 | -class ConfigurationTest < ActiveSupport::TestCase | ||
6 | - | ||
7 | - def setup | ||
8 | - @hash = ConfigurationFixtures.kalibro_configuration_hash | ||
9 | - @configuration = ConfigurationFixtures.kalibro_configuration | ||
10 | - end | ||
11 | - | ||
12 | - should 'create configuration from hash' do | ||
13 | - assert_equal @configuration, Kalibro::Entities::Configuration.from_hash(@hash) | ||
14 | - end | ||
15 | - | ||
16 | - should 'convert configuration to hash' do | ||
17 | - assert_equal @hash, @configuration.to_hash | ||
18 | - end | ||
19 | - | ||
20 | -end |
plugins/mezuro/test/unit/kalibro/entities/entity_test.rb
@@ -1,51 +0,0 @@ | @@ -1,51 +0,0 @@ | ||
1 | -require "test_helper" | ||
2 | - | ||
3 | -class EntityTest < ActiveSupport::TestCase | ||
4 | - | ||
5 | - def setup | ||
6 | - @hash = {:name => 'Carlos', :age => 25, | ||
7 | - :brothers => [{:name => 'Saulo', :age => 22}, {:name => 'Isis', :age => 26}]} | ||
8 | - @person = Person.create('Carlos', 25) | ||
9 | - @person.brothers = [Person.create('Saulo', 22), Person.create('Isis', 26)] | ||
10 | - @clone = @person.clone | ||
11 | - end | ||
12 | - | ||
13 | - should 'be equal to clone' do | ||
14 | - assert_equal @person, @clone | ||
15 | - end | ||
16 | - | ||
17 | - should 'be different when field is different' do | ||
18 | - @clone.name = 'Other' | ||
19 | - assert @person != @clone | ||
20 | - end | ||
21 | - | ||
22 | - should 'not throw exception when comparing with incompatible object' do | ||
23 | - assert @person != @hash | ||
24 | - end | ||
25 | - | ||
26 | - should 'create from hash' do | ||
27 | - assert_equal @person, Person.from_hash(@hash) | ||
28 | - end | ||
29 | - | ||
30 | - should 'convert to hash' do | ||
31 | - assert_equal @hash, @person.to_hash | ||
32 | - end | ||
33 | - | ||
34 | - class Person < Kalibro::Entities::Entity | ||
35 | - | ||
36 | - attr_accessor :name, :age, :brothers | ||
37 | - | ||
38 | - def self.create(name, age) | ||
39 | - person = Person.new | ||
40 | - person.name = name | ||
41 | - person.age = age | ||
42 | - person | ||
43 | - end | ||
44 | - | ||
45 | - def brothers=(value) | ||
46 | - @brothers = to_entity_array(value, Person) | ||
47 | - end | ||
48 | - | ||
49 | - end | ||
50 | - | ||
51 | -end | ||
52 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/test/unit/kalibro/project_test.rb
@@ -27,7 +27,7 @@ class ProjectTest < ActiveSupport::TestCase | @@ -27,7 +27,7 @@ class ProjectTest < ActiveSupport::TestCase | ||
27 | should 'raise error when project doesnt exist' do | 27 | should 'raise error when project doesnt exist' do |
28 | request_body = {:project_name => @project.name} | 28 | request_body = {:project_name => @project.name} |
29 | Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) | 29 | Kalibro::Project.expects(:request).with("Project", :get_project, request_body).raises(Exception.new("(S:Server) There is no project named " + @project.name)) |
30 | - assert_nil Kalibro::Project.find_by_name(@project.name) | 30 | + assert_raise Exception do Kalibro::Project.find_by_name(@project.name) end |
31 | end | 31 | end |
32 | 32 | ||
33 | should 'return true when project is saved successfully' do | 33 | should 'return true when project is saved successfully' do |
plugins/mezuro/test/unit/mezuro_plugin/configuration_content_test.rb
@@ -5,7 +5,7 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | @@ -5,7 +5,7 @@ require "#{RAILS_ROOT}/plugins/mezuro/test/fixtures/configuration_fixtures" | ||
5 | class ConfigurationContentTest < ActiveSupport::TestCase | 5 | class ConfigurationContentTest < ActiveSupport::TestCase |
6 | 6 | ||
7 | def setup | 7 | def setup |
8 | - @configuration = ConfigurationFixtures.kalibro_configuration | 8 | + @configuration = ConfigurationFixtures.configuration |
9 | @content = MezuroPlugin::ConfigurationContent.new | 9 | @content = MezuroPlugin::ConfigurationContent.new |
10 | @content.name = @configuration.name | 10 | @content.name = @configuration.name |
11 | @content.description = @configuration.description | 11 | @content.description = @configuration.description |
@@ -28,15 +28,13 @@ class ConfigurationContentTest < ActiveSupport::TestCase | @@ -28,15 +28,13 @@ class ConfigurationContentTest < ActiveSupport::TestCase | ||
28 | end | 28 | end |
29 | 29 | ||
30 | should 'not save a configuration with an existing cofiguration name in kalibro' do | 30 | should 'not save a configuration with an existing cofiguration name in kalibro' do |
31 | - client = mock | ||
32 | - Kalibro::Client::ConfigurationClient.expects(:new).returns(client) | ||
33 | - client.expects(:configuration_names).returns([@content.name.upcase]) | 31 | + Kalibro::Configuration.expects(:all_names).returns([@content.name.upcase]) |
34 | @content.send :validate_kalibro_configuration_name | 32 | @content.send :validate_kalibro_configuration_name |
35 | assert_equal "Configuration name already exists in Kalibro", @content.errors.on_base | 33 | assert_equal "Configuration name already exists in Kalibro", @content.errors.on_base |
36 | end | 34 | end |
37 | 35 | ||
38 | should 'get configuration from service' do | 36 | should 'get configuration from service' do |
39 | - Kalibro::Client::ConfigurationClient.expects(:configuration).with(@content.name).returns(@configuration) | 37 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) |
40 | assert_equal @configuration, @content.configuration | 38 | assert_equal @configuration, @content.configuration |
41 | end | 39 | end |
42 | 40 | ||
@@ -46,12 +44,20 @@ class ConfigurationContentTest < ActiveSupport::TestCase | @@ -46,12 +44,20 @@ class ConfigurationContentTest < ActiveSupport::TestCase | ||
46 | end | 44 | end |
47 | 45 | ||
48 | should 'send correct configuration to service' do | 46 | should 'send correct configuration to service' do |
49 | - Kalibro::Client::ConfigurationClient.expects(:save).with(@content) | 47 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) |
48 | + @configuration.expects(:save).returns(true) | ||
49 | + @content.send :send_configuration_to_service | ||
50 | + end | ||
51 | + | ||
52 | + should 'send correct configuration to service but comunication fails' do | ||
53 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) | ||
54 | + @configuration.expects(:save).returns(false) | ||
50 | @content.send :send_configuration_to_service | 55 | @content.send :send_configuration_to_service |
51 | end | 56 | end |
52 | 57 | ||
53 | should 'remove configuration from service' do | 58 | should 'remove configuration from service' do |
54 | - Kalibro::Client::ConfigurationClient.expects(:remove).with(@content.name) | 59 | + Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) |
60 | + @configuration.expects(:destroy) | ||
55 | @content.send :remove_configuration_from_service | 61 | @content.send :remove_configuration_from_service |
56 | end | 62 | end |
57 | 63 |
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | <% | 3 | <% |
4 | begin | 4 | begin |
5 | - @configuration = @article.title.nil? ? nil : Kalibro::Client::ConfigurationClient.new.configuration(@article.title) | 5 | + @configuration = @article.title.nil? ? nil : Kalibro::Configuration.find_by_name(@article.title) |
6 | rescue | 6 | rescue |
7 | @configuration = nil | 7 | @configuration = nil |
8 | end | 8 | end |
plugins/mezuro/views/content_viewer/show_configuration.rhtml
1 | <% @configuration_content = @page | 1 | <% @configuration_content = @page |
2 | -@configuration = Kalibro::Client::ConfigurationClient.new.configuration(@configuration_content.name) %> | 2 | +@configuration = Kalibro::Configuration.find_by_name(@configuration_content.name) %> |
3 | 3 | ||
4 | <table id="project_info"> | 4 | <table id="project_info"> |
5 | <tr> | 5 | <tr> |
@@ -26,7 +26,7 @@ | @@ -26,7 +26,7 @@ | ||
26 | <% @configuration.metric_configurations.each do |metric_configuration| %> | 26 | <% @configuration.metric_configurations.each do |metric_configuration| %> |
27 | <tr class="metric"> | 27 | <tr class="metric"> |
28 | <td><%= metric_configuration.metric.name %></td> | 28 | <td><%= metric_configuration.metric.name %></td> |
29 | - <% if metric_configuration.metric.instance_of? Kalibro::Entities::NativeMetric %> | 29 | + <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %> |
30 | <td> | 30 | <td> |
31 | <%= metric_configuration.metric.origin %> | 31 | <%= metric_configuration.metric.origin %> |
32 | </td> | 32 | </td> |
plugins/mezuro/views/mezuro_plugin_myprofile/edit_compound_metric_configuration.html.erb
@@ -2,6 +2,8 @@ | @@ -2,6 +2,8 @@ | ||
2 | 2 | ||
3 | <% form_for :metric_configuration, :url => {:action =>"update_compound_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | 3 | <% form_for :metric_configuration, :url => {:action =>"update_compound_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> |
4 | <%= hidden_field_tag :id, @configuration_content.id %> | 4 | <%= hidden_field_tag :id, @configuration_content.id %> |
5 | + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %> | ||
6 | + | ||
5 | <p> | 7 | <p> |
6 | <%= "Metric Name:" + @metric.name %> | 8 | <%= "Metric Name:" + @metric.name %> |
7 | </p> | 9 | </p> |
plugins/mezuro/views/mezuro_plugin_myprofile/edit_metric_configuration.html.erb
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | 4 | ||
5 | <% form_for :metric_configuration, :url => {:action =>"update_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | 5 | <% form_for :metric_configuration, :url => {:action =>"update_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> |
6 | <%= hidden_field_tag :id, @configuration_content.id %> | 6 | <%= hidden_field_tag :id, @configuration_content.id %> |
7 | + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %> | ||
7 | 8 | ||
8 | <% f.fields_for :metric do |m| %> | 9 | <% f.fields_for :metric do |m| %> |
9 | 10 | ||
@@ -67,7 +68,9 @@ | @@ -67,7 +68,9 @@ | ||
67 | </td> | 68 | </td> |
68 | <td> | 69 | <td> |
69 | Color | 70 | Color |
70 | - </td> | 71 | + </td> |
72 | + <td></td> | ||
73 | + <td></td> | ||
71 | </tr> | 74 | </tr> |
72 | <% if (@metric_configuration.ranges!=nil) | 75 | <% if (@metric_configuration.ranges!=nil) |
73 | @metric_configuration.ranges.each do |range| %> | 76 | @metric_configuration.ranges.each do |range| %> |
plugins/mezuro/views/mezuro_plugin_myprofile/new_compound_metric_configuration.html.erb
@@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
3 | <% form_for :metric_configuration, :url => {:action =>"create_compound_metric_configuration", | 3 | <% form_for :metric_configuration, :url => {:action =>"create_compound_metric_configuration", |
4 | :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | 4 | :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> |
5 | <%= hidden_field_tag :id, @configuration_content.id %> | 5 | <%= hidden_field_tag :id, @configuration_content.id %> |
6 | + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %> | ||
7 | + | ||
6 | <% f.fields_for :metric do |m| %> | 8 | <% f.fields_for :metric do |m| %> |
7 | <p> | 9 | <p> |
8 | <%= m.label :name, "Name:" %> | 10 | <%= m.label :name, "Name:" %> |
plugins/mezuro/views/mezuro_plugin_myprofile/new_metric_configuration.html.erb
1 | <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script> | 1 | <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script> |
2 | 2 | ||
3 | -<h2><%= @configuration_content.name %> Configuration</h2> | 3 | +<h2><%= @configuration_content.name %>Configuration</h2> |
4 | 4 | ||
5 | <% form_for :metric_configuration, :url => {:action =>"create_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> | 5 | <% form_for :metric_configuration, :url => {:action =>"create_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> |
6 | <%= hidden_field_tag :id, @configuration_content.id %> | 6 | <%= hidden_field_tag :id, @configuration_content.id %> |
7 | + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %> | ||
7 | 8 | ||
8 | <% f.fields_for :metric do |m| %> | 9 | <% f.fields_for :metric do |m| %> |
9 | 10 |