Class: ConfigurationService::Test::OrchestrationProvider Abstract
- Inherits:
-
Object
- Object
- ConfigurationService::Test::OrchestrationProvider
- Defined in:
- lib/configuration_service/test/orchestration_provider.rb
Overview
It is a base provider for the test Orchestrator.
Extend this class if you want your test orchestration provider toconstrain your implementation’s interface to work as a configuration service provider. If you have no intention of plugging your implementation into Client, build your own test orchestration provider from scratch, using Orchestrator and StubOrchestrationProvider as a guide.
Extensions should implement:
Direct Known Subclasses
Constant Summary collapse
- ACTIVITY_ROLE_MAP =
{ :admin => :admin, :requesting_configurations => :consumer, :publishing_configurations => :publisher, :nothing => :none # if possible, provide credentials that don't allow operations on the configuration identifier }
- ROLES =
if possible, provide credentials that don’t allow operations on the configuration identifier
ACTIVITY_ROLE_MAP.values
Instance Method Summary collapse
- #authorize(role, identifier = @identifier) ⇒ Object
-
#authorize_consumption ⇒ String
Authorize consumption of a configuration.
-
#broken_service_provider ⇒ Object
A broken service provider.
-
#configuration_found_for_identifier? ⇒ true
Configuration was found for requested identifier.
- #credentials_allow_consumption? ⇒ Boolean
- #credentials_allow_publication? ⇒ Boolean
-
#credentials_allow_reference_consumption? ⇒ Array
Of responses.
-
#credentials_allow_reference_publication? ⇒ Array
Of responses.
-
#credentials_for(role, identifier = @identifier) ⇒ String
Provide a credentials that authorizes a role.
- #deauthorize ⇒ Object
-
#delete_configuration ⇒ nil
Delete configuration data.
- #existing_revision ⇒ Object
-
#fail_next_request ⇒ nil
Arrange for the next publish or request operation to fail.
- #given_existing_configuration ⇒ Object
- #given_existing_configuration_containing_references ⇒ Object
- #given_invalid_configuration ⇒ Object
- #given_metadata ⇒ Object
- #given_missing_configuration ⇒ Object
- #given_referenced_configuration_exists ⇒ Object
-
#initialize ⇒ OrchestrationProvider
constructor
The provider is always initialized with the same configuration
identifier. -
#pending(message = nil) ⇒ Object
Mark a cucumber step as pending.
-
#publish_configuration(identifier = @identifier, configuration = @configuration) ⇒ ConfigurationService::Test::Response
Publish configuration.
- #references_replaced_with_configuration_data? ⇒ Boolean
-
#request_configuration(identifier = @identifier) ⇒ ConfigurationService::Test::Response
Request configuration.
-
#service_provider ⇒ Object
The service provider under test.
-
#service_provider_configuration ⇒ Hash
The configuration for the service provider under test.
-
#service_provider_id ⇒ String
The registered identifier of the service provider under test.
Constructor Details
#initialize ⇒ OrchestrationProvider
The provider is always initialized with the same configuration identifier
41 42 43 44 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 41 def initialize @identifier = 'acme' @configuration = { "verbose" => true } end |
Instance Method Details
#authorize(role, identifier = @identifier) ⇒ Object
119 120 121 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 119 def (role, identifier = @identifier) @credentials = credentials_for(role, identifier) end |
#authorize_consumption ⇒ String
Authorize consumption of a configuration
215 216 217 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 215 def @credentials = service.(identifier: @identifier) end |
#broken_service_provider ⇒ Object
A broken service provider
81 82 83 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 81 def broken_service_provider raise NotImplementedError, "#{self.class} must implement broken_service_provider" end |
#configuration_found_for_identifier? ⇒ true
Configuration was found for requested identifier
274 275 276 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 274 def configuration_found_for_identifier? @requested_configuration.identifier == @identifier end |
#credentials_allow_consumption? ⇒ Boolean
219 220 221 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 219 def credentials_allow_consumption? request_configuration end |
#credentials_allow_publication? ⇒ Boolean
223 224 225 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 223 def credentials_allow_publication? publish_configuration end |
#credentials_allow_reference_consumption? ⇒ Array
Returns of responses.
230 231 232 233 234 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 230 def credentials_allow_reference_consumption? @references.map { |ref| request_configuration(ref) } end |
#credentials_allow_reference_publication? ⇒ Array
Returns of responses.
239 240 241 242 243 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 239 def credentials_allow_reference_publication? @references.map { |ref| publish_configuration(ref) } end |
#credentials_for(role, identifier = @identifier) ⇒ String
Provide a credentials that authorizes a role
Valid roles are:
-
:consumer -
:publisher -
:nothing
Note that a credentials should be returned for :nothing, but the credentials should not be authorized to consume or publish to the identifier.
112 113 114 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 112 def credentials_for(role, identifier = @identifier) raise NotImplementedError, "#{self.class} must implement credentials_for(role)" end |
#deauthorize ⇒ Object
126 127 128 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 126 def @credentials = nil end |
#delete_configuration ⇒ nil
Delete configuration data
Deleting non-existent configuration should not produce an error. The @identifier instance variable may be used to identify the configuration to delete, but @credentials should not be used, because it may not be sufficiently authorized.
94 95 96 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 94 def delete_configuration raise NotImplementedError, "#{self.class} must implement delete_configuration" end |
#existing_revision ⇒ Object
188 189 190 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 188 def existing_revision @existing_configuration.revision end |
#fail_next_request ⇒ nil
Arrange for the next publish or request operation to fail
This is done by using a #broken_service_provider to service the next operation.
299 300 301 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 299 def fail_next_request @fail_next = true end |
#given_existing_configuration ⇒ Object
140 141 142 143 144 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 140 def given_existing_configuration (:publisher, @identifier) do @existing_configuration = publish_configuration(@identifier, @configuration) end end |
#given_existing_configuration_containing_references ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 146 def given_existing_configuration_containing_references @references = ["ref1", "ref2", "ref3"] @unresolved_configuration_data = @references.each_with_object({}) do |reference, configuration_data| configuration_data[reference] = "%{#{reference}}" end (:publisher, @identifier) do @existing_configuration = publish_configuration(@identifier, @unresolved_configuration_data) end end |
#given_invalid_configuration ⇒ Object
171 172 173 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 171 def given_invalid_configuration @configuration = "This should be an object!" end |
#given_metadata ⇒ Object
133 134 135 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 133 def @metadata = {"version" => "1.0"} end |
#given_missing_configuration ⇒ Object
178 179 180 181 182 183 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 178 def given_missing_configuration (:publisher, @identifier) do delete_configuration @existing_configuration = nil end end |
#given_referenced_configuration_exists ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 156 def given_referenced_configuration_exists @references.each { |ref| identifier = ref configuration = { "#{ref}key" => "#{ref}value" } (:publisher, identifier) do publish_configuration(identifier, configuration) end } end |
#pending(message = nil) ⇒ Object
Mark a cucumber step as pending
308 309 310 311 312 313 314 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 308 def pending( = nil) if raise Cucumber::Pending, else raise Cucumber::Pending end end |
#publish_configuration(identifier = @identifier, configuration = @configuration) ⇒ ConfigurationService::Test::Response
Publish configuration
Publish configuration through the configuration service. This exercises the configuration service provider under test through the configuration service API.
The response from the service is wrapped in a test response.
257 258 259 260 261 262 263 264 265 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 257 def publish_configuration(identifier = @identifier, configuration = @configuration) wrap_response do if @metadata service.publish_configuration(identifier: identifier, data: configuration, metadata: @metadata) else service.publish_configuration(identifier: identifier, data: configuration) end end end |
#references_replaced_with_configuration_data? ⇒ Boolean
278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 278 def references_replaced_with_configuration_data? requested_configuration = @requested_configuration.data resolved_configuration = {} @unresolved_configuration_data.each { |key, value| next if not value.is_a? String match = value.match(ConfigurationService::Decorator::ReferenceResolver::PATTERN) if not match.nil? identifier = match[1] resolved_configuration[key] = service.request_configuration(identifier: identifier).data end } return requested_configuration === resolved_configuration end |
#request_configuration(identifier = @identifier) ⇒ ConfigurationService::Test::Response
Request configuration
Request configuration from the configuration service. This exercises the configuration service provider under test through the configuration service API.
The response from the service is wrapped in a test response.
204 205 206 207 208 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 204 def request_configuration(identifier = @identifier) wrap_response do @requested_configuration = service.request_configuration(identifier: identifier) end end |
#service_provider ⇒ Object
The service provider under test
70 71 72 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 70 def service_provider raise NotImplementedError, "#{self.class} must implement service_provider" end |
#service_provider_configuration ⇒ Hash
The configuration for the service provider under test
61 62 63 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 61 def service_provider_configuration raise NotImplementedError, "#{self.class} must implement service_provider_configuration" end |
#service_provider_id ⇒ String
The registered identifier of the service provider under test
52 53 54 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 52 def service_provider_id raise NotImplementedError, "#{self.class} must implement service_provider_id" end |