mockserver-client 0.0.3 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDRhZTQwOTYwOTZjZjQ3ZThlNWFlZTk0NjIwMjIzZjUwMzRiY2UxMA==
5
- data.tar.gz: !binary |-
6
- MGM5MWMyZWYzYzJjZTU5Y2NjZDhiNjM2YWI0OWM1MTU4ZWE1OWYzNg==
2
+ SHA1:
3
+ metadata.gz: 6549161ca51a971fc321ebe5da63c14212c53c0d
4
+ data.tar.gz: b89a79a7b67637194d00714c33e186f41344695d
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NzlmZDZlYTcyMzQ0YWFkOWViMmI0ZmFlZDgwODdmM2ZhM2QyYWIwZWRkYThj
10
- MmU2YzkyNDEyZDI3NWZiN2NkNjc1Mzk5NGJhYmI1ZTU3YTdiYmEzYTI3NzM5
11
- ZGEwMWRkYWUwYWQ2MjQwZjM0YWUwZTQ4MWUzOWYxMTc4MGVmMmQ=
12
- data.tar.gz: !binary |-
13
- MzljZWQ0MjNkMGJiOGFkMjM1N2FlM2MzYjczOWQxODZlOGJhYWFmODg4NDg3
14
- MjBlMmYyMGI2NGI3ZTA0MjdhNWNhMDUxN2QwYTZmOTBmODI4NWZhZjA1ZDUz
15
- NGRjYzhjOGRmN2VlNGQ1YWMxMGEzNjk2NTEwMjg2MGNlZjQ1YzQ=
6
+ metadata.gz: 5ab50f696abe0df060f1059ed6365b6b27e7648d4fb7d37e998c97e7c02080b95637de7d8c0aaadd60e65e4c9d7d4e690a6d6475691d563229d8de108725694f
7
+ data.tar.gz: 4a196fa9b3357f2c97ff2ccfe8e705c8892f801a8e9c866bcce8f5c8491e184fabd625462d51607ecd38adba4122c1242f1957ccbad763fdc1532642910cad6c
@@ -2,12 +2,6 @@ Style/LineLength:
2
2
  Max: 180
3
3
  Style/ClassAndModuleChildren:
4
4
  EnforcedStyle: compact
5
- Style/CyclomaticComplexity:
6
- Enabled: false
7
- Lint/LiteralInInterpolation:
8
- Enabled: false
9
- Style/MethodLength:
10
- Enabled: false
11
5
  Style/FileName:
12
6
  Exclude:
13
7
  - '**/mockserver-client.rb'
@@ -0,0 +1,11 @@
1
+ ### Version 0.0.1
2
+ - Basic code.
3
+
4
+ ### Version 0.0.2
5
+ - CLI for this gem.
6
+
7
+ ### Version 0.0.3
8
+ - Changes responses returned from /retrieve and /verify to be Ruby models.
9
+
10
+ ### Version 1.0.0
11
+ - Merged ruby client fully into main MockServer build on master.
data/README.md CHANGED
@@ -1,22 +1,26 @@
1
1
  # Mockserver Client
2
2
 
3
- [![Build Status](https://travis-ci.org/nayyara-samuel/mockserver-client.svg?branch=master)](https://travis-ci.org/nayyara-samuel/mockserver-client)
4
-
5
3
  A Ruby client for [MockServer](http://www.mock-server.com) project. This client follows the Java client's fluent style closely by using Ruby blocks.
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
- gem 'mockserver-client'
9
+ ```ruby
10
+ gem 'mockserver-client'
11
+ ```
12
12
 
13
13
  And then execute:
14
14
 
15
- $ bundle
15
+ ```bash
16
+ bundle
17
+ ```
16
18
 
17
19
  Or install it yourself as:
18
20
 
19
- $ gem install mockserver-client
21
+ ```bash
22
+ gem install mockserver-client
23
+ ```
20
24
 
21
25
  ## Usage
22
26
 
@@ -30,8 +34,8 @@ include MockServer::Model::DSL
30
34
  ### Create Expectations
31
35
 
32
36
  ##### Java
33
- ```java
34
37
 
38
+ ```java
35
39
  new MockServerClient("localhost", 9999)
36
40
  .when(
37
41
  request()
@@ -61,7 +65,6 @@ new MockServerClient("localhost", 9999)
61
65
  ##### Ruby
62
66
 
63
67
  ```ruby
64
-
65
68
  client = MockServerClient.new('localhost', 9999)
66
69
  expectation = expectation do |expectation|
67
70
  expectation.request do |request|
@@ -122,7 +125,6 @@ new ProxyClient("localhost", 9090).verify(
122
125
  ##### Ruby
123
126
 
124
127
  ```ruby
125
-
126
128
  # Not providing times here because the default is exactly(1) i.e. the second argument to verify method
127
129
  ProxyClient.new('localhost', 9090).verify(request(:POST, '/login') do |request|
128
130
  request.body = exact("{username: 'foo', password: 'bar'}")
@@ -144,6 +146,7 @@ new ProxyClient("localhost", 9090).dumpToLogAsJava(
144
146
  ```
145
147
 
146
148
  ##### Ruby
149
+
147
150
  ```ruby
148
151
  # Second argument is true to set output to Java; false to set output to default JSON (default)
149
152
  ProxyClient.new('localhost', 9090).dump_log(request(:POST, '/login'), true)
@@ -194,7 +197,7 @@ Getter methods for `request`, `response` and `forward` methods will optionally a
194
197
 
195
198
  This gem comes with a command line interface which allow you to run the Mock Server calls from the command line. When this gem is installed, you will have the `mockserver` executable on your PATH. Type `mockserver --help` and you will get this output:
196
199
 
197
- ```
200
+ ```bash
198
201
  mockserver --help
199
202
 
200
203
  Commands:
@@ -216,7 +219,7 @@ Options:
216
219
 
217
220
  To get help for an individual command, e.g. `dump_log`, you would do:
218
221
 
219
- ```
222
+ ```bash
220
223
  mockserver --help dump_log
221
224
 
222
225
  Usage:
@@ -235,7 +238,7 @@ Dumps the matching request to the mock server logs.
235
238
 
236
239
  Here is an example on how you would run the command:
237
240
 
238
- ```
241
+ ```bash
239
242
  mockserver dump_log -j true
240
243
 
241
244
  Running with parameters:
@@ -248,11 +251,10 @@ Running with parameters:
248
251
  [2014-06-21 09:23:32] DEBUG [MockServerClient] Got dump to log response: 202
249
252
  ```
250
253
 
251
- ## Contributing
254
+ # Issues
255
+
256
+ If you have any problems, please [check the project issues](https://github.com/jamesdbloom/mockserver/issues?state=open).
257
+
258
+ # Contributions
252
259
 
253
- 1. Fork it ( https://github.com/[my-github-username]/mockserver-client/fork )
254
- 2. Create your feature branch (`git checkout -b my-new-feature`)
255
- 3. Commit your changes (`git commit -am 'Add some feature'`)
256
- 4. Push to the branch (`git push origin my-new-feature`)
257
- 5. Create a new Pull Request
258
- 6. **IMPORTANT**: Keep code coverage high. Preferably above 95%. This project uses SimpleCov for code coverage which reports percentage coverage.
260
+ Pull requests are, of course, very welcome! Please read our [contributing to the project](https://github.com/jamesdbloom/mockserver/wiki/Contributing-to-the-project) guide first. Then head over to the [open issues](https://github.com/jamesdbloom/mockserver/issues?state=open) to see what we need help with. Make sure you let us know if you intend to work on something. Also, check out the [milestones](https://github.com/jamesdbloom/mockserver/issues/milestones) to see what is planned for future releases.
File without changes
data/lib/cli.rb CHANGED
@@ -23,7 +23,7 @@ module CLIHelpers
23
23
  # @param options [Struct] with host and port set
24
24
  # @return [MockServerClient] the mockserver client with the host and port
25
25
  def mockserver_client(options)
26
- client = MockServerClient.new(options.host, options.port)
26
+ client = MockServerClient.new(options.host, options.port)
27
27
  client.logger = LOGGER
28
28
  client
29
29
  end
@@ -32,7 +32,7 @@ module CLIHelpers
32
32
  # @param options [Struct] with host and port set
33
33
  # @return [ProxyClient] the proxy client with the host and port
34
34
  def proxy_client(options)
35
- client = ProxyClient.new(options.host, options.port)
35
+ client = ProxyClient.new(options.host, options.port)
36
36
  client.logger = LOGGER
37
37
  client
38
38
  end
@@ -96,7 +96,7 @@ class MockServerCLI < Thor
96
96
 
97
97
  def register
98
98
  execute_command(true, true) do |client, options|
99
- payload = read_file(options.data)
99
+ payload = read_file(options.data)
100
100
  mock_expectation = expectation do |expectation|
101
101
  expectation.populate_from_payload(payload)
102
102
  end
@@ -135,9 +135,9 @@ class MockServerCLI < Thor
135
135
 
136
136
  def verify
137
137
  execute_command(false, true) do |client, _|
138
- payload = read_file(options.data)
138
+ payload = read_file(options.data)
139
139
  mock_request = payload[HTTP_REQUEST]
140
- mock_times = payload[HTTP_TIMES]
140
+ mock_times = payload[HTTP_TIMES]
141
141
 
142
142
  error 'No request found for verifying against' unless mock_request
143
143
  mock_times ? client.verify(mock_request, mock_times) : client.verify(mock_request)
@@ -10,8 +10,8 @@ require_relative './utility_methods'
10
10
  # @author Nayyara Samuel(mailto: nayyara.samuel@opower.com)
11
11
  #
12
12
  module MockServer
13
- RESET_ENDPOINT = '/reset'
14
- CLEAR_ENDPOINT = '/clear'
13
+ RESET_ENDPOINT = '/reset'
14
+ CLEAR_ENDPOINT = '/clear'
15
15
  RETRIEVE_ENDPOINT = '/retrieve'
16
16
  DUMP_LOG_ENDPOINT = '/dumpToLog'
17
17
 
@@ -26,7 +26,7 @@ module MockServer
26
26
  def initialize(host, port)
27
27
  fail 'Cannot instantiate AbstractClient class. You must subclass it.' if self.class == AbstractClient
28
28
  fail 'Host/port must not be nil' unless host && port
29
- @base = RestClient::Resource.new("http://#{host}:#{port}")
29
+ @base = RestClient::Resource.new("http://#{host}:#{port}")
30
30
  @logger = ::LoggingFactory::DEFAULT_FACTORY.log(self.class)
31
31
  end
32
32
 
@@ -35,28 +35,26 @@ module MockServer
35
35
  # @return [Object] the response from the clear action
36
36
  def clear(request)
37
37
  request = camelized_hash(HTTP_REQUEST => Request.new(symbolize_keys(request)))
38
- url = CLEAR_ENDPOINT
39
38
 
40
39
  logger.debug("Clearing expectation with request: #{request}")
41
- logger.debug("URL: #{url}. Payload: #{request.to_hash}")
40
+ logger.debug("URL: #{CLEAR_ENDPOINT}. Payload: #{request.to_hash}")
42
41
 
43
- response = @base[url].put(request.to_json, content_type: :json)
42
+ response = @base[CLEAR_ENDPOINT].put(request.to_json, content_type: :json)
44
43
  logger.debug("Got clear response: #{response.code}")
45
- parse_response(response)
44
+ parse_string_to_json(response)
46
45
  end
47
46
 
48
47
  # Reset the mock server clearing all expectations previously registered
49
48
  # @return [Object] the response from the reset action
50
49
  def reset
51
50
  request = {}
52
- url = RESET_ENDPOINT
53
51
 
54
52
  logger.debug('Resetting mockserver')
55
- logger.debug("URL: #{url}. Payload: #{request.to_hash}")
53
+ logger.debug("URL: #{RESET_ENDPOINT}. Payload: #{request.to_hash}")
56
54
 
57
- response = @base[url].put(request.to_json)
55
+ response = @base[RESET_ENDPOINT].put(request.to_json)
58
56
  logger.debug("Got reset response: #{response.code}")
59
- parse_response(response)
57
+ parse_string_to_json(response)
60
58
  end
61
59
 
62
60
  # Retrieve the list of requests that have been processed by the server
@@ -64,25 +62,17 @@ module MockServer
64
62
  # @return [Object] the list of responses processed by the server
65
63
  def retrieve(request = nil)
66
64
  request = request ? camelized_hash(HTTP_REQUEST => Request.new(symbolize_keys(request))) : {}
67
- url = RETRIEVE_ENDPOINT
68
65
 
69
66
  logger.debug('Retrieving request list from mockserver')
70
- logger.debug("URL: #{url}. Payload: #{request.to_hash}")
67
+ logger.debug("URL: #{RETRIEVE_ENDPOINT}. Payload: #{request.to_hash}")
71
68
 
72
69
  response = @base[RETRIEVE_ENDPOINT].put(request.to_json)
73
70
  logger.debug("Got retrieve response: #{response.code}")
74
- results = parse_response(response)
75
- mocks = Mocks.new([])
76
- unless results.empty?
77
- results.each do |result|
78
- mock = Mock.new
79
- mock.populate_from_payload(result)
80
- mocks << mock
81
- end
82
- end
83
- mocks.code = response.code
84
-
85
- mocks
71
+ expectations = Expectations.new([])
72
+ parse_string_to_json(response).map { |result| expectations << expectation_from_json(result) } unless response.empty?
73
+ # expectations = Expectations.new([]).insert(0, (parse_string_to_json(response).map { |result| expectation_from_json(result) } unless response.empty?))
74
+ expectations.code = response.code
75
+ expectations
86
76
  end
87
77
 
88
78
  # Request to dump logs to file
@@ -90,15 +80,15 @@ module MockServer
90
80
  # @return [Object] the list of responses processed by the server
91
81
  def dump_log(request = nil, java = false)
92
82
  type_params = java ? '?type=java' : ''
93
- url = "#{DUMP_LOG_ENDPOINT}#{type_params}"
94
- request = request ? Request.new(symbolize_keys(request)) : {}
83
+ url = "#{DUMP_LOG_ENDPOINT}#{type_params}"
84
+ request = request ? Request.new(symbolize_keys(request)) : {}
95
85
 
96
86
  logger.debug('Sending dump log request to mockserver')
97
87
  logger.debug("URL: #{url}. Payload: #{request.to_hash}")
98
88
 
99
89
  response = @base[url].put(request.to_json)
100
90
  logger.debug("Got dump to log response: #{response.code}")
101
- parse_response(response)
91
+ parse_string_to_json(response)
102
92
  end
103
93
 
104
94
  # Verify that the given request is called the number of times expected
@@ -107,12 +97,12 @@ module MockServer
107
97
  # @return [Object] the list of responses processed by the server that match the request
108
98
  def verify(request, times = exactly(1))
109
99
  logger.debug('Sending query for verify to mockserver')
110
- results = retrieve(request)
100
+ results = retrieve(request)
111
101
 
112
102
  # Reusing the times model here so interpreting values here
113
- times = Times.new(symbolize_keys(times))
103
+ times = Times.new(symbolize_keys(times))
114
104
  num_times = times.remaining_times
115
- is_exact = !times.unlimited
105
+ is_exact = !times.unlimited
116
106
 
117
107
  fulfilled = is_exact ? (num_times == results.size) : (num_times <= results.size)
118
108
  fail "Expected request to be present: [#{num_times}] (#{is_exact ? 'exactly' : 'at least'}). But found: [#{results.size}]" unless fulfilled
@@ -20,15 +20,14 @@ module MockServer
20
20
  # @return [Object] the response from the register action
21
21
  def register(expectation)
22
22
  fail 'Expectation passed in is not valid type' unless expectation.is_a?(Expectation)
23
- url = EXPECTATION_ENDPOINT
24
23
  request = create_expectation_request(expectation)
25
24
 
26
25
  logger.debug('Registering new expectation')
27
- logger.debug("URL: #{url} Payload: #{request.to_hash}")
26
+ logger.debug("URL: #{EXPECTATION_ENDPOINT} Payload: #{request.to_hash}")
28
27
 
29
- response = @base[url].put(request.to_json, content_type: :json)
28
+ response = @base[EXPECTATION_ENDPOINT].put(request.to_json, content_type: :json)
30
29
  logger.debug("Got register response: #{response.code}")
31
- parse_response(response)
30
+ parse_string_to_json(response)
32
31
  end
33
32
 
34
33
  private
@@ -36,6 +35,7 @@ module MockServer
36
35
  # Create an expecation request to send to the expectation endpoint of
37
36
  # @param expectation [Expectation] the expectation to create the request from
38
37
  # @return [Hash] a hash representing the request to use in registering an expectation with the mock server
38
+ # rubocop:disable Lint/LiteralInInterpolation
39
39
  def create_expectation_request(expectation)
40
40
  expectation_request = camelized_hash(expectation)
41
41
  logger.debug("Expectation JSON: #{expectation_request.to_json}")
@@ -1,10 +1,11 @@
1
1
  # encoding: UTF-8
2
+ require_relative './array_of'
2
3
  require_relative './request'
3
4
  require_relative './response'
4
5
  require_relative './forward'
5
6
  require_relative './times'
6
7
  require_relative '../utility_methods'
7
- require_relative './mock'
8
+
8
9
  #
9
10
  # A class to model an expectation sent to the Mockserver instance.
10
11
  # See http://www.mock-server.com/#create-expectations for details.
@@ -12,15 +13,111 @@ require_relative './mock'
12
13
  # @author:: Nayyara Samuel (mailto: nayyara.samuel@opower.com)
13
14
  #
14
15
  module MockServer
15
- HTTP_REQUEST = 'httpRequest'
16
- HTTP_RESPONSE = 'httpResponse'
17
- HTTP_FORWARD = 'httpForward'
18
- HTTP_TIMES = 'times'
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)
19
20
 
20
21
  # Models
21
22
  module Model
22
23
  # Expectation model
23
- class Expectation < Mock
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
24
121
  end
25
122
 
26
123
  # DSL method for creating expectation
@@ -30,6 +127,13 @@ module MockServer
30
127
  yield expectation if block_given?
31
128
  expectation
32
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
33
137
  end
34
138
  end
35
139
  end
@@ -10,14 +10,16 @@ module MockServer::UtilityMethods
10
10
  # Does the following filter/transform operations on a hash
11
11
  # - exclude null or empty valued keys from the hash
12
12
  # - camelize the keys of the hash
13
- # @param hash [Object] an object which will be used to create the hash. Must support :to_hash method
13
+ # @param obj [Object] an object which will be used to create the hash. Must support :to_hash method
14
14
  # @return [Hash] the transformed hash
15
+ # rubocop:disable Style/MethodLength
16
+ # rubocop:disable Style/CyclomaticComplexity
15
17
  def camelized_hash(obj)
16
18
  obj = obj && obj.respond_to?(:to_hash) ? obj.to_hash : obj
17
19
 
18
20
  if obj.is_a?(Hash)
19
21
  obj.each_with_object({}) do |(k, v), acc|
20
- is_empty = v.nil? || (v.respond_to?(:empty?) ? v.empty? : false)
22
+ is_empty = v.nil? || (v.respond_to?(:empty?) ? v.empty? : false)
21
23
  acc[camelize(k)] = camelized_hash(v) unless is_empty
22
24
  end
23
25
  elsif obj.respond_to?(:map)
@@ -40,7 +42,7 @@ module MockServer::UtilityMethods
40
42
  end
41
43
  end
42
44
 
43
- # @param [Object] an object to camelize the string representation of
45
+ # @param str [Object] an object to camelize the string representation of
44
46
  # @return [String] the string converted to camelcase with first letter in lower case
45
47
  def camelize(str)
46
48
  str.to_s.camelize(:lower)
@@ -49,7 +51,7 @@ module MockServer::UtilityMethods
49
51
  # Parse string response into JSON
50
52
  # @param response [Response] from RestClient response
51
53
  # @return [Hash] the parsed response or the object unmodified if parsing is not possible
52
- def parse_response(response)
54
+ def parse_string_to_json(response)
53
55
  JSON.parse(response)
54
56
  rescue JSON::ParserError
55
57
  response
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  # Version for this gem
3
3
  module MockServer
4
- VERSION = '0.0.3'
4
+ VERSION = '1.0.0.pre'
5
5
  end
@@ -4,30 +4,34 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'mockserver/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = 'mockserver-client'
8
- spec.version = MockServer::VERSION
9
- spec.authors = ['Nayyara Samuel']
10
- spec.email = ['nayyara.samuel@opower.com']
11
- spec.summary = %q(A Ruby client for MockServer)
12
- spec.required_ruby_version = '~> 1.9.3'
7
+ spec.name = 'mockserver-client'
8
+ spec.version = MockServer::VERSION
9
+ spec.authors = ['Nayyara Samuel', 'James D Bloom']
10
+ spec.email = ['nayyara.samuel@opower.com', 'jamesdbloom@gmail.com']
11
+ spec.homepage = 'http://www.mock-server.com'
12
+ spec.summary = 'A Ruby client for MockServer'
13
+ spec.description = 'A Ruby Client for MockServer that enables easy mocking of any system you integrate with via HTTP or HTTPS (i.e. services, web sites, etc)'
13
14
 
14
- spec.files = `git ls-files -z`.split("\x0")
15
- spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(/^(test|spec|features)\//)
15
+ spec.required_ruby_version = '>= 1.9'
16
+ spec.required_rubygems_version = '~> 1'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
17
21
  spec.require_paths = ['lib']
18
22
 
19
- spec.add_development_dependency 'bundler', '~> 1.6'
20
- spec.add_development_dependency 'rake', '~> 10.3.2'
21
- spec.add_development_dependency 'rspec', '~> 3.0.0'
22
- spec.add_development_dependency 'simplecov', '~> 0.8.2'
23
- spec.add_development_dependency 'webmock', '~> 1.18'
24
- spec.add_development_dependency 'rubocop', '~> 0.23.0'
23
+ spec.add_development_dependency 'bundler', '~> 1'
24
+ spec.add_development_dependency 'rake', '~> 10'
25
+ spec.add_development_dependency 'rspec', '~> 3'
26
+ spec.add_development_dependency 'simplecov', '~> 0'
27
+ spec.add_development_dependency 'webmock', '~> 1'
28
+ spec.add_development_dependency 'rubocop', '~> 0'
25
29
 
26
- spec.add_dependency 'hashie', '~> 3.0'
27
- spec.add_dependency 'json', '~> 1.8.1'
28
- spec.add_dependency 'activesupport', '~> 4.1.1'
29
- spec.add_dependency 'rest-client', '~> 1.6.7'
30
- spec.add_dependency 'logging_factory', '~> 0.0.2'
31
- spec.add_dependency 'thor', '~> 0.19.1'
32
- spec.add_dependency 'colorize', '~> 0.7.0'
30
+ spec.add_dependency 'hashie', '~> 3'
31
+ spec.add_dependency 'json', '~> 1'
32
+ spec.add_dependency 'activesupport', '~> 4'
33
+ spec.add_dependency 'rest-client', '~> 1'
34
+ spec.add_dependency 'logging_factory', '~> 0'
35
+ spec.add_dependency 'thor', '~> 0'
36
+ spec.add_dependency 'colorize', '~> 0'
33
37
  end
data/pom.xml ADDED
@@ -0,0 +1,80 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
+ <parent>
4
+ <artifactId>mockserver</artifactId>
5
+ <groupId>org.mock-server</groupId>
6
+ <version>3.4-SNAPSHOT</version>
7
+ </parent>
8
+ <modelVersion>4.0.0</modelVersion>
9
+
10
+ <artifactId>mockserver-client-ruby</artifactId>
11
+ <name>MockServer Ruby Client</name>
12
+ <description>A ruby client for the MockServer</description>
13
+ <url>http://www.mock-server.com</url>
14
+
15
+ <build>
16
+ <plugins>
17
+ <plugin>
18
+ <groupId>org.codehaus.mojo</groupId>
19
+ <artifactId>exec-maven-plugin</artifactId>
20
+ <version>1.2.1</version>
21
+ <executions>
22
+ <execution>
23
+ <id>bundle_install</id>
24
+ <phase>prepare-package</phase>
25
+ <goals>
26
+ <goal>exec</goal>
27
+ </goals>
28
+ <configuration>
29
+ <executable>bundle</executable>
30
+ <arguments>
31
+ <argument>install</argument>
32
+ </arguments>
33
+ <environmentVariables>
34
+ <BUNDLE_GEMFILE>${basedir}/Gemfile</BUNDLE_GEMFILE>
35
+ </environmentVariables>
36
+ </configuration>
37
+ </execution>
38
+ <execution>
39
+ <id>ruby_make</id>
40
+ <phase>prepare-package</phase>
41
+ <goals>
42
+ <goal>exec</goal>
43
+ </goals>
44
+ <configuration>
45
+ <executable>bundle</executable>
46
+ <arguments>
47
+ <argument>exec</argument>
48
+ <argument>rake</argument>
49
+ <argument>build</argument>
50
+ </arguments>
51
+ <environmentVariables>
52
+ <BUNDLE_GEMFILE>${basedir}/Gemfile</BUNDLE_GEMFILE>
53
+ </environmentVariables>
54
+ </configuration>
55
+ </execution>
56
+ <!-- TODO setup release permissions to https://rubygems.org/gems/mockserver-client -->
57
+ <!--<execution>-->
58
+ <!--<id>ruby_release</id>-->
59
+ <!--<phase>deploy</phase>-->
60
+ <!--<goals>-->
61
+ <!--<goal>exec</goal>-->
62
+ <!--</goals>-->
63
+ <!--<configuration>-->
64
+ <!--<executable>bundle</executable>-->
65
+ <!--<arguments>-->
66
+ <!--<argument>exec</argument>-->
67
+ <!--<argument>rake</argument>-->
68
+ <!--<argument>release</argument>-->
69
+ <!--</arguments>-->
70
+ <!--<environmentVariables>-->
71
+ <!--<BUNDLE_GEMFILE>${basedir}/Gemfile</BUNDLE_GEMFILE>-->
72
+ <!--</environmentVariables>-->
73
+ <!--</configuration>-->
74
+ <!--</execution>-->
75
+ </executions>
76
+ </plugin>
77
+ </plugins>
78
+ </build>
79
+
80
+ </project>
@@ -4,29 +4,29 @@ require_relative '../spec_helper'
4
4
  describe MockServer::Model::DSL do
5
5
 
6
6
  it 'generates http requests correctly' do
7
- mock_request = http_request(:POST, '/login')
7
+ mock_request = http_request(:POST, '/login')
8
8
  mock_request.query_parameters = [parameter('returnUrl', '/account')]
9
- mock_request.cookies = [cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')]
10
- mock_request.body = exact("{username:'foo', password:'bar'}")
9
+ mock_request.cookies = [cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')]
10
+ mock_request.body = exact("{username:'foo', password:'bar'}")
11
11
 
12
12
  expect(to_camelized_hash(HTTP_REQUEST => mock_request)).to eq(FIXTURES.read('post_login_request.json'))
13
13
 
14
14
  # Block style
15
15
  mock_request = request(:POST, '/login') do |request|
16
16
  request.query_parameters = [parameter('returnUrl', '/account')]
17
- request.cookies = [cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')]
18
- request.body = exact("{username:'foo', password:'bar'}")
17
+ request.cookies = [cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')]
18
+ request.body = exact("{username:'foo', password:'bar'}")
19
19
  end
20
20
 
21
21
  expect(to_camelized_hash(HTTP_REQUEST => mock_request)).to eq(FIXTURES.read('post_login_request.json'))
22
22
  end
23
23
 
24
24
  it 'generates http responses correctly' do
25
- mock_response = http_response
25
+ mock_response = http_response
26
26
  mock_response.status_code = 401
27
- mock_response.headers = [header('Content-Type', 'application/json; charset=utf-8')]
27
+ mock_response.headers = [header('Content-Type', 'application/json; charset=utf-8')]
28
28
  mock_response.headers << header('Cache-Control', 'public, max-age=86400')
29
- mock_response.body = body('incorrect username and password combination')
29
+ mock_response.body = body('incorrect username and password combination')
30
30
  mock_response.delay = delay_by(:SECONDS, 1)
31
31
 
32
32
  expect(to_camelized_hash(HTTP_RESPONSE => mock_response)).to eq(FIXTURES.read('incorrect_login_response.json'))
@@ -34,9 +34,9 @@ describe MockServer::Model::DSL do
34
34
  # Block style
35
35
  mock_response = response do |response|
36
36
  response.status_code = 401
37
- response.headers = [header('Content-Type', 'application/json; charset=utf-8')]
37
+ response.headers = [header('Content-Type', 'application/json; charset=utf-8')]
38
38
  response.headers << header('Cache-Control', 'public, max-age=86400')
39
- response.body = body('incorrect username and password combination')
39
+ response.body = body('incorrect username and password combination')
40
40
  response.delay = delay_by(:SECONDS, 1)
41
41
  end
42
42
 
@@ -44,7 +44,7 @@ describe MockServer::Model::DSL do
44
44
  end
45
45
 
46
46
  it 'generates http forwards correctly' do
47
- mock_forward = http_forward
47
+ mock_forward = http_forward
48
48
  mock_forward.host = 'www.mock-server.com'
49
49
  mock_forward.port = 80
50
50
 
@@ -70,9 +70,8 @@ describe MockServer::Model::DSL do
70
70
  end
71
71
 
72
72
  it 'generates expectation correctly from file' do
73
- payload = FIXTURES.read('register_expectation.json')
74
- mock_expectation = expectation
75
- mock_expectation.populate_from_payload(payload)
73
+ payload = FIXTURES.read('register_expectation.json')
74
+ mock_expectation = expectation_from_json(payload)
76
75
 
77
76
  expect(to_camelized_hash(mock_expectation.to_hash)).to eq(payload)
78
77
  end
@@ -22,7 +22,7 @@ describe MockServer::MockServerClient do
22
22
  mock_expectation = expectation do |expectation|
23
23
  expectation.request do |request|
24
24
  request.method = 'POST'
25
- request.path = '/login'
25
+ request.path = '/login'
26
26
  request.query_parameters << parameter('returnUrl', '/account')
27
27
  request.cookies << cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')
28
28
  request.body = exact({ username: 'foo', password: 'bar' }.to_json)
@@ -32,7 +32,7 @@ describe MockServer::MockServerClient do
32
32
  response.status_code = 401
33
33
  response.headers << header('Content-Type', 'application/json; charset=utf-8')
34
34
  response.headers << header('Cache-Control', 'public, max-age=86400')
35
- response.body = body({ message: 'incorrect username and password combination' }.to_json)
35
+ response.body = body({ message: 'incorrect username and password combination' }.to_json)
36
36
  response.delay = delay_by(:SECONDS, 1)
37
37
  end
38
38
 
@@ -47,7 +47,7 @@ describe MockServer::MockServerClient do
47
47
  mock_expectation = expectation do |expectation|
48
48
  expectation.request do |request|
49
49
  request.method = 'POST'
50
- request.path = '/login'
50
+ request.path = '/login'
51
51
  end
52
52
 
53
53
  expectation.response do |response|
@@ -14,7 +14,7 @@ describe MockServer::ProxyClient do
14
14
 
15
15
  # Stub requests
16
16
  stub_request(:put, /.+\/retrieve/).with(body: search_request_json).to_return(
17
- body: "[#{register_expectation_json}, #{register_expectation_json}]",
17
+ body: "[#{register_expectation_json}, #{register_expectation_json}]",
18
18
  status: 200
19
19
  )
20
20
  stub_request(:put, /.+\/dumpToLog$/).to_return(status: 202).once
metadata CHANGED
@@ -1,208 +1,210 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mockserver-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nayyara Samuel
8
+ - James D Bloom
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-06-24 00:00:00.000000000 Z
12
+ date: 2014-06-30 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ~>
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '1.6'
20
+ version: '1'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ~>
25
+ - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '1.6'
27
+ version: '1'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ~>
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: 10.3.2
34
+ version: '10'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ~>
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: 10.3.2
41
+ version: '10'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rspec
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ~>
46
+ - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: 3.0.0
48
+ version: '3'
48
49
  type: :development
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ~>
53
+ - - "~>"
53
54
  - !ruby/object:Gem::Version
54
- version: 3.0.0
55
+ version: '3'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: simplecov
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
- - - ~>
60
+ - - "~>"
60
61
  - !ruby/object:Gem::Version
61
- version: 0.8.2
62
+ version: '0'
62
63
  type: :development
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
- - - ~>
67
+ - - "~>"
67
68
  - !ruby/object:Gem::Version
68
- version: 0.8.2
69
+ version: '0'
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: webmock
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
- - - ~>
74
+ - - "~>"
74
75
  - !ruby/object:Gem::Version
75
- version: '1.18'
76
+ version: '1'
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - ~>
81
+ - - "~>"
81
82
  - !ruby/object:Gem::Version
82
- version: '1.18'
83
+ version: '1'
83
84
  - !ruby/object:Gem::Dependency
84
85
  name: rubocop
85
86
  requirement: !ruby/object:Gem::Requirement
86
87
  requirements:
87
- - - ~>
88
+ - - "~>"
88
89
  - !ruby/object:Gem::Version
89
- version: 0.23.0
90
+ version: '0'
90
91
  type: :development
91
92
  prerelease: false
92
93
  version_requirements: !ruby/object:Gem::Requirement
93
94
  requirements:
94
- - - ~>
95
+ - - "~>"
95
96
  - !ruby/object:Gem::Version
96
- version: 0.23.0
97
+ version: '0'
97
98
  - !ruby/object:Gem::Dependency
98
99
  name: hashie
99
100
  requirement: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - ~>
102
+ - - "~>"
102
103
  - !ruby/object:Gem::Version
103
- version: '3.0'
104
+ version: '3'
104
105
  type: :runtime
105
106
  prerelease: false
106
107
  version_requirements: !ruby/object:Gem::Requirement
107
108
  requirements:
108
- - - ~>
109
+ - - "~>"
109
110
  - !ruby/object:Gem::Version
110
- version: '3.0'
111
+ version: '3'
111
112
  - !ruby/object:Gem::Dependency
112
113
  name: json
113
114
  requirement: !ruby/object:Gem::Requirement
114
115
  requirements:
115
- - - ~>
116
+ - - "~>"
116
117
  - !ruby/object:Gem::Version
117
- version: 1.8.1
118
+ version: '1'
118
119
  type: :runtime
119
120
  prerelease: false
120
121
  version_requirements: !ruby/object:Gem::Requirement
121
122
  requirements:
122
- - - ~>
123
+ - - "~>"
123
124
  - !ruby/object:Gem::Version
124
- version: 1.8.1
125
+ version: '1'
125
126
  - !ruby/object:Gem::Dependency
126
127
  name: activesupport
127
128
  requirement: !ruby/object:Gem::Requirement
128
129
  requirements:
129
- - - ~>
130
+ - - "~>"
130
131
  - !ruby/object:Gem::Version
131
- version: 4.1.1
132
+ version: '4'
132
133
  type: :runtime
133
134
  prerelease: false
134
135
  version_requirements: !ruby/object:Gem::Requirement
135
136
  requirements:
136
- - - ~>
137
+ - - "~>"
137
138
  - !ruby/object:Gem::Version
138
- version: 4.1.1
139
+ version: '4'
139
140
  - !ruby/object:Gem::Dependency
140
141
  name: rest-client
141
142
  requirement: !ruby/object:Gem::Requirement
142
143
  requirements:
143
- - - ~>
144
+ - - "~>"
144
145
  - !ruby/object:Gem::Version
145
- version: 1.6.7
146
+ version: '1'
146
147
  type: :runtime
147
148
  prerelease: false
148
149
  version_requirements: !ruby/object:Gem::Requirement
149
150
  requirements:
150
- - - ~>
151
+ - - "~>"
151
152
  - !ruby/object:Gem::Version
152
- version: 1.6.7
153
+ version: '1'
153
154
  - !ruby/object:Gem::Dependency
154
155
  name: logging_factory
155
156
  requirement: !ruby/object:Gem::Requirement
156
157
  requirements:
157
- - - ~>
158
+ - - "~>"
158
159
  - !ruby/object:Gem::Version
159
- version: 0.0.2
160
+ version: '0'
160
161
  type: :runtime
161
162
  prerelease: false
162
163
  version_requirements: !ruby/object:Gem::Requirement
163
164
  requirements:
164
- - - ~>
165
+ - - "~>"
165
166
  - !ruby/object:Gem::Version
166
- version: 0.0.2
167
+ version: '0'
167
168
  - !ruby/object:Gem::Dependency
168
169
  name: thor
169
170
  requirement: !ruby/object:Gem::Requirement
170
171
  requirements:
171
- - - ~>
172
+ - - "~>"
172
173
  - !ruby/object:Gem::Version
173
- version: 0.19.1
174
+ version: '0'
174
175
  type: :runtime
175
176
  prerelease: false
176
177
  version_requirements: !ruby/object:Gem::Requirement
177
178
  requirements:
178
- - - ~>
179
+ - - "~>"
179
180
  - !ruby/object:Gem::Version
180
- version: 0.19.1
181
+ version: '0'
181
182
  - !ruby/object:Gem::Dependency
182
183
  name: colorize
183
184
  requirement: !ruby/object:Gem::Requirement
184
185
  requirements:
185
- - - ~>
186
+ - - "~>"
186
187
  - !ruby/object:Gem::Version
187
- version: 0.7.0
188
+ version: '0'
188
189
  type: :runtime
189
190
  prerelease: false
190
191
  version_requirements: !ruby/object:Gem::Requirement
191
192
  requirements:
192
- - - ~>
193
+ - - "~>"
193
194
  - !ruby/object:Gem::Version
194
- version: 0.7.0
195
- description:
195
+ version: '0'
196
+ description: A Ruby Client for MockServer that enables easy mocking of any system
197
+ you integrate with via HTTP or HTTPS (i.e. services, web sites, etc)
196
198
  email:
197
199
  - nayyara.samuel@opower.com
200
+ - jamesdbloom@gmail.com
198
201
  executables:
199
202
  - mockserver
200
203
  extensions: []
201
204
  extra_rdoc_files: []
202
205
  files:
203
- - .gitignore
204
- - .rubocop.yml
205
- - .travis.yml
206
+ - ".rubocop.yml"
207
+ - CHANGELOG.md
206
208
  - Gemfile
207
209
  - README.md
208
210
  - Rakefile
@@ -217,7 +219,6 @@ files:
217
219
  - lib/mockserver/model/enum.rb
218
220
  - lib/mockserver/model/expectation.rb
219
221
  - lib/mockserver/model/forward.rb
220
- - lib/mockserver/model/mock.rb
221
222
  - lib/mockserver/model/parameter.rb
222
223
  - lib/mockserver/model/request.rb
223
224
  - lib/mockserver/model/response.rb
@@ -226,6 +227,7 @@ files:
226
227
  - lib/mockserver/utility_methods.rb
227
228
  - lib/mockserver/version.rb
228
229
  - mockserver-client.gemspec
230
+ - pom.xml
229
231
  - spec/fixtures/forward_mockserver.json
230
232
  - spec/fixtures/incorrect_login_response.json
231
233
  - spec/fixtures/post_login_request.json
@@ -236,7 +238,7 @@ files:
236
238
  - spec/mockserver/mock_client_spec.rb
237
239
  - spec/mockserver/proxy_client_spec.rb
238
240
  - spec/spec_helper.rb
239
- homepage:
241
+ homepage: http://www.mock-server.com
240
242
  licenses: []
241
243
  metadata: {}
242
244
  post_install_message:
@@ -245,14 +247,14 @@ require_paths:
245
247
  - lib
246
248
  required_ruby_version: !ruby/object:Gem::Requirement
247
249
  requirements:
248
- - - ~>
250
+ - - ">="
249
251
  - !ruby/object:Gem::Version
250
- version: 1.9.3
252
+ version: '1.9'
251
253
  required_rubygems_version: !ruby/object:Gem::Requirement
252
254
  requirements:
253
- - - ! '>='
255
+ - - "~>"
254
256
  - !ruby/object:Gem::Version
255
- version: '0'
257
+ version: '1'
256
258
  requirements: []
257
259
  rubyforge_project:
258
260
  rubygems_version: 2.2.2
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
23
- tmp.log
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- script:
5
- - bundle exec rake rubocop
6
- - bundle exec rake spec
7
- - bundle exec rake build
@@ -1,123 +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 a mock object used to create and retrieve mock requests.
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'
17
- HTTP_RESPONSE = 'httpResponse'
18
- HTTP_FORWARD = 'httpForward'
19
- HTTP_TIMES = 'times'
20
-
21
- # Models
22
- module Model # rubocop:disable Style/ClassAndModuleChildren
23
- # Mock object model
24
- class Mock
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 Mocks < ArrayOf
115
- # Code is used to store HTTP status code returned from retrieve endpoint
116
- attr_accessor :code
117
-
118
- def child_class
119
- Mock
120
- end
121
- end
122
- end
123
- end