kalibro_gatekeeper_client 0.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +29 -0
  6. data/AUTHORS +4 -0
  7. data/COPYING +674 -0
  8. data/COPYING.LESSER +165 -0
  9. data/Gemfile +4 -0
  10. data/README.md +77 -0
  11. data/Rakefile +6 -0
  12. data/cucumber.yml +1 -0
  13. data/features/base_tool/all_names.feature +8 -0
  14. data/features/base_tool/find_by_name.feature +12 -0
  15. data/features/configuration/all.feature +10 -0
  16. data/features/metric_configuration/find.feature +18 -0
  17. data/features/metric_configuration/metric_configurations_of.feature +18 -0
  18. data/features/metric_result/descendant_results.feature +19 -0
  19. data/features/metric_result/history_of.feature +20 -0
  20. data/features/metric_result/metric_results_of.feature +19 -0
  21. data/features/module_result/children.feature +18 -0
  22. data/features/module_result/find.feature +15 -0
  23. data/features/module_result/history_of.feature +11 -0
  24. data/features/processing/first_processing_after.feature +18 -0
  25. data/features/processing/first_processing_of.feature +18 -0
  26. data/features/processing/has_processing.feature +18 -0
  27. data/features/processing/has_processing_after.feature +18 -0
  28. data/features/processing/has_processing_before.feature +18 -0
  29. data/features/processing/has_ready_processing.feature +18 -0
  30. data/features/processing/last_processing_before.feature +18 -0
  31. data/features/processing/last_processing_of.feature +18 -0
  32. data/features/processing/last_processing_state_of.feature +18 -0
  33. data/features/processing/last_ready_processing_of.feature +18 -0
  34. data/features/processing/processing_of.feature +32 -0
  35. data/features/processing/processing_with_date_of.feature +32 -0
  36. data/features/project/all.feature +10 -0
  37. data/features/project/creation.feature +9 -0
  38. data/features/project/destroy.feature +10 -0
  39. data/features/project/exists.feature +9 -0
  40. data/features/project/find.feature +10 -0
  41. data/features/range/all.feature +14 -0
  42. data/features/range/exists.feature +13 -0
  43. data/features/range/find.feature +14 -0
  44. data/features/range/ranges_of.feature +22 -0
  45. data/features/range/save.feature +14 -0
  46. data/features/reading/all.feature +13 -0
  47. data/features/reading/exists.feature +13 -0
  48. data/features/reading/find.feature +11 -0
  49. data/features/reading/readings_of.feature +11 -0
  50. data/features/reading_group/all.feature +10 -0
  51. data/features/repository/all.feature +14 -0
  52. data/features/repository/cancel_processing.feature +14 -0
  53. data/features/repository/exists.feature +14 -0
  54. data/features/repository/find.feature +14 -0
  55. data/features/repository/of.feature +15 -0
  56. data/features/repository/process.feature +16 -0
  57. data/features/repository/types.feature +9 -0
  58. data/features/step_definitions/base_tool_steps.rb +28 -0
  59. data/features/step_definitions/configuration_steps.rb +11 -0
  60. data/features/step_definitions/metric_configuration_steps.rb +52 -0
  61. data/features/step_definitions/metric_result_steps.rb +29 -0
  62. data/features/step_definitions/metric_steps.rb +3 -0
  63. data/features/step_definitions/module_result_steps.rb +30 -0
  64. data/features/step_definitions/processing_steps.rb +91 -0
  65. data/features/step_definitions/project_steps.rb +48 -0
  66. data/features/step_definitions/range_steps.rb +68 -0
  67. data/features/step_definitions/reading_group_steps.rb +19 -0
  68. data/features/step_definitions/reading_steps.rb +39 -0
  69. data/features/step_definitions/repository_steps.rb +61 -0
  70. data/features/support/env.rb +25 -0
  71. data/features/support/kalibro_cucumber_helpers.yml.sample +10 -0
  72. data/kalibro_gatekeeper_client.gemspec +49 -0
  73. data/lib/kalibro_gatekeeper_client/entities/base_tool.rb +55 -0
  74. data/lib/kalibro_gatekeeper_client/entities/configuration.rb +34 -0
  75. data/lib/kalibro_gatekeeper_client/entities/date_metric_result.rb +39 -0
  76. data/lib/kalibro_gatekeeper_client/entities/date_module_result.rb +39 -0
  77. data/lib/kalibro_gatekeeper_client/entities/metric.rb +21 -0
  78. data/lib/kalibro_gatekeeper_client/entities/metric_configuration.rb +76 -0
  79. data/lib/kalibro_gatekeeper_client/entities/metric_configuration_snapshot.rb +57 -0
  80. data/lib/kalibro_gatekeeper_client/entities/metric_result.rb +72 -0
  81. data/lib/kalibro_gatekeeper_client/entities/model.rb +174 -0
  82. data/lib/kalibro_gatekeeper_client/entities/module.rb +27 -0
  83. data/lib/kalibro_gatekeeper_client/entities/module_result.rb +75 -0
  84. data/lib/kalibro_gatekeeper_client/entities/process_time.rb +31 -0
  85. data/lib/kalibro_gatekeeper_client/entities/processing.rb +113 -0
  86. data/lib/kalibro_gatekeeper_client/entities/project.rb +35 -0
  87. data/lib/kalibro_gatekeeper_client/entities/range.rb +100 -0
  88. data/lib/kalibro_gatekeeper_client/entities/range_snapshot.rb +37 -0
  89. data/lib/kalibro_gatekeeper_client/entities/reading.rb +67 -0
  90. data/lib/kalibro_gatekeeper_client/entities/reading_group.rb +44 -0
  91. data/lib/kalibro_gatekeeper_client/entities/repository.rb +89 -0
  92. data/lib/kalibro_gatekeeper_client/entities/repository_observer.rb +50 -0
  93. data/lib/kalibro_gatekeeper_client/entities/stack_trace_element.rb +31 -0
  94. data/lib/kalibro_gatekeeper_client/entities/throwable.rb +42 -0
  95. data/lib/kalibro_gatekeeper_client/entities.rb +37 -0
  96. data/lib/kalibro_gatekeeper_client/errors/record_not_found.rb +22 -0
  97. data/lib/kalibro_gatekeeper_client/errors/standard.rb +24 -0
  98. data/lib/kalibro_gatekeeper_client/errors.rb +18 -0
  99. data/lib/kalibro_gatekeeper_client/helpers/aggregation_options.rb +25 -0
  100. data/lib/kalibro_gatekeeper_client/helpers/hash_converters.rb +48 -0
  101. data/lib/kalibro_gatekeeper_client/helpers/request_methods.rb +47 -0
  102. data/lib/kalibro_gatekeeper_client/helpers/xml_converters.rb +20 -0
  103. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/configuration.rb +39 -0
  104. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/hooks.rb +56 -0
  105. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/delete_all_kalibro_entries.sh +23 -0
  106. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/prepare_kalibro_query_file.sh +38 -0
  107. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/put_kalibro_on_test_mode.sh +39 -0
  108. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers/scripts/return_kalibro_from_test_mode.sh +26 -0
  109. data/lib/kalibro_gatekeeper_client/kalibro_cucumber_helpers.rb +40 -0
  110. data/lib/kalibro_gatekeeper_client/version.rb +19 -0
  111. data/lib/kalibro_gatekeeper_client.rb +61 -0
  112. data/lib/rake/test_task.rb +57 -0
  113. data/spec/entities/base_tool_spec.rb +168 -0
  114. data/spec/entities/configuration_spec.rb +61 -0
  115. data/spec/entities/date_metric_result_spec.rb +62 -0
  116. data/spec/entities/date_module_result_spec.rb +61 -0
  117. data/spec/entities/metric_configuration_snapshot_spec.rb +107 -0
  118. data/spec/entities/metric_configuration_spec.rb +173 -0
  119. data/spec/entities/metric_result_spec.rb +188 -0
  120. data/spec/entities/metric_spec.rb +47 -0
  121. data/spec/entities/model_spec.rb +322 -0
  122. data/spec/entities/module_result_spec.rb +163 -0
  123. data/spec/entities/process_time_spec.rb +33 -0
  124. data/spec/entities/processing_spec.rb +334 -0
  125. data/spec/entities/project_spec.rb +68 -0
  126. data/spec/entities/range_snapshot_spec.rb +50 -0
  127. data/spec/entities/range_spec.rb +225 -0
  128. data/spec/entities/reading_group_spec.rb +90 -0
  129. data/spec/entities/reading_spec.rb +148 -0
  130. data/spec/entities/repository_observer_spec.rb +123 -0
  131. data/spec/entities/repository_spec.rb +191 -0
  132. data/spec/entities/stack_trace_element_spec.rb +26 -0
  133. data/spec/entities/throwable_spec.rb +51 -0
  134. data/spec/factories/base_tools.rb +31 -0
  135. data/spec/factories/configurations.rb +29 -0
  136. data/spec/factories/date_metric_results.rb +28 -0
  137. data/spec/factories/date_module_results.rb +22 -0
  138. data/spec/factories/metric_configurations.rb +28 -0
  139. data/spec/factories/metric_configurations_snapshot.rb +26 -0
  140. data/spec/factories/metric_results.rb +24 -0
  141. data/spec/factories/metrics.rb +35 -0
  142. data/spec/factories/models.rb +20 -0
  143. data/spec/factories/module_results.rb +33 -0
  144. data/spec/factories/modules.rb +22 -0
  145. data/spec/factories/process_times.rb +27 -0
  146. data/spec/factories/processings.rb +25 -0
  147. data/spec/factories/projects.rb +29 -0
  148. data/spec/factories/ranges.rb +35 -0
  149. data/spec/factories/ranges_snapshot.rb +26 -0
  150. data/spec/factories/reading_groups.rb +23 -0
  151. data/spec/factories/readings.rb +25 -0
  152. data/spec/factories/repositories.rb +34 -0
  153. data/spec/factories/repository_observers.rb +24 -0
  154. data/spec/factories/stack_trace_elements.rb +24 -0
  155. data/spec/factories/throwables.rb +23 -0
  156. data/spec/helpers/aggregation_options_spec.rb +31 -0
  157. data/spec/helpers/hash_converters_spec.rb +111 -0
  158. data/spec/helpers/xml_converters_spec.rb +64 -0
  159. data/spec/kalibro_entities_spec.rb +108 -0
  160. data/spec/savon/fixtures/config.yml +1 -0
  161. data/spec/savon/fixtures/invalid_config.yml +2 -0
  162. data/spec/savon/fixtures/project/does_not_exists.xml +1 -0
  163. data/spec/savon/savon_test_helper.rb +14 -0
  164. data/spec/spec_helper.rb +56 -0
  165. metadata +466 -0
@@ -0,0 +1,23 @@
1
+ #!/bin/bash
2
+
3
+ # This file is part of KalibroGatekeeperClient
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
+ PASSWORD=$1
20
+ DATABASE=$2
21
+ QUERYFILE=$3
22
+
23
+ sudo su - postgres -c "export PGPASSWORD=$PASSWORD && psql -q -d $DATABASE -f $QUERYFILE"
@@ -0,0 +1,38 @@
1
+ #!/bin/bash
2
+
3
+ # This file is part of KalibroGatekeeperClient
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
+ PSQLFILE=$1
20
+ QUERYFILE=$2
21
+
22
+ if ! [ -f $PSQLFILE ]
23
+ then wget https://raw.github.com/mezuro/kalibro/kalibro-dev/KalibroCore/src/META-INF/PostgreSQL.sql -O $PSQLFILE
24
+ fi
25
+
26
+ DROPLIMIT="END OF DROP TABLES"
27
+ RANGE=$(grep -n "$DROPLIMIT" $PSQLFILE | cut -d":" -f1)
28
+ START=1
29
+ END=$(($RANGE - 1))
30
+ CUT=$START,$END\!d
31
+ REPLACE="s/DROP TABLE IF EXISTS sequences,/TRUNCATE/"
32
+
33
+ if [ -f $QUERYFILE ]
34
+ then sudo rm $QUERYFILE
35
+ fi
36
+
37
+ sed -e "$CUT" -e "$REPLACE" $PSQLFILE > $QUERYFILE
38
+ sudo chown postgres.postgres $QUERYFILE
@@ -0,0 +1,39 @@
1
+ #!/bin/bash
2
+
3
+ # This file is part of KalibroGatekeeperClient
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
+ # where are your .kalibro dir?
20
+ KALIBRO_HOME=$1
21
+
22
+ TOMCAT_RESTART_COMMAND=$2
23
+ TOMCAT_USER=$3
24
+ TOMCAT_GROUP=$4
25
+
26
+ # create a kalibro test dir
27
+ echo "--> Creating tests directory"
28
+ sudo mkdir $KALIBRO_HOME/tests
29
+ echo "--> Copying test settings"
30
+ sudo cp $KALIBRO_HOME/kalibro_test.settings $KALIBRO_HOME/tests/kalibro.settings
31
+ echo "--> Copying log folder"
32
+ sudo cp -r $KALIBRO_HOME/logs $KALIBRO_HOME/tests/logs/
33
+ echo "--> Changing owner of tests directory to tomcat6"
34
+ sudo chown -R $TOMCAT_USER:$TOMCAT_GROUP $KALIBRO_HOME/tests
35
+ sudo chmod 777 -R $KALIBRO_HOME/tests
36
+
37
+ echo "--> Restarting tomcat"
38
+ # you must restart tomcat6
39
+ $TOMCAT_RESTART_COMMAND
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+
3
+ # This file is part of KalibroGatekeeperClient
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
+ KALIBRO_HOME=$1
20
+ TOMCAT_RESTART_COMMAND=$2
21
+
22
+ echo "--> Removing tests directory"
23
+ sudo rm -rf $KALIBRO_HOME/tests
24
+
25
+ # you must restart tomcat6
26
+ $TOMCAT_RESTART_COMMAND
@@ -0,0 +1,40 @@
1
+ # This file is part of KalibroGatekeeperClient
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_gatekeeper_client/kalibro_cucumber_helpers/configuration'
19
+
20
+ module KalibroGatekeeperClient
21
+ module KalibroCucumberHelpers
22
+ @configuration = KalibroGatekeeperClient::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
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient
18
+ VERSION = "0.0.1.rc1"
19
+ end
@@ -0,0 +1,61 @@
1
+ # This file is part of KalibroGatekeeperClient
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 'logger'
19
+ require "kalibro_gatekeeper_client/version"
20
+ require "kalibro_gatekeeper_client/errors"
21
+ require "kalibro_gatekeeper_client/entities"
22
+
23
+ module KalibroGatekeeperClient
24
+ @config = {
25
+ address: "http://localhost:8081"
26
+ }
27
+
28
+ @valid_config_keys = @config.keys
29
+
30
+ @logger = Logger.new(STDOUT)
31
+
32
+ # Configure through hash
33
+ def KalibroGatekeeperClient.configure(opts = {})
34
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
35
+ end
36
+
37
+ # Configure through yaml file
38
+ def KalibroGatekeeperClient.configure_with(path_to_yaml_file)
39
+ begin
40
+ config = YAML::load(IO.read(path_to_yaml_file))
41
+ rescue Errno::ENOENT
42
+ logger.warn("YAML configuration file couldn't be found. Using defaults."); return
43
+ rescue Psych::SyntaxError
44
+ logger.warn("YAML configuration file contains invalid syntax. Using defaults."); return
45
+ end
46
+
47
+ configure(config)
48
+ end
49
+
50
+ def KalibroGatekeeperClient.config
51
+ @config
52
+ end
53
+
54
+ def KalibroGatekeeperClient.logger
55
+ @logger
56
+ end
57
+
58
+ def KalibroGatekeeperClient.logger=(logger)
59
+ @logger = logger
60
+ end
61
+ end
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient
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,168 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient::Entities::BaseTool do
20
+ describe 'all_names' do
21
+ context 'with no base tools' do
22
+ before :each do
23
+ KalibroGatekeeperClient::Entities::BaseTool.
24
+ expects(:request).
25
+ with(:all_names, {}, :get).
26
+ returns({'names' => nil}.to_json)
27
+ end
28
+
29
+ it 'should return empty array' do
30
+ KalibroGatekeeperClient::Entities::BaseTool.all_names.should be_empty
31
+ end
32
+ end
33
+
34
+ context 'with many base tools' do
35
+ let(:base_tool_hash) { FactoryGirl.build(:base_tool).to_hash }
36
+ let(:another_base_tool_hash) { FactoryGirl.build(:another_base_tool).to_hash }
37
+
38
+ before :each do
39
+ KalibroGatekeeperClient::Entities::BaseTool.
40
+ expects(:request).
41
+ with(:all_names, {}, :get).
42
+ returns({'base_tool_names' => [base_tool_hash, another_base_tool_hash]}.to_json)
43
+ end
44
+
45
+ it 'should return the two elements' do
46
+ names = KalibroGatekeeperClient::Entities::BaseTool.all_names
47
+
48
+ names.size.should eq(2)
49
+ names.first.should eq(JSON.parse(base_tool_hash.to_json))
50
+ names.last.should eq(JSON.parse(another_base_tool_hash.to_json))
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'all' do
56
+ context 'with no base tools' do
57
+ before :each do
58
+ KalibroGatekeeperClient::Entities::BaseTool.
59
+ expects(:request).
60
+ with(:all_names, {}, :get).
61
+ returns({'names' => nil}.to_json)
62
+ end
63
+
64
+ it 'should return empty array' do
65
+ KalibroGatekeeperClient::Entities::BaseTool.all_names.should be_empty
66
+ end
67
+ end
68
+
69
+ context 'with many base tools' do
70
+ let(:base_tool) { FactoryGirl.build(:base_tool) }
71
+ let(:another_base_tool) { FactoryGirl.build(:another_base_tool) }
72
+
73
+ before :each do
74
+ KalibroGatekeeperClient::Entities::BaseTool.
75
+ expects(:request).
76
+ with(:all_names, {}, :get).
77
+ returns({'base_tool_names' => [base_tool.name, another_base_tool.name]}.to_json)
78
+
79
+ KalibroGatekeeperClient::Entities::BaseTool.
80
+ expects(:request).
81
+ with(:get, {name: base_tool.name}).
82
+ returns(base_tool.to_hash)
83
+
84
+ KalibroGatekeeperClient::Entities::BaseTool.
85
+ expects(:request).
86
+ with(:get, {name: another_base_tool.name}).
87
+ returns(another_base_tool.to_hash)
88
+ end
89
+
90
+ it 'should return the two elements' do
91
+ base_tools = KalibroGatekeeperClient::Entities::BaseTool.all
92
+
93
+ base_tools.size.should eq(2)
94
+ base_tools.first.name.should eq(base_tool.name)
95
+ base_tools.last.name.should eq(another_base_tool.name)
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'find_by_name' do
101
+ subject { FactoryGirl.build(:base_tool) }
102
+
103
+ context 'with an inexistent name' do
104
+ before :each do
105
+ KalibroGatekeeperClient::Entities::BaseTool.
106
+ expects(:request).
107
+ with(:get, {name: subject.name}).
108
+ returns(nil)
109
+ end
110
+
111
+ it 'should raise a RecordNotFound error' do
112
+ expect { KalibroGatekeeperClient::Entities::BaseTool.find_by_name(subject.name)}.
113
+ to raise_error(KalibroGatekeeperClient::Errors::RecordNotFound)
114
+ end
115
+ end
116
+
117
+ context 'with an existent name' do
118
+ before :each do
119
+ KalibroGatekeeperClient::Entities::BaseTool.
120
+ expects(:request).
121
+ with(:get,{name: subject.name}).
122
+ returns(subject.to_hash)
123
+ end
124
+
125
+ it 'should return a base_tool' do
126
+ KalibroGatekeeperClient::Entities::BaseTool.find_by_name(subject.name).name.should eq(subject.name)
127
+ end
128
+ end
129
+ end
130
+
131
+ describe 'Supported Metric' do
132
+ let(:metric) { FactoryGirl.build(:metric) }
133
+
134
+ before :each do
135
+ KalibroGatekeeperClient::Entities::Metric.
136
+ expects(:to_objects_array).at_least_once.
137
+ with(metric.to_hash).
138
+ returns([metric])
139
+ end
140
+
141
+ context 'supported_metric=' do
142
+ it 'should set the value of the array of supported metrics' do
143
+ subject.supported_metric = metric.to_hash
144
+ subject.supported_metric.first.name.should eq(metric.name)
145
+ end
146
+ end
147
+
148
+ context 'supported_metrics' do
149
+ it 'should return the array of the supported metrics' do
150
+ subject.supported_metric = metric.to_hash
151
+ subject.supported_metrics.first.name.should eq(metric.name)
152
+ end
153
+ end
154
+ end
155
+
156
+ describe 'metric' do
157
+ subject { FactoryGirl.build(:base_tool) }
158
+ let(:metric) { subject.supported_metrics.first }
159
+
160
+ it 'should return nil with an inexistent name' do
161
+ subject.metric("fake name").should be_nil
162
+ end
163
+
164
+ it 'should return a metric with an existent name' do
165
+ subject.metric(metric.name).name.should eq(metric.name)
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,61 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient::Entities::Configuration do
20
+ describe 'id=' do
21
+ it 'should set the value of the attribute id as an Integer' do
22
+ subject.id = "42"
23
+ subject.id.should eq(42)
24
+ end
25
+ end
26
+
27
+ describe 'all' do
28
+ context 'with no configurations' do
29
+ before :each do
30
+ KalibroGatekeeperClient::Entities::Configuration.
31
+ expects(:request).
32
+ with(:all, {}, :get).
33
+ returns({'configurations' => nil}.to_json)
34
+ end
35
+
36
+ it 'should return nil' do
37
+ KalibroGatekeeperClient::Entities::Configuration.all.should be_empty
38
+ end
39
+ end
40
+
41
+ context 'with many configurations' do
42
+ let(:configuration) { FactoryGirl.build(:configuration) }
43
+ let(:another_configuration) { FactoryGirl.build(:another_configuration) }
44
+
45
+ before :each do
46
+ KalibroGatekeeperClient::Entities::Configuration.
47
+ expects(:request).
48
+ with(:all, {}, :get).
49
+ returns({'configurations' => [configuration.to_hash, another_configuration.to_hash]}.to_json)
50
+ end
51
+
52
+ it 'should return the two elements' do
53
+ configurations = KalibroGatekeeperClient::Entities::Configuration.all
54
+
55
+ configurations.size.should eq(2)
56
+ configurations.first.name.should eq(configuration.name)
57
+ configurations.last.name.should eq(another_configuration.name)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,62 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient::Entities::DateMetricResult do
20
+ describe 'date=' do
21
+ context 'when the given value is a String' do
22
+ it 'should set the date and convert it to DateTime' do
23
+ subject.date = "21/12/1995" # Ruby's first publication
24
+
25
+ subject.date.should be_a(DateTime)
26
+ subject.date.should eq(DateTime.parse("21/12/1995"))
27
+ end
28
+ end
29
+
30
+ context 'when the given value is something else than a String' do
31
+ it 'should just set the value' do
32
+ subject.date = :something_else
33
+
34
+ subject.date.should eq(:something_else)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe 'metric_result=' do
40
+ let(:metric_result) { FactoryGirl.build(:metric_result) }
41
+
42
+ before :each do
43
+ KalibroGatekeeperClient::Entities::MetricResult.
44
+ expects(:to_object).
45
+ with(metric_result.to_hash).
46
+ returns(metric_result)
47
+ end
48
+
49
+ it 'should set the metric_result with the given one' do
50
+ subject.metric_result = metric_result.to_hash
51
+ subject.metric_result.should eq(metric_result)
52
+ end
53
+ end
54
+
55
+ describe 'result' do
56
+ subject { FactoryGirl.build(:date_metric_result) }
57
+
58
+ it 'should return the metric result value' do
59
+ subject.result.should eq(10)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,61 @@
1
+ # This file is part of KalibroGatekeeperClient
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 KalibroGatekeeperClient::Entities::DateModuleResult do
20
+ describe 'date=' do
21
+ context 'when the given value is a String' do
22
+ it 'should set the date and convert it to DateTime' do
23
+ subject.date = "21/12/1995" # Ruby's first publication
24
+
25
+ subject.date.should be_a(DateTime)
26
+ subject.date.should eq(DateTime.parse("21/12/1995"))
27
+ end
28
+ end
29
+
30
+ context 'when the given value is something else than a String' do
31
+ it 'should just set the value' do
32
+ subject.date = :something_else
33
+
34
+ subject.date.should eq(:something_else)
35
+ end
36
+ end
37
+ end
38
+
39
+ describe 'module_result=' do
40
+ let(:module_result) { FactoryGirl.build(:module_result) }
41
+ before :each do
42
+ KalibroGatekeeperClient::Entities::ModuleResult.
43
+ expects(:to_object).
44
+ with(module_result.to_hash).
45
+ returns(module_result)
46
+ end
47
+
48
+ it 'should set the module_result with the given one' do
49
+ subject.module_result = module_result.to_hash
50
+ subject.module_result.should eq(module_result)
51
+ end
52
+ end
53
+
54
+ describe 'result' do
55
+ subject {FactoryGirl.build(:date_module_result)}
56
+
57
+ it 'should return the module_result grade' do
58
+ subject.result.should eq(10)
59
+ end
60
+ end
61
+ end