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



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

#authorize_consumptionString

Authorize consumption of a configuration

Returns:

  • (String)

    credentials allowing consumption of a configuration



219
220
221
# File 'lib/configuration_service/test/orchestration_provider.rb', line 219

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)


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

Returns:

  • (true)

    if last request returned configuration with the identifier.

See Also:



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

Returns:

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

Returns:

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

Returns:

  • (Array)

    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.

Returns:

  • (Array)

    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.

Returns:

  • (String)

    a credentials

Raises:

  • (NotImplementedError)


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

#deauthorizeObject



126
127
128
# File 'lib/configuration_service/test/orchestration_provider.rb', line 126

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)


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_revisionObject



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

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)


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_resolvedObject



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

def given_configuration_should_be_resolved
  @resolve = true
end

#given_existing_configurationObject



144
145
146
147
148
# File 'lib/configuration_service/test/orchestration_provider.rb', line 144

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

#given_existing_configuration_containing_referencesObject



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
  authorized_as(:publisher, @identifier) do
    @existing_configuration = publish_configuration(@identifier, @unresolved_configuration_data)
  end
end

#given_invalid_configurationObject



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_metadataObject



133
134
135
# File 'lib/configuration_service/test/orchestration_provider.rb', line 133

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

#given_missing_configurationObject



182
183
184
185
186
187
# File 'lib/configuration_service/test/orchestration_provider.rb', line 182

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

#given_referenced_configuration_existsObject



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"
      }
      authorized_as(:publisher, identifier) do
        publish_configuration(identifier, configuration)
      end
    }
end

#pending(message = nil) ⇒ Object

Mark a cucumber step as pending

Raises:

  • (Cucumber::Pending)

    always



312
313
314
315
316
317
318
# File 'lib/configuration_service/test/orchestration_provider.rb', line 312

def pending(message = nil)
  if message
    raise Cucumber::Pending, message
  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

Returns:

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

The service provider under test

Returns:

  • (Object)

    a provider to be plugged into Client

Raises:

  • (NotImplementedError)


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


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


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