mockserver-client 1.0.8.pre → 6.0.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 (46) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +2 -1
  3. data/README.md +79 -227
  4. data/lib/mockserver/client.rb +518 -0
  5. data/lib/mockserver/errors.rb +18 -0
  6. data/lib/mockserver/forward_chain_expectation.rb +117 -0
  7. data/lib/mockserver/models.rb +1507 -0
  8. data/lib/mockserver/version.rb +3 -3
  9. data/lib/mockserver/websocket_client.rb +353 -0
  10. data/lib/mockserver-client.rb +7 -16
  11. data/mockserver-client.gemspec +26 -27
  12. metadata +54 -206
  13. data/.gitignore +0 -21
  14. data/.rubocop.yml +0 -7
  15. data/Rakefile +0 -10
  16. data/bin/mockserver +0 -9
  17. data/lib/cli.rb +0 -146
  18. data/lib/mockserver/abstract_client.rb +0 -111
  19. data/lib/mockserver/mock_server_client.rb +0 -46
  20. data/lib/mockserver/model/array_of.rb +0 -85
  21. data/lib/mockserver/model/body.rb +0 -56
  22. data/lib/mockserver/model/cookie.rb +0 -36
  23. data/lib/mockserver/model/delay.rb +0 -34
  24. data/lib/mockserver/model/enum.rb +0 -47
  25. data/lib/mockserver/model/expectation.rb +0 -139
  26. data/lib/mockserver/model/forward.rb +0 -41
  27. data/lib/mockserver/model/header.rb +0 -43
  28. data/lib/mockserver/model/parameter.rb +0 -43
  29. data/lib/mockserver/model/request.rb +0 -81
  30. data/lib/mockserver/model/response.rb +0 -45
  31. data/lib/mockserver/model/times.rb +0 -61
  32. data/lib/mockserver/proxy_client.rb +0 -9
  33. data/lib/mockserver/utility_methods.rb +0 -59
  34. data/pom.xml +0 -118
  35. data/spec/fixtures/forward_mockserver.json +0 -7
  36. data/spec/fixtures/incorrect_login_response.json +0 -20
  37. data/spec/fixtures/post_login_request.json +0 -22
  38. data/spec/fixtures/register_expectation.json +0 -50
  39. data/spec/fixtures/retrieved_request.json +0 -22
  40. data/spec/fixtures/search_request.json +0 -6
  41. data/spec/fixtures/times_once.json +0 -6
  42. data/spec/integration/mock_client_integration_spec.rb +0 -82
  43. data/spec/mockserver/builder_spec.rb +0 -90
  44. data/spec/mockserver/mock_client_spec.rb +0 -80
  45. data/spec/mockserver/proxy_client_spec.rb +0 -38
  46. data/spec/spec_helper.rb +0 -61
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5949e6484134d15b965631dad80fde5bce36b48b
4
- data.tar.gz: 11dbadd346eae086b0b93e981d9f4b55e6900bed
2
+ SHA256:
3
+ metadata.gz: 52c92809897fcdfe317afdab740419e5bef114b46482df4a9756821916bd4a73
4
+ data.tar.gz: 8b8ee1a6a5c341edecbe70a90ccb1dda4c481162eca2f30e83ee121beaa656d5
5
5
  SHA512:
6
- metadata.gz: 7404475b6281eef548a4c27baf6397c47a3bfb0d7de8a2154ac3d0c92e4b85a2429a0c8aafca47918dc0f2a158154cefd7dfc61e11d94182a9cdb69b25e382d6
7
- data.tar.gz: 16776ab334b6690eec900c3cf694902e3c2119617d18339ba2af621296b3af1f0f0eb7b631486277c538e3802f0662e4853578a9c606c6ef4ca747321c7e81ac
6
+ metadata.gz: 476994411a429882a93e0fe6852527b14ac9ce60ffc2ac328f0536eef2adee69f7c2ce8061bc8dfda7cc32869fe0e227ed3f5e979a3a1e1513c1ae3540be2f27
7
+ data.tar.gz: 94828363b6159101e0288c15b604e7e9acf19716f67efb5edf56f591a79946aaf987ed2c32f079f421d3ad74045d61fa0aac62b93820d162df3299b284108cd7
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- # Gem's dependencies in mockserver-client.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -1,260 +1,112 @@
1
- # Mockserver Client
1
+ # MockServer Ruby Client
2
2
 
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.
3
+ Hand-written Ruby client for [MockServer](https://www.mock-server.com) with full REST API, fluent builder DSL, and WebSocket callback support.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add to your Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'mockserver-client'
10
+ gem 'mockserver-client', '~> 5.16'
11
11
  ```
12
12
 
13
- And then execute:
14
-
15
- ```bash
16
- bundle
17
- ```
18
-
19
- Or install it yourself as:
13
+ Or install directly:
20
14
 
21
15
  ```bash
22
16
  gem install mockserver-client
23
17
  ```
24
18
 
25
- ## Usage
26
-
27
- The usage notes here compare the Java syntax with the Ruby DSL for the various actions the MockServer client/proxy client supports. The Ruby code here assumes you have included `MockServer` and `MockServer::Model::DSL` modules. So these lines should typically be at the top of your code:
19
+ ## Quick Start
28
20
 
29
21
  ```ruby
30
- include MockServer
31
- include MockServer::Model::DSL
32
- ```
33
-
34
- ### Create Expectations
35
-
36
- ##### Java
37
-
38
- ```java
39
- new MockServerClient("localhost", 9999)
40
- .when(
41
- request()
42
- .withMethod("POST")
43
- .withPath("/login")
44
- .withQueryStringParameters(
45
- new Parameter("returnUrl", "/account")
46
- )
47
- .withCookies(
48
- new Cookie("sessionId", "2By8LOhBmaW5nZXJwcmludCIlMDAzMW")
49
- )
50
- .withBody("{username: 'foo', password: 'bar'}"),
51
- Times.exactly(1)
52
- )
53
- .respond(
54
- response()
55
- .withStatusCode(401)
56
- .withHeaders(
57
- new Header("Content-Type", "application/json; charset=utf-8"),
58
- new Header("Cache-Control", "public, max-age=86400")
59
- )
60
- .withBody("{ message: 'incorrect username and password combination' }")
61
- .withDelay(new Delay(TimeUnit.SECONDS, 1))
62
- );
22
+ require 'mockserver-client'
23
+
24
+ # Create a client
25
+ client = MockServer::Client.new('localhost', 1080)
26
+
27
+ # Set up an expectation using the fluent API
28
+ client.when(
29
+ MockServer::HttpRequest.request(path: '/hello')
30
+ .with_method('GET')
31
+ ).respond(
32
+ MockServer::HttpResponse.response(body: 'world', status_code: 200)
33
+ )
34
+
35
+ # Verify a request was received
36
+ client.verify(
37
+ MockServer::HttpRequest.request(path: '/hello'),
38
+ times: MockServer::VerificationTimes.at_least(1)
39
+ )
40
+
41
+ # Clean up
42
+ client.reset
43
+ client.close
63
44
  ```
64
45
 
65
- ##### Ruby
46
+ ## Block Form
66
47
 
67
48
  ```ruby
68
- client = MockServerClient.new('localhost', 9999)
69
- expectation = expectation do |expectation|
70
- expectation.request do |request|
71
- request.method = 'POST'
72
- request.path = '/login'
73
- request.query_string_parameters << parameter('returnUrl', '/account')
74
- request.cookies = [cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')]
75
- request.body = exact("{username: 'foo', password: 'bar'}")
76
- end
77
-
78
- expectation.response do |response|
79
- response.status_code = 401
80
- response.headers << header('Content-Type', 'application/json; charset=utf-8')
81
- response.headers << header('Cache-Control', 'public, max-age=86400')
82
- response.body = body("{ message: 'incorrect username and password combination' }")
83
- response.delay = delay_by(:SECONDS, 1)
84
- end
49
+ MockServer::Client.new('localhost', 1080) do |client|
50
+ client.when(
51
+ MockServer::HttpRequest.request(path: '/api/test')
52
+ ).respond(
53
+ MockServer::HttpResponse.response(body: '{"status":"ok"}', status_code: 200)
54
+ )
85
55
  end
86
- client.register(expectation)
87
- ```
88
-
89
- ### Clear & Reset Server
90
-
91
- ##### Java
92
-
93
- ```java
94
- mockServerClient.clear(
95
- request()
96
- .withMethod("POST")
97
- .withPath("/login")
98
- );
99
- mockServerClient.reset();
56
+ # Client is automatically closed when the block exits
100
57
  ```
101
58
 
102
- ##### Ruby
103
-
104
- ```ruby
105
- client.clear(request('POST', '/login'))
106
- client.reset
107
- ```
108
- ### Verifying Behavior
109
-
110
- ##### Java
111
-
112
- ```java
113
- new ProxyClient("localhost", 9090).verify(
114
- request()
115
- .withMethod("POST")
116
- .withPath("/login")
117
- .withBody(exact("{username: 'foo', password: 'bar'}"))
118
- .withCookies(
119
- new Cookie("sessionId", ".*")
120
- ),
121
- Times.exactly(1)
122
- );
123
- ```
124
-
125
- ##### Ruby
59
+ ## WebSocket Callbacks
126
60
 
127
61
  ```ruby
128
- # Not providing times here because the default is exactly(1) i.e. the second argument to verify method
129
- ProxyClient.new('localhost', 9090).verify(request(:POST, '/login') do |request|
130
- request.body = exact("{username: 'foo', password: 'bar'}")
131
- request.cookies = [cookie("sessionId", ".*")]
132
- end)
62
+ client = MockServer::Client.new('localhost', 1080)
63
+
64
+ # Response callback - dynamically generate responses
65
+ client.mock_with_callback(
66
+ MockServer::HttpRequest.request(path: '/dynamic'),
67
+ ->(request) {
68
+ MockServer::HttpResponse.new(
69
+ status_code: 200,
70
+ body: "Echo: #{request.path}"
71
+ )
72
+ }
73
+ )
74
+
75
+ # Forward callback - modify requests before forwarding
76
+ client.mock_with_forward_callback(
77
+ MockServer::HttpRequest.request(path: '/proxy'),
78
+ ->(request) {
79
+ request.with_header('X-Proxied', 'true')
80
+ }
81
+ )
82
+
83
+ client.close
133
84
  ```
134
85
 
86
+ ## Models
135
87
 
136
- ### Analyzing Behavior
137
-
138
- ##### Java
139
-
140
- ```java
141
- new ProxyClient("localhost", 9090).dumpToLogAsJava(
142
- request()
143
- .withMethod("POST")
144
- .withPath("/login")
145
- );
146
- ```
147
-
148
- ##### Ruby
149
-
150
- ```ruby
151
- # Second argument is true to set output to Java; false to set output to default JSON (default)
152
- ProxyClient.new('localhost', 9090).dump_log(request(:POST, '/login'), true)
153
- ```
154
-
155
- ## Complete Ruby DSL
156
- The DSL is provided via the `MockServer::Model::DSL` module. Include this module in your code to make the DSL available.
88
+ All 25 domain model classes are available under the `MockServer` module:
157
89
 
158
- Request
159
- * **request**: Used to build a request object. If a block is passed, will configure request first and then return the configured request. Example: `request(:POST, '/login') {|r| r.headers << header("Content-Type", "application/json")}`.
160
- * **http_request**: Alias for `request`.
90
+ - `Delay`, `Times`, `TimeToLive`
91
+ - `KeyToMultiValue`, `Body`, `SocketAddress`
92
+ - `HttpRequest`, `HttpResponse`, `HttpForward`, `HttpTemplate`
93
+ - `HttpClassCallback`, `HttpObjectCallback`, `HttpError`
94
+ - `HttpOverrideForwardedRequest`, `HttpRequestAndHttpResponse`
95
+ - `ConnectionOptions`
96
+ - `Expectation`, `ExpectationId`
97
+ - `OpenAPIDefinition`, `OpenAPIExpectation`
98
+ - `Verification`, `VerificationSequence`, `VerificationTimes`
99
+ - `Ports`
100
+ - `RequestDefinition` (alias for `HttpRequest`)
161
101
 
162
- Body
163
- * **body**: Create a string body object (use in a response). Example: `body("unaccepted")`.
164
- * **exact**: Create a body of type `STRING`. Example: `exact('{"reason": "unauthorized"}')`.
165
- * **regex**: Create a body of type `REGEX`. Example: `regex('username[a-z]{4}')`.
166
- * **xpath**: Used to create a body of type `XPATH`. Example: `xpath("/element[key = 'some_key' and value = 'some_value']")`.
167
- * **parameterized**; Create a body to type `PARAMETERS`. Example `parameterized(parameter('someValue', 1, 2), parameter('otherValue', 4, 5))`.
168
-
169
- Parameters
170
- * **parameter**: Create a generic parameter. Example: `parameter('key', 'value1' , 'value2')`.
171
- * **cookie**: Create a cookie (same as `parameter` above but exists as syntactic sugar). Example: `cookie('sessionId', 'sessionid1ldj')`.
172
- * **header**: Create a header (same as `parameter` above but exists as syntactic sugar). Example: `header('Content-Type', 'application/json')`.
173
-
174
- Forward
175
- * **forward**: Create a forwarding response. If a block is passed, will configure forward response first and then return the configured object. Example: `forward {|f| f.scheme = 'HTTPS' }`.
176
- * **http_forward**: Alias for `forward`.
177
-
178
- Response
179
- * **response**: Create a response object. If a block is passed, will configure response first and then return the configured response. Example: `response {|r| r.status_code = 201 }`.
180
- * **http_response**: Alias for `response`.
181
-
182
- Delay
183
- * **delay_by**. Create a delay object in a response. Example : `delay_by(:MICROSECONDS, 20)`.
184
-
185
- Times (used in Expectation)
186
- * **times**: Create an 'times' object. If a block is passed, will configure the object first before returning it. Example: `times {|t| t.unlimited = false }`.
187
- * **unlimited**: Create an object with unlimited repeats. Example: `unlimited()`. (No parameters).
188
- * **once**. Create an object that repeats only once. Example: `once()`. (No parameters).
189
- * **exactly**. Create an object that repeats exactly the number of times specified. Example: `exactly(2)`.
190
- * **at_least**: Create an object that repeats at least the given number of times. (Use in verify). Example: `at_least(2)`.
191
-
192
- Expectation (use in register)
193
- * **expectation**: Create an expectation object. If a block is passed, will configure the object first before returning it. Example: `expectation {|e| e.request {|r| r.path = "index.html} }`.
194
- Getter methods for `request`, `response` and `forward` methods will optionally accept a block. If block is passed object is configured before it is returned. The attribute `times` has conventional getter and setter methods.
195
-
196
- ## CLI
197
-
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:
199
-
200
- ```bash
201
- mockserver --help
202
-
203
- Commands:
204
- mockserver clear # Clears all stored mock request/responses from server.
205
- mockserver dump_log # Dumps the matching request to the mock server logs.
206
- mockserver help [COMMAND] # Describe available commands or one specific command
207
- mockserver register # Register an expectation with the mock server.
208
- mockserver reset # Resets the server clearing all data.
209
- mockserver retrieve # Retrieve the list of requests that have been made to the mock/proxy server.
210
- mockserver verify # Verify that a request has been made the specified number of times to the server.
211
-
212
- Options:
213
- -h, --host=HOST # The host for the MockServer client.
214
- # Default: localhost
215
- -p, --port=N # The port for the MockServer client.
216
- # Default: 8080
217
- -d, [--data=DATA] # A JSON or YAML file containing the request payload.
218
- ```
219
-
220
- To get help for an individual command, e.g. `dump_log`, you would do:
221
-
222
- ```bash
223
- mockserver --help dump_log
224
-
225
- Usage:
226
- mockserver dump_log
227
-
228
- Options:
229
- -j, [--java], [--no-java] # A switch to turn Java format for logs on/off.
230
- -h, --host=HOST # The host for the MockServer client.
231
- # Default: localhost
232
- -p, --port=N # The port for the MockServer client.
233
- # Default: 8080
234
- -d, [--data=DATA] # A JSON or YAML file containing the request payload.
235
-
236
- Dumps the matching request to the mock server logs.
237
- ```
238
-
239
- Here is an example on how you would run the command:
240
-
241
- ```bash
242
- mockserver dump_log -j true
243
-
244
- Running with parameters:
245
- host: localhost
246
- port: 8080
247
- java: true
248
-
249
- [2014-06-21 09:23:32] DEBUG [MockServerClient] Sending dump log request to mockserver
250
- [2014-06-21 09:23:32] DEBUG [MockServerClient] URL: /dumpToLog?type=java. Payload: {}
251
- [2014-06-21 09:23:32] DEBUG [MockServerClient] Got dump to log response: 202
252
- ```
102
+ ## License
253
103
 
254
- # Issues
104
+ Apache-2.0
255
105
 
256
- If you have any problems, please [check the project issues](https://github.com/jamesdbloom/mockserver/issues?state=open).
106
+ ## AI Assistant Integration
257
107
 
258
- # Contributions
108
+ MockServer includes a built-in [MCP](https://modelcontextprotocol.io) (Model Context Protocol) server that enables AI coding assistants to create expectations, verify requests, and debug HTTP traffic programmatically.
259
109
 
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.
110
+ - **MCP Endpoint:** `http://localhost:1080/mockserver/mcp`
111
+ - **AI Documentation:** [llms.txt](https://www.mock-server.com/llms.txt)
112
+ - **Setup Guide:** [AI Integration](https://www.mock-server.com/mock_server/ai_mcp_setup.html)