kalibro_client 3.0.1 → 4.0.0.alpha1

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/features/metric_collector_details/find_by_name.feature +12 -4
  3. data/features/step_definitions/metric_collector_details_steps.rb +11 -7
  4. data/features/step_definitions/metric_configuration_steps.rb +2 -2
  5. data/features/step_definitions/module_result_steps.rb +1 -1
  6. data/features/support/env.rb +0 -3
  7. data/kalibro_client.gemspec +1 -0
  8. data/lib/kalibro_client.rb +4 -39
  9. data/lib/kalibro_client/entities/base.rb +12 -207
  10. data/lib/kalibro_client/entities/configurations/base.rb +3 -3
  11. data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +0 -4
  12. data/lib/kalibro_client/entities/configurations/metric_configuration.rb +1 -19
  13. data/lib/kalibro_client/entities/configurations/reading_group.rb +1 -5
  14. data/lib/kalibro_client/entities/miscellaneous/base.rb +4 -2
  15. data/lib/kalibro_client/entities/miscellaneous/metric.rb +0 -2
  16. data/lib/kalibro_client/entities/processor/base.rb +3 -3
  17. data/lib/kalibro_client/entities/processor/hotspot_metric_result.rb +1 -1
  18. data/lib/kalibro_client/entities/processor/metric_collector_details.rb +19 -7
  19. data/lib/kalibro_client/entities/processor/module_result.rb +0 -13
  20. data/lib/kalibro_client/entities/processor/project.rb +0 -4
  21. data/lib/kalibro_client/entities/processor/repository.rb +0 -4
  22. data/lib/kalibro_client/entities/processor/tree_metric_result.rb +1 -1
  23. data/lib/kalibro_client/errors.rb +1 -4
  24. data/lib/kalibro_client/kalibro_cucumber_helpers.rb +7 -36
  25. data/lib/kalibro_client/kalibro_cucumber_helpers/cleaner.rb +27 -0
  26. data/lib/kalibro_client/version.rb +1 -1
  27. data/spec/entities/base_spec.rb +17 -449
  28. data/spec/entities/configurations/kalibro_configuration_spec.rb +0 -35
  29. data/spec/entities/configurations/kalibro_range_spec.rb +3 -3
  30. data/spec/entities/configurations/metric_configuration_spec.rb +1 -58
  31. data/spec/entities/configurations/reading_group_spec.rb +0 -32
  32. data/spec/entities/configurations/reading_spec.rb +3 -3
  33. data/spec/entities/processor/metric_collector_details_spec.rb +46 -25
  34. data/spec/entities/processor/module_result_spec.rb +0 -41
  35. data/spec/entities/processor/project_spec.rb +1 -35
  36. data/spec/entities/processor/repository_spec.rb +1 -14
  37. data/spec/{savon/fixtures → fixtures}/config.yml +0 -0
  38. data/spec/{savon/fixtures → fixtures}/invalid_config.yml +0 -0
  39. data/spec/kalibro_cucumber_helpers/cleaner_spec.rb +32 -0
  40. metadata +26 -32
  41. data/lib/kalibro_client/errors/record_invalid.rb +0 -19
  42. data/lib/kalibro_client/errors/record_not_found.rb +0 -22
  43. data/lib/kalibro_client/errors/request_error.rb +0 -27
  44. data/lib/kalibro_client/errors/standard.rb +0 -24
  45. data/lib/kalibro_client/helpers/date_attributes.rb +0 -11
  46. data/lib/kalibro_client/helpers/hash_converters.rb +0 -48
  47. data/lib/kalibro_client/helpers/request_methods.rb +0 -64
  48. data/lib/kalibro_client/helpers/xml_converters.rb +0 -20
  49. data/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb +0 -30
  50. data/spec/errors/record_invalid_spec.rb +0 -45
  51. data/spec/helpers/date_attributes_spec.rb +0 -30
  52. data/spec/helpers/hash_converters_spec.rb +0 -120
  53. data/spec/helpers/xml_converters_spec.rb +0 -64
  54. data/spec/kalibro_entities_spec.rb +0 -112
  55. data/spec/savon/fixtures/project/does_not_exists.xml +0 -1
  56. data/spec/savon/savon_test_helper.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a0a99f3e80edcdf15e34bed010d9a80dec56dc2
4
- data.tar.gz: 8c8259418525e1f52d447df0e0c07db16e9d7a52
3
+ metadata.gz: 6661e355aef4c385cec5b0e63fb1852955c12167
4
+ data.tar.gz: c9e65755d06ff18b3771ad2a5955cc41aec4685a
5
5
  SHA512:
6
- metadata.gz: 8d666c0b2db1ca7028e9e5bbafd32d5375da518f826b22a9910e986e6acb1546ab85afbedf1dbba972cf0050ce0abf4d9ca819edea6d121015cdc6bab6ef8e63
7
- data.tar.gz: 889a0bafb7f686be82cc54de80cf54413b397a58fcbb58ed4e307d6e1ec035247dd9a333c63f5ef850be180fd33ac3f8e5b831f5581a9ad6d115bd87be61c1c2
6
+ metadata.gz: 5957c37b63cc460456d7cefd6281ea7923e90c847394f9c420edf83b02b231ad0205e05de644e01039dd678613a11ef2786185c2b2ec91cbad92d3004e712efa
7
+ data.tar.gz: 11d63b8ba202abdce33662caa54544c1be73383aee7b6559700d2b63715dabb150de710d4d18df98b33e9238fbae7c179558871bc5251007c23df5c53ce7af73
@@ -3,10 +3,18 @@ Feature: Find By Name
3
3
  As a developer
4
4
  I want to get a metric collector by name
5
5
 
6
+ Scenario: get a metric collector by name!
7
+ When I search metric collector Analizo by name!
8
+ Then I should get "Analizo" metric collector
9
+
10
+ Scenario: get a metric collector by inexistent name!
11
+ When I search metric collector Avalio by name!
12
+ Then I should get an error
13
+
6
14
  Scenario: get a metric collector by name
7
- When I search metric collector Analizo by name
8
- Then I should get Analizo metric collector
15
+ When I search metric collector "Analizo" by name
16
+ Then I should get "Analizo" metric collector
9
17
 
10
18
  Scenario: get a metric collector by inexistent name
11
- When I search metric collector Avalio by name
12
- Then I should get an error
19
+ When I search metric collector "Avalio" by name
20
+ Then I should get nil
@@ -2,25 +2,29 @@ When(/^I get all metric collector names$/) do
2
2
  @metric_collector_names = KalibroClient::Entities::Processor::MetricCollectorDetails.all_names
3
3
  end
4
4
 
5
- When(/^I search metric collector Analizo by name$/) do
6
- @result = KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name("Analizo")
5
+ When(/^I search metric collector Analizo by name\!$/) do
6
+ @response = KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name!("Analizo")
7
7
  end
8
8
 
9
- When(/^I search metric collector Avalio by name$/) do
9
+ When(/^I search metric collector Avalio by name\!$/) do
10
10
  @is_error = false
11
11
  begin
12
- KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name("Avalio")
13
- rescue KalibroClient::Errors::RecordNotFound
12
+ KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name!("Avalio")
13
+ rescue Likeno::Errors::RecordNotFound
14
14
  @is_error = true
15
15
  end
16
16
  end
17
17
 
18
+ When(/^I search metric collector "(.+)" by name$/) do |name|
19
+ @response = KalibroClient::Entities::Processor::MetricCollectorDetails.find_by_name(name)
20
+ end
21
+
18
22
  Then(/^it should return Analizo string inside of an array$/) do
19
23
  expect(@metric_collector_names.include?("Analizo")).to be_truthy
20
24
  end
21
25
 
22
- Then(/^I should get Analizo metric collector$/) do
23
- expect(@result.name).to eq("Analizo")
26
+ Then(/^I should get "(.+)" metric collector$/) do |name|
27
+ expect(@response.name).to eq(name)
24
28
  end
25
29
 
26
30
  Then(/^I should get an error$/) do
@@ -38,7 +38,7 @@ When(/^I search an inexistent metric configuration$/) do
38
38
  inexistent_id = rand(Time.now.to_i)
39
39
  begin
40
40
  KalibroClient::Entities::Configurations::MetricConfiguration.find(inexistent_id)
41
- rescue KalibroClient::Errors::RecordNotFound
41
+ rescue Likeno::Errors::RecordNotFound
42
42
  @is_error = true
43
43
  end
44
44
  end
@@ -81,7 +81,7 @@ Then(/^I should get an empty list of metric configurations$/) do
81
81
  end
82
82
 
83
83
  Then(/^the metric configuration should no longer exist$/) do
84
- expect { KalibroClient::Entities::Configurations::MetricConfiguration.find(@metric_configuration.id)}.to raise_error(KalibroClient::Errors::RecordNotFound)
84
+ expect { KalibroClient::Entities::Configurations::MetricConfiguration.find(@metric_configuration.id)}.to raise_error(Likeno::Errors::RecordNotFound)
85
85
  end
86
86
 
87
87
  Then(/^the metric configuration should exist$/) do
@@ -6,7 +6,7 @@ When(/^I ask for an inexistent module result$/) do
6
6
  @is_error = false
7
7
  begin
8
8
  KalibroClient::Entities::Processor::ModuleResult.find(-1)
9
- rescue KalibroClient::Errors::RecordNotFound
9
+ rescue Likeno::Errors::RecordNotFound
10
10
  @is_error = true
11
11
  end
12
12
  end
@@ -15,9 +15,6 @@ end
15
15
  # Kalibro hooks
16
16
  require 'kalibro_client/kalibro_cucumber_helpers/hooks'
17
17
 
18
- # Configuring the right hooks
19
- KalibroClient::KalibroCucumberHelpers.configure_from_yml("#{__dir__}/kalibro_cucumber_helpers.yml")
20
-
21
18
  # The gem itself
22
19
  require 'kalibro_client'
23
20
 
@@ -47,4 +47,5 @@ Gem::Specification.new do |spec|
47
47
 
48
48
  spec.add_dependency "activesupport", ">= 2.2.1" #version in which underscore was introduced
49
49
  spec.add_dependency "faraday_middleware", "~> 0.9"
50
+ spec.add_dependency "likeno", "~> 1.1"
50
51
  end
@@ -14,49 +14,14 @@
14
14
  # You should have received a copy of the GNU General Public License
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
- require 'yaml'
18
- require 'logger'
17
+ require 'likeno'
19
18
  require "kalibro_client/version"
20
19
  require "kalibro_client/errors"
21
20
  require "kalibro_client/entities"
22
21
 
23
22
  module KalibroClient
24
- @config = {
25
- processor_address: "http://localhost:8082",
26
- configurations_address: "http://localhost:8083"
27
- }
23
+ # Apply default configuration to Likeno
24
+ Likeno.configure(processor_address: "http://localhost:8082",
25
+ configurations_address: "http://localhost:8083")
28
26
 
29
- @valid_config_keys = @config.keys
30
-
31
- @logger = Logger.new(STDOUT)
32
-
33
- # Configure through hash
34
- def KalibroClient.configure(opts = {})
35
- opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
36
- end
37
-
38
- # Configure through yaml file
39
- def KalibroClient.configure_with(path_to_yaml_file)
40
- begin
41
- config = YAML::load(IO.read(path_to_yaml_file))
42
- rescue Errno::ENOENT
43
- logger.warn("YAML configuration file couldn't be found. Using defaults."); return
44
- rescue Psych::SyntaxError
45
- logger.warn("YAML configuration file contains invalid syntax. Using defaults."); return
46
- end
47
-
48
- configure(config)
49
- end
50
-
51
- def KalibroClient.config
52
- @config
53
- end
54
-
55
- def KalibroClient.logger
56
- @logger
57
- end
58
-
59
- def KalibroClient.logger=(logger)
60
- @logger = logger
61
- end
62
27
  end
@@ -1,4 +1,4 @@
1
- # This file is part of KalibroClient
1
+ # This file is part of KalibroClient
2
2
  # Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
3
3
  #
4
4
  # This program is free software: you can redistribute it and/or modify
@@ -14,218 +14,23 @@
14
14
  # You should have received a copy of the GNU General Public License
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
- require 'faraday_middleware'
18
- require 'kalibro_client/helpers/hash_converters'
19
- require 'kalibro_client/helpers/request_methods'
17
+ require 'likeno'
18
+ require 'kalibro_client/errors'
20
19
 
21
20
  module KalibroClient
22
21
  module Entities
23
- class Base
24
- attr_accessor :kalibro_errors, :persisted
25
-
26
- def initialize(attributes={}, persisted=false)
27
- attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
28
- @kalibro_errors = []
29
- @persisted = persisted
30
- end
31
-
32
- def to_hash(options={})
33
- hash = Hash.new
34
- excepts = options[:except].nil? ? [] : options[:except]
35
- excepts << "kalibro_errors"
36
- excepts << "persisted"
37
- fields.each do |field|
38
- hash = field_to_hash(field).merge(hash) if !excepts.include?(field)
39
- end
40
- hash
41
- end
42
-
43
- def self.request(action, params = {}, method = :post, prefix="")
44
- response = client.send(method) do |request|
45
- url = "/#{endpoint}/#{action}".gsub(":id", params[:id].to_s)
46
- url = "/#{prefix}#{url}" unless prefix.empty?
47
- request.url url
48
- request.body = params unless method == :get || params.empty?
49
- request.options.timeout = 300
50
- request.options.open_timeout = 300
51
- end
52
-
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
61
- end
62
-
63
-
64
- def self.to_object value
65
- value.kind_of?(Hash) ? new(value, true) : value
66
- end
67
-
68
- def self.to_objects_array value
69
- array = value.kind_of?(Array) ? value : [value]
70
- array.each.map { |element| to_object(element) }
71
- end
72
-
73
- def save
74
- if persisted?
75
- self.update
76
- else
77
- without_request_error? do
78
- response = self.class.request(save_action, save_params, :post, save_prefix)
79
-
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
84
- end
85
- end
86
- end
87
-
88
- def save!
89
- return true if save
90
- raise KalibroClient::Errors::RecordInvalid.new(self)
22
+ class Base < Likeno::Entity
23
+ # We do not track coverage here as it is deprecated and will be removed soon
24
+ # :nocov:
25
+ def kalibro_errors
26
+ STDERR.puts "DEPRECATED: use 'likeno_errors' instead of 'kalibro_errors'."
27
+ self.likeno_errors
91
28
  end
29
+ # :nocov:
92
30
 
93
- def self.create(attributes={})
94
- new_model = new attributes
95
- new_model.save
96
- new_model
31
+ def self.module_name
32
+ 'KalibroClient'
97
33
  end
98
-
99
- def update(attributes={})
100
- attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
101
- without_request_error? do
102
- self.class.request(update_action, update_params, :put, update_prefix)
103
- end
104
- end
105
-
106
- def ==(another)
107
- unless self.class == another.class
108
- return false
109
- end
110
-
111
- self.variable_names.each do |name|
112
- next if name == "created_at" or name == "updated_at" or name == "persisted"
113
- unless self.send("#{name}") == another.send("#{name}") then
114
- return false
115
- end
116
- end
117
-
118
- return true
119
- end
120
-
121
- def self.exists?(id)
122
- request(exists_action, id_params(id), :get)['exists']
123
- end
124
-
125
- def self.find(id)
126
- response = request(find_action, id_params(id), :get)
127
- new(response[entity_name], true)
128
- end
129
-
130
- def destroy
131
- without_request_error? do
132
- response = self.class.request(destroy_action, destroy_params, :delete, destroy_prefix)
133
- @persisted = false
134
- end
135
- end
136
-
137
- def self.create_objects_array_from_hash (response)
138
- create_array_from_hash(response[entity_name.pluralize]).map { |hash| new(hash, true) }
139
- end
140
-
141
- def self.create_array_from_hash (response)
142
- response = [] if response.nil?
143
- response = [response] if response.is_a?(Hash)
144
- response
145
- end
146
-
147
- alias_method :persisted?, :persisted
148
-
149
- protected
150
-
151
- def instance_variable_names
152
- instance_variables.map { |var| var.to_s }
153
- end
154
-
155
- def fields
156
- instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '') }
157
- end
158
-
159
- def variable_names
160
- instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '') }
161
- end
162
-
163
- def self.address
164
- raise NotImplementedError
165
- end
166
-
167
- # TODO: probably the connection could be a class static variable.
168
- def self.client
169
- Faraday.new(:url => KalibroClient.config[address]) do |conn|
170
- conn.request :json
171
- conn.response :json, :content_type => /\bjson$/
172
- conn.adapter Faraday.default_adapter # make requests with Net::HTTP
173
- end
174
- end
175
-
176
- def self.is_valid?(field)
177
- field.to_s[0] != '@' and field != :attributes! and (field =~ /attributes!/).nil? and (field.to_s =~ /xsi/).nil? and (field.to_s =~ /errors/).nil?
178
- end
179
-
180
- # TODO rename to instance_entity_name
181
- def instance_class_name
182
- self.class.entity_name
183
- end
184
-
185
- include RequestMethods
186
- extend RequestMethods::ClassMethods
187
-
188
- def add_error(exception)
189
- @kalibro_errors << exception
190
- end
191
-
192
- def self.endpoint
193
- entity_name.pluralize
194
- end
195
-
196
- def self.entity_name
197
- # This loop is a generic way to make this work even when the children class has a different name
198
- entity_class = self
199
- until entity_class.name.include?("KalibroClient::Entities::") do
200
- entity_class = entity_class.superclass
201
- end
202
-
203
- return entity_class.name.split("::").last.underscore.downcase
204
- end
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
-
228
- include HashConverters
229
34
  end
230
35
  end
231
36
  end
@@ -1,13 +1,13 @@
1
- require 'kalibro_client/helpers/date_attributes'
1
+ require 'likeno/helpers/date_attributes'
2
2
 
3
3
  module KalibroClient
4
4
  module Entities
5
5
  module Configurations
6
6
  class Base < KalibroClient::Entities::Base
7
- include DateAttributes
7
+ include Likeno::DateAttributes
8
8
 
9
9
  def self.address
10
- :configurations_address
10
+ Likeno.config[:configurations_address]
11
11
  end
12
12
  end
13
13
  end
@@ -24,10 +24,6 @@ module KalibroClient
24
24
  @id = value.to_i
25
25
  end
26
26
 
27
- def self.all
28
- create_objects_array_from_hash(request('', {}, :get))
29
- end
30
-
31
27
  def metric_configurations
32
28
  KalibroClient::Entities::Configurations::MetricConfiguration.create_objects_array_from_hash(self.class.request(':id/metric_configurations', {id: id}, :get))
33
29
  end
@@ -56,7 +56,7 @@ module KalibroClient
56
56
  end
57
57
 
58
58
  def update_attributes(attributes={})
59
- attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
59
+ attributes.each { |field, value| send("#{field}=", value) if self.class.valid?(field) }
60
60
  save
61
61
  end
62
62
 
@@ -68,24 +68,6 @@ module KalibroClient
68
68
  create_objects_array_from_hash(request('', {}, :get, "kalibro_configurations/#{configuration_id}"))
69
69
  end
70
70
 
71
- def self.find(id)
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
79
- end
80
-
81
- def self.exists?(id)
82
- begin
83
- return true unless find(id).nil?
84
- rescue KalibroClient::Errors::RecordNotFound
85
- return false
86
- end
87
- end
88
-
89
71
  def kalibro_ranges
90
72
  KalibroClient::Entities::Configurations::KalibroRange.create_objects_array_from_hash(self.class.request(':id/kalibro_ranges', {id: id}, :get))
91
73
  end