diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/WiremockRequestStubStrategy.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/WiremockRequestStubStrategy.groovy index 0bee93bfad..e8396e15c7 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/WiremockRequestStubStrategy.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/WiremockRequestStubStrategy.groovy @@ -31,7 +31,9 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy { url : request?.url?.clientValue, urlPattern: request?.urlPattern?.clientValue, urlPath : request?.urlPath?.clientValue, - headers : buildClientHeadersSection(request.headers)].findAll { it.value } + headers : buildClientHeadersSection(request.headers), + body : request?.body?.forClientSide() + ].findAll { it.value } } private Map buildRequestContent(ServerRequest request) { @@ -39,6 +41,8 @@ class WiremockRequestStubStrategy extends BaseWiremockStubStrategy { url : request?.url?.serverValue, urlPattern: request?.urlPattern?.serverValue, urlPath : request?.urlPath?.serverValue, - headers : buildServerHeadersSection(request.headers)].findAll { it.value } + headers : buildServerHeadersSection(request.headers), + body : request?.body?.forServerSide() + ].findAll { it.value } } } diff --git a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Request.groovy b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Request.groovy index a6ff0b9af0..bb8ae5b9bf 100644 --- a/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Request.groovy +++ b/accurest-core/src/main/groovy/io/coderate/accurest/dsl/internal/Request.groovy @@ -15,6 +15,7 @@ class Request extends Common { DslProperty urlPattern DslProperty urlPath Headers headers + Body body Request() { } @@ -25,6 +26,7 @@ class Request extends Common { this.urlPattern = request.urlPattern this.urlPath = request.urlPath this.headers = request.headers + this.body = request.body } void method(String method) { @@ -64,6 +66,22 @@ class Request extends Common { void urlPath(DslProperty urlPath) { this.urlPath = toDslProperty(urlPath) } + + void body(Map body) { + this.body = new Body(convertObjectsToDslProperties(body)) + } + + void body(List body) { + this.body = new Body(convertObjectsToDslProperties(body)) + } + + void body(Object bodyAsValue) { + this.body = new Body(bodyAsValue) + } + + Body getBody() { + return body + } } @CompileStatic diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy index 6022b95d4d..47e6a7cfd1 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WiremockGroovyDslSpec.groovy @@ -114,6 +114,12 @@ class WiremockGroovyDslSpec extends Specification { request { method('GET') urlPattern $(client('/[0-9]{2}'), server('/12')) + body("""\ + { + "name": "Jan" + } + """ + ) } response { status 200 @@ -135,7 +141,10 @@ class WiremockGroovyDslSpec extends Specification { { "request": { "method": "GET", - "urlPattern": "/[0-9]{2}" + "urlPattern": "/[0-9]{2}", + "body": { + "name": "Jan" + } }, "response": { "status": 200,