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 Base, 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 =
{
  :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



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 authorize(role)
  @token = token_for(role)
end

#broken_service_providerObject

A broken service provider

Returns:

  • (Object)

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

Raises:

  • (NotImplementedError)


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

Returns:

  • (true)

    if last request returned configuration with the identifier.

See Also:



214
215
216
# File 'lib/configuration_service/test/orchestration_provider.rb', line 214

def configuration_found_for_identifier?
  @requested_configuration.identifier == @identifier
end

#deauthorizeObject



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

def deauthorize
  @token = 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 @token should not be used, because it may not be sufficiently authorized.

Returns:

  • (nil)

    always

Raises:

  • (NotImplementedError)


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_revisionObject



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

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)


225
226
227
# File 'lib/configuration_service/test/orchestration_provider.rb', line 225

def fail_next_request
  @fail_next = true
end

#given_existing_configurationObject



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

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

#given_invalid_configurationObject



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_metadataObject



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

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

#given_missing_configurationObject



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

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



234
235
236
237
238
239
240
# File 'lib/configuration_service/test/orchestration_provider.rb', line 234

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.



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_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.



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_providerObject

The service provider under test

Returns:

  • (Object)

    a provider to be plugged into Base

Raises:

  • (NotImplementedError)


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_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)


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_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)


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.

Returns:

  • (String)

    a token

Raises:

  • (NotImplementedError)


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