Add mock validation
This commit is contained in:
parent
fda5b6ca5c
commit
88bb4f3067
6 changed files with 78 additions and 51 deletions
|
@ -13,7 +13,7 @@ class ContextExecutor {
|
|||
|
||||
ContextExecutor(HttpServerWraper httpServerWraper, Mock initialMock) {
|
||||
this.httpServerWraper = httpServerWraper
|
||||
this.path = initialMock.path
|
||||
this.path = '/' + initialMock.path
|
||||
this.mocks = new CopyOnWriteArrayList<>([initialMock])
|
||||
httpServerWraper.createContext(path, {
|
||||
HttpExchange ex ->
|
||||
|
@ -36,6 +36,14 @@ class ContextExecutor {
|
|||
})
|
||||
}
|
||||
|
||||
String getPath() {
|
||||
return path.substring(1)
|
||||
}
|
||||
|
||||
String getContextPath() {
|
||||
return path
|
||||
}
|
||||
|
||||
private static void fillExchange(HttpExchange httpExchange, MockResponse response) {
|
||||
response.headers.each {
|
||||
httpExchange.responseHeaders.add(it.key, it.value)
|
||||
|
@ -60,4 +68,7 @@ class ContextExecutor {
|
|||
void addMock(Mock mock) {
|
||||
mocks << mock
|
||||
}
|
||||
|
||||
void stop(){
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class HttpServerWraper {
|
|||
}
|
||||
|
||||
void stop() {
|
||||
executors.each { httpServer.removeContext(it.path) }
|
||||
executors.each { httpServer.removeContext(it.contextPath) }
|
||||
httpServer.stop(0)
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ class Mock {
|
|||
int counter = 0
|
||||
|
||||
Mock(String name, String path, int port) {
|
||||
if (!(name)) {
|
||||
throw new RuntimeException("Mock name must be given")
|
||||
}
|
||||
this.name = name
|
||||
this.path = path
|
||||
this.port = port
|
||||
|
@ -43,37 +46,37 @@ class Mock {
|
|||
</soap-env:Envelope>"""
|
||||
}
|
||||
|
||||
void setPredicate(String predicate){
|
||||
void setPredicate(String predicate) {
|
||||
if (predicate) {
|
||||
this.predicate = Eval.me(predicate) as Closure
|
||||
}
|
||||
}
|
||||
|
||||
void setResponse(String response){
|
||||
void setResponse(String response) {
|
||||
if (response) {
|
||||
this.response = Eval.me(response) as Closure
|
||||
}
|
||||
}
|
||||
|
||||
void setSoap(String soap){
|
||||
void setSoap(String soap) {
|
||||
if (soap) {
|
||||
this.soap = Boolean.valueOf(soap)
|
||||
}
|
||||
}
|
||||
|
||||
void setStatusCode(String statusCode){
|
||||
void setStatusCode(String statusCode) {
|
||||
if (statusCode) {
|
||||
this.statusCode = Integer.valueOf(statusCode)
|
||||
}
|
||||
}
|
||||
|
||||
void setMethod(String method){
|
||||
if(method){
|
||||
void setMethod(String method) {
|
||||
if (method) {
|
||||
this.method = method
|
||||
}
|
||||
}
|
||||
|
||||
void setResponseHeaders(String responseHeaders){
|
||||
void setResponseHeaders(String responseHeaders) {
|
||||
if (responseHeaders) {
|
||||
this.responseHeaders = Eval.me(responseHeaders) as Closure
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue