Add soap support
This commit is contained in:
parent
54bbfd7fdf
commit
5db690c434
3 changed files with 36 additions and 10 deletions
|
@ -19,21 +19,38 @@ class ContextExecutor {
|
||||||
ex.sendResponseHeaders(200, 0)
|
ex.sendResponseHeaders(200, 0)
|
||||||
String input = ex.requestBody.text
|
String input = ex.requestBody.text
|
||||||
println "Mock received input"
|
println "Mock received input"
|
||||||
GPathResult xml = new XmlSlurper().parseText(input)
|
GPathResult inputXml = new XmlSlurper().parseText(input)
|
||||||
for (Mock mock : mocks){
|
for (Mock mock : mocks){
|
||||||
if(mock.predicate(xml)){
|
GPathResult xml = inputXml
|
||||||
|
try {
|
||||||
|
if (mock.soap) {
|
||||||
|
if(xml.name() == 'Envelope' && xml.Body.size() > 0){
|
||||||
|
xml = getSoapBodyContent(xml)
|
||||||
|
}else{
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (xml != null && mock.predicate(xml)) {
|
||||||
println "Mock ${mock.name} invoked"
|
println "Mock ${mock.name} invoked"
|
||||||
++mock.counter
|
++mock.counter
|
||||||
ex.responseBody << mock.responseOk(xml)
|
String response = mock.responseOk(xml)
|
||||||
|
ex.responseBody << (mock.soap ? wrapSoap(response) : response)
|
||||||
ex.responseBody.close()
|
ex.responseBody.close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ex.responseBody << "<invalidInput/>"
|
ex.responseBody << "<invalidInput/>"
|
||||||
ex.responseBody.close()
|
ex.responseBody.close()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static GPathResult getSoapBodyContent(GPathResult xml) {
|
||||||
|
return xml.Body.'**'[1]
|
||||||
|
}
|
||||||
|
|
||||||
int removeMock(String name) {
|
int removeMock(String name) {
|
||||||
Mock mock = mocks.find {it.name == name}
|
Mock mock = mocks.find {it.name == name}
|
||||||
if(mock){
|
if(mock){
|
||||||
|
@ -41,4 +58,11 @@ class ContextExecutor {
|
||||||
}
|
}
|
||||||
return mock.counter
|
return mock.counter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String wrapSoap(String request) {
|
||||||
|
"""<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<soap-env:Envelope xmlns:soap-env='http://schemas.xmlsoap.org/soap/envelope/' xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
|
||||||
|
<soap-env:Body>${request}</soap-env:Body>
|
||||||
|
</soap-env:Envelope>"""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,8 @@ class HttpMockServer {
|
||||||
int mockPort = Integer.valueOf(request.port as String)
|
int mockPort = Integer.valueOf(request.port as String)
|
||||||
Closure predicate = Eval.me(request.predicate as String) as Closure
|
Closure predicate = Eval.me(request.predicate as String) as Closure
|
||||||
Closure okResponse = Eval.me(request.response as String) as Closure
|
Closure okResponse = Eval.me(request.response as String) as Closure
|
||||||
Mock mock = new Mock(name, predicate, okResponse)
|
boolean soap = Boolean.valueOf(request.soap as String)
|
||||||
|
Mock mock = new Mock(name, predicate, okResponse, soap)
|
||||||
HttpServerWraper child = childServers.find { it.port == mockPort }
|
HttpServerWraper child = childServers.find { it.port == mockPort }
|
||||||
if (!child) {
|
if (!child) {
|
||||||
child = new HttpServerWraper(mockPort)
|
child = new HttpServerWraper(mockPort)
|
||||||
|
|
|
@ -7,13 +7,14 @@ class Mock {
|
||||||
final String name
|
final String name
|
||||||
final Closure predicate
|
final Closure predicate
|
||||||
final Closure responseOk
|
final Closure responseOk
|
||||||
|
final boolean soap
|
||||||
//TODO add http method
|
//TODO add http method
|
||||||
//TODO add is soap method
|
|
||||||
int counter = 0
|
int counter = 0
|
||||||
|
|
||||||
Mock(String name, Closure predicate, Closure responseOk) {
|
Mock(String name, Closure predicate, Closure responseOk, boolean soap) {
|
||||||
this.name = name
|
this.name = name
|
||||||
this.predicate = predicate
|
this.predicate = predicate
|
||||||
this.responseOk = responseOk
|
this.responseOk = responseOk
|
||||||
|
this.soap = soap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue