Handle any method as mock request method
This commit is contained in:
parent
8ba339b8a0
commit
374947847d
4 changed files with 29 additions and 2 deletions
|
@ -166,7 +166,7 @@ Send POST request to localhost:<PORT>/serverControl
|
||||||
- response - groovy closure as string which must evaluate to string which will be response of mock when predicate is satisfied, optional, default { _ -> '' }
|
- response - groovy closure as string which must evaluate to string which will be response of mock when predicate is satisfied, optional, default { _ -> '' }
|
||||||
- soap - true or false, is request and response should be wrapped in soap Envelope and Body elements, default false
|
- soap - true or false, is request and response should be wrapped in soap Envelope and Body elements, default false
|
||||||
- statusCode - integer, status code of response when predicate is satisfied, default 200
|
- statusCode - integer, status code of response when predicate is satisfied, default 200
|
||||||
- method - POST|PUT|DELETE|GET|TRACE|OPTION|HEAD, expected http method of request, default POST
|
- method - POST|PUT|DELETE|GET|TRACE|OPTION|HEAD|ANY_METHOD, expected http method of request, default `POST`, `ANY_METHOD` matches all HTTP methods
|
||||||
- responseHeaders - groovyClosure as string which must evaluate to Map which will be added to response headers, default { _ -> \[:] }
|
- responseHeaders - groovyClosure as string which must evaluate to Map which will be added to response headers, default { _ -> \[:] }
|
||||||
- schema - path to xsd schema file on mockserver classpath; default empty, so no vallidation of request is performed; if validation fails then response has got status 400 and response is raw message from validator
|
- schema - path to xsd schema file on mockserver classpath; default empty, so no vallidation of request is performed; if validation fails then response has got status 400 and response is raw message from validator
|
||||||
- imports - list of imports for closures (each import is separate tag); `alias` is the name of `fullClassName` available in closure; `fullClassName` must be available on classpath of mock server
|
- imports - list of imports for closures (each import is separate tag); `alias` is the name of `fullClassName` available in closure; `fullClassName` must be available on classpath of mock server
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<xs:enumeration value="HEAD"/>
|
<xs:enumeration value="HEAD"/>
|
||||||
<xs:enumeration value="OPTIONS"/>
|
<xs:enumeration value="OPTIONS"/>
|
||||||
<xs:enumeration value="PATCH"/>
|
<xs:enumeration value="PATCH"/>
|
||||||
|
<xs:enumeration value="ANY_METHOD" />
|
||||||
</xs:restriction>
|
</xs:restriction>
|
||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
|
|
||||||
|
|
|
@ -1152,4 +1152,30 @@ class MockServerIntegrationTest extends Specification {
|
||||||
'test/other' | 'test/other'
|
'test/other' | 'test/other'
|
||||||
'/test/other' | 'test/other'
|
'/test/other' | 'test/other'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def 'should match any method'() {
|
||||||
|
given:
|
||||||
|
String name = "testRest-${UUID.randomUUID().toString()}"
|
||||||
|
remoteMockServer.addMock(new AddMock(
|
||||||
|
name: name,
|
||||||
|
path: 'any-method',
|
||||||
|
port: 9999,
|
||||||
|
statusCode: 201,
|
||||||
|
soap: false,
|
||||||
|
method: Method.ANY_METHOD
|
||||||
|
))
|
||||||
|
when:
|
||||||
|
CloseableHttpResponse response = client.execute(req)
|
||||||
|
then:
|
||||||
|
response.statusLine.statusCode == 201
|
||||||
|
Util.consumeResponse(response)
|
||||||
|
cleanup:
|
||||||
|
remoteMockServer.removeMock(name)
|
||||||
|
where:
|
||||||
|
req << [
|
||||||
|
new HttpGet('http://localhost:9999/any-method'),
|
||||||
|
new HttpPost('http://localhost:9999/any-method'),
|
||||||
|
new HttpPatch('http://localhost:9999/any-method')
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Mock implements Comparable<Mock> {
|
||||||
|
|
||||||
boolean match(Method method, MockRequest request) {
|
boolean match(Method method, MockRequest request) {
|
||||||
boolean usesCondition = hasLimitedUses() ? usesLeft > 0 : true
|
boolean usesCondition = hasLimitedUses() ? usesLeft > 0 : true
|
||||||
return usesCondition && this.method == method && predicate(request)
|
return usesCondition && (this.method == method || this.method == Method.ANY_METHOD) && predicate(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
MockResponse apply(MockRequest request) {
|
MockResponse apply(MockRequest request) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue