testerhjnew 1.1.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.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +55 -0
  4. data/lib/tester.rb +56 -0
  5. data/lib/tester/api_helper.rb +261 -0
  6. data/lib/tester/configuration.rb +66 -0
  7. data/lib/tester/controllers/base_controller.rb +59 -0
  8. data/lib/tester/controllers/body_params_controller.rb +1270 -0
  9. data/lib/tester/controllers/echo_controller.rb +134 -0
  10. data/lib/tester/controllers/error_codes_controller.rb +179 -0
  11. data/lib/tester/controllers/form_params_controller.rb +1391 -0
  12. data/lib/tester/controllers/header_controller.rb +63 -0
  13. data/lib/tester/controllers/query_param_controller.rb +779 -0
  14. data/lib/tester/controllers/response_types_controller.rb +717 -0
  15. data/lib/tester/controllers/template_params_controller.rb +93 -0
  16. data/lib/tester/exceptions/api_exception.rb +18 -0
  17. data/lib/tester/exceptions/global_test_exception.rb +32 -0
  18. data/lib/tester/exceptions/local_test_exception.rb +30 -0
  19. data/lib/tester/exceptions/nested_model_exception.rb +37 -0
  20. data/lib/tester/http/faraday_client.rb +55 -0
  21. data/lib/tester/http/http_call_back.rb +22 -0
  22. data/lib/tester/http/http_client.rb +92 -0
  23. data/lib/tester/http/http_context.rb +18 -0
  24. data/lib/tester/http/http_method_enum.rb +11 -0
  25. data/lib/tester/http/http_request.rb +48 -0
  26. data/lib/tester/http/http_response.rb +21 -0
  27. data/lib/tester/models/additional_model_parameters.rb +70 -0
  28. data/lib/tester/models/base_model.rb +52 -0
  29. data/lib/tester/models/boss.rb +129 -0
  30. data/lib/tester/models/days.rb +30 -0
  31. data/lib/tester/models/delete_body.rb +52 -0
  32. data/lib/tester/models/echo_response.rb +88 -0
  33. data/lib/tester/models/employee.rb +155 -0
  34. data/lib/tester/models/job.rb +43 -0
  35. data/lib/tester/models/person.rb +113 -0
  36. data/lib/tester/models/query_parameter.rb +43 -0
  37. data/lib/tester/models/server_response.rb +61 -0
  38. data/lib/tester/models/suite_code.rb +21 -0
  39. data/lib/tester/models/test_nstring_encoding.rb +52 -0
  40. data/lib/tester/models/test_r_nstring_encoding.rb +52 -0
  41. data/lib/tester/models/test_rstring_encoding.rb +52 -0
  42. data/lib/tester/models/validate.rb +61 -0
  43. data/lib/tester/tester_client.rb +61 -0
  44. data/test/controllers/controller_test_base.rb +33 -0
  45. data/test/controllers/test_body_params_controller.rb +1210 -0
  46. data/test/controllers/test_echo_controller.rb +29 -0
  47. data/test/controllers/test_error_codes_controller.rb +47 -0
  48. data/test/controllers/test_form_params_controller.rb +1099 -0
  49. data/test/controllers/test_header_controller.rb +30 -0
  50. data/test/controllers/test_query_param_controller.rb +345 -0
  51. data/test/controllers/test_response_types_controller.rb +429 -0
  52. data/test/controllers/test_template_params_controller.rb +47 -0
  53. data/test/http_response_catcher.rb +16 -0
  54. data/test/test_helper.rb +91 -0
  55. metadata +178 -0
@@ -0,0 +1,93 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # TemplateParamsController
6
+ class TemplateParamsController < BaseController
7
+ @instance = TemplateParamsController.new
8
+
9
+ class << self
10
+ attr_accessor :instance
11
+ end
12
+
13
+ def instance
14
+ self.class.instance
15
+ end
16
+
17
+ # TODO: type endpoint description here
18
+ # @param [List of String] strings Required parameter: Example:
19
+ # @return EchoResponse response from the API call
20
+ def send_string_array(strings)
21
+ # Validate required parameters.
22
+ validate_parameters(
23
+ 'strings' => strings
24
+ )
25
+ # Prepare query url.
26
+ _query_builder = Configuration.get_base_uri
27
+ _query_builder << '/{strings}'
28
+ _query_builder = APIHelper.append_url_with_template_parameters(
29
+ _query_builder,
30
+ 'strings' => strings
31
+ )
32
+ _query_url = APIHelper.clean_url _query_builder
33
+
34
+ # Prepare headers.
35
+ _headers = {
36
+ 'accept' => 'application/json'
37
+ }
38
+
39
+ # Prepare and execute HttpRequest.
40
+ _request = @http_client.get(
41
+ _query_url,
42
+ headers: _headers
43
+ )
44
+ _context = execute_request(_request)
45
+
46
+ # Validate response against endpoint and global error codes.
47
+ return nil if _context.response.status_code == 404
48
+ validate_response(_context)
49
+
50
+ # Return appropriate response type.
51
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
52
+ EchoResponse.from_hash(decoded)
53
+ end
54
+
55
+ # TODO: type endpoint description here
56
+ # @param [List of Integer] integers Required parameter: Example:
57
+ # @return EchoResponse response from the API call
58
+ def send_integer_array(integers)
59
+ # Validate required parameters.
60
+ validate_parameters(
61
+ 'integers' => integers
62
+ )
63
+ # Prepare query url.
64
+ _query_builder = Configuration.get_base_uri
65
+ _query_builder << '/{integers}'
66
+ _query_builder = APIHelper.append_url_with_template_parameters(
67
+ _query_builder,
68
+ 'integers' => integers
69
+ )
70
+ _query_url = APIHelper.clean_url _query_builder
71
+
72
+ # Prepare headers.
73
+ _headers = {
74
+ 'accept' => 'application/json'
75
+ }
76
+
77
+ # Prepare and execute HttpRequest.
78
+ _request = @http_client.get(
79
+ _query_url,
80
+ headers: _headers
81
+ )
82
+ _context = execute_request(_request)
83
+
84
+ # Validate response against endpoint and global error codes.
85
+ return nil if _context.response.status_code == 404
86
+ validate_response(_context)
87
+
88
+ # Return appropriate response type.
89
+ decoded = APIHelper.json_deserialize(_context.response.raw_body)
90
+ EchoResponse.from_hash(decoded)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,18 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # Class for exceptions when there is a network error, status code error, etc.
6
+ class APIException < StandardError
7
+ attr_reader :context, :response_code
8
+
9
+ # The constructor.
10
+ # @param [String] The reason for raising an exception.
11
+ # @param [HttpContext] The HttpContext of the API call.
12
+ def initialize(reason, context)
13
+ super(reason)
14
+ @context = context
15
+ @response_code = context.response.status_code
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # To test specific global exceptions.
6
+ class GlobalTestException < APIException
7
+ # Represents the server's exception message
8
+ # @return [String]
9
+ attr_accessor :server_message
10
+
11
+ # Represents the server's error code
12
+ # @return [Integer]
13
+ attr_accessor :server_code
14
+
15
+ # The constructor.
16
+ # @param [String] The reason for raising an exception.
17
+ # @param [HttpContext] The HttpContext of the API call.
18
+ def initialize(reason, context)
19
+ super(reason, context)
20
+ hash = APIHelper.json_deserialize(@context.response.raw_body)
21
+ unbox(hash)
22
+ end
23
+
24
+ # Populates this object by extracting properties from a hash.
25
+ # @param [Hash] The deserialized response sent by the server in the
26
+ # response body.
27
+ def unbox(hash)
28
+ @server_message = hash['ServerMessage']
29
+ @server_code = hash['ServerCode']
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ require_relative 'global_test_exception'
5
+
6
+ module Tester
7
+ # To test specific local exceptions.
8
+ class LocalTestException < GlobalTestException
9
+ # Represents the specific endpoint info
10
+ # @return [String]
11
+ attr_accessor :secret_message_for_endpoint
12
+
13
+ # The constructor.
14
+ # @param [String] The reason for raising an exception.
15
+ # @param [HttpContext] The HttpContext of the API call.
16
+ def initialize(reason, context)
17
+ super(reason, context)
18
+ hash = APIHelper.json_deserialize(@context.response.raw_body)
19
+ unbox(hash)
20
+ end
21
+
22
+ # Populates this object by extracting properties from a hash.
23
+ # @param [Hash] The deserialized response sent by the server in the
24
+ # response body.
25
+ def unbox(hash)
26
+ super(hash)
27
+ @secret_message_for_endpoint = hash['SecretMessageForEndpoint']
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # NestedModelException class.
6
+ class NestedModelException < APIException
7
+ # TODO: Write general description for this method
8
+ # @return [String]
9
+ attr_accessor :server_message
10
+
11
+ # TODO: Write general description for this method
12
+ # @return [String]
13
+ attr_accessor :server_code
14
+
15
+ # TODO: Write general description for this method
16
+ # @return [Validate]
17
+ attr_accessor :model
18
+
19
+ # The constructor.
20
+ # @param [String] The reason for raising an exception.
21
+ # @param [HttpContext] The HttpContext of the API call.
22
+ def initialize(reason, context)
23
+ super(reason, context)
24
+ hash = APIHelper.json_deserialize(@context.response.raw_body)
25
+ unbox(hash)
26
+ end
27
+
28
+ # Populates this object by extracting properties from a hash.
29
+ # @param [Hash] The deserialized response sent by the server in the
30
+ # response body.
31
+ def unbox(hash)
32
+ @server_message = hash['ServerMessage']
33
+ @server_code = hash['ServerCode']
34
+ @model = Validate.from_hash(hash['model']) if hash['model']
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,55 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+ require 'faraday/http_cache'
4
+
5
+ module Tester
6
+ # An implementation of HttpClient.
7
+ class FaradayClient < HttpClient
8
+ # The constructor.
9
+ def initialize(timeout: nil, cache: false,
10
+ max_retries: nil, retry_interval: nil)
11
+ @connection = Faraday.new do |faraday|
12
+ faraday.use Faraday::HttpCache, serializer: Marshal if cache
13
+ faraday.request :multipart
14
+ faraday.request :url_encoded
15
+ faraday.ssl[:ca_file] = Certifi.where
16
+ faraday.adapter Faraday.default_adapter
17
+ faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
18
+ faraday.options[:open_timeout] = timeout if timeout
19
+ faraday.request :retry, max: max_retries, interval: if max_retries &&
20
+ retry_interval
21
+ retry_interval
22
+ end
23
+ end
24
+ end
25
+
26
+ # Method overridden from HttpClient.
27
+ def execute_as_string(http_request)
28
+ response = @connection.send(
29
+ http_request.http_method.downcase,
30
+ http_request.query_url
31
+ ) do |request|
32
+ request.headers = http_request.headers
33
+ request.body = http_request.parameters
34
+ end
35
+ convert_response(response)
36
+ end
37
+
38
+ # Method overridden from HttpClient.
39
+ def execute_as_binary(http_request)
40
+ response = @connection.send(
41
+ http_request.http_method.downcase,
42
+ http_request.query_url
43
+ ) do |request|
44
+ request.headers = http_request.headers
45
+ request.body = http_request.parameters
46
+ end
47
+ convert_response(response)
48
+ end
49
+
50
+ # Method overridden from HttpClient.
51
+ def convert_response(response)
52
+ HttpResponse.new(response.status, response.headers, response.body)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # HttpCallBack allows defining callables for pre and post API calls.
6
+ class HttpCallBack
7
+ # A controller will call this method before making an HTTP Request.
8
+ # @param [HttpRequest] The HttpRequest object which the HttpClient
9
+ # will execute.
10
+ def on_before_request(_http_request)
11
+ raise NotImplementedError, 'This method needs
12
+ to be implemented in a child class.'
13
+ end
14
+
15
+ # A controller will call this method after making an HTTP Request.
16
+ # @param [HttpContext] The HttpContext of the API call.
17
+ def on_after_response(_http_context)
18
+ raise NotImplementedError, 'This method needs
19
+ to be implemented in a child class.'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,92 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # An interface for the methods that an HTTP Client must implement.
6
+ #
7
+ # This class should not be instantiated but should be used as a base class
8
+ # for HTTP Client classes.
9
+ class HttpClient
10
+ # Execute an HttpRequest when the response is expected to be a string.
11
+ # @param [HttpRequest] The HttpRequest to be executed.
12
+ def execute_as_string(_http_request)
13
+ raise NotImplementedError, 'This method needs
14
+ to be implemented in a child class.'
15
+ end
16
+
17
+ # Execute an HttpRequest when the response is expected to be binary.
18
+ # @param [HttpRequest] The HttpRequest to be executed.
19
+ def execute_as_binary(_http_request)
20
+ raise NotImplementedError, 'This method needs
21
+ to be implemented in a child class.'
22
+ end
23
+
24
+ # Converts the HTTP Response from the client to an HttpResponse object.
25
+ # @param [Dynamic] The response object received from the client.
26
+ def convert_response(_response)
27
+ raise NotImplementedError, 'This method needs
28
+ to be implemented in a child class.'
29
+ end
30
+
31
+ # Get a GET HttpRequest object.
32
+ # @param [String] The URL to send the request to.
33
+ # @param [Hash, Optional] The headers for the HTTP Request.
34
+ def get(query_url,
35
+ headers: {})
36
+ HttpRequest.new(HttpMethodEnum::GET,
37
+ query_url,
38
+ headers: headers)
39
+ end
40
+
41
+ # Get a POST HttpRequest object.
42
+ # @param [String] The URL to send the request to.
43
+ # @param [Hash, Optional] The headers for the HTTP Request.
44
+ # @param [Hash, Optional] The parameters for the HTTP Request.
45
+ def post(query_url,
46
+ headers: {},
47
+ parameters: {})
48
+ HttpRequest.new(HttpMethodEnum::POST,
49
+ query_url,
50
+ headers: headers,
51
+ parameters: parameters)
52
+ end
53
+
54
+ # Get a PUT HttpRequest object.
55
+ # @param [String] The URL to send the request to.
56
+ # @param [Hash, Optional] The headers for the HTTP Request.
57
+ # @param [Hash, Optional] The parameters for the HTTP Request.
58
+ def put(query_url,
59
+ headers: {},
60
+ parameters: {})
61
+ HttpRequest.new(HttpMethodEnum::PUT,
62
+ query_url,
63
+ headers: headers,
64
+ parameters: parameters)
65
+ end
66
+
67
+ # Get a PATCH HttpRequest object.
68
+ # @param [String] The URL to send the request to.
69
+ # @param [Hash, Optional] The headers for the HTTP Request.
70
+ # @param [Hash, Optional] The parameters for the HTTP Request.
71
+ def patch(query_url,
72
+ headers: {},
73
+ parameters: {})
74
+ HttpRequest.new(HttpMethodEnum::PATCH,
75
+ query_url,
76
+ headers: headers,
77
+ parameters: parameters)
78
+ end
79
+
80
+ # Get a DELETE HttpRequest object.
81
+ # @param [String] The URL to send the request to.
82
+ # @param [Hash, Optional] The headers for the HTTP Request.
83
+ def delete(query_url,
84
+ headers: {},
85
+ parameters: {})
86
+ HttpRequest.new(HttpMethodEnum::DELETE,
87
+ query_url,
88
+ headers: headers,
89
+ parameters: parameters)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,18 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # Represents an Http call in context.
6
+ class HttpContext
7
+ attr_accessor :request, :response
8
+
9
+ # The constructor.
10
+ # @param [HttpRequest] An HttpRequest object representing the HTTP request.
11
+ # @param [HttpResponse] An HttpResponse object representing the HTTP
12
+ # response.
13
+ def initialize(request, response)
14
+ @request = request
15
+ @response = response
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # HTTP Methods Enumeration.
6
+ class HttpMethodEnum
7
+ HTTPMETHODENUM = [GET = 'GET'.freeze, POST = 'POST'.freeze,
8
+ PUT = 'PUT'.freeze, PATCH = 'PATCH'.freeze,
9
+ DELETE = 'DELETE'.freeze].freeze
10
+ end
11
+ end
@@ -0,0 +1,48 @@
1
+ # This file was automatically generated for Stamplay by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
3
+
4
+ module Tester
5
+ # Represents a single Http Request.
6
+ class HttpRequest
7
+ attr_accessor :http_method, :query_url, :headers,
8
+ :parameters, :username, :password
9
+
10
+ # The constructor.
11
+ # @param [HttpMethodEnum] The HTTP method.
12
+ # @param [String] The URL to send the request to.
13
+ # @param [Hash, Optional] The headers for the HTTP Request.
14
+ # @param [Hash, Optional] The parameters for the HTTP Request.
15
+ def initialize(http_method,
16
+ query_url,
17
+ headers: {},
18
+ parameters: {})
19
+ @http_method = http_method
20
+ @query_url = query_url
21
+ @headers = headers
22
+ @parameters = parameters
23
+ end
24
+
25
+ # Add a header to the HttpRequest.
26
+ # @param [String] The name of the header.
27
+ # @param [String] The value of the header.
28
+ def add_header(name, value)
29
+ @headers[name] = value
30
+ end
31
+
32
+ # Add a parameter to the HttpRequest.
33
+ # @param [String] The name of the parameter.
34
+ # @param [String] The value of the parameter.
35
+ def add_parameter(name, value)
36
+ @parameters[name] = value
37
+ end
38
+
39
+ # Add a query parameter to the HttpRequest.
40
+ # @param [String] The name of the query parameter.
41
+ # @param [String] The value of the query parameter.
42
+ def add_query_parameter(name, value)
43
+ @query_url = APIHelper.append_url_with_query_parameters(@query_url,
44
+ name => value)
45
+ @query_url = APIHelper.clean_url(@query_url)
46
+ end
47
+ end
48
+ end