mockserver-client 1.0.8.pre → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,15 @@
|
|
1
|
+
=begin
|
2
|
+
#Mock Server API
|
3
|
+
|
4
|
+
#MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
|
5
|
+
|
6
|
+
OpenAPI spec version: 5.3.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 3.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module MockServer
|
14
|
+
VERSION = '5.3.0'
|
15
|
+
end
|
data/mockserver-client.gemspec
CHANGED
@@ -1,37 +1,45 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
=begin
|
4
|
+
#Mock Server API
|
5
|
+
|
6
|
+
#MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
|
7
|
+
|
8
|
+
OpenAPI spec version: 5.3.0
|
9
|
+
|
10
|
+
Generated by: https://openapi-generator.tech
|
11
|
+
OpenAPI Generator version: 3.3.1
|
12
|
+
|
13
|
+
=end
|
14
|
+
|
15
|
+
$:.push File.expand_path("../lib", __FILE__)
|
16
|
+
require "mockserver-client/version"
|
17
|
+
|
18
|
+
Gem::Specification.new do |s|
|
19
|
+
s.name = "mockserver-client"
|
20
|
+
s.version = MockServer::VERSION
|
21
|
+
s.platform = Gem::Platform::RUBY
|
22
|
+
s.authors = ["James D Bloom"]
|
23
|
+
s.email = ["jamesdbloom@gmail.com"]
|
24
|
+
s.homepage = "http://www.mock-server.com"
|
25
|
+
s.summary = "Mock Server API Ruby Gem"
|
26
|
+
s.description = "MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test."
|
27
|
+
s.license = 'Apache-2.0'
|
28
|
+
s.required_ruby_version = ">= 2.0"
|
29
|
+
|
30
|
+
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
|
31
|
+
s.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
|
32
|
+
|
33
|
+
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
34
|
+
s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1'
|
35
|
+
s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3'
|
36
|
+
s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6'
|
37
|
+
s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2'
|
38
|
+
s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16'
|
39
|
+
s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12'
|
40
|
+
|
41
|
+
s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }
|
42
|
+
s.test_files = `find spec/*`.split("\n")
|
43
|
+
s.executables = []
|
44
|
+
s.require_paths = ["lib"]
|
37
45
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
=begin
|
2
|
+
#Mock Server API
|
3
|
+
|
4
|
+
#MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
|
5
|
+
|
6
|
+
OpenAPI spec version: 5.3.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 3.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for MockServer::ControlApi
|
17
|
+
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'ControlApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = MockServer::ControlApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of ControlApi' do
|
30
|
+
it 'should create an instance of ControlApi' do
|
31
|
+
expect(@instance).to be_instance_of(MockServer::ControlApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for bind_put
|
36
|
+
# bind additional listening ports
|
37
|
+
# only supported on Netty version
|
38
|
+
# @param ports list of ports to bind to, where 0 indicates dynamically bind to any available port
|
39
|
+
# @param [Hash] opts the optional parameters
|
40
|
+
# @return [Ports]
|
41
|
+
describe 'bind_put test' do
|
42
|
+
it 'should work' do
|
43
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# unit tests for clear_put
|
48
|
+
# clears expectations and recorded requests that match the request matcher
|
49
|
+
# @param [Hash] opts the optional parameters
|
50
|
+
# @option opts [HttpRequest] :http_request request used to match expectations and recored requests to clear
|
51
|
+
# @return [nil]
|
52
|
+
describe 'clear_put test' do
|
53
|
+
it 'should work' do
|
54
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# unit tests for reset_put
|
59
|
+
# clears all expectations and recorded requests
|
60
|
+
# @param [Hash] opts the optional parameters
|
61
|
+
# @return [nil]
|
62
|
+
describe 'reset_put test' do
|
63
|
+
it 'should work' do
|
64
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# unit tests for retrieve_put
|
69
|
+
# retrieve recorded requests, active expectations, recorded expectations or log messages
|
70
|
+
# @param [Hash] opts the optional parameters
|
71
|
+
# @option opts [String] :format changes response format, default if not specificed is \"json\", supported values are \"java\", \"json\"
|
72
|
+
# @option opts [String] :type specifies the type of object that is retrieve, default if not specified is \"requests\", supported values are \"logs\", \"requests\", \"recorded_expectations\", \"active_expectations\"
|
73
|
+
# @option opts [HttpRequest] :http_request request used to match which recorded requests, expectations or log messages to return, an empty body matches all requests, expectations or log messages
|
74
|
+
# @return [Object]
|
75
|
+
describe 'retrieve_put test' do
|
76
|
+
it 'should work' do
|
77
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# unit tests for status_put
|
82
|
+
# return listening ports
|
83
|
+
# @param [Hash] opts the optional parameters
|
84
|
+
# @return [Ports]
|
85
|
+
describe 'status_put test' do
|
86
|
+
it 'should work' do
|
87
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# unit tests for stop_put
|
92
|
+
# stop running process
|
93
|
+
# only supported on Netty version
|
94
|
+
# @param [Hash] opts the optional parameters
|
95
|
+
# @return [nil]
|
96
|
+
describe 'stop_put test' do
|
97
|
+
it 'should work' do
|
98
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
=begin
|
2
|
+
#Mock Server API
|
3
|
+
|
4
|
+
#MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
|
5
|
+
|
6
|
+
OpenAPI spec version: 5.3.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 3.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for MockServer::ExpectationApi
|
17
|
+
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'ExpectationApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = MockServer::ExpectationApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of ExpectationApi' do
|
30
|
+
it 'should create an instance of ExpectationApi' do
|
31
|
+
expect(@instance).to be_instance_of(MockServer::ExpectationApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for expectation_put
|
36
|
+
# create expectation
|
37
|
+
# @param expectations expectation to create
|
38
|
+
# @param [Hash] opts the optional parameters
|
39
|
+
# @return [nil]
|
40
|
+
describe 'expectation_put test' do
|
41
|
+
it 'should work' do
|
42
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
=begin
|
2
|
+
#Mock Server API
|
3
|
+
|
4
|
+
#MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
|
5
|
+
|
6
|
+
OpenAPI spec version: 5.3.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 3.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# Unit tests for MockServer::VerifyApi
|
17
|
+
# Automatically generated by openapi-generator (https://openapi-generator.tech)
|
18
|
+
# Please update as you see appropriate
|
19
|
+
describe 'VerifyApi' do
|
20
|
+
before do
|
21
|
+
# run before each test
|
22
|
+
@instance = MockServer::VerifyApi.new
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
# run after each test
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'test an instance of VerifyApi' do
|
30
|
+
it 'should create an instance of VerifyApi' do
|
31
|
+
expect(@instance).to be_instance_of(MockServer::VerifyApi)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# unit tests for verify_put
|
36
|
+
# verify a request has been received a specific number of times
|
37
|
+
# @param verification request matcher and the number of times to match
|
38
|
+
# @param [Hash] opts the optional parameters
|
39
|
+
# @return [nil]
|
40
|
+
describe 'verify_put test' do
|
41
|
+
it 'should work' do
|
42
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# unit tests for verify_sequence_put
|
47
|
+
# verify a sequence of request has been received in the specific order
|
48
|
+
# @param verification_sequence the sequence of requests matchers
|
49
|
+
# @param [Hash] opts the optional parameters
|
50
|
+
# @return [nil]
|
51
|
+
describe 'verify_sequence_put test' do
|
52
|
+
it 'should work' do
|
53
|
+
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
=begin
|
2
|
+
#Mock Server API
|
3
|
+
|
4
|
+
#MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby and a simple REST API (as shown below). MockServer Proxy is a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding). Both MockServer and the MockServer Proxy record all received requests so that it is possible to verify exactly what requests have been sent by the system under test.
|
5
|
+
|
6
|
+
OpenAPI spec version: 5.3.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 3.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'spec_helper'
|
14
|
+
|
15
|
+
describe MockServer::ApiClient do
|
16
|
+
context 'initialization' do
|
17
|
+
context 'URL stuff' do
|
18
|
+
context 'host' do
|
19
|
+
it 'removes http from host' do
|
20
|
+
MockServer.configure { |c| c.host = 'http://example.com' }
|
21
|
+
expect(MockServer::Configuration.default.host).to eq('example.com')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'removes https from host' do
|
25
|
+
MockServer.configure { |c| c.host = 'https://wookiee.com' }
|
26
|
+
expect(MockServer::ApiClient.default.config.host).to eq('wookiee.com')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'removes trailing path from host' do
|
30
|
+
MockServer.configure { |c| c.host = 'hobo.com/v4' }
|
31
|
+
expect(MockServer::Configuration.default.host).to eq('hobo.com')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'base_path' do
|
36
|
+
it "prepends a slash to base_path" do
|
37
|
+
MockServer.configure { |c| c.base_path = 'v4/dog' }
|
38
|
+
expect(MockServer::Configuration.default.base_path).to eq('/v4/dog')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "doesn't prepend a slash if one is already there" do
|
42
|
+
MockServer.configure { |c| c.base_path = '/v4/dog' }
|
43
|
+
expect(MockServer::Configuration.default.base_path).to eq('/v4/dog')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "ends up as a blank string if nil" do
|
47
|
+
MockServer.configure { |c| c.base_path = nil }
|
48
|
+
expect(MockServer::Configuration.default.base_path).to eq('')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'params_encoding in #build_request' do
|
55
|
+
let(:config) { MockServer::Configuration.new }
|
56
|
+
let(:api_client) { MockServer::ApiClient.new(config) }
|
57
|
+
|
58
|
+
it 'defaults to nil' do
|
59
|
+
expect(MockServer::Configuration.default.params_encoding).to eq(nil)
|
60
|
+
expect(config.params_encoding).to eq(nil)
|
61
|
+
|
62
|
+
request = api_client.build_request(:get, '/test')
|
63
|
+
expect(request.options[:params_encoding]).to eq(nil)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'can be customized' do
|
67
|
+
config.params_encoding = :multi
|
68
|
+
request = api_client.build_request(:get, '/test')
|
69
|
+
expect(request.options[:params_encoding]).to eq(:multi)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'timeout in #build_request' do
|
74
|
+
let(:config) { MockServer::Configuration.new }
|
75
|
+
let(:api_client) { MockServer::ApiClient.new(config) }
|
76
|
+
|
77
|
+
it 'defaults to 0' do
|
78
|
+
expect(MockServer::Configuration.default.timeout).to eq(0)
|
79
|
+
expect(config.timeout).to eq(0)
|
80
|
+
|
81
|
+
request = api_client.build_request(:get, '/test')
|
82
|
+
expect(request.options[:timeout]).to eq(0)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'can be customized' do
|
86
|
+
config.timeout = 100
|
87
|
+
request = api_client.build_request(:get, '/test')
|
88
|
+
expect(request.options[:timeout]).to eq(100)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#deserialize' do
|
93
|
+
it "handles Array<Integer>" do
|
94
|
+
api_client = MockServer::ApiClient.new
|
95
|
+
headers = { 'Content-Type' => 'application/json' }
|
96
|
+
response = double('response', headers: headers, body: '[12, 34]')
|
97
|
+
data = api_client.deserialize(response, 'Array<Integer>')
|
98
|
+
expect(data).to be_instance_of(Array)
|
99
|
+
expect(data).to eq([12, 34])
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'handles Array<Array<Integer>>' do
|
103
|
+
api_client = MockServer::ApiClient.new
|
104
|
+
headers = { 'Content-Type' => 'application/json' }
|
105
|
+
response = double('response', headers: headers, body: '[[12, 34], [56]]')
|
106
|
+
data = api_client.deserialize(response, 'Array<Array<Integer>>')
|
107
|
+
expect(data).to be_instance_of(Array)
|
108
|
+
expect(data).to eq([[12, 34], [56]])
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'handles Hash<String, String>' do
|
112
|
+
api_client = MockServer::ApiClient.new
|
113
|
+
headers = { 'Content-Type' => 'application/json' }
|
114
|
+
response = double('response', headers: headers, body: '{"message": "Hello"}')
|
115
|
+
data = api_client.deserialize(response, 'Hash<String, String>')
|
116
|
+
expect(data).to be_instance_of(Hash)
|
117
|
+
expect(data).to eq(:message => 'Hello')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#object_to_hash" do
|
122
|
+
it 'ignores nils and includes empty arrays' do
|
123
|
+
# uncomment below to test object_to_hash for model
|
124
|
+
# api_client = MockServer::ApiClient.new
|
125
|
+
# _model = MockServer::ModelName.new
|
126
|
+
# update the model attribute below
|
127
|
+
# _model.id = 1
|
128
|
+
# update the expected value (hash) below
|
129
|
+
# expected = {id: 1, name: '', tags: []}
|
130
|
+
# expect(api_client.object_to_hash(_model)).to eq(expected)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#build_collection_param' do
|
135
|
+
let(:param) { ['aa', 'bb', 'cc'] }
|
136
|
+
let(:api_client) { MockServer::ApiClient.new }
|
137
|
+
|
138
|
+
it 'works for csv' do
|
139
|
+
expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'works for ssv' do
|
143
|
+
expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'works for tsv' do
|
147
|
+
expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'works for pipes' do
|
151
|
+
expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'works for multi' do
|
155
|
+
expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'fails for invalid collection format' do
|
159
|
+
expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#json_mime?' do
|
164
|
+
let(:api_client) { MockServer::ApiClient.new }
|
165
|
+
|
166
|
+
it 'works' do
|
167
|
+
expect(api_client.json_mime?(nil)).to eq false
|
168
|
+
expect(api_client.json_mime?('')).to eq false
|
169
|
+
|
170
|
+
expect(api_client.json_mime?('application/json')).to eq true
|
171
|
+
expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
|
172
|
+
expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
|
173
|
+
|
174
|
+
expect(api_client.json_mime?('application/xml')).to eq false
|
175
|
+
expect(api_client.json_mime?('text/plain')).to eq false
|
176
|
+
expect(api_client.json_mime?('application/jsonp')).to eq false
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe '#select_header_accept' do
|
181
|
+
let(:api_client) { MockServer::ApiClient.new }
|
182
|
+
|
183
|
+
it 'works' do
|
184
|
+
expect(api_client.select_header_accept(nil)).to be_nil
|
185
|
+
expect(api_client.select_header_accept([])).to be_nil
|
186
|
+
|
187
|
+
expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
|
188
|
+
expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
189
|
+
expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
190
|
+
|
191
|
+
expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
|
192
|
+
expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#select_header_content_type' do
|
197
|
+
let(:api_client) { MockServer::ApiClient.new }
|
198
|
+
|
199
|
+
it 'works' do
|
200
|
+
expect(api_client.select_header_content_type(nil)).to eq('application/json')
|
201
|
+
expect(api_client.select_header_content_type([])).to eq('application/json')
|
202
|
+
|
203
|
+
expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
|
204
|
+
expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
|
205
|
+
expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
|
206
|
+
expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
|
207
|
+
expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '#sanitize_filename' do
|
212
|
+
let(:api_client) { MockServer::ApiClient.new }
|
213
|
+
|
214
|
+
it 'works' do
|
215
|
+
expect(api_client.sanitize_filename('sun')).to eq('sun')
|
216
|
+
expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
|
217
|
+
expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
|
218
|
+
expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
|
219
|
+
expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
|
220
|
+
expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
|
221
|
+
expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
|
222
|
+
expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
|
223
|
+
expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|