Add support for each http method

This commit is contained in:
Dominik Adam Przybysz 2014-12-10 22:07:26 +01:00
parent b3e3dfb3f3
commit 1be072f440
6 changed files with 192 additions and 24 deletions

View file

@ -18,10 +18,9 @@ class ContextExecutor {
HttpExchange ex ->
String input = ex.requestBody.text
println "Mock received input"
GPathResult inputXml = new XmlSlurper().parseText(input)
for (Mock mock : mocks){
GPathResult xml = inputXml
try {
GPathResult xml = input ? new XmlSlurper().parseText(input) : null
if (mock.soap) {
if(xml.name() == 'Envelope' && xml.Body.size() > 0){
xml = getSoapBodyContent(xml)
@ -29,7 +28,7 @@ class ContextExecutor {
continue
}
}
if (xml != null && mock.predicate(xml)) {
if (ex.requestMethod == mock.method && mock.predicate(xml)) {
ex.sendResponseHeaders(mock.statusCode, 0)
println "Mock ${mock.name} invoked"
++mock.counter

View file

@ -57,6 +57,10 @@ class HttpMockServer {
if(statusCode){
mock.statusCode = Integer.valueOf(statusCode)
}
String method = request.method
if(method){
mock.method = method
}
HttpServerWraper child = childServers.find { it.port == mockPort }
if (!child) {
child = new HttpServerWraper(mockPort)

View file

@ -11,7 +11,7 @@ class Mock {
Closure responseOk = { xml -> '' }
boolean soap = false
int statusCode = 200
//TODO add http method - default POST
String method = 'POST'
//TODO add request headers - default [:]
//TODO add response headers - default [:]
int counter = 0