kalibro_client 1.4.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -6
  3. data/features/kalibro_range/find.feature +1 -1
  4. data/features/kalibro_range/update.feature +1 -2
  5. data/features/metric_result/hotspot_related_results.feature +17 -0
  6. data/features/metric_result/{descendant_values.feature → tree/descendant_values.feature} +0 -0
  7. data/features/metric_result/{history_of.feature → tree/history_of.feature} +0 -0
  8. data/features/step_definitions/hotspot_metric_result_step.rb +15 -0
  9. data/features/step_definitions/metric_result_steps.rb +3 -3
  10. data/features/step_definitions/processing_steps.rb +5 -7
  11. data/features/step_definitions/repository_steps.rb +5 -0
  12. data/lib/kalibro_client/entities.rb +3 -1
  13. data/lib/kalibro_client/entities/base.rb +45 -44
  14. data/lib/kalibro_client/entities/configurations/metric_configuration.rb +7 -3
  15. data/lib/kalibro_client/entities/processor/hotspot_metric_result.rb +41 -0
  16. data/lib/kalibro_client/entities/processor/metric_result.rb +12 -32
  17. data/lib/kalibro_client/entities/processor/module_result.rb +20 -2
  18. data/lib/kalibro_client/entities/processor/tree_metric_result.rb +54 -0
  19. data/lib/kalibro_client/errors.rb +3 -1
  20. data/lib/kalibro_client/errors/record_invalid.rb +19 -0
  21. data/lib/kalibro_client/errors/record_not_found.rb +2 -2
  22. data/lib/kalibro_client/errors/request_error.rb +27 -0
  23. data/lib/kalibro_client/helpers/aggregation_options.rb +1 -1
  24. data/lib/kalibro_client/version.rb +1 -1
  25. data/spec/entities/base_spec.rb +292 -201
  26. data/spec/entities/configurations/metric_configuration_spec.rb +1 -1
  27. data/spec/entities/processor/hotspot_metric_result_spec.rb +49 -0
  28. data/spec/entities/processor/metric_result_spec.rb +31 -89
  29. data/spec/entities/processor/module_result_spec.rb +90 -61
  30. data/spec/entities/processor/tree_metric_result_spec.rb +128 -0
  31. data/spec/errors/record_invalid_spec.rb +45 -0
  32. data/spec/factories/hotspot_metric_results.rb +24 -0
  33. data/spec/factories/metric_configurations.rb +1 -1
  34. data/spec/factories/metric_results.rb +0 -1
  35. data/spec/factories/tree_metric_results.rb +24 -0
  36. data/spec/helpers/aggregation_options_spec.rb +1 -1
  37. metadata +24 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed65cbefe30d43263bfeb3de750e2cefa8a369e7
4
- data.tar.gz: c931c4e8fc1caa2388c28799f9e04855da4704e0
3
+ metadata.gz: 3a5bcfbb03d6e6c0d2bf2c3b4d671daf6fe2dcc6
4
+ data.tar.gz: 968a58a0f973981f2909bdb0ef6969a0c19cce24
5
5
  SHA512:
6
- metadata.gz: aa7ecfe6855dee9d5270eaf84521acf67166d436a3450053226aa34fb8ca020ca11db7b9879da4ca71e38ecf44cd5d1f5be1c22851899be5918d64abb7ddefdf
7
- data.tar.gz: a8586ac0368fccb3265b596c363d2c88e364691c1f8d701007756d09b68a161ec1b45a42452c1a929e446b2e3b08f1fe1c3e72fc0f39dd414c691c948c18914f
6
+ metadata.gz: 815e31061ec7660983846ffed1052d3d2bcfaee8c373b287757ca2ba192f3943939fc292687738504a964f664a1dda6d5a4534512e808653407ce8fe9989022b
7
+ data.tar.gz: cec3da37bf2df5bd5926679ddbda0aa7fc76f5c276f309acc46daf732e75d4953b0f3e25408f59ce0c471618a545d40ccee990cf7772c3c4926889959935d754
@@ -5,13 +5,11 @@ rvm:
5
5
  addons:
6
6
  postgresql: "9.3"
7
7
 
8
- before_script:
9
- - git clone https://github.com/mezuro/kalibro_install.git -b v3.5 kalibro_install
10
- - pushd kalibro_install
11
- # Remove bugged libzmq3 package, see https://github.com/travis-ci/travis-ci/issues/982 and https://github.com/travis-ci/travis-ci/issues/1715 for details
8
+ before_script:
9
+ # Remove bugged libzmq3 package, see https://github.com/travis-ci/travis-ci/issues/982 and https://github.com/travis-ci/travis-ci/issues/1715 for details
12
10
  - sudo apt-get remove libzmq3
13
- - bash install.sh
14
- - popd
11
+ - git clone https://github.com/mezuro/kalibro_install.git -b v3.8 kalibro_install
12
+ - KALIBRO_PROCESSOR_VERSION='v1.0.0' KALIBRO_CONFIGURATIONS_VERSION='v1.1.1' ./kalibro_install/install.sh
15
13
  - cp features/support/kalibro_cucumber_helpers.yml.sample features/support/kalibro_cucumber_helpers.yml
16
14
  - export BUNDLE_GEMFILE=$PWD/Gemfile
17
15
  - export CODECLIMATE_REPO_TOKEN=46cbb96b053b03ad66b0355bd96d0787f56fc5a4fc171b8d6eb30c421c5e6777
@@ -20,6 +18,10 @@ script:
20
18
  - bundle exec rspec spec
21
19
  - bundle exec cucumber --tags ~@wip
22
20
 
21
+ after_failure:
22
+ - echo Tests failed - preparing to ship logs to Gist
23
+ - ./kalibro_install/travis-send-logs.sh
24
+
23
25
  notifications:
24
26
  email:
25
27
  recipients:
@@ -11,4 +11,4 @@ Scenario: find a valid range
11
11
  And I have a reading within the given reading group
12
12
  And I have a range within the given reading
13
13
  When I search a range with the same id of the given range
14
- Then it should return the same range as the given one
14
+ Then it should return the same range as the given one
@@ -49,6 +49,5 @@ Feature: Update
49
49
  And I have another range within the given reading
50
50
  When I change the "beginning" to "0"
51
51
  And I ask to update the given range
52
- Then I should get the error "Beginning Should be unique within a Metric Configuration"
52
+ Then I should get the error "Beginning Should be unique within a Metric Configuration"
53
53
  And I should get the error "Beginning There is already a KalibroRange within these boundaries! Please, choose another interval."
54
-
@@ -0,0 +1,17 @@
1
+ Feature: Related HotspotMetricResults
2
+ In order to list which HotspotMetricResult is related to a given one
3
+ As a developer
4
+ I want to be able to call them directly as they were associated
5
+
6
+ @kalibro_configuration_restart @kalibro_processor_restart
7
+ Scenario: when there are HotspotMetricResults
8
+ Given I have a kalibro configuration with name "Conf"
9
+ And I have a flay configuration within the given kalibro configuration
10
+ And I have the given repository:
11
+ | name | scm_type | address | branch |
12
+ | Kalibro Processor | GIT | https://github.com/mezuro/kalibro_processor.git | v0.11.0 |
13
+ And I call the process method for the given repository
14
+ And I wait up for a ready processing
15
+ When I request the first hotspot metric result from the root module result
16
+ And I ask for the related results for the given metric result
17
+ Then I should get a list of hotspot metric results including the given one
@@ -0,0 +1,15 @@
1
+ When(/^I request the first hotspot metric result from the root module result$/) do
2
+ root_module_result = KalibroClient::Entities::Processor::ModuleResult.find @repository.last_ready_processing.root_module_result_id
3
+ @hotspot_metric_result = root_module_result.hotspot_metric_results.first
4
+ end
5
+
6
+ When(/^I ask for the related results for the given metric result$/) do
7
+ @related_results = @hotspot_metric_result.related_results
8
+ end
9
+
10
+ Then(/^I should get a list of hotspot metric results including the given one$/) do
11
+ expect(@related_results).to include(@hotspot_metric_result)
12
+ @related_results.each do |related_result|
13
+ expect(related_result).to be_a KalibroClient::Entities::Processor::HotspotMetricResult
14
+ end
15
+ end
@@ -1,16 +1,16 @@
1
1
  When(/^I call the metric results of method with the results root id of the given processing$/) do
2
- @response = KalibroClient::Entities::Processor::ModuleResult.find(@response.root_module_result_id).metric_results
2
+ @response = KalibroClient::Entities::Processor::ModuleResult.find(@response.root_module_result_id).tree_metric_results
3
3
  end
4
4
 
5
5
  Given(/^I search a metric result with descendant values for the given metric result$/) do
6
6
  first_module_result = KalibroClient::Entities::Processor::ModuleResult.find(@response.root_module_result_id)
7
7
 
8
- metric_results = first_module_result.metric_results
8
+ metric_results = first_module_result.tree_metric_results
9
9
  @response = metric_results.first.descendant_values
10
10
  end
11
11
 
12
12
  When(/^I call the history of method with the metric name and the results root id of the given processing$/) do
13
- @response = KalibroClient::Entities::Processor::MetricResult.history_of(@metric.name, @response.root_module_result_id, @repository.id)
13
+ @response = KalibroClient::Entities::Processor::TreeMetricResult.history_of(@metric.name, @response.root_module_result_id, @repository.id)
14
14
  end
15
15
 
16
16
  Then (/^I should get a Float list$/) do
@@ -1,11 +1,9 @@
1
+ require 'timeout'
2
+
1
3
  Given(/^I wait up for a ready processing$/) do
2
- unless @repository.has_ready_processing
3
- while(true)
4
- if @repository.has_ready_processing
5
- break
6
- else
7
- sleep(10)
8
- end
4
+ Timeout::timeout(300) do
5
+ while !@repository.has_ready_processing
6
+ sleep(2)
9
7
  end
10
8
  end
11
9
  end
@@ -10,6 +10,11 @@ Given(/^the given project has the following Repositories:$/) do |table|
10
10
  @repository = FactoryGirl.create(:repository, hash)
11
11
  end
12
12
 
13
+ Given(/^I have the given repository:$/) do |table|
14
+ repository_attrs = table.hashes.first
15
+ @repository = FactoryGirl.create(:repository, repository_attrs)
16
+ end
17
+
13
18
  When(/^I call the cancel_process method for the given repository$/) do
14
19
  @response = @repository.cancel_processing_of_repository
15
20
  end
@@ -33,10 +33,12 @@ require 'kalibro_client/entities/miscellaneous/compound_metric'
33
33
  require 'kalibro_client/entities/processor/base'
34
34
  require 'kalibro_client/entities/processor/metric_collector_details'
35
35
  require 'kalibro_client/entities/processor/metric_result'
36
+ require 'kalibro_client/entities/processor/tree_metric_result'
37
+ require 'kalibro_client/entities/processor/hotspot_metric_result'
36
38
  require 'kalibro_client/entities/processor/kalibro_module'
37
39
  require 'kalibro_client/entities/processor/module_result'
38
40
  require 'kalibro_client/entities/processor/process_time'
39
41
  require 'kalibro_client/entities/processor/processing'
40
42
  require 'kalibro_client/entities/processor/project'
41
43
  require 'kalibro_client/entities/processor/repository'
42
- require 'kalibro_client/entities/configurations/statistic'
44
+ require 'kalibro_client/entities/configurations/statistic'
@@ -45,14 +45,22 @@ module KalibroClient
45
45
  url = "/#{endpoint}/#{action}".gsub(":id", params[:id].to_s)
46
46
  url = "/#{prefix}#{url}" unless prefix.empty?
47
47
  request.url url
48
- request.body = params unless params.empty?
48
+ request.body = params unless method == :get || params.empty?
49
49
  request.options.timeout = 300
50
50
  request.options.open_timeout = 300
51
51
  end
52
52
 
53
- response.body
53
+ if response.success?
54
+ response.body
55
+ # FIXME This condition was added to preserve the deprecated error codes that are returned by kalibro processor
56
+ elsif response.status == 404 || (response.body.key?('errors') && /NotFound/ === response.body['errors'])
57
+ raise KalibroClient::Errors::RecordNotFound.new(response: response)
58
+ else
59
+ raise KalibroClient::Errors::RequestError.new(response: response)
60
+ end
54
61
  end
55
62
 
63
+
56
64
  def self.to_object value
57
65
  value.kind_of?(Hash) ? new(value, true) : value
58
66
  end
@@ -66,28 +74,20 @@ module KalibroClient
66
74
  if persisted?
67
75
  self.update
68
76
  else
69
- begin
77
+ without_request_error? do
70
78
  response = self.class.request(save_action, save_params, :post, save_prefix)
71
79
 
72
- if response["errors"].nil?
73
- self.id = response[instance_class_name]["id"]
74
- self.created_at = response[instance_class_name]["created_at"] unless response[instance_class_name]["created_at"].nil?
75
- self.updated_at = response[instance_class_name]["updated_at"] unless response[instance_class_name]["updated_at"].nil?
76
- @persisted = true
77
- true
78
- else
79
- self.kalibro_errors = response["errors"]
80
- false
81
- end
82
- rescue Exception => exception
83
- add_error exception
84
- false
80
+ self.id = response[instance_class_name]["id"]
81
+ self.created_at = response[instance_class_name]["created_at"] unless response[instance_class_name]["created_at"].nil?
82
+ self.updated_at = response[instance_class_name]["updated_at"] unless response[instance_class_name]["updated_at"].nil?
83
+ @persisted = true
85
84
  end
86
85
  end
87
86
  end
88
87
 
89
88
  def save!
90
- save
89
+ return true if save
90
+ raise KalibroClient::Errors::RecordInvalid.new(self)
91
91
  end
92
92
 
93
93
  def self.create(attributes={})
@@ -98,12 +98,8 @@ module KalibroClient
98
98
 
99
99
  def update(attributes={})
100
100
  attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
101
- response = self.class.request(update_action, update_params, :put, update_prefix)
102
- unless response["errors"].nil?
103
- response["errors"].each { |error| add_error(error) }
104
- false
105
- else
106
- true
101
+ without_request_error? do
102
+ self.class.request(update_action, update_params, :put, update_prefix)
107
103
  end
108
104
  end
109
105
 
@@ -127,31 +123,14 @@ module KalibroClient
127
123
  end
128
124
 
129
125
  def self.find(id)
130
- if(exists?(id))
131
- response = request(find_action, id_params(id), :get)
132
- new(response[entity_name], true)
133
- else
134
- raise KalibroClient::Errors::RecordNotFound
135
- end
126
+ response = request(find_action, id_params(id), :get)
127
+ new(response[entity_name], true)
136
128
  end
137
129
 
138
130
  def destroy
139
- begin
131
+ without_request_error? do
140
132
  response = self.class.request(destroy_action, destroy_params, :delete, destroy_prefix)
141
-
142
- unless response['errors'].nil?
143
- response['errors'].each { |error| add_error(error) }
144
- end
145
-
146
- if self.kalibro_errors.empty?
147
- @persisted = false
148
- true
149
- else
150
- false
151
- end
152
- rescue Exception => exception
153
- add_error exception
154
- false
133
+ @persisted = false
155
134
  end
156
135
  end
157
136
 
@@ -224,6 +203,28 @@ module KalibroClient
224
203
  return entity_class.name.split("::").last.underscore.downcase
225
204
  end
226
205
 
206
+ def without_request_error?(&block)
207
+ begin
208
+ block.call
209
+ true
210
+ rescue KalibroClient::Errors::RecordNotFound => error
211
+ raise error
212
+ rescue KalibroClient::Errors::RequestError => error
213
+ raise error if error.response.status.between?(500, 599)
214
+
215
+ response_errors = error.response.body['errors']
216
+ if response_errors.is_a?(Array)
217
+ response_errors.each { |error_msg| add_error(error_msg) }
218
+ elsif !response_errors.nil?
219
+ add_error response_errors
220
+ else
221
+ add_error error
222
+ end
223
+
224
+ false
225
+ end
226
+ end
227
+
227
228
  include HashConverters
228
229
  end
229
230
  end
@@ -69,9 +69,13 @@ module KalibroClient
69
69
  end
70
70
 
71
71
  def self.find(id)
72
- metric_configuration = request(':id', {id: id}, :get)
73
- raise KalibroClient::Errors::RecordNotFound unless metric_configuration['errors'].nil?
74
- return new(metric_configuration['metric_configuration'], true)
72
+ begin
73
+ metric_configuration = request(':id', {id: id}, :get)
74
+ return new(metric_configuration['metric_configuration'], true)
75
+ #FIXME Temporary until KalibroProcessor returns proper http statuses
76
+ rescue KalibroClient::Errors::RequestError
77
+ raise KalibroClient::Errors::RecordNotFound
78
+ end
75
79
  end
76
80
 
77
81
  def self.exists?(id)
@@ -0,0 +1,41 @@
1
+ # This file is part of KalibroClient
2
+ # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module KalibroClient
18
+ module Entities
19
+ module Processor
20
+ class HotspotMetricResult < KalibroClient::Entities::Processor::MetricResult
21
+
22
+ attr_accessor :line_number, :message
23
+
24
+ def initialize(attributes={}, persisted=false)
25
+ @line_number = attributes["line_number"].to_i
26
+ attributes.each do |field, value|
27
+ if field != "line_number" and self.class.is_valid?(field)
28
+ send("#{field}=", value)
29
+ end
30
+ end
31
+ @persisted = persisted
32
+ end
33
+
34
+ def related_results
35
+ HotspotMetricResult.create_objects_array_from_hash(self.class.request(":id/related_results",
36
+ {id: self.id}, :get))
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -21,55 +21,35 @@ module KalibroClient
21
21
 
22
22
  # TODO: related_hotspot_metric_results_id should be enclosed to Processor which does not return this id into the response
23
23
  # there should be a controller that returns all the HotspotMetricResults associated through RelatedHotspotMetricResult
24
- attr_accessor :id, :value, :aggregated_value, :module_result_id, :metric_configuration_id,
24
+ attr_accessor :id, :value, :module_result_id, :metric_configuration_id,
25
25
  :line_number, :message, :related_hotspot_metric_results_id
26
26
  attr_reader :metric_configuration
27
27
 
28
- def initialize(attributes={}, persisted=false)
29
- value = attributes["value"]
30
- @value = (value == "NaN") ? attributes["aggregated_value"].to_f : value.to_f
31
- attributes.each do |field, value|
32
- if field!= "value" and field!= "aggregated_value" and self.class.is_valid?(field)
33
- send("#{field}=", value)
34
- end
35
- end
36
- @kalibro_errors = []
37
- @persisted = persisted
38
- end
39
-
40
28
  def id=(value)
41
29
  @id = value.to_i
42
30
  end
43
31
 
32
+ def metric_configuration
33
+ return nil if @metric_configuration_id.nil?
34
+ if @metric_configuration.nil? || @metric_configuration.id != @metric_configuration_id
35
+ @metric_configuration = KalibroClient::Entities::Configurations::MetricConfiguration.find(@metric_configuration_id)
36
+ end
37
+
38
+ @metric_configuration
39
+ end
40
+
44
41
  def metric_configuration_id=(value)
45
- self.metric_configuration = KalibroClient::Entities::Configurations::MetricConfiguration.request(":id", {id: value.to_i}, :get)["metric_configuration"]
42
+ @metric_configuration_id = (value.nil? ? nil : value.to_i)
46
43
  end
47
44
 
48
45
  def metric_configuration=(value)
49
46
  @metric_configuration = KalibroClient::Entities::Configurations::MetricConfiguration.to_object value
50
- @metric_configuration_id = @metric_configuration.id
47
+ @metric_configuration_id = (@metric_configuration.nil? ? nil : @metric_configuration.id)
51
48
  end
52
49
 
53
50
  def value=(value)
54
51
  @value = value.to_f
55
52
  end
56
-
57
- def aggregated_value=(value)
58
- @aggregated_value = value.to_f
59
- end
60
-
61
- def descendant_values
62
- descendant_values = self.class.request(':id/descendant_values', {id: id}, :get)['descendant_values']
63
- descendant_values.map {|descendant_value| descendant_value.to_f}
64
- end
65
-
66
- def self.history_of(metric_name, kalibro_module_id, repository_id)
67
- response = Repository.request(':id/metric_result_history_of', {metric_name: metric_name,
68
- kalibro_module_id: kalibro_module_id,
69
- id: repository_id})['metric_result_history_of']
70
- response.map { |date_metric_result|
71
- KalibroClient::Entities::Miscellaneous::DateMetricResult.new date_metric_result }
72
- end
73
53
  end
74
54
  end
75
55
  end
@@ -81,8 +81,26 @@ module KalibroClient
81
81
  end
82
82
  end
83
83
 
84
- def metric_results
85
- MetricResult.create_objects_array_from_hash self.class.request(":id/metric_results", {id: self.id}, :get)
84
+ def tree_metric_results
85
+ TreeMetricResult.create_objects_array_from_hash(self.class.request(":id/metric_results", {id: self.id}, :get))
86
+ end
87
+
88
+ def hotspot_metric_results
89
+ HotspotMetricResult.create_objects_array_from_hash(self.class.request(":id/hotspot_metric_results",
90
+ {id: self.id}, :get))
91
+ end
92
+
93
+ # FIXME: KalibroProcessor should return a 404 if the object does not exist instead of 422
94
+ def self.find(id)
95
+ begin
96
+ super
97
+ rescue KalibroClient::Errors::RequestError => e
98
+ if(e.response.status == 422)
99
+ raise KalibroClient::Errors::RecordNotFound.new(response: e.response)
100
+ else
101
+ raise e
102
+ end
103
+ end
86
104
  end
87
105
  end
88
106
  end