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 Base, 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 =
{ :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
-
#broken_service_provider ⇒ Object
A broken service provider.
-
#configuration_found_for_identifier? ⇒ true
Configuration was found for requested identifier.
- #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.
-
#token_for(role) ⇒ String
Provide a token that authorizes a role.
Constructor Details
#initialize ⇒ OrchestrationProvider
The provider is always initialized with the same configuration identifier
39 40 41 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 39 def initialize @identifier = "acme" end |
Instance Method Details
#authorize(role) ⇒ Object
116 117 118 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 116 def (role) @token = token_for(role) end |
#broken_service_provider ⇒ Object
A broken service provider
78 79 80 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 78 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
214 215 216 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 214 def configuration_found_for_identifier? @requested_configuration.identifier == @identifier end |
#deauthorize ⇒ Object
123 124 125 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 123 def @token = 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 @token should not be used, because it may not be sufficiently authorized.
91 92 93 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 91 def delete_configuration raise NotImplementedError, "#{self.class} must implement delete_configuration" end |
#existing_revision ⇒ Object
163 164 165 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 163 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.
225 226 227 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 225 def fail_next_request @fail_next = true end |
#given_existing_configuration ⇒ Object
137 138 139 140 141 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 137 def given_existing_configuration (:publisher) do @existing_configuration = publish_configuration end end |
#given_invalid_configuration ⇒ Object
146 147 148 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 146 def given_invalid_configuration @configuration = "This should be an object!" end |
#given_metadata ⇒ Object
130 131 132 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 130 def @metadata = {"version" => "1.0"} end |
#given_missing_configuration ⇒ Object
153 154 155 156 157 158 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 153 def given_missing_configuration (:publisher) do delete_configuration @existing_configuration = nil end end |
#pending(message = nil) ⇒ Object
Mark a cucumber step as pending
234 235 236 237 238 239 240 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 234 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.
197 198 199 200 201 202 203 204 205 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 197 def publish_configuration wrap_response do if @metadata service.publish_configuration(configuration, @metadata) else service.publish_configuration(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.
179 180 181 182 183 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 179 def request_configuration wrap_response do @requested_configuration = service.request_configuration end end |
#service_provider ⇒ Object
The service provider under test
67 68 69 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 67 def service_provider raise NotImplementedError, "#{self.class} must implement service_provider" end |
#service_provider_configuration ⇒ Hash
The configuration for the service provider under test
58 59 60 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 58 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
49 50 51 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 49 def service_provider_id raise NotImplementedError, "#{self.class} must implement service_provider_id" end |
#token_for(role) ⇒ String
Provide a token that authorizes a role
Valid roles are:
-
:consumer -
:publisher -
:nothing
Note that a token should be returned for :nothing, but the token should not be authorized to consume or publish to the identifier.
109 110 111 |
# File 'lib/configuration_service/test/orchestration_provider.rb', line 109 def token_for(role) raise NotImplementedError, "#{self.class} must implement token_for(role)" end |