mockserver-client 1.0.8.pre → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -1
- data/Gemfile.lock +79 -0
- data/README.md +89 -229
- data/Rakefile +8 -8
- data/docs/Body.md +7 -0
- data/docs/BodyWithContentType.md +7 -0
- data/docs/ConnectionOptions.md +12 -0
- data/docs/ControlApi.md +269 -0
- data/docs/Delay.md +9 -0
- data/docs/Expectation.md +7 -0
- data/docs/ExpectationApi.md +51 -0
- data/docs/Expectations.md +7 -0
- data/docs/HttpClassCallback.md +8 -0
- data/docs/HttpError.md +10 -0
- data/docs/HttpForward.md +11 -0
- data/docs/HttpObjectCallback.md +8 -0
- data/docs/HttpOverrideForwardedRequest.md +9 -0
- data/docs/HttpRequest.md +15 -0
- data/docs/HttpResponse.md +14 -0
- data/docs/HttpTemplate.md +10 -0
- data/docs/KeyToMultiValue.md +7 -0
- data/docs/KeyToValue.md +7 -0
- data/docs/Ports.md +8 -0
- data/docs/TimeToLive.md +10 -0
- data/docs/Times.md +9 -0
- data/docs/Verification.md +9 -0
- data/docs/VerificationSequence.md +8 -0
- data/docs/VerificationTimes.md +9 -0
- data/docs/VerifyApi.md +94 -0
- data/lib/mockserver-client.rb +62 -15
- data/lib/mockserver-client/api/control_api.rb +316 -0
- data/lib/mockserver-client/api/expectation_api.rb +73 -0
- data/lib/mockserver-client/api/verify_api.rb +127 -0
- data/lib/mockserver-client/api_client.rb +388 -0
- data/lib/mockserver-client/api_error.rb +38 -0
- data/lib/mockserver-client/configuration.rb +202 -0
- data/lib/mockserver-client/models/body.rb +174 -0
- data/lib/mockserver-client/models/body_with_content_type.rb +174 -0
- data/lib/mockserver-client/models/connection_options.rb +219 -0
- data/lib/mockserver-client/models/delay.rb +192 -0
- data/lib/mockserver-client/models/expectation.rb +174 -0
- data/lib/mockserver-client/models/expectations.rb +174 -0
- data/lib/mockserver-client/models/http_class_callback.rb +183 -0
- data/lib/mockserver-client/models/http_error.rb +201 -0
- data/lib/mockserver-client/models/http_forward.rb +244 -0
- data/lib/mockserver-client/models/http_object_callback.rb +183 -0
- data/lib/mockserver-client/models/http_override_forwarded_request.rb +192 -0
- data/lib/mockserver-client/models/http_request.rb +246 -0
- data/lib/mockserver-client/models/http_response.rb +237 -0
- data/lib/mockserver-client/models/http_template.rb +235 -0
- data/lib/mockserver-client/models/key_to_multi_value.rb +174 -0
- data/lib/mockserver-client/models/key_to_value.rb +174 -0
- data/lib/mockserver-client/models/ports.rb +185 -0
- data/lib/mockserver-client/models/time_to_live.rb +235 -0
- data/lib/mockserver-client/models/times.rb +192 -0
- data/lib/mockserver-client/models/verification.rb +192 -0
- data/lib/mockserver-client/models/verification_sequence.rb +185 -0
- data/lib/mockserver-client/models/verification_times.rb +192 -0
- data/lib/mockserver-client/version.rb +15 -0
- data/mockserver-client.gemspec +44 -36
- data/spec/api/control_api_spec.rb +102 -0
- data/spec/api/expectation_api_spec.rb +46 -0
- data/spec/api/verify_api_spec.rb +57 -0
- data/spec/api_client_spec.rb +226 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/body_spec.rb +35 -0
- data/spec/models/body_with_content_type_spec.rb +35 -0
- data/spec/models/connection_options_spec.rb +65 -0
- data/spec/models/delay_spec.rb +47 -0
- data/spec/models/expectation_spec.rb +35 -0
- data/spec/models/expectations_spec.rb +35 -0
- data/spec/models/http_class_callback_spec.rb +41 -0
- data/spec/models/http_error_spec.rb +53 -0
- data/spec/models/http_forward_spec.rb +63 -0
- data/spec/models/http_object_callback_spec.rb +41 -0
- data/spec/models/http_override_forwarded_request_spec.rb +47 -0
- data/spec/models/http_request_spec.rb +83 -0
- data/spec/models/http_response_spec.rb +77 -0
- data/spec/models/http_template_spec.rb +57 -0
- data/spec/models/key_to_multi_value_spec.rb +35 -0
- data/spec/models/key_to_value_spec.rb +35 -0
- data/spec/models/ports_spec.rb +41 -0
- data/spec/models/time_to_live_spec.rb +57 -0
- data/spec/models/times_spec.rb +47 -0
- data/spec/models/verification_sequence_spec.rb +41 -0
- data/spec/models/verification_spec.rb +47 -0
- data/spec/models/verification_times_spec.rb +47 -0
- data/spec/spec_helper.rb +103 -53
- metadata +225 -158
- data/.gitignore +0 -21
- data/.rubocop.yml +0 -7
- data/bin/mockserver +0 -9
- data/lib/cli.rb +0 -146
- data/lib/mockserver/abstract_client.rb +0 -111
- data/lib/mockserver/mock_server_client.rb +0 -46
- data/lib/mockserver/model/array_of.rb +0 -85
- data/lib/mockserver/model/body.rb +0 -56
- data/lib/mockserver/model/cookie.rb +0 -36
- data/lib/mockserver/model/delay.rb +0 -34
- data/lib/mockserver/model/enum.rb +0 -47
- data/lib/mockserver/model/expectation.rb +0 -139
- data/lib/mockserver/model/forward.rb +0 -41
- data/lib/mockserver/model/header.rb +0 -43
- data/lib/mockserver/model/parameter.rb +0 -43
- data/lib/mockserver/model/request.rb +0 -81
- data/lib/mockserver/model/response.rb +0 -45
- data/lib/mockserver/model/times.rb +0 -61
- data/lib/mockserver/proxy_client.rb +0 -9
- data/lib/mockserver/utility_methods.rb +0 -59
- data/lib/mockserver/version.rb +0 -5
- data/pom.xml +0 -118
- data/spec/fixtures/forward_mockserver.json +0 -7
- data/spec/fixtures/incorrect_login_response.json +0 -20
- data/spec/fixtures/post_login_request.json +0 -22
- data/spec/fixtures/register_expectation.json +0 -50
- data/spec/fixtures/retrieved_request.json +0 -22
- data/spec/fixtures/search_request.json +0 -6
- data/spec/fixtures/times_once.json +0 -6
- data/spec/integration/mock_client_integration_spec.rb +0 -82
- data/spec/mockserver/builder_spec.rb +0 -90
- data/spec/mockserver/mock_client_spec.rb +0 -80
- data/spec/mockserver/proxy_client_spec.rb +0 -38
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require 'hashie'
|
|
3
|
-
require_relative './array_of'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# A class to model cookies in payloads.
|
|
7
|
-
# @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
|
|
8
|
-
#
|
|
9
|
-
module MockServer::Model
|
|
10
|
-
# Model for cookie
|
|
11
|
-
class Cookie < Hashie::Dash
|
|
12
|
-
include Hashie::Extensions::MethodAccess
|
|
13
|
-
include Hashie::Extensions::IgnoreUndeclared
|
|
14
|
-
include Hashie::Extensions::Coercion
|
|
15
|
-
|
|
16
|
-
property :name, required: true
|
|
17
|
-
property :value, required: true
|
|
18
|
-
|
|
19
|
-
coerce_key :name, String
|
|
20
|
-
coerce_key :value, String
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# A collection that only stores cookies
|
|
24
|
-
class Cookies < ArrayOf
|
|
25
|
-
def child_class
|
|
26
|
-
Cookie
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# DSL methods for cookie
|
|
31
|
-
module DSL
|
|
32
|
-
def cookie(key, value)
|
|
33
|
-
Cookie.new(name: key, value: value)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require_relative './enum'
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
# A model for a delay in a response.
|
|
6
|
-
# @author: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
|
|
7
|
-
#
|
|
8
|
-
module MockServer::Model
|
|
9
|
-
# Enum for time unit
|
|
10
|
-
class TimeUnit < SymbolizedEnum
|
|
11
|
-
def allowed_values
|
|
12
|
-
[:NANOSECONDS, :MICROSECONDS, :MILLISECONDS, :SECONDS, :MINUTES, :HOURS, :DAYS]
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Model a delay object
|
|
17
|
-
class Delay < Hashie::Dash
|
|
18
|
-
include Hashie::Extensions::MethodAccess
|
|
19
|
-
include Hashie::Extensions::IgnoreUndeclared
|
|
20
|
-
include Hashie::Extensions::Coercion
|
|
21
|
-
|
|
22
|
-
property :time_unit, default: 'SECONDS'
|
|
23
|
-
property :value, required: true
|
|
24
|
-
|
|
25
|
-
coerce_key :time_unit, TimeUnit
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# DSL methods related to delay model
|
|
29
|
-
module DSL
|
|
30
|
-
def delay_by(time_unit, value)
|
|
31
|
-
Delay.new(time_unit: time_unit, value: value)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
#
|
|
3
|
-
# A class to model a Java-like Enum.
|
|
4
|
-
# To create an Enum extend this class and override :allowed_values method with allowed enum values.
|
|
5
|
-
#
|
|
6
|
-
# @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
|
|
7
|
-
#
|
|
8
|
-
module MockServer::Model
|
|
9
|
-
# Enum generic class
|
|
10
|
-
class Enum
|
|
11
|
-
# Create an instance of the enum from the value supplied
|
|
12
|
-
# @param supplied_value [Object] value used to create instance of an enum
|
|
13
|
-
# @raise [Exception] if the supplied value is not valid for this enum
|
|
14
|
-
def initialize(supplied_value)
|
|
15
|
-
supplied_value = pre_process_value(supplied_value)
|
|
16
|
-
fail "Supplied value: #{supplied_value} is not valid. Allowed values are: #{allowed_values.inspect}" unless allowed_values.include?(supplied_value)
|
|
17
|
-
@value = supplied_value
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# @return [Array] a list of values allowed by this enum
|
|
21
|
-
def allowed_values
|
|
22
|
-
fail 'Override :allowed_values in Enum class'
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# A pre-process hook for a value before it is stored
|
|
26
|
-
# @param value [Object] a value used to instantiate the enum
|
|
27
|
-
# @return [Object] the processed value. By default, a no-op implementation.
|
|
28
|
-
def pre_process_value(value)
|
|
29
|
-
value
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Override this for JSON representation
|
|
33
|
-
def to_s
|
|
34
|
-
@value.to_s
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Subclass of Enum that has a list of symbols as allowed values.
|
|
39
|
-
class SymbolizedEnum < Enum
|
|
40
|
-
# Pre-process the value passed in and convert to a symbol
|
|
41
|
-
# @param value [Object] a value used to instantiate the enum
|
|
42
|
-
# @return [Symbol] a symbolized version of the value passed in (first calls to_s)
|
|
43
|
-
def pre_process_value(value)
|
|
44
|
-
value.to_s.to_sym
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require_relative './array_of'
|
|
3
|
-
require_relative './request'
|
|
4
|
-
require_relative './response'
|
|
5
|
-
require_relative './forward'
|
|
6
|
-
require_relative './times'
|
|
7
|
-
require_relative '../utility_methods'
|
|
8
|
-
|
|
9
|
-
#
|
|
10
|
-
# A class to model an expectation sent to the Mockserver instance.
|
|
11
|
-
# See http://www.mock-server.com/#create-expectations for details.
|
|
12
|
-
#
|
|
13
|
-
# @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
|
|
14
|
-
#
|
|
15
|
-
module MockServer
|
|
16
|
-
HTTP_REQUEST = 'httpRequest' unless const_defined?(:HTTP_REQUEST)
|
|
17
|
-
HTTP_RESPONSE = 'httpResponse' unless const_defined?(:HTTP_RESPONSE)
|
|
18
|
-
HTTP_FORWARD = 'httpForward' unless const_defined?(:HTTP_FORWARD)
|
|
19
|
-
HTTP_TIMES = 'times' unless const_defined?(:HTTP_TIMES)
|
|
20
|
-
|
|
21
|
-
# Models
|
|
22
|
-
module Model
|
|
23
|
-
# Expectation model
|
|
24
|
-
class Expectation
|
|
25
|
-
include MockServer::UtilityMethods
|
|
26
|
-
attr_accessor :times
|
|
27
|
-
|
|
28
|
-
# Creates an expectation from a hash
|
|
29
|
-
# @param payload [Hash] a hash representation of the expectation
|
|
30
|
-
def populate_from_payload(payload)
|
|
31
|
-
@request = payload[MockServer::HTTP_REQUEST]
|
|
32
|
-
@request = Request.new(symbolize_keys(@request)) if @request
|
|
33
|
-
|
|
34
|
-
@response = payload[MockServer::HTTP_RESPONSE]
|
|
35
|
-
@response = Response.new(symbolize_keys(@response)) if @response
|
|
36
|
-
|
|
37
|
-
@forward = payload[MockServer::HTTP_FORWARD]
|
|
38
|
-
@forward = Forward.new(symbolize_keys(@forward)) if @forward
|
|
39
|
-
|
|
40
|
-
@times = payload[MockServer::HTTP_TIMES]
|
|
41
|
-
@times = Times.new(symbolize_keys(@times)) if @times
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Method to setup the request on the expectation object
|
|
45
|
-
# @yieldparam [Request] the request that this expectation references
|
|
46
|
-
# @return [Expectation] this object according to the the builder pattern
|
|
47
|
-
def request(&_)
|
|
48
|
-
if block_given?
|
|
49
|
-
@request ||= Request.new
|
|
50
|
-
yield @request
|
|
51
|
-
end
|
|
52
|
-
@request
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Method to setup the response on the expectation object
|
|
56
|
-
# @yieldparam [Response] the response that this expectation references
|
|
57
|
-
# @return [Expectation] this object according to the the builder pattern
|
|
58
|
-
def response(&_)
|
|
59
|
-
if block_given?
|
|
60
|
-
@response ||= Response.new
|
|
61
|
-
yield @response
|
|
62
|
-
end
|
|
63
|
-
@response
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Method to setup the request on the expectation object
|
|
67
|
-
# @yieldparam [Forward] the forward object that this expectation references
|
|
68
|
-
# @return [Expectation] this object according to the the builder pattern
|
|
69
|
-
def forward(&_)
|
|
70
|
-
if block_given?
|
|
71
|
-
@forward ||= Forward.new
|
|
72
|
-
yield @forward
|
|
73
|
-
end
|
|
74
|
-
@forward
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Setter for request
|
|
78
|
-
# @param request [Request] a request object
|
|
79
|
-
def request=(request)
|
|
80
|
-
@request = Request.new(request)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
# Setter for response
|
|
84
|
-
# @param response [Response] a response object
|
|
85
|
-
def response=(response)
|
|
86
|
-
@response = Response.new(response)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Setter for forward
|
|
90
|
-
# @param forward [Forward] a forward object
|
|
91
|
-
def forward=(forward)
|
|
92
|
-
@forward = Forward.new(forward)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# Override to_json method
|
|
96
|
-
# @return [String] the json representation for this object
|
|
97
|
-
def to_json(*p)
|
|
98
|
-
to_hash.to_json(*p)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
# Convert to hash
|
|
102
|
-
# @return [Hash] the hash representation for this object
|
|
103
|
-
def to_hash
|
|
104
|
-
{
|
|
105
|
-
MockServer::HTTP_REQUEST => @request,
|
|
106
|
-
MockServer::HTTP_RESPONSE => @response,
|
|
107
|
-
MockServer::HTTP_FORWARD => @forward,
|
|
108
|
-
MockServer::HTTP_TIMES => @times
|
|
109
|
-
}
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
# Class to store a list of mocks - useful for modeling retrieve endpoint result
|
|
114
|
-
class Expectations < ArrayOf
|
|
115
|
-
# Code is used to store HTTP status code returned from retrieve endpoint
|
|
116
|
-
attr_accessor :code
|
|
117
|
-
|
|
118
|
-
def child_class
|
|
119
|
-
Expectation
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# DSL method for creating expectation
|
|
124
|
-
module DSL
|
|
125
|
-
def expectation(&_)
|
|
126
|
-
expectation = Expectation.new
|
|
127
|
-
yield expectation if block_given?
|
|
128
|
-
expectation
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def expectation_from_json(payload)
|
|
132
|
-
expectation = Expectation.new
|
|
133
|
-
yield expectation if block_given?
|
|
134
|
-
expectation.populate_from_payload(payload)
|
|
135
|
-
expectation
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require 'hashie'
|
|
3
|
-
require_relative './enum'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# A class to model a forwarding on a request.
|
|
7
|
-
# @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
|
|
8
|
-
#
|
|
9
|
-
module MockServer::Model
|
|
10
|
-
# Enum for a scheme used in a forward request
|
|
11
|
-
class Scheme < SymbolizedEnum
|
|
12
|
-
def allowed_values
|
|
13
|
-
[:HTTP, :HTTPS]
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Model for forwarding
|
|
18
|
-
class Forward < Hashie::Dash
|
|
19
|
-
include Hashie::Extensions::MethodAccess
|
|
20
|
-
include Hashie::Extensions::IgnoreUndeclared
|
|
21
|
-
include Hashie::Extensions::Coercion
|
|
22
|
-
|
|
23
|
-
property :host, default: 'localhost'
|
|
24
|
-
property :port, default: 80
|
|
25
|
-
property :scheme, default: 'HTTP'
|
|
26
|
-
|
|
27
|
-
coerce_key :host, String
|
|
28
|
-
coerce_key :scheme, Scheme
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# DSL methods for forward
|
|
32
|
-
module DSL
|
|
33
|
-
def forward(&_)
|
|
34
|
-
obj = Forward.new
|
|
35
|
-
yield obj if block_given?
|
|
36
|
-
obj
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
alias_method :http_forward, :forward
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require 'hashie'
|
|
3
|
-
require_relative './array_of'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# A class to model headers in payloads.
|
|
7
|
-
# @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
|
|
8
|
-
#
|
|
9
|
-
module MockServer::Model
|
|
10
|
-
# A class that only stores strings
|
|
11
|
-
class Strings < ArrayOf
|
|
12
|
-
def child_class
|
|
13
|
-
String
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Model for header
|
|
18
|
-
class Header < Hashie::Dash
|
|
19
|
-
include Hashie::Extensions::MethodAccess
|
|
20
|
-
include Hashie::Extensions::IgnoreUndeclared
|
|
21
|
-
include Hashie::Extensions::Coercion
|
|
22
|
-
|
|
23
|
-
property :name, required: true
|
|
24
|
-
property :values, default: Strings.new([])
|
|
25
|
-
|
|
26
|
-
coerce_key :name, String
|
|
27
|
-
coerce_key :values, Strings
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# A collection that only stores headers
|
|
31
|
-
class Headers < ArrayOf
|
|
32
|
-
def child_class
|
|
33
|
-
Header
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# DSL methods for header
|
|
38
|
-
module DSL
|
|
39
|
-
def header(key, *value)
|
|
40
|
-
Header.new(name: key, values: value)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require 'hashie'
|
|
3
|
-
require_relative './array_of'
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# A class to model parameters in payloads.
|
|
7
|
-
# @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
|
|
8
|
-
#
|
|
9
|
-
module MockServer::Model
|
|
10
|
-
# A class that only stores strings
|
|
11
|
-
class Strings < ArrayOf
|
|
12
|
-
def child_class
|
|
13
|
-
String
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Model for parameter
|
|
18
|
-
class Parameter < Hashie::Dash
|
|
19
|
-
include Hashie::Extensions::MethodAccess
|
|
20
|
-
include Hashie::Extensions::IgnoreUndeclared
|
|
21
|
-
include Hashie::Extensions::Coercion
|
|
22
|
-
|
|
23
|
-
property :name, required: true
|
|
24
|
-
property :values, default: Strings.new([])
|
|
25
|
-
|
|
26
|
-
coerce_key :name, String
|
|
27
|
-
coerce_key :values, Strings
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# A collection that only stores parameters
|
|
31
|
-
class Parameters < ArrayOf
|
|
32
|
-
def child_class
|
|
33
|
-
Parameter
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# DSL methods for parameter
|
|
38
|
-
module DSL
|
|
39
|
-
def parameter(key, *value)
|
|
40
|
-
Parameter.new(name: key, values: value)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require 'hashie'
|
|
3
|
-
require_relative './parameter'
|
|
4
|
-
require_relative './header'
|
|
5
|
-
require_relative './cookie'
|
|
6
|
-
require_relative './body'
|
|
7
|
-
require_relative './enum'
|
|
8
|
-
require 'base64'
|
|
9
|
-
#
|
|
10
|
-
# A class to model a request in an expectation.
|
|
11
|
-
# @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
|
|
12
|
-
#
|
|
13
|
-
module MockServer::Model
|
|
14
|
-
# Enum for HTTP methods
|
|
15
|
-
class HTTPMethod < SymbolizedEnum
|
|
16
|
-
def allowed_values
|
|
17
|
-
[:GET, :POST, :PUT, :DELETE]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# Request model
|
|
22
|
-
class Request < Hashie::Trash
|
|
23
|
-
include Hashie::Extensions::MethodAccess
|
|
24
|
-
include Hashie::Extensions::IgnoreUndeclared
|
|
25
|
-
include Hashie::Extensions::Coercion
|
|
26
|
-
|
|
27
|
-
ALLOWED_METHODS = [:GET, :POST, :PUT, :DELETE]
|
|
28
|
-
|
|
29
|
-
property :method, required: true, default: :GET
|
|
30
|
-
property :path, required: true, default: ''
|
|
31
|
-
property :query_string_parameters, default: Parameters.new([])
|
|
32
|
-
property :cookies, default: Cookies.new([])
|
|
33
|
-
property :headers, default: Headers.new([])
|
|
34
|
-
property :body, transform_with: (lambda do |body|
|
|
35
|
-
is_base_64_body = body && body.type == :BINARY
|
|
36
|
-
body_value = is_base_64_body ? Base64.decode64(body.value) : body.value
|
|
37
|
-
Body.new(type: :STRING, value: body_value)
|
|
38
|
-
end)
|
|
39
|
-
|
|
40
|
-
coerce_key :method, HTTPMethod
|
|
41
|
-
coerce_key :path, String
|
|
42
|
-
coerce_key :query_string_parameters, Parameters
|
|
43
|
-
coerce_key :cookies, Cookies
|
|
44
|
-
coerce_key :headers, Headers
|
|
45
|
-
coerce_key :body, Body
|
|
46
|
-
|
|
47
|
-
# Creates a request from a hash
|
|
48
|
-
# @param payload [Hash] a hash representation of the request
|
|
49
|
-
def populate_from_payload(payload)
|
|
50
|
-
@request = payload[MockServer::HTTP_REQUEST]
|
|
51
|
-
@request = Request.new(symbolize_keys(@request)) if @request
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Class to store a list of mocks - useful for modeling retrieve endpoint result
|
|
56
|
-
class Requests < ArrayOf
|
|
57
|
-
# Code is used to store HTTP status code returned from retrieve endpoint
|
|
58
|
-
attr_accessor :code
|
|
59
|
-
|
|
60
|
-
def child_class
|
|
61
|
-
Request
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# DSL methods related to requests
|
|
66
|
-
module DSL
|
|
67
|
-
def request(method, path, &_)
|
|
68
|
-
obj = Request.new(method: method, path: path)
|
|
69
|
-
yield obj if block_given?
|
|
70
|
-
obj
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def request_from_json(payload)
|
|
74
|
-
request = Request.new(symbolize_keys(payload))
|
|
75
|
-
yield request if block_given?
|
|
76
|
-
request
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
alias_method :http_request, :request
|
|
80
|
-
end
|
|
81
|
-
end
|