Refactor response generation and xmls

This commit is contained in:
Dominik Adam Przybysz 2014-12-13 21:49:24 +01:00
parent ba63d36fa0
commit 0bfa0d91b4
8 changed files with 50 additions and 36 deletions

View file

@ -13,6 +13,7 @@ import org.apache.http.util.EntityUtils
class Util {
static GPathResult extractXmlResponse(CloseableHttpResponse response) {
HttpEntity entity = response.entity
GPathResult xml = new XmlSlurper().parseText(EntityUtils.toString(entity))
EntityUtils.consumeQuietly(entity)
return xml

View file

@ -11,6 +11,7 @@ import pl.touk.mockserver.client.*
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
import pl.touk.mockserver.client.Util
class MockServerIntegrationTest extends Specification {

View file

@ -29,10 +29,10 @@ class ServerMockPT extends Specification {
int port = 9000 + (current % 7)
controlServerClient.addMock(new AddMockRequestData(
name: "testRest$current",
path: "/testEndpoint$endpointNumber",
path: "testEndpoint$endpointNumber",
port: port,
predicate: """{xml -> xml.name() == 'request$current'}""",
response: """{xml -> "<goodResponse$current/>"}"""
predicate: """{req -> req.xml.name() == 'request$current'}""",
response: """{req -> "<goodResponse$current/>"}"""
))
HttpPost restPost = new HttpPost("http://localhost:$port/testEndpoint$endpointNumber")
restPost.entity = new StringEntity("<request$current/>", ContentType.create("text/xml", "UTF-8"))