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_configuration_should_be_resolved ⇒ Object
- #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
219 220 221 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 219 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
278 279 280 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 278 def configuration_found_for_identifier? @requested_configuration.identifier == @identifier end |
#credentials_allow_consumption? ⇒ Boolean
223 224 225 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 223 def credentials_allow_consumption? request_configuration end |
#credentials_allow_publication? ⇒ Boolean
227 228 229 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 227 def credentials_allow_publication? publish_configuration end |
#credentials_allow_reference_consumption? ⇒ Array
Returns of responses.
234 235 236 237 238 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 234 def credentials_allow_reference_consumption? @references.map { |ref| request_configuration(ref) } end |
#credentials_allow_reference_publication? ⇒ Array
Returns of responses.
243 244 245 246 247 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 243 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
192 193 194 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 192 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.
303 304 305 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 303 def fail_next_request @fail_next = true end |
#given_configuration_should_be_resolved ⇒ Object
137 138 139 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 137 def given_configuration_should_be_resolved @resolve = true end |
#given_existing_configuration ⇒ Object
144 145 146 147 148 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 144 def given_existing_configuration (:publisher, @identifier) do @existing_configuration = publish_configuration(@identifier, @configuration) end end |
#given_existing_configuration_containing_references ⇒ Object
150 151 152 153 154 155 156 157 158 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 150 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
175 176 177 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 175 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
182 183 184 185 186 187 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 182 def given_missing_configuration (:publisher, @identifier) do delete_configuration @existing_configuration = nil end end |
#given_referenced_configuration_exists ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 160 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
312 313 314 315 316 317 318 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 312 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.
261 262 263 264 265 266 267 268 269 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 261 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
282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 282 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.
208 209 210 211 212 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 208 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 |