diff --git a/README.md b/README.md index 042fc5d..a8336d3 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Send POST request to localhost:/serverControl - 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 - 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 { _ -> \[:] } - 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 diff --git a/mockserver-api/src/main/xsd/pl/touk/mockserver/api/common.xsd b/mockserver-api/src/main/xsd/pl/touk/mockserver/api/common.xsd index 673be7d..4b084dd 100644 --- a/mockserver-api/src/main/xsd/pl/touk/mockserver/api/common.xsd +++ b/mockserver-api/src/main/xsd/pl/touk/mockserver/api/common.xsd @@ -11,6 +11,7 @@ + diff --git a/mockserver-tests/src/test/groovy/pl/touk/mockserver/tests/MockServerIntegrationTest.groovy b/mockserver-tests/src/test/groovy/pl/touk/mockserver/tests/MockServerIntegrationTest.groovy index d0c3593..1ab1dad 100644 --- a/mockserver-tests/src/test/groovy/pl/touk/mockserver/tests/MockServerIntegrationTest.groovy +++ b/mockserver-tests/src/test/groovy/pl/touk/mockserver/tests/MockServerIntegrationTest.groovy @@ -1152,4 +1152,30 @@ class MockServerIntegrationTest extends Specification { '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') + ] + } } diff --git a/mockserver/src/main/groovy/pl/touk/mockserver/server/Mock.groovy b/mockserver/src/main/groovy/pl/touk/mockserver/server/Mock.groovy index 434dd0f..3f0f4fe 100644 --- a/mockserver/src/main/groovy/pl/touk/mockserver/server/Mock.groovy +++ b/mockserver/src/main/groovy/pl/touk/mockserver/server/Mock.groovy @@ -60,7 +60,7 @@ class Mock implements Comparable { boolean match(Method method, MockRequest request) { 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) {