Request now contains body

This commit is contained in:
Jakub Kubrynski
2015-02-21 15:29:40 +01:00
parent 845f121a0c
commit 672cad956c
3 changed files with 34 additions and 3 deletions

View File

@@ -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<String, Object> 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 }
}
}

View File

@@ -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<String, Object> 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

View File

@@ -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,