Class: ConfigurationService::Test::OrchestrationProvider

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

Overview

Abstract Orchestrator provider

Extend this class if you want your test orchestration provider to constrain your implementation’s interface to work as a configuration service provider. If you have no intention of plugging your implementation into ConfigurationService::Base, build your own test orchestration provider from scratch, using Orchestrator as a guide.

Extensions should implement:

  • #service_provider_id

  • #service_provider_configuration

  • #service_provider

  • #broken_service_provider

  • #token_for

  • #delete_configuration

Direct Known Subclasses

StubOrchestrationProvider

Constant Summary collapse

ACTIVITY_ROLE_MAP =
  • :requesting_configurations

  • :publishing_configurations

  • :nothing (if possible, provide credentials that don’t allow operations on the configuration identifier)

{
  :requesting_configurations => :consumer,
  :publishing_configurations => :publisher,
  :nothing => :none
}
ROLES =
  • :consumer

  • :publisher

  • :none

ACTIVITY_ROLE_MAP.values

Instance Method Summary collapse

Constructor Details

#initializeOrchestrationProvider

Returns a new Orchestrator provider

The provider is always initialized with the same configuration identifier



50
51
52
# File 'lib/configuration_service/test/orchestration_provider.rb', line 50

def initialize
  @identifier = "acme"
end

Instance Method Details

#authorize(role) ⇒ Object

See Orchestrator#authorize



77
78
79
# File 'lib/configuration_service/test/orchestration_provider.rb', line 77

def authorize(role)
  @token = token_for(role)
end

#deauthorizeObject

See Orchestrator#deauthorize



84
85
86
# File 'lib/configuration_service/test/orchestration_provider.rb', line 84

def deauthorize
  @token = nil
end

#existing_configurationObject

See Orchestrator#existing_configuration



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

def existing_configuration
  @existing_configuration.data
end

#existing_revisionObject

See Orchestrator#existing_revision



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

def existing_revision
  @existing_configuration.revision
end

#fail_next_requestObject

Arrange for the next publication or consuming operation to fail

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



167
168
169
# File 'lib/configuration_service/test/orchestration_provider.rb', line 167

def fail_next_request
  @fail_next = true
end

#given_existing_configurationObject

See Orchestrator#given_existing_configuration



98
99
100
101
102
# File 'lib/configuration_service/test/orchestration_provider.rb', line 98

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

#given_invalid_configurationObject

See Orchestrator#given_invalid_configuration



107
108
109
# File 'lib/configuration_service/test/orchestration_provider.rb', line 107

def given_invalid_configuration
  @configuration = "This should be an object!"
end

#given_metadataObject

See Orchestrator#given_metadata



91
92
93
# File 'lib/configuration_service/test/orchestration_provider.rb', line 91

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

#given_missing_configurationObject

See Orchestrator#given_missing_configuration



114
115
116
117
118
119
# File 'lib/configuration_service/test/orchestration_provider.rb', line 114

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

#publish_configurationObject

Perform a publishing operation against the service under test

The response from the service is wrapped in a test Response.



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

def publish_configuration
  wrap_response do
    if 
      service.publish_configuration(configuration, )
    else
      service.publish_configuration(configuration)
    end
  end
end

#request_configurationObject

Perform a consuming operation against the service under test

The response from the service is wrapped in a test Response.



140
141
142
143
144
# File 'lib/configuration_service/test/orchestration_provider.rb', line 140

def request_configuration
  wrap_response do
    service.request_configuration
  end
end

#service_provider_configurationObject

Return configuration for the service provider

The configuration should be a dictionary of keyword arguments that can be passed to the constructor of the service provider class.

Raises:

  • (NotImplementedError)


70
71
72
# File 'lib/configuration_service/test/orchestration_provider.rb', line 70

def service_provider_configuration # :doc:
  raise NotImplementedError, "#{self.class} must implement service_provider_configuration"
end

#service_provider_idObject

Returns the string identifier of the service provider

This should be the identifier with which the service provider registers into the ProviderRegistry.

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/configuration_service/test/orchestration_provider.rb', line 60

def service_provider_id
  raise NotImplementedError, "#{self.class} must implement service_provider_id"
end