Class: ConfigurationService::Test::OrchestrationProvider Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/configuration_service/test/orchestration_provider.rb

Overview

This class is abstract.

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

StubOrchestrationProvider

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

Constructor Details

#initializeOrchestrationProvider

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 authorize(role)
  @credentials = credentials_for(role)
end

#authorize_consumptionString

Authorize consumption of a configuration

Returns:

  • (String)

    credentials allowing consumption of a configuration



191
192
193
# File 'lib/configuration_service/test/orchestration_provider.rb', line 191

def authorize_consumption
  @credentials = service.authorize_consumption(identifier: @identifier)
end

#broken_service_providerObject

A broken service provider

Returns:

  • (Object)

    a provider to be plugged into Client. The service provider’s publish_configuration and request_configuration methods must raise an Error other than AuthorizationError.

Raises:

  • (NotImplementedError)


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

Returns:

  • (true)

    if last request returned configuration with the identifier.

See Also:



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

Returns:

  • (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

Returns:

  • (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.

Returns:

  • (String)

    a credentials

Raises:

  • (NotImplementedError)


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

#deauthorizeObject



124
125
126
# File 'lib/configuration_service/test/orchestration_provider.rb', line 124

def deauthorize
  @credentials = nil
end

#delete_configurationnil

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.

Returns:

  • (nil)

    always

Raises:

  • (NotImplementedError)


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_revisionObject



164
165
166
# File 'lib/configuration_service/test/orchestration_provider.rb', line 164

def existing_revision
  @existing_configuration.revision
end

#fail_next_requestnil

Arrange for the next publish or request operation to fail

This is done by using a #broken_service_provider to service the next operation.

Returns:

  • (nil)


243
244
245
# File 'lib/configuration_service/test/orchestration_provider.rb', line 243

def fail_next_request
  @fail_next = true
end

#given_existing_configurationObject



138
139
140
141
142
# File 'lib/configuration_service/test/orchestration_provider.rb', line 138

def given_existing_configuration
  authorized_as(:publisher) do
    @existing_configuration = publish_configuration
  end
end

#given_invalid_configurationObject



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_metadataObject



131
132
133
# File 'lib/configuration_service/test/orchestration_provider.rb', line 131

def 
   = {"version" => "1.0"}
end

#given_missing_configurationObject



154
155
156
157
158
159
# File 'lib/configuration_service/test/orchestration_provider.rb', line 154

def given_missing_configuration
  authorized_as(:publisher) do
    delete_configuration
    @existing_configuration = nil
  end
end

#pending(message = nil) ⇒ Object

Mark a cucumber step as pending

Raises:

  • (Cucumber::Pending)

    always



252
253
254
255
256
257
258
# File 'lib/configuration_service/test/orchestration_provider.rb', line 252

def pending(message = nil)
  if message
    raise Cucumber::Pending, message
  else
    raise Cucumber::Pending
  end
end

#publish_configurationConfigurationService::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_configurationConfigurationService::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_providerObject

The service provider under test

Returns:

  • (Object)

    a provider to be plugged into Client

Raises:

  • (NotImplementedError)


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_configurationHash

The configuration for the service provider under test

Returns:

  • (Hash)

    dictionary of keyword arguments that can be passed to the constructor of the service provider class

Raises:

  • (NotImplementedError)


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_idString

The registered identifier of the service provider under test

Returns:

  • (String)

    the identifier with which the service provider is registered into the ProviderRegistry

Raises:

  • (NotImplementedError)


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