Add support for response headers

This commit is contained in:
Dominik Adam Przybysz 2014-12-11 22:52:46 +01:00
parent 1be072f440
commit 3b6e4c8faf
6 changed files with 34 additions and 4 deletions

View file

@ -11,6 +11,7 @@ class AddMockRequestData {
Boolean soap
Integer statusCode
Method method
String responseHeaders
void setPredicate(String predicate) {
this.predicate = StringEscapeUtils.escapeXml11(predicate)
@ -20,6 +21,10 @@ class AddMockRequestData {
this.response = StringEscapeUtils.escapeXml11(response)
}
void setResponseHeaders(String responseHeaders) {
this.responseHeaders = StringEscapeUtils.escapeXml11(responseHeaders)
}
enum Method {
POST,
GET,

View file

@ -60,6 +60,7 @@ class ControlServerClient {
${data.soap != null ? "<soap>${data.soap}</soap>" : ''}
${data.statusCode ? "<statusCode>${data.statusCode}</statusCode>" : ''}
${data.method ? "<method>${data.method}</method>" : ''}
${data.responseHeaders ? "<responseHeaders>${data.responseHeaders}</responseHeaders>" : ''}
</addMock>
""", ContentType.create("text/xml", "UTF-8"))
}

View file

@ -336,7 +336,6 @@ class MockServerIntegrationTest extends Specification {
then:
response.statusLine.statusCode == 200
EntityUtils.consumeQuietly(response.entity)
//TODO check headers
}
def "should dispatch rest mock with options method"() {
@ -434,8 +433,28 @@ class MockServerIntegrationTest extends Specification {
secondXmlResponse.name() == 'goodResponseRest1'
}
def "should add mock that return headers"() {
given:
controlServerClient.addMock(new AddMockRequestData(
name: 'testRest',
path: '/testEndpoint',
port: 9999,
predicate: '''{xml -> xml.name() == 'request'}''',
response: '''{xml -> "<goodResponse/>"}''',
responseHeaders: '''{ xml -> [input:"${xml.name()}"]}'''
))
HttpPost restPost = new HttpPost('http://localhost:9999/testEndpoint')
restPost.entity = new StringEntity('<request/>', ContentType.create("text/xml", "UTF-8"))
when:
CloseableHttpResponse response = client.execute(restPost)
then:
response.allHeaders.findAll { it.name == 'Input' && it.value == 'request' }
GPathResult restPostResponse = Util.extractXmlResponse(response)
restPostResponse.name() == 'goodResponse'
}
//TODO def "should dispatch rest mock with post method and request headers"(){}
//TODO def "should dispatch rest mock with post method and response headers"(){}
//TODO def "should dispatch rest mock with post method, response headers and request headers"(){}
//TODO def "should get mock report"(){}
//TODO def "should get list mocks"(){}