kalibro_client 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +27 -0
- data/AUTHORS +4 -0
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/Gemfile +4 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/cucumber.yml +1 -0
- data/features/kalibro_configuration/all.feature +10 -0
- data/features/kalibro_configuration/creation.feature +9 -0
- data/features/kalibro_configuration/destroy.feature +10 -0
- data/features/kalibro_configuration/metric_configurations.feature +12 -0
- data/features/metric_collector_details/all_names.feature +8 -0
- data/features/metric_collector_details/find_by_name.feature +12 -0
- data/features/metric_configuration/creation.feature +11 -0
- data/features/metric_configuration/destroy.feature +12 -0
- data/features/metric_configuration/find.feature +18 -0
- data/features/metric_configuration/metric_configurations_of.feature +18 -0
- data/features/metric_result/descendant_values.feature +19 -0
- data/features/metric_result/history_of.feature +20 -0
- data/features/metric_result/metric_results_of.feature +20 -0
- data/features/module_result/children.feature +19 -0
- data/features/module_result/find.feature +22 -0
- data/features/module_result/history_of.feature +19 -0
- data/features/processing/first_processing_after.feature +18 -0
- data/features/processing/first_processing_of.feature +18 -0
- data/features/processing/has_processing.feature +18 -0
- data/features/processing/has_processing_after.feature +18 -0
- data/features/processing/has_processing_before.feature +18 -0
- data/features/processing/has_ready_processing.feature +18 -0
- data/features/processing/last_processing_before.feature +18 -0
- data/features/processing/last_processing_of.feature +18 -0
- data/features/processing/last_processing_state_of.feature +18 -0
- data/features/processing/last_ready_processing_of.feature +19 -0
- data/features/processing/processing_of.feature +32 -0
- data/features/processing/processing_with_date_of.feature +32 -0
- data/features/project/all.feature +10 -0
- data/features/project/creation.feature +9 -0
- data/features/project/destroy.feature +10 -0
- data/features/project/exists.feature +9 -0
- data/features/project/find.feature +10 -0
- data/features/range/destroy.feature +14 -0
- data/features/range/exists.feature +13 -0
- data/features/range/find.feature +14 -0
- data/features/range/ranges_of.feature +22 -0
- data/features/range/save.feature +14 -0
- data/features/reading/destroy.feature +13 -0
- data/features/reading/exists.feature +13 -0
- data/features/reading/find.feature +11 -0
- data/features/reading/readings_of.feature +11 -0
- data/features/reading_group/all.feature +10 -0
- data/features/reading_group/creation.feature +9 -0
- data/features/reading_group/destroy.feature +11 -0
- data/features/repository/all.feature +14 -0
- data/features/repository/cancel_processing.feature +14 -0
- data/features/repository/destroy.feature +14 -0
- data/features/repository/exists.feature +14 -0
- data/features/repository/find.feature +14 -0
- data/features/repository/of.feature +15 -0
- data/features/repository/process.feature +16 -0
- data/features/repository/types.feature +8 -0
- data/features/step_definitions/configuration_steps.rb +40 -0
- data/features/step_definitions/metric_collector_details_steps.rb +28 -0
- data/features/step_definitions/metric_configuration_steps.rb +61 -0
- data/features/step_definitions/metric_result_steps.rb +33 -0
- data/features/step_definitions/metric_steps.rb +3 -0
- data/features/step_definitions/module_result_steps.rb +46 -0
- data/features/step_definitions/processing_steps.rb +95 -0
- data/features/step_definitions/project_steps.rb +48 -0
- data/features/step_definitions/range_steps.rb +72 -0
- data/features/step_definitions/reading_group_steps.rb +36 -0
- data/features/step_definitions/reading_steps.rb +47 -0
- data/features/step_definitions/repository_steps.rb +71 -0
- data/features/support/env.rb +25 -0
- data/features/support/kalibro_cucumber_helpers.yml.sample +3 -0
- data/kalibro_client.gemspec +49 -0
- data/lib/kalibro_client.rb +62 -0
- data/lib/kalibro_client/entities.rb +40 -0
- data/lib/kalibro_client/entities/base.rb +196 -0
- data/lib/kalibro_client/entities/configurations/base.rb +13 -0
- data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +37 -0
- data/lib/kalibro_client/entities/configurations/kalibro_range.rb +77 -0
- data/lib/kalibro_client/entities/configurations/metric_configuration.rb +93 -0
- data/lib/kalibro_client/entities/configurations/range_snapshot.rb +37 -0
- data/lib/kalibro_client/entities/configurations/reading.rb +56 -0
- data/lib/kalibro_client/entities/configurations/reading_group.rb +34 -0
- data/lib/kalibro_client/entities/miscellaneous/base.rb +57 -0
- data/lib/kalibro_client/entities/miscellaneous/compound_metric.rb +21 -0
- data/lib/kalibro_client/entities/miscellaneous/date_metric_result.rb +14 -0
- data/lib/kalibro_client/entities/miscellaneous/date_module_result.rb +18 -0
- data/lib/kalibro_client/entities/miscellaneous/granularity.rb +54 -0
- data/lib/kalibro_client/entities/miscellaneous/metric.rb +19 -0
- data/lib/kalibro_client/entities/miscellaneous/native_metric.rb +24 -0
- data/lib/kalibro_client/entities/processor/base.rb +16 -0
- data/lib/kalibro_client/entities/processor/kalibro_module.rb +27 -0
- data/lib/kalibro_client/entities/processor/metric_collector_details.rb +53 -0
- data/lib/kalibro_client/entities/processor/metric_result.rb +79 -0
- data/lib/kalibro_client/entities/processor/module_result.rb +82 -0
- data/lib/kalibro_client/entities/processor/process_time.rb +31 -0
- data/lib/kalibro_client/entities/processor/processing.rb +109 -0
- data/lib/kalibro_client/entities/processor/project.rb +34 -0
- data/lib/kalibro_client/entities/processor/repository.rb +75 -0
- data/lib/kalibro_client/errors.rb +18 -0
- data/lib/kalibro_client/errors/record_not_found.rb +22 -0
- data/lib/kalibro_client/errors/standard.rb +24 -0
- data/lib/kalibro_client/helpers/aggregation_options.rb +25 -0
- data/lib/kalibro_client/helpers/hash_converters.rb +48 -0
- data/lib/kalibro_client/helpers/request_methods.rb +55 -0
- data/lib/kalibro_client/helpers/xml_converters.rb +20 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers.rb +60 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers/configuration.rb +30 -0
- data/lib/kalibro_client/kalibro_cucumber_helpers/hooks.rb +25 -0
- data/lib/kalibro_client/version.rb +19 -0
- data/lib/rake/test_task.rb +57 -0
- data/spec/entities/base_spec.rb +313 -0
- data/spec/entities/configurations/base_spec.rb +26 -0
- data/spec/entities/configurations/kalibro_configuration_spec.rb +91 -0
- data/spec/entities/configurations/kalibro_range_spec.rb +174 -0
- data/spec/entities/configurations/metric_configuration_spec.rb +230 -0
- data/spec/entities/configurations/range_snapshot_spec.rb +50 -0
- data/spec/entities/configurations/reading_group_spec.rb +60 -0
- data/spec/entities/configurations/reading_spec.rb +87 -0
- data/spec/entities/miscellaneous/base_spec.rb +49 -0
- data/spec/entities/miscellaneous/compound_metric_spec.rb +36 -0
- data/spec/entities/miscellaneous/date_metric_result_spec.rb +4 -0
- data/spec/entities/miscellaneous/date_module_result_spec.rb +0 -0
- data/spec/entities/miscellaneous/granularity_spec.rb +96 -0
- data/spec/entities/miscellaneous/metric_spec.rb +15 -0
- data/spec/entities/miscellaneous/native_metric_spec.rb +37 -0
- data/spec/entities/processor/base_spec.rb +26 -0
- data/spec/entities/processor/metric_collector_details_spec.rb +146 -0
- data/spec/entities/processor/metric_result_spec.rb +209 -0
- data/spec/entities/processor/module_result_spec.rb +178 -0
- data/spec/entities/processor/process_time_spec.rb +33 -0
- data/spec/entities/processor/processing_spec.rb +333 -0
- data/spec/entities/processor/project_spec.rb +68 -0
- data/spec/entities/processor/repository_spec.rb +140 -0
- data/spec/factories/date_metric_results.rb +30 -0
- data/spec/factories/date_module_results.rb +24 -0
- data/spec/factories/granularities.rb +23 -0
- data/spec/factories/kalibro_configurations.rb +34 -0
- data/spec/factories/kalibro_module.rb +28 -0
- data/spec/factories/kalibro_ranges.rb +40 -0
- data/spec/factories/metric_collector_details.rb +30 -0
- data/spec/factories/metric_configurations.rb +31 -0
- data/spec/factories/metric_results.rb +24 -0
- data/spec/factories/metrics.rb +48 -0
- data/spec/factories/models.rb +23 -0
- data/spec/factories/module_results.rb +43 -0
- data/spec/factories/process_times.rb +27 -0
- data/spec/factories/processings.rb +24 -0
- data/spec/factories/projects.rb +35 -0
- data/spec/factories/ranges_snapshot.rb +26 -0
- data/spec/factories/reading_groups.rb +28 -0
- data/spec/factories/readings.rb +30 -0
- data/spec/factories/repositories.rb +39 -0
- data/spec/helpers/aggregation_options_spec.rb +31 -0
- data/spec/helpers/hash_converters_spec.rb +111 -0
- data/spec/helpers/xml_converters_spec.rb +64 -0
- data/spec/kalibro_entities_spec.rb +112 -0
- data/spec/savon/fixtures/config.yml +2 -0
- data/spec/savon/fixtures/invalid_config.yml +2 -0
- data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
- data/spec/savon/savon_test_helper.rb +14 -0
- data/spec/spec_helper.rb +111 -0
- metadata +479 -0
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
#Inspired on:
|
|
18
|
+
#https://github.com/rails/rails/blob/master/activerecord/lib/active_record/errors.rb
|
|
19
|
+
module KalibroClient
|
|
20
|
+
module Errors
|
|
21
|
+
class Standard < StandardError
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
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 AggregationOptions
|
|
18
|
+
#TODO: internationalization
|
|
19
|
+
def all_with_label
|
|
20
|
+
[
|
|
21
|
+
["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
|
|
22
|
+
["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]
|
|
23
|
+
]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
require 'date'
|
|
18
|
+
require 'kalibro_client/helpers/xml_converters'
|
|
19
|
+
|
|
20
|
+
module HashConverters
|
|
21
|
+
include XMLConverters
|
|
22
|
+
|
|
23
|
+
#FIXME: we can think about a better name. This method actually receives an DateTime and converts it to string
|
|
24
|
+
def date_with_milliseconds(date)
|
|
25
|
+
milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s
|
|
26
|
+
date.to_s[0..18] + milliseconds + date.to_s[19..-1]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def convert_to_hash(value)
|
|
30
|
+
return value if value.nil?
|
|
31
|
+
return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array)
|
|
32
|
+
return value.to_hash if value.is_a?(KalibroClient::Entities::Base) || value.is_a?(KalibroClient::Entities::Miscellaneous::Base)
|
|
33
|
+
return date_with_milliseconds(value) if value.is_a?(DateTime)
|
|
34
|
+
return 'INF' if value.is_a?(Float) and value.infinite? == 1
|
|
35
|
+
return '-INF' if value.is_a?(Float) and value.infinite? == -1
|
|
36
|
+
value.to_s
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def field_to_hash(field)
|
|
40
|
+
hash = Hash.new
|
|
41
|
+
field_value = send(field)
|
|
42
|
+
if !field_value.nil?
|
|
43
|
+
hash[field] = convert_to_hash(field_value)
|
|
44
|
+
hash = get_xml(field, field_value).merge(hash)
|
|
45
|
+
end
|
|
46
|
+
hash
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
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 RequestMethods
|
|
18
|
+
def save_params
|
|
19
|
+
{instance_class_name.underscore.to_sym => self.to_hash}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def save_action
|
|
23
|
+
""
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def save_prefix
|
|
27
|
+
""
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def destroy_action
|
|
31
|
+
":id"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def destroy_params
|
|
35
|
+
{id: self.id}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def destroy_prefix
|
|
39
|
+
""
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
module ClassMethods
|
|
43
|
+
def exists_action
|
|
44
|
+
":id/exists"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def id_params(id)
|
|
48
|
+
{id: id}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def find_action
|
|
52
|
+
":id"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module XMLConverters
|
|
2
|
+
def xml_instance_class_name(object)
|
|
3
|
+
xml_name = object.class.name
|
|
4
|
+
xml_name["KalibroClient::Entities::"] = "" if xml_name.start_with?("KalibroClient::Entities::")
|
|
5
|
+
xml_name[0..0] = xml_name[0..0].downcase
|
|
6
|
+
xml_name + "Xml"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def get_xml(field, field_value)
|
|
10
|
+
hash = Hash.new
|
|
11
|
+
if field_value.is_a?(KalibroClient::Entities::Base)
|
|
12
|
+
hash = {:attributes! => {}}
|
|
13
|
+
hash[:attributes!][field.to_sym] = {
|
|
14
|
+
'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance',
|
|
15
|
+
'xsi:type' => 'kalibro:' + xml_instance_class_name(field_value)
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
hash
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
require 'yaml'
|
|
18
|
+
require 'kalibro_client/kalibro_cucumber_helpers/configuration'
|
|
19
|
+
|
|
20
|
+
module KalibroClient
|
|
21
|
+
module KalibroCucumberHelpers
|
|
22
|
+
@configuration = KalibroClient::KalibroCucumberHelpers::Configuration.new
|
|
23
|
+
|
|
24
|
+
def KalibroCucumberHelpers.configure(&config_block)
|
|
25
|
+
config_block.call(@configuration)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def KalibroCucumberHelpers.configure_from_yml(file_path)
|
|
29
|
+
configuration = YAML.load(File.open("features/support/kalibro_cucumber_helpers.yml"))
|
|
30
|
+
|
|
31
|
+
configuration["kalibro_cucumber_helpers"].each do |config, value|
|
|
32
|
+
@configuration.send("#{config}=", value)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def KalibroCucumberHelpers.configuration
|
|
37
|
+
@configuration
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def KalibroCucumberHelpers.clean_processor
|
|
41
|
+
client = Faraday.new(:url => @configuration.kalibro_processor_address) do |conn|
|
|
42
|
+
conn.request :json
|
|
43
|
+
conn.response :json, :content_type => /\bjson$/
|
|
44
|
+
conn.adapter Faraday.default_adapter # make requests with Net::HTTP
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
client.send(:post, "/tests/clean_database", {})
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def KalibroCucumberHelpers.clean_configurations
|
|
51
|
+
client = Faraday.new(:url => @configuration.kalibro_configurations_address) do |conn|
|
|
52
|
+
conn.request :json
|
|
53
|
+
conn.response :json, :content_type => /\bjson$/
|
|
54
|
+
conn.adapter Faraday.default_adapter # make requests with Net::HTTP
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
client.send(:post, "/tests/clean_database", {})
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
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 KalibroCucumberHelpers
|
|
19
|
+
class Configuration
|
|
20
|
+
attr_accessor :kalibro_processor_address, :kalibro_configurations_address
|
|
21
|
+
|
|
22
|
+
def initialize(attributes={})
|
|
23
|
+
self.kalibro_processor_address = "http://localhost:8082"
|
|
24
|
+
self.kalibro_configurations_address = "http://localhost:8083"
|
|
25
|
+
|
|
26
|
+
attributes.each { |field, value| send("#{field}=", value) if respond_to?("#{field}=") }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
require 'kalibro_client/kalibro_cucumber_helpers'
|
|
18
|
+
|
|
19
|
+
After('@kalibro_processor_restart') do
|
|
20
|
+
KalibroClient::KalibroCucumberHelpers.clean_processor
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
After('@kalibro_configuration_restart') do
|
|
24
|
+
KalibroClient::KalibroCucumberHelpers.clean_configurations
|
|
25
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# This file is part of KalibroClient
|
|
2
|
+
# Copyright (C) 2014 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
|
+
VERSION = "0.0.1"
|
|
19
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# This file is part of KalibroClient
|
|
4
|
+
# Copyright (C) 2013 it's respectives authors (please see the AUTHORS file)
|
|
5
|
+
#
|
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
# (at your option) any later version.
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU General Public License for more details.
|
|
15
|
+
|
|
16
|
+
# You should have received a copy of the GNU General Public License
|
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
# Inspired on: https://github.com/fog/fog/blob/master/lib/tasks/test_task.rb
|
|
20
|
+
|
|
21
|
+
require 'rake'
|
|
22
|
+
require 'rake/tasklib'
|
|
23
|
+
|
|
24
|
+
module KalibroClient
|
|
25
|
+
module Rake
|
|
26
|
+
class TestTask < ::Rake::TaskLib
|
|
27
|
+
def initialize
|
|
28
|
+
|
|
29
|
+
namespace :test do
|
|
30
|
+
desc 'Runs acceptance and unit tests'
|
|
31
|
+
task :all => [:units, :acceptance]
|
|
32
|
+
|
|
33
|
+
desc 'Runs the unit tests'
|
|
34
|
+
task :units do
|
|
35
|
+
unit_tests_command = "bundle exec rspec spec"
|
|
36
|
+
|
|
37
|
+
puts "Running the unit tests with \"#{unit_tests_command}\"\n\n"
|
|
38
|
+
system unit_tests_command
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
desc 'Runs the acceptance tests'
|
|
42
|
+
task :acceptance, [:feature] do |t, args|
|
|
43
|
+
if args.feature.nil?
|
|
44
|
+
acceptance_tests_command = "bundle exec cucumber"
|
|
45
|
+
else
|
|
46
|
+
acceptance_tests_command = "bundle exec cucumber #{args.feature} features/step_definitions/ features/support/"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
puts "Running the acceptance tests with \"#{acceptance_tests_command}\"\n\n"
|
|
50
|
+
system acceptance_tests_command
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
@@ -0,0 +1,313 @@
|
|
|
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
|
+
require 'spec_helper'
|
|
18
|
+
|
|
19
|
+
describe KalibroClient::Entities::Base do
|
|
20
|
+
subject { FactoryGirl.build(:model) }
|
|
21
|
+
|
|
22
|
+
describe 'new' do
|
|
23
|
+
it 'should create a model from an empty hash' do
|
|
24
|
+
subject = KalibroClient::Entities::Base.new {}
|
|
25
|
+
expect(subject.kalibro_errors).to eq([])
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe 'entity_name' do
|
|
30
|
+
it 'should be a String' do
|
|
31
|
+
expect(subject.class.entity_name).to be_a(String)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'should return Base' do
|
|
35
|
+
expect(subject.class.entity_name).to eq('base')
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe 'endpoint' do
|
|
40
|
+
it 'should return the entity_name' do
|
|
41
|
+
endpoint = 'tests'
|
|
42
|
+
KalibroClient::Entities::Base.expects(:entity_name).returns(endpoint)
|
|
43
|
+
expect(KalibroClient::Entities::Base.endpoint).to eq(endpoint)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe 'client' do
|
|
48
|
+
it 'returns a Faraday::Connection' do
|
|
49
|
+
expect { KalibroClient::Entities::Base.client }.to raise_error(NotImplementedError)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe 'request' do
|
|
54
|
+
let(:fixture) { File.read("spec/savon/fixtures/project/does_not_exists.xml") }
|
|
55
|
+
let(:client) { mock('client') }
|
|
56
|
+
let(:response) { mock('response') }
|
|
57
|
+
let(:request) { mock('request') }
|
|
58
|
+
let(:options) { mock('options') }
|
|
59
|
+
|
|
60
|
+
before :each do
|
|
61
|
+
options.expects(:timeout=)
|
|
62
|
+
options.expects(:open_timeout=)
|
|
63
|
+
request.expects(:url).with('/bases/exists')
|
|
64
|
+
request.expects(:body=).with({id: 1})
|
|
65
|
+
request.expects(:options).twice.returns(options)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'for the KalibroClient::Entities module' do
|
|
69
|
+
it 'should successfully get the Kalibro version' do
|
|
70
|
+
response.expects(:body).returns({exists: false})
|
|
71
|
+
client.expects(:post).yields(request).returns(response)
|
|
72
|
+
KalibroClient::Entities::Base.expects(:client).with(any_parameters).returns(client)
|
|
73
|
+
expect(KalibroClient::Entities::Base.request('exists', {id: 1})[:exists]).to eq(false)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context 'with a children class from outside' do
|
|
78
|
+
class Child < KalibroClient::Entities::Base; end
|
|
79
|
+
|
|
80
|
+
it 'should successfully get the Kalibro version' do
|
|
81
|
+
response.expects(:body).returns({exists: false})
|
|
82
|
+
client.expects(:post).yields(request).returns(response)
|
|
83
|
+
Child.expects(:client).with(any_parameters).returns(client)
|
|
84
|
+
expect(Child.request('exists', {id: 1})[:exists]).to eq(false)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe 'to_hash' do
|
|
90
|
+
it 'should return an empty hash' do
|
|
91
|
+
expect(subject.to_hash).to be_empty
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe 'to_object' do
|
|
96
|
+
it 'should return an Object with an empty hash' do
|
|
97
|
+
expect(KalibroClient::Entities::Base.to_object({})).to eq(FactoryGirl.build(:model))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should remain an object if it isn't a Hash" do
|
|
101
|
+
expect(KalibroClient::Entities::Base.to_object(Object.new)).to be_an(Object)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe 'to_objects_array' do
|
|
106
|
+
it 'should convert [{}] to [Model]' do
|
|
107
|
+
expect(KalibroClient::Entities::Base.to_objects_array({})).to eq([FactoryGirl.build(:model)])
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'should remain an array if it already is one' do
|
|
111
|
+
object = Object.new
|
|
112
|
+
expect(KalibroClient::Entities::Base.to_objects_array([object])).to eq([object])
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe 'save' do
|
|
117
|
+
before :each do
|
|
118
|
+
KalibroClient::Entities::Base.
|
|
119
|
+
expects(:request).
|
|
120
|
+
with('', {base: {}}, :post, '').returns({"base" => {'id' => 42, 'kalibro_errors' => []}})
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context "when it doesn't have the method id=" do
|
|
124
|
+
it 'should make a request to save model with id returning false and an error' do
|
|
125
|
+
expect(subject.save).to be(false)
|
|
126
|
+
expect(subject.kalibro_errors[0]).to be_a(NoMethodError)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
context 'when it has the method id=' do
|
|
131
|
+
before :each do
|
|
132
|
+
KalibroClient::Entities::Base.any_instance.expects(:id=).with(42).returns(42)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it 'should make a request to save model with id and return true without errors' do
|
|
136
|
+
expect(subject.save).to be(true)
|
|
137
|
+
expect(subject.kalibro_errors).to be_empty
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
describe 'save!' do
|
|
143
|
+
subject { FactoryGirl.build(:project) }
|
|
144
|
+
|
|
145
|
+
it 'should call save' do
|
|
146
|
+
subject.expects(:save)
|
|
147
|
+
subject.save!
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
describe 'create' do
|
|
152
|
+
before :each do
|
|
153
|
+
subject.expects(:save)
|
|
154
|
+
KalibroClient::Entities::Base.
|
|
155
|
+
expects(:new).
|
|
156
|
+
with({}).
|
|
157
|
+
returns(subject)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it 'should instantiate and save the model' do
|
|
161
|
+
expect(KalibroClient::Entities::Base.create {}).to eq(subject)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
describe '==' do
|
|
166
|
+
context 'comparing objects from different classes' do
|
|
167
|
+
it 'should return false' do
|
|
168
|
+
expect(subject).not_to eq(Object.new)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
context 'with two models with different attribute values' do
|
|
173
|
+
let(:another_model) { FactoryGirl.build(:model) }
|
|
174
|
+
before :each do
|
|
175
|
+
subject.expects(:variable_names).returns(["answer"])
|
|
176
|
+
subject.expects(:send).with("answer").returns(42)
|
|
177
|
+
another_model.expects(:send).with("answer").returns(41)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'should return false' do
|
|
181
|
+
expect(subject).not_to eq(another_model)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
context 'with two empty models' do
|
|
186
|
+
it 'should return true' do
|
|
187
|
+
expect(subject).to eq(FactoryGirl.build(:model))
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
describe 'exists?' do
|
|
193
|
+
context 'with an inexistent id' do
|
|
194
|
+
before :each do
|
|
195
|
+
KalibroClient::Entities::Base.
|
|
196
|
+
expects(:request).
|
|
197
|
+
with(':id/exists', {id: 0}, :get).
|
|
198
|
+
returns({'exists' => false})
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it 'should return false' do
|
|
202
|
+
expect(KalibroClient::Entities::Base.exists?(0)).to eq(false)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
context 'with an existent id' do
|
|
207
|
+
before :each do
|
|
208
|
+
KalibroClient::Entities::Base.
|
|
209
|
+
expects(:request).
|
|
210
|
+
with(':id/exists', {id: 42}, :get).
|
|
211
|
+
returns({'exists' => true})
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it 'should return false' do
|
|
215
|
+
expect(KalibroClient::Entities::Base.exists?(42)).to eq(true)
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
describe 'find' do
|
|
221
|
+
context 'with an inexistent id' do
|
|
222
|
+
before :each do
|
|
223
|
+
KalibroClient::Entities::Base.expects(:exists?).with(0).returns(false)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it 'should raise a RecordNotFound error' do
|
|
227
|
+
expect { KalibroClient::Entities::Base.find(0)}.to raise_error(KalibroClient::Errors::RecordNotFound)
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
context 'with an existent id' do
|
|
232
|
+
before :each do
|
|
233
|
+
KalibroClient::Entities::Base.
|
|
234
|
+
expects(:exists?).with(42).
|
|
235
|
+
returns(true)
|
|
236
|
+
KalibroClient::Entities::Base.
|
|
237
|
+
expects(:request).
|
|
238
|
+
with(':id',{id: 42}, :get).returns("base" => {})
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it 'should return an empty model' do
|
|
242
|
+
expect(KalibroClient::Entities::Base.find(42)).to eq(subject)
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
describe 'destroy' do
|
|
248
|
+
context 'when it gets successfully destroyed' do
|
|
249
|
+
before :each do
|
|
250
|
+
subject.expects(:id).at_least_once.returns(42)
|
|
251
|
+
KalibroClient::Entities::Base.expects(:request).with(':id',{id: subject.id}, :delete, '')
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
it 'should remain with the errors array empty' do
|
|
255
|
+
subject.destroy
|
|
256
|
+
expect(subject.kalibro_errors).to be_empty
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
context 'when the destruction fails' do
|
|
261
|
+
before :each do
|
|
262
|
+
subject.expects(:id).at_least_once.returns(42)
|
|
263
|
+
KalibroClient::Entities::Base.expects(:request).with(':id',{id: subject.id}, :delete, '').raises(Exception.new)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
it "should have an exception inside it's errors" do
|
|
267
|
+
subject.destroy
|
|
268
|
+
|
|
269
|
+
expect(subject.kalibro_errors[0]).to be_an(Exception)
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
describe 'create_objects_array_from_hash' do
|
|
275
|
+
context 'with nil' do
|
|
276
|
+
it 'should return an empty array' do
|
|
277
|
+
expect(KalibroClient::Entities::Base.create_objects_array_from_hash("bases" => nil)).to eq([])
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
context 'with a Hash' do
|
|
282
|
+
it 'should return the correspondent object to the given hash inside of an Array' do
|
|
283
|
+
expect(KalibroClient::Entities::Base.create_objects_array_from_hash("bases" => {})).to eq([subject])
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
describe 'is_valid?' do
|
|
289
|
+
context 'with a global var' do
|
|
290
|
+
it 'should return false' do
|
|
291
|
+
expect(KalibroClient::Entities::Base.is_valid?('@test')).to be_falsey
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
context 'with the attributes var' do
|
|
296
|
+
it 'should return false' do
|
|
297
|
+
expect(KalibroClient::Entities::Base.is_valid?(:attributes!)).to be_falsey
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
context 'with a xsi var' do
|
|
302
|
+
it 'should return false' do
|
|
303
|
+
expect(KalibroClient::Entities::Base.is_valid?('test_xsi')).to be_falsey
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
context 'with a valid var' do
|
|
308
|
+
it 'should return true' do
|
|
309
|
+
expect(KalibroClient::Entities::Base.is_valid?('test')).to be_truthy
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
end
|
|
313
|
+
end
|