Add query parameters validation
This commit is contained in:
parent
c97ce11837
commit
e9eb6b55e1
6 changed files with 45 additions and 6 deletions
|
@ -17,6 +17,12 @@ class ContextExecutor {
|
|||
httpServerWraper.createContext(path, {
|
||||
HttpExchange ex ->
|
||||
String input = ex.requestBody.text
|
||||
Map<String, String> queryParams = ex.requestURI.query?.split('&')?.collectEntries {
|
||||
String[] keyValue = it.split('='); [(keyValue[0]): keyValue[1]]
|
||||
} ?: [:]
|
||||
Map<String, String> headers = ex.requestHeaders.collectEntries {
|
||||
[it.key.toLowerCase(), it.value.join(',')]
|
||||
}
|
||||
println "Mock received input"
|
||||
for (Mock mock : mocks) {
|
||||
try {
|
||||
|
@ -28,10 +34,10 @@ class ContextExecutor {
|
|||
continue
|
||||
}
|
||||
}
|
||||
Map<String,String> headers = ex.requestHeaders.collectEntries { [it.key.toLowerCase(), it.value.join(',')] }
|
||||
if (ex.requestMethod == mock.method &&
|
||||
mock.predicate(xml) &&
|
||||
mock.requestHeaders(headers)) {
|
||||
mock.requestHeaders(headers) &&
|
||||
mock.queryParams(queryParams)) {
|
||||
println "Mock ${mock.name} invoked"
|
||||
++mock.counter
|
||||
String response = mock.responseOk(xml)
|
||||
|
|
|
@ -69,6 +69,10 @@ class HttpMockServer {
|
|||
if(requestHeaders){
|
||||
mock.requestHeaders = Eval.me(requestHeaders) as Closure
|
||||
}
|
||||
String queryParams = request.queryParams
|
||||
if(queryParams){
|
||||
mock.queryParams = Eval.me(queryParams) as Closure
|
||||
}
|
||||
HttpServerWraper child = childServers.find { it.port == mockPort }
|
||||
if (!child) {
|
||||
child = new HttpServerWraper(mockPort)
|
||||
|
|
|
@ -14,8 +14,8 @@ class Mock {
|
|||
String method = 'POST'
|
||||
Closure requestHeaders = {hs -> true}
|
||||
Closure responseHeaders = {xml -> [:]}
|
||||
Closure queryParams = {qs -> true}
|
||||
int counter = 0
|
||||
//TODO add historical invocations
|
||||
|
||||
Mock(String name, String path, int port) {
|
||||
this.name = name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue