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) ⇒ 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_for(role) ⇒ 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_invalid_configuration ⇒ Object
- #given_metadata ⇒ Object
- #given_missing_configuration ⇒ 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 ⇒ ConfigurationService::Test::Response
Publish configuration.
-
#request_configuration ⇒ 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
40 41 42 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 40 def initialize @identifier = "acme" end |
Instance Method Details
#authorize(role) ⇒ Object
117 118 119 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 117 def (role) @credentials = credentials_for(role) end |
#authorize_consumption ⇒ String
Authorize consumption of a configuration
191 192 193 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 191 def @credentials = service.(identifier: @identifier) end |
#broken_service_provider ⇒ Object
A broken service provider
79 80 81 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 79 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
232 233 234 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 232 def configuration_found_for_identifier? @requested_configuration.identifier == @identifier end |
#credentials_allow_consumption? ⇒ Boolean
195 196 197 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 195 def credentials_allow_consumption? request_configuration end |
#credentials_allow_publication? ⇒ Boolean
199 200 201 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 199 def credentials_allow_publication? publish_configuration end |
#credentials_for(role) ⇒ 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.
110 111 112 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 110 def credentials_for(role) raise NotImplementedError, "#{self.class} must implement credentials_for(role)" end |
#deauthorize ⇒ Object
124 125 126 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 124 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.
92 93 94 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 92 def delete_configuration raise NotImplementedError, "#{self.class} must implement delete_configuration" end |
#existing_revision ⇒ Object
164 165 166 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 164 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.
243 244 245 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 243 def fail_next_request @fail_next = true end |
#given_existing_configuration ⇒ Object
138 139 140 141 142 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 138 def given_existing_configuration (:publisher) do @existing_configuration = publish_configuration end end |
#given_invalid_configuration ⇒ Object
147 148 149 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 147 def given_invalid_configuration @configuration = "This should be an object!" end |
#given_metadata ⇒ Object
131 132 133 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 131 def = {"version" => "1.0"} end |
#given_missing_configuration ⇒ Object
154 155 156 157 158 159 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 154 def given_missing_configuration (:publisher) do delete_configuration @existing_configuration = nil end end |
#pending(message = nil) ⇒ Object
Mark a cucumber step as pending
252 253 254 255 256 257 258 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 252 def pending( = nil) if raise Cucumber::Pending, else raise Cucumber::Pending end end |
#publish_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.
215 216 217 218 219 220 221 222 223 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 215 def publish_configuration wrap_response do if service.publish_configuration(identifier: @identifier, data: configuration, metadata: ) else service.publish_configuration(identifier: @identifier, data: configuration) end end end |
#request_configuration ⇒ 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.
180 181 182 183 184 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 180 def request_configuration wrap_response do @requested_configuration = service.request_configuration(identifier: @identifier) end end |
#service_provider ⇒ Object
The service provider under test
68 69 70 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 68 def service_provider raise NotImplementedError, "#{self.class} must implement service_provider" end |
#service_provider_configuration ⇒ Hash
The configuration for the service provider under test
59 60 61 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 59 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
50 51 52 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 50 def service_provider_id raise NotImplementedError, "#{self.class} must implement service_provider_id" end |